From fda0e5c66d36c5ece0658d0755b6782f94dedf5d Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 8 May 2025 08:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=B8=E9=87=8F=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Emit/DefaultModuleMetadataImporter.cs | 58 ++++++++++--- .../EncryptVirtualMachineSimulator.cs | 85 +++++++++---------- .../ConstObfus/DefaultConstObfuscator.cs | 58 +++++++++---- Editor/Obfuz.Editor.asmdef | 2 +- Runtime/DefaultEncryptor.cs | 23 ++--- Runtime/EncryptionService.cs | 18 ++-- Runtime/IEncryptor.cs | 8 +- 7 files changed, 156 insertions(+), 96 deletions(-) diff --git a/Editor/Emit/DefaultModuleMetadataImporter.cs b/Editor/Emit/DefaultModuleMetadataImporter.cs index 4780d18..f212315 100644 --- a/Editor/Emit/DefaultModuleMetadataImporter.cs +++ b/Editor/Emit/DefaultModuleMetadataImporter.cs @@ -24,34 +24,49 @@ namespace Obfuz.Emit _initializeArray = mod.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) })); Assert.IsNotNull(_initializeArray); - _encryptBlock = mod.Import(typeof(EncryptionService).GetMethod("EncryptBlock", new[] { typeof(byte[]), typeof(long), typeof(int) })); + + Type encryptionService = typeof(EncryptionService); + _encryptBlock = mod.Import(encryptionService.GetMethod("EncryptBlock", new[] { typeof(byte[]), typeof(long), typeof(int) })); Assert.IsNotNull(_encryptBlock); - _decryptBlock = mod.Import(typeof(EncryptionService).GetMethod("DecryptBlock", new[] { typeof(byte[]), typeof(long), typeof(int) })); + _decryptBlock = mod.Import(encryptionService.GetMethod("DecryptBlock", new[] { typeof(byte[]), typeof(long), typeof(int) })); Assert.IsNotNull(_decryptBlock); - _encryptInt = mod.Import(typeof(EncryptionService).GetMethod("Encrypt", new[] { typeof(int), typeof(int), typeof(int) })); + _encryptInt = mod.Import(encryptionService.GetMethod("Encrypt", new[] { typeof(int), typeof(int), typeof(int) })); Assert.IsNotNull(_encryptInt); - _decryptInt = mod.Import(typeof(EncryptionService).GetMethod("Decrypt", new[] { typeof(int), typeof(int), typeof(int) })); + _decryptInt = mod.Import(encryptionService.GetMethod("Decrypt", new[] { typeof(int), typeof(int), typeof(int) })); Assert.IsNotNull(_decryptInt); - _encryptLong = mod.Import(typeof(EncryptionService).GetMethod("Encrypt", new[] { typeof(long), typeof(int), typeof(int) })); + _encryptLong = mod.Import(encryptionService.GetMethod("Encrypt", new[] { typeof(long), typeof(int), typeof(int) })); Assert.IsNotNull(_encryptLong); - _decryptLong = mod.Import(typeof(EncryptionService).GetMethod("Decrypt", new[] { typeof(long), typeof(int), typeof(int) })); + _decryptLong = mod.Import(encryptionService.GetMethod("Decrypt", new[] { typeof(long), typeof(int), typeof(int) })); Assert.IsNotNull(_decryptLong); - _encryptFloat = mod.Import(typeof(EncryptionService).GetMethod("Encrypt", new[] { typeof(float), typeof(int), typeof(int) })); + _encryptFloat = mod.Import(encryptionService.GetMethod("Encrypt", new[] { typeof(float), typeof(int), typeof(int) })); Assert.IsNotNull(_encryptFloat); - _decryptFloat = mod.Import(typeof(EncryptionService).GetMethod("Decrypt", new[] { typeof(float), typeof(int), typeof(int) })); + _decryptFloat = mod.Import(encryptionService.GetMethod("Decrypt", new[] { typeof(float), typeof(int), typeof(int) })); Assert.IsNotNull(_decryptFloat); - _encryptDouble = mod.Import(typeof(EncryptionService).GetMethod("Encrypt", new[] { typeof(double), typeof(int), typeof(int) })); + _encryptDouble = mod.Import(encryptionService.GetMethod("Encrypt", new[] { typeof(double), typeof(int), typeof(int) })); Assert.IsNotNull(_encryptDouble); - _decryptDouble = mod.Import(typeof(EncryptionService).GetMethod("Decrypt", new[] { typeof(double), typeof(int), typeof(int) })); + _decryptDouble = mod.Import(encryptionService.GetMethod("Decrypt", new[] { typeof(double), typeof(int), typeof(int) })); Assert.IsNotNull(_decryptDouble); - _encryptString = mod.Import(typeof(EncryptionService).GetMethod("Encrypt", new[] { typeof(string), typeof(int), typeof(int) })); + _encryptString = mod.Import(encryptionService.GetMethod("Encrypt", new[] { typeof(string), typeof(int), typeof(int) })); Assert.IsNotNull(_encryptString); - _decryptString = mod.Import(typeof(EncryptionService).GetMethod("DecryptString", new[] { typeof(int[]), typeof(int), typeof(int), typeof(int), typeof(int) })); + _decryptString = mod.Import(encryptionService.GetMethod("DecryptString", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) })); Assert.IsNotNull(_decryptString); - _encryptBytes = mod.Import(typeof(EncryptionService).GetMethod("Encrypt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) })); + _encryptBytes = mod.Import(encryptionService.GetMethod("Encrypt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) })); Assert.IsNotNull(_encryptBytes); - _decryptBytes = mod.Import(typeof(EncryptionService).GetMethod("Decrypt", new[] { typeof(int[]), typeof(int), typeof(int), typeof(int), typeof(int) })); + _decryptBytes = mod.Import(encryptionService.GetMethod("Decrypt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) })); Assert.IsNotNull(_decryptBytes); + + _decryptFromRvaInt = mod.Import(encryptionService.GetMethod("DecryptFromRvaInt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) })); + Assert.IsNotNull(_decryptFromRvaInt); + _decryptFromRvaLong = mod.Import(encryptionService.GetMethod("DecryptFromRvaLong", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) })); + Assert.IsNotNull(_decryptFromRvaLong); + _decryptFromRvaFloat = mod.Import(encryptionService.GetMethod("DecryptFromRvaFloat", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) })); + Assert.IsNotNull(_decryptFromRvaFloat); + _decryptFromRvaDouble = mod.Import(encryptionService.GetMethod("DecryptFromRvaDouble", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) })); + Assert.IsNotNull(_decryptFromRvaDouble); + _decryptFromRvaBytes = mod.Import(encryptionService.GetMethod("DecryptFromRvaBytes", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) })); + Assert.IsNotNull(_decryptFromRvaBytes); + _decryptFromRvaString = mod.Import(encryptionService.GetMethod("DecryptFromRvaString", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) })); + Assert.IsNotNull(_decryptFromRvaString); } private ModuleDef _module; @@ -76,6 +91,13 @@ namespace Obfuz.Emit private IMethod _encryptBytes; private IMethod _decryptBytes; + private IMethod _decryptFromRvaInt; + private IMethod _decryptFromRvaLong; + private IMethod _decryptFromRvaFloat; + private IMethod _decryptFromRvaDouble; + private IMethod _decryptFromRvaString; + private IMethod _decryptFromRvaBytes; + public IMethod CastIntAsFloat => _castIntAsFloat; public IMethod CastLongAsDouble => _castLongAsDouble; public IMethod CastFloatAsInt => _castFloatAsInt; @@ -98,5 +120,13 @@ namespace Obfuz.Emit public IMethod DecryptString => _decryptString; public IMethod EncryptBytes => _encryptBytes; public IMethod DecryptBytes => _decryptBytes; + + public IMethod DecryptFromRvaInt => _decryptFromRvaInt; + public IMethod DecryptFromRvaLong => _decryptFromRvaLong; + public IMethod DecryptFromRvaFloat => _decryptFromRvaFloat; + public IMethod DecryptFromRvaDouble => _decryptFromRvaDouble; + public IMethod DecryptFromRvaBytes => _decryptFromRvaBytes; + public IMethod DecryptFromRvaString => _decryptFromRvaString; + } } diff --git a/Editor/Encryption/EncryptVirtualMachineSimulator.cs b/Editor/Encryption/EncryptVirtualMachineSimulator.cs index f02018a..80f9736 100644 --- a/Editor/Encryption/EncryptVirtualMachineSimulator.cs +++ b/Editor/Encryption/EncryptVirtualMachineSimulator.cs @@ -2,9 +2,11 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Runtime.CompilerServices; using System.Text; using Unity.Collections.LowLevel.Unsafe; using UnityEngine.Assertions; +using UnityEngine.UIElements; namespace Obfuz.Encryption { @@ -185,76 +187,71 @@ namespace Obfuz.Encryption return UnsafeUtility.As(ref decValue); } - public int[] Encrypt(byte[] bytes, int offset, int length, int ops, int salt) + public unsafe byte[] Encrypt(byte[] bytes, int offset, int length, int ops, int salt) { if (length == 0) { - return Array.Empty(); + return Array.Empty(); } - int intLength = (length + 3) / 4; - int[] encInts = new int[intLength]; + // align size to 4 + int align4Length = (length + 3) & ~3; + byte[] encInts = new byte[align4Length]; Buffer.BlockCopy(bytes, offset, encInts, 0, length); - for (int i = 0; i < intLength; i++) + + int intLength = align4Length >> 2; + fixed (byte* intArr = &bytes[0]) { - encInts[i] = Encrypt(encInts[i], ops, salt); + for (int i = 0; i < intLength; i++) + { + int* ele = (int*)intArr + i; + *ele = Encrypt(*ele, ops, salt); + } } return encInts; } - public int[] Encrypt(byte[] bytes, int ops, int salt) + public unsafe byte[] Decrypt(byte[] value, int offset, int length, int ops, int salt) + { + if (length == 0) + { + return Array.Empty(); + } + int align4Length = (length + 3) & ~3; + int intLength = align4Length >> 2; + byte[] decInts = new byte[align4Length]; + fixed (byte* intArr = &decInts[0]) + { + for (int i = 0; i < intLength; i++) + { + int* ele = (int*)intArr + i; + *ele = Decrypt(*ele, ops, salt); + } + } + return decInts; + } + + public byte[] Encrypt(byte[] bytes, int ops, int salt) { return Encrypt(bytes, 0, bytes.Length, ops, salt); } - public byte[] Decrypt(int[] value, int offset, int byteLength, int ops, int salt) - { - if (byteLength == 0) - { - return Array.Empty(); - } - int intLength = (byteLength + 3) / 4; - int[] decValue = new int[intLength]; - for (int i = 0; i < intLength; i++) - { - decValue[i] = Decrypt(value[i], ops, salt); - } - - byte[] bytes = new byte[byteLength]; - Buffer.BlockCopy(decValue, 0, bytes, 0, byteLength); - return bytes; - } - - public byte[] Decrypt(int[] value, int byteLength, int ops, int salt) - { - return Decrypt(value, 0, byteLength, ops, salt); - } - - public int[] Encrypt(string value, int ops, int salt) + public byte[] Encrypt(string value, int ops, int salt) { if (value.Length == 0) { - return Array.Empty(); + return Array.Empty(); } byte[] bytes = System.Text.Encoding.UTF8.GetBytes(value); return Encrypt(bytes, 0, bytes.Length, ops, salt); } - public string DecryptString(int[] value, int offset, int stringBytesLength, int ops, int salt) + public string DecryptString(byte[] value, int offset, int length, int ops, int salt) { - if (stringBytesLength == 0) + if (length == 0) { return string.Empty; } - int intLength = (stringBytesLength + 3) / 4; - int[] intValue = new int[intLength]; - for (int i = 0; i < intLength; i++) - { - intValue[i] = Decrypt(value[i], ops, salt); - } - - byte[] bytes = new byte[stringBytesLength]; - Buffer.BlockCopy(intValue, 0, bytes, 0, stringBytesLength); - return System.Text.Encoding.UTF8.GetString(bytes); + return System.Text.Encoding.UTF8.GetString(Decrypt(value, offset, length, ops, salt)); } } } diff --git a/Editor/ObfusPasses/ConstObfus/DefaultConstObfuscator.cs b/Editor/ObfusPasses/ConstObfus/DefaultConstObfuscator.cs index ef579cc..34e8292 100644 --- a/Editor/ObfusPasses/ConstObfus/DefaultConstObfuscator.cs +++ b/Editor/ObfusPasses/ConstObfus/DefaultConstObfuscator.cs @@ -6,6 +6,7 @@ using Obfuz.Utils; using System; using System.Collections.Generic; using NUnit.Framework; +using System.Text; namespace Obfuz.ObfusPasses.ConstObfus { @@ -61,10 +62,11 @@ namespace Obfuz.ObfusPasses.ConstObfus RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue); DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method); - obfuscatedInstructions.Add(Instruction.CreateLdcI4(encryptedValue)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(salt)); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptInt)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaInt)); } public void ObfuscateLong(MethodDef method, long value, List obfuscatedInstructions) @@ -72,12 +74,14 @@ namespace Obfuz.ObfusPasses.ConstObfus int ops = GenerateEncryptionOperations(); int salt = GenerateSalt(); long encryptedValue = _encryptor.Encrypt(value, ops, salt); + RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue); DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_I8, encryptedValue)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(salt)); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptLong)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaLong)); } public void ObfuscateFloat(MethodDef method, float value, List obfuscatedInstructions) @@ -85,12 +89,14 @@ namespace Obfuz.ObfusPasses.ConstObfus int ops = GenerateEncryptionOperations(); int salt = GenerateSalt(); float encryptedValue = _encryptor.Encrypt(value, ops, salt); + RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue); DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_R4, encryptedValue)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(salt)); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFloat)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaFloat)); } public void ObfuscateDouble(MethodDef method, double value, List obfuscatedInstructions) @@ -98,29 +104,51 @@ namespace Obfuz.ObfusPasses.ConstObfus int ops = GenerateEncryptionOperations(); int salt = GenerateSalt(); double encryptedValue = _encryptor.Encrypt(value, ops, salt); + RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue); + DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_R8, encryptedValue)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops)); obfuscatedInstructions.Add(Instruction.CreateLdcI4(salt)); - obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptDouble)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaDouble)); } public void ObfuscateBytes(MethodDef method, byte[] value, List obfuscatedInstructions) { int ops = GenerateEncryptionOperations(); int salt = GenerateSalt(); + byte[] encryptedValue = _encryptor.Encrypt(value, 0, value.Length, ops, salt); + Assert.IsTrue(encryptedValue.Length % 4 == 0); + RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue); - Assert.IsTrue(value.Length % 4 == 0); - int[] intArr = new int[value.Length / 4]; - Buffer.BlockCopy(value, 0, intArr, 0, value.Length); - byte[] encryptedValue = _encryptor.Decrypt(intArr, 0, value.Length, ops, salt); + DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset)); + // should use value.Length, can't use rvaData.size, because rvaData.size is align to 4, it's not the actual length. + obfuscatedInstructions.Add(Instruction.CreateLdcI4(value.Length)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(salt)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaBytes)); } public void ObfuscateString(MethodDef method, string value, List obfuscatedInstructions) { - IDataNode node = _nodeCreator.CreateRandom(DataNodeType.String, value); - CompileNode(node, method, obfuscatedInstructions); - //obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldstr, value)); + int ops = GenerateEncryptionOperations(); + int salt = GenerateSalt(); + int stringByteLength = Encoding.UTF8.GetByteCount(value); + byte[] encryptedValue = _encryptor.Encrypt(value, ops, salt); + Assert.IsTrue(encryptedValue.Length % 4 == 0); + RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue); + + DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset)); + // should use stringByteLength, can't use rvaData.size, because rvaData.size is align to 4, it's not the actual length. + obfuscatedInstructions.Add(Instruction.CreateLdcI4(stringByteLength)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops)); + obfuscatedInstructions.Add(Instruction.CreateLdcI4(salt)); + obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaString)); } public void Done() diff --git a/Editor/Obfuz.Editor.asmdef b/Editor/Obfuz.Editor.asmdef index 241eca7..be19d71 100644 --- a/Editor/Obfuz.Editor.asmdef +++ b/Editor/Obfuz.Editor.asmdef @@ -9,7 +9,7 @@ "Editor" ], "excludePlatforms": [], - "allowUnsafeCode": false, + "allowUnsafeCode": true, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, diff --git a/Runtime/DefaultEncryptor.cs b/Runtime/DefaultEncryptor.cs index df44ff1..ba12c95 100644 --- a/Runtime/DefaultEncryptor.cs +++ b/Runtime/DefaultEncryptor.cs @@ -71,30 +71,31 @@ namespace Obfuz return value; } - public int[] Encrypt(byte[] value, int offset, int length, int opts, int salt) + public byte[] Encrypt(byte[] value, int offset, int length, int opts, int salt) { - var intArr = new int[(length + 3) / 4]; - Buffer.BlockCopy(value, offset, intArr, 0, length); - return intArr; + int align4Length = (length + 3) & ~3; + var encryptedBytes = new byte[align4Length]; + Buffer.BlockCopy(value, offset, encryptedBytes, 0, length); + return encryptedBytes; } - public byte[] Decrypt(int[] value, int offset, int byteLength, int ops, int salt) + public byte[] Decrypt(byte[] value, int offset, int length, int ops, int salt) { - byte[] byteArr = new byte[byteLength]; - Buffer.BlockCopy(value, 0, byteArr, 0, byteLength); + byte[] byteArr = new byte[length]; + Buffer.BlockCopy(value, 0, byteArr, 0, length); return byteArr; } - public int[] Encrypt(string value, int ops, int salt) + public byte[] Encrypt(string value, int ops, int salt) { byte[] bytes = Encoding.UTF8.GetBytes(value); return Encrypt(bytes, 0, bytes.Length, ops, salt); } - public string DecryptString(int[] value, int offset, int stringBytesLength, int ops, int salt) + public string DecryptString(byte[] value, int offset, int length, int ops, int salt) { - byte[] bytes = new byte[stringBytesLength]; - Buffer.BlockCopy(value, 0, bytes, 0, stringBytesLength); + byte[] bytes = new byte[length]; + Buffer.BlockCopy(value, 0, bytes, 0, length); return Encoding.UTF8.GetString(bytes); } } diff --git a/Runtime/EncryptionService.cs b/Runtime/EncryptionService.cs index f4e0308..e29e7ab 100644 --- a/Runtime/EncryptionService.cs +++ b/Runtime/EncryptionService.cs @@ -60,22 +60,22 @@ namespace Obfuz return _encryptor.Decrypt(value, opts, salt); } - public static int[] Encrypt(byte[] value, int offset, int length, int opts, int salt) + public static byte[] Encrypt(byte[] value, int offset, int length, int opts, int salt) { return _encryptor.Encrypt(value, offset, length, opts, salt); } - public static byte[] Decrypt(int[] value, int offset, int byteLength, int ops, int salt) + public static byte[] Decrypt(byte[] value, int offset, int byteLength, int ops, int salt) { return _encryptor.Decrypt(value, offset, byteLength, ops, salt); } - public static int[] Encrypt(string value, int ops, int salt) + public static byte[] Encrypt(string value, int ops, int salt) { return _encryptor.Encrypt(value, ops, salt); } - public static string DecryptString(int[] value, int offset, int stringBytesLength, int ops, int salt) + public static string DecryptString(byte[] value, int offset, int stringBytesLength, int ops, int salt) { return _encryptor.DecryptString(value, offset, stringBytesLength, ops, salt); } @@ -105,10 +105,14 @@ namespace Obfuz return Decrypt(encryptedValue, ops, salt); } - public static string DecryptFromRvaString(byte[] data, int offset, int stringBytesLength, int ops, int salt) + public static string DecryptFromRvaString(byte[] data, int offset, int length, int ops, int salt) { - int[] encryptedValue = ConstUtility.GetBytes(data, offset, stringBytesLength); - return DecryptString(encryptedValue, 0, stringBytesLength, ops, salt); + return DecryptString(data, offset, length, ops, salt); + } + + public static byte[] DecryptFromRvaBytes(byte[] data, int offset, int bytesLength, int ops, int salt) + { + return Decrypt(data, offset, bytesLength, ops, salt); } } } diff --git a/Runtime/IEncryptor.cs b/Runtime/IEncryptor.cs index ebe54a1..06af582 100644 --- a/Runtime/IEncryptor.cs +++ b/Runtime/IEncryptor.cs @@ -23,10 +23,10 @@ namespace Obfuz double Encrypt(double value, int opts, int salt); double Decrypt(double value, int opts, int salt); - int[] Encrypt(byte[] value, int offset, int length, int opts, int salt); - public byte[] Decrypt(int[] value, int offset, int byteLength, int ops, int salt); + byte[] Encrypt(byte[] value, int offset, int length, int opts, int salt); + public byte[] Decrypt(byte[] value, int offset, int byteLength, int ops, int salt); - public int[] Encrypt(string value, int ops, int salt); - public string DecryptString(int[] value, int offset, int stringBytesLength, int ops, int salt); + public byte[] Encrypt(string value, int ops, int salt); + public string DecryptString(byte[] value, int offset, int stringBytesLength, int ops, int salt); } }