2025-04-21 21:02:47 +08:00
|
|
|
|
using dnlib.DotNet;
|
|
|
|
|
using dnlib.DotNet.Emit;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Obfuz.Virtualization
|
|
|
|
|
{
|
|
|
|
|
public class DefaultDataObfuscator : IDataObfuscator
|
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
private readonly RandomDataNodeCreator _nodeCreator = new RandomDataNodeCreator();
|
|
|
|
|
|
|
|
|
|
public void ObfuscateInt(MethodDef method, int value, List<Instruction> obfuscatedInstructions)
|
2025-04-21 21:02:47 +08:00
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
IDataNode node = _nodeCreator.CreateRandom(DataNodeType.Int32, value);
|
2025-04-22 08:58:00 +08:00
|
|
|
|
var ctx = new CompileContext
|
|
|
|
|
{
|
|
|
|
|
method = method,
|
|
|
|
|
obfuscatedInstructions = obfuscatedInstructions,
|
|
|
|
|
};
|
|
|
|
|
node.Compile(ctx);
|
|
|
|
|
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_I4, value));
|
2025-04-21 21:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 08:13:58 +08:00
|
|
|
|
public void ObfuscateLong(MethodDef method, long value, List<Instruction> obfuscatedInstructions)
|
2025-04-21 21:02:47 +08:00
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_I8, value));
|
2025-04-21 21:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 08:13:58 +08:00
|
|
|
|
public void ObfuscateFloat(MethodDef method, float value, List<Instruction> obfuscatedInstructions)
|
2025-04-21 21:02:47 +08:00
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_R4, value));
|
2025-04-21 21:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 08:13:58 +08:00
|
|
|
|
public void ObfuscateDouble(MethodDef method, double value, List<Instruction> obfuscatedInstructions)
|
2025-04-21 21:02:47 +08:00
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_R8, value));
|
2025-04-21 21:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 08:13:58 +08:00
|
|
|
|
public void ObfuscateBytes(MethodDef method, Array value, List<Instruction> obfuscatedInstructions)
|
2025-04-21 21:02:47 +08:00
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
//obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldc_I4, value.Length));
|
2025-04-21 21:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 08:13:58 +08:00
|
|
|
|
public void ObfuscateString(MethodDef method, string value, List<Instruction> obfuscatedInstructions)
|
2025-04-21 21:02:47 +08:00
|
|
|
|
{
|
2025-04-22 08:13:58 +08:00
|
|
|
|
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldstr, value));
|
2025-04-21 21:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|