From 45a07bc2ae2fddcde72d1db85986419579b32ee0 Mon Sep 17 00:00:00 2001 From: walon Date: Sun, 18 May 2025 17:09:56 +0800 Subject: [PATCH] change: warning when GenerateEncryptionOpCodes exceeds uint.MaxValue --- .../Editor/Utils/EncryptionUtil.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Obfuz/Packages/com.code-philosophy.obfuz/Editor/Utils/EncryptionUtil.cs b/Obfuz/Packages/com.code-philosophy.obfuz/Editor/Utils/EncryptionUtil.cs index 5199a6a..5785800 100644 --- a/Obfuz/Packages/com.code-philosophy.obfuz/Editor/Utils/EncryptionUtil.cs +++ b/Obfuz/Packages/com.code-philosophy.obfuz/Editor/Utils/EncryptionUtil.cs @@ -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;