change: warning when GenerateEncryptionOpCodes exceeds uint.MaxValue

before-split
walon 2025-05-18 17:09:56 +08:00
parent 274f827493
commit 45a07bc2ae
1 changed files with 9 additions and 4 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Obfuz.Utils
{
@ -29,13 +30,17 @@ namespace Obfuz.Utils
long ops = 0;
for (int i = 0; i < encryptionLevel; i++)
{
ops *= vmOpCodeCount;
long newOps = ops * vmOpCodeCount;
// don't use 0
int op = random.NextInt(1, vmOpCodeCount);
ops |= (uint)op;
if (ops > uint.MaxValue)
newOps |= (uint)op;
if (newOps > uint.MaxValue)
{
throw new Exception($"OpCode overflow. encryptionLevel:{encryptionLevel}, vmOpCodeCount:{vmOpCodeCount}");
Debug.LogWarning($"OpCode overflow. encryptionLevel:{encryptionLevel}, vmOpCodeCount:{vmOpCodeCount}");
}
else
{
ops = newOps;
}
}
return (int)ops;