Encryption改名为EncryptionVM

backup
walon 2025-05-11 12:53:24 +08:00
parent f0818e3df1
commit fcb2cb1d89
10 changed files with 23 additions and 26 deletions

View File

@ -1,4 +1,4 @@
namespace Obfuz.Encryption namespace Obfuz.EncryptionVM
{ {
public class EncryptionInstructionWithOpCode public class EncryptionInstructionWithOpCode
{ {

View File

@ -1,4 +1,4 @@
namespace Obfuz.Encryption namespace Obfuz.EncryptionVM
{ {
public interface IEncryptionInstruction public interface IEncryptionInstruction
{ {

View File

@ -1,4 +1,4 @@
namespace Obfuz.Encryption.Instructions namespace Obfuz.EncryptionVM.Instructions
{ {
public class AddInstruction : EncryptionInstructionBase public class AddInstruction : EncryptionInstructionBase
{ {

View File

@ -1,4 +1,4 @@
namespace Obfuz.Encryption.Instructions namespace Obfuz.EncryptionVM.Instructions
{ {
public class BitRotateInstruction : EncryptionInstructionBase public class BitRotateInstruction : EncryptionInstructionBase
{ {

View File

@ -3,7 +3,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Encryption.Instructions namespace Obfuz.EncryptionVM.Instructions
{ {
public class EncryptFunction : EncryptionInstructionBase public class EncryptFunction : EncryptionInstructionBase

View File

@ -1,4 +1,4 @@
namespace Obfuz.Encryption.Instructions namespace Obfuz.EncryptionVM.Instructions
{ {
public class XorInstruction : EncryptionInstructionBase public class XorInstruction : EncryptionInstructionBase
{ {

View File

@ -1,13 +1,13 @@
namespace Obfuz.Encryption namespace Obfuz.EncryptionVM
{ {
public class EncryptionVirtualMachine public class VirtualMachine
{ {
public const int SecretKeyLength = 1024; public const int SecretKeyLength = 1024;
public readonly int[] secretKey; public readonly int[] secretKey;
public readonly EncryptionInstructionWithOpCode[] opCodes; public readonly EncryptionInstructionWithOpCode[] opCodes;
public EncryptionVirtualMachine(int[] secretKey, EncryptionInstructionWithOpCode[] opCodes) public VirtualMachine(int[] secretKey, EncryptionInstructionWithOpCode[] opCodes)
{ {
this.secretKey = secretKey; this.secretKey = secretKey;
this.opCodes = opCodes; this.opCodes = opCodes;

View File

@ -1,21 +1,19 @@
using Obfuz.Encryption.Instructions; using Obfuz.EncryptionVM.Instructions;
using Obfuz.Utils; using Obfuz.Utils;
using UnityEngine.Assertions; using UnityEngine.Assertions;
namespace Obfuz.Encryption namespace Obfuz.EncryptionVM
{ {
public class EncryptionVirtualMachineCreator public class VirtualMachineCreator
{ {
private readonly int[] _vmGenerationSecretKey; private readonly int[] _vmGenerationSecretKey;
private readonly byte[] _encryptionSecretKey;
private readonly IRandom _random; private readonly IRandom _random;
public const int CodeGenerationSecretKeyLength = 1024; public const int CodeGenerationSecretKeyLength = 1024;
public EncryptionVirtualMachineCreator(string vmGenerationSecretKey, byte[] encryptionSecretKey) public VirtualMachineCreator(string vmGenerationSecretKey, byte[] encryptionSecretKey)
{ {
_vmGenerationSecretKey = KeyGenerator.ConvertToIntKey(KeyGenerator.GenerateKey(vmGenerationSecretKey, CodeGenerationSecretKeyLength)); _vmGenerationSecretKey = KeyGenerator.ConvertToIntKey(KeyGenerator.GenerateKey(vmGenerationSecretKey, CodeGenerationSecretKeyLength));
_encryptionSecretKey = encryptionSecretKey;
_random = new RandomWithKey(encryptionSecretKey, 0); _random = new RandomWithKey(encryptionSecretKey, 0);
} }
@ -36,12 +34,12 @@ namespace Obfuz.Encryption
private EncryptionInstructionWithOpCode CreateEncryptOpCode(ushort code) private EncryptionInstructionWithOpCode CreateEncryptOpCode(ushort code)
{ {
IEncryptionInstruction inst = CreateRandomInstruction(EncryptionVirtualMachine.SecretKeyLength / sizeof(int)); IEncryptionInstruction inst = CreateRandomInstruction(VirtualMachine.SecretKeyLength / sizeof(int));
Assert.AreEqual(1234, inst.Decrypt(inst.Encrypt(1234, _vmGenerationSecretKey, 0x12345678), _vmGenerationSecretKey, 0x12345678)); Assert.AreEqual(1234, inst.Decrypt(inst.Encrypt(1234, _vmGenerationSecretKey, 0x12345678), _vmGenerationSecretKey, 0x12345678));
return new EncryptionInstructionWithOpCode(code, inst); return new EncryptionInstructionWithOpCode(code, inst);
} }
public EncryptionVirtualMachine CreateVirtualMachine(int opCodeCount) public VirtualMachine CreateVirtualMachine(int opCodeCount)
{ {
Assert.IsTrue(opCodeCount > 0); Assert.IsTrue(opCodeCount > 0);
Assert.AreEqual(0, opCodeCount & (opCodeCount - 1)); Assert.AreEqual(0, opCodeCount & (opCodeCount - 1));
@ -50,7 +48,7 @@ namespace Obfuz.Encryption
{ {
opCodes[i] = CreateEncryptOpCode((ushort)i); opCodes[i] = CreateEncryptOpCode((ushort)i);
} }
return new EncryptionVirtualMachine(_vmGenerationSecretKey, opCodes); return new VirtualMachine(_vmGenerationSecretKey, opCodes);
} }
} }
} }

View File

@ -3,19 +3,18 @@ using System.Collections.Generic;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Assertions; using UnityEngine.Assertions;
using UnityEngine.UIElements; using UnityEngine.UIElements;
namespace Obfuz.Encryption namespace Obfuz.EncryptionVM
{ {
public class EncryptionVirtualMachineSimulator : EncryptorBase public class VirtualMachineSimulator : EncryptorBase
{ {
private readonly EncryptionInstructionWithOpCode[] _opCodes; private readonly EncryptionInstructionWithOpCode[] _opCodes;
private readonly int[] _secretKey; private readonly int[] _secretKey;
public EncryptionVirtualMachineSimulator(EncryptionVirtualMachine vm) public VirtualMachineSimulator(VirtualMachine vm)
{ {
_opCodes = vm.opCodes; _opCodes = vm.opCodes;
_secretKey = vm.secretKey; _secretKey = vm.secretKey;

View File

@ -2,7 +2,7 @@
using dnlib.Protection; using dnlib.Protection;
using Obfuz.Data; using Obfuz.Data;
using Obfuz.Emit; using Obfuz.Emit;
using Obfuz.Encryption; using Obfuz.EncryptionVM;
using Obfuz.ObfusPasses; using Obfuz.ObfusPasses;
using Obfuz.ObfusPasses.CleanUp; using Obfuz.ObfusPasses.CleanUp;
using Obfuz.Utils; using Obfuz.Utils;
@ -41,7 +41,7 @@ namespace Obfuz
string obfuscatedAssemblyOutputDir, string obfuscatedAssemblyOutputDir,
List<IObfuscationPass> obfuscationPasses, string rawSecretKey, int globalRandomSeed, string encryptionVmSecretKey) List<IObfuscationPass> obfuscationPasses, string rawSecretKey, int globalRandomSeed, string encryptionVmSecretKey)
{ {
_secretKey = KeyGenerator.GenerateKey(rawSecretKey, EncryptionVirtualMachine.SecretKeyLength); _secretKey = KeyGenerator.GenerateKey(rawSecretKey, VirtualMachine.SecretKeyLength);
_globalRandomSeed = globalRandomSeed; _globalRandomSeed = globalRandomSeed;
_encryptionVmSecretKey = encryptionVmSecretKey; _encryptionVmSecretKey = encryptionVmSecretKey;
@ -67,9 +67,9 @@ namespace Obfuz
private IEncryptor CreateEncryptionVirtualMachine() private IEncryptor CreateEncryptionVirtualMachine()
{ {
var vmCreator = new EncryptionVirtualMachineCreator(_encryptionVmSecretKey, _secretKey); var vmCreator = new VirtualMachineCreator(_encryptionVmSecretKey, _secretKey);
var vm = vmCreator.CreateVirtualMachine(1); var vm = vmCreator.CreateVirtualMachine(1);
return new EncryptionVirtualMachineSimulator(vm); return new VirtualMachineSimulator(vm);
} }
private void OnPreObfuscation() private void OnPreObfuscation()