diff --git a/Editor/EncryptionVM/VirtualMachineCodeGenerator.cs b/Editor/EncryptionVM/VirtualMachineCodeGenerator.cs index 2845ef4..ecf826a 100644 --- a/Editor/EncryptionVM/VirtualMachineCodeGenerator.cs +++ b/Editor/EncryptionVM/VirtualMachineCodeGenerator.cs @@ -152,19 +152,20 @@ namespace Obfuz.EncryptionVM public override int Encrypt(int value, int opts, int salt) { - int revertOps = 0; - while (opts > 0) + uint uopts = (uint)opts; + uint revertOps = 0; + while (uopts != 0) { - int opCode = opts & kOpCodeMask; + uint opCode = uopts & kOpCodeMask; revertOps <<= kOpCodeBits; revertOps |= opCode; - opts >>= kOpCodeBits; + uopts >>= kOpCodeBits; } - while (revertOps > 0) + while (revertOps != 0) { - int opCode = revertOps & kOpCodeMask; - value = ExecuteEncrypt(value, opCode, salt); + uint opCode = revertOps & kOpCodeMask; + value = ExecuteEncrypt(value, (int)opCode, salt); revertOps >>= kOpCodeBits; } return value; @@ -172,11 +173,12 @@ namespace Obfuz.EncryptionVM public override int Decrypt(int value, int opts, int salt) { - while (opts > 0) + uint uopts = (uint)opts; + while (uopts != 0) { - int opCode = opts & kOpCodeMask; - value = ExecuteDecrypt(value, opCode, salt); - opts >>= kOpCodeBits; + uint opCode = uopts & kOpCodeMask; + value = ExecuteDecrypt(value, (int)opCode, salt); + uopts >>= kOpCodeBits; } return value; } diff --git a/Editor/EncryptionVM/VirtualMachineSimulator.cs b/Editor/EncryptionVM/VirtualMachineSimulator.cs index 43e1804..74f2e33 100644 --- a/Editor/EncryptionVM/VirtualMachineSimulator.cs +++ b/Editor/EncryptionVM/VirtualMachineSimulator.cs @@ -62,7 +62,7 @@ namespace Obfuz.EncryptionVM private List DecodeOps(uint ops) { var codes = new List(); - while (ops > 0) + while (ops != 0) { uint code = ops % (uint)_opCodes.Length; codes.Add(code); diff --git a/Editor/Obfuscator.cs b/Editor/Obfuscator.cs index 8535365..6f58080 100644 --- a/Editor/Obfuscator.cs +++ b/Editor/Obfuscator.cs @@ -133,14 +133,17 @@ namespace Obfuz for (int i = 0; i < vm.opCodes.Length; i++) { int ops = i * vm.opCodes.Length + i; - int encryptedValueOfVms = vms.Encrypt(testValue, ops, i); - int decryptedValueOfVms = vms.Decrypt(encryptedValueOfVms, ops, i); + //int salt = i; + //int ops = -1135538782; + int salt = -879409147; + int encryptedValueOfVms = vms.Encrypt(testValue, ops, salt); + int decryptedValueOfVms = vms.Decrypt(encryptedValueOfVms, ops, salt); if (decryptedValueOfVms != testValue) { throw new Exception($"VirtualMachineSimulator decrypt failed! opCode:{i}, originalValue:{testValue} decryptedValue:{decryptedValueOfVms}"); } - int encryptedValueOfGvm = gvmInstance.Encrypt(testValue, ops, i); - int decryptedValueOfGvm = gvmInstance.Decrypt(encryptedValueOfGvm, ops, i); + int encryptedValueOfGvm = gvmInstance.Encrypt(testValue, ops, salt); + int decryptedValueOfGvm = gvmInstance.Decrypt(encryptedValueOfGvm, ops, salt); if (encryptedValueOfGvm != encryptedValueOfVms) { throw new Exception($"encryptedValue not match! opCode:{i}, originalValue:{testValue} encryptedValue VirtualMachineSimulator:{encryptedValueOfVms} GeneratedEncryptionVirtualMachine:{encryptedValueOfGvm}"); @@ -150,14 +153,14 @@ namespace Obfuz throw new Exception($"GeneratedEncryptionVirtualMachine decrypt failed! opCode:{i}, originalValue:{testValue} decryptedValue:{decryptedValueOfGvm}"); } - byte[] encryptedStrOfVms = vms.Encrypt(testString, ops, i); - string descryptedStrOfVms = vms.DecryptString(encryptedStrOfVms, 0, encryptedStrOfVms.Length, ops, i); + byte[] encryptedStrOfVms = vms.Encrypt(testString, ops, salt); + string descryptedStrOfVms = vms.DecryptString(encryptedStrOfVms, 0, encryptedStrOfVms.Length, ops, salt); if (descryptedStrOfVms != testString) { throw new Exception($"VirtualMachineSimulator decrypt string failed! opCode:{i}, originalValue:{testString} decryptedValue:{descryptedStrOfVms}"); } - byte[] encryptedStrOfGvm = gvmInstance.Encrypt(testString, ops, i); - string descryptedStrOfGvm = gvmInstance.DecryptString(encryptedStrOfGvm, 0, encryptedStrOfGvm.Length, ops, i); + byte[] encryptedStrOfGvm = gvmInstance.Encrypt(testString, ops, salt); + string descryptedStrOfGvm = gvmInstance.DecryptString(encryptedStrOfGvm, 0, encryptedStrOfGvm.Length, ops, salt); if (!encryptedStrOfGvm.SequenceEqual(encryptedStrOfVms)) { throw new Exception($"encryptedValue not match! opCode:{i}, originalValue:{testString} encryptedValue VirtualMachineSimulator:{encryptedStrOfVms} GeneratedEncryptionVirtualMachine:{encryptedStrOfGvm}");