initial commit

This commit is contained in:
i2p
2026-08-27 11:21:58 -06:00
commit c21fb61050
336 changed files with 74161 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
using System;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Mutation2;
public class Abs : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Call, method.Module.Import(typeof(Math).GetMethod("Abs", new Type[1] { typeof(int) }))));
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
+27
View File
@@ -0,0 +1,27 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class Add : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
int num = Methods.Random.Next((int)((double)ldcI4Value / 1.5));
method.Body.Instructions[index].OpCode = OpCodes.Ldc_I4;
method.Body.Instructions[index].Operand = ldcI4Value - num;
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, num));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Add));
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
@@ -0,0 +1,29 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class CharMutations : iMutation
{
public MethodDef Converter { get; set; }
public void Prepare(TypeDef type)
{
MethodDef methodDef = ModuleDefMD.Load(typeof(FuncMutation).Module).ResolveTypeDef(MDToken.ToRID(typeof(FuncMutation).MetadataToken)).FindMethod("CharToInt");
methodDef.Name = Methods.GenerateString();
methodDef.DeclaringType = null;
type.Methods.Add(methodDef);
Converter = methodDef;
}
public void Process(MethodDef method, ref int index)
{
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Call, Converter));
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class ComparerMutation : iMutation
{
public void Prepare(TypeDef type)
{
if (type == type.Module.GlobalType)
{
return;
}
for (int i = 0; i < type.Methods.Count; i++)
{
MethodDef methodDef = type.Methods[i];
if (!methodDef.HasBody || methodDef.IsConstructor)
{
continue;
}
methodDef.Body.SimplifyBranches();
for (int j = 0; j < methodDef.Body.Instructions.Count; j++)
{
if (Utils.CheckArithmetic(methodDef.Body.Instructions[j]))
{
Execute(methodDef, ref j);
}
}
}
}
public void Execute(MethodDef method, ref int index)
{
if (method.Body.Instructions[index].OpCode == OpCodes.Call)
{
return;
}
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
Local local = new Local(method.Module.CorLibTypes.Int32);
Local local2 = new Local(method.Module.CorLibTypes.Int32);
method.Body.Variables.Add(local);
method.Body.Variables.Add(local2);
int num = Methods.Random.Next();
int num2 = Methods.Random.Next();
bool flag = Convert.ToBoolean(Methods.Random.Next(2));
int num3;
if (flag)
{
num3 = num2 - num;
}
else
{
num3 = Methods.Random.Next();
while (num3 + num == num2)
{
num3 = Methods.Random.Next();
}
}
method.Body.Instructions[index] = Instruction.CreateLdcI4(num);
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Stloc, local));
method.Body.Instructions.Insert(++index, Instruction.CreateLdcI4(num3));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Stloc, local2));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldloc, local));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldloc, local2));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Add));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, num2));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ceq));
Instruction instruction = OpCodes.Nop.ToInstruction();
method.Body.Instructions.Insert(++index, new Instruction(flag ? OpCodes.Brfalse : OpCodes.Brtrue, instruction));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Nop));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, ldcI4Value));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Stloc, local));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Nop));
Instruction instruction2 = OpCodes.Ldloc_S.ToInstruction(local);
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Br, instruction2));
method.Body.Instructions.Insert(++index, instruction);
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, Methods.Random.Next()));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Stloc, local));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Nop));
method.Body.Instructions.Insert(++index, instruction2);
}
public void Process(MethodDef method, ref int index)
{
}
public static void InsertInstructions(IList<Instruction> instructions, Dictionary<Instruction, int> keyValuePairs)
{
foreach (KeyValuePair<Instruction, int> keyValuePair in keyValuePairs)
{
Instruction key = keyValuePair.Key;
int value = keyValuePair.Value;
instructions.Insert(value, key);
}
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
+27
View File
@@ -0,0 +1,27 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class Div : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
int num = Methods.Random.Next(1, 5);
method.Body.Instructions[index].OpCode = OpCodes.Ldc_I4;
method.Body.Instructions[index].Operand = ldcI4Value * num;
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, num));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Div));
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
+49
View File
@@ -0,0 +1,49 @@
using System;
using System.Linq;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Mutation2;
public class Func : iMutation
{
public FieldDef Decryptor { get; set; }
public void Process(MethodDef method, ref int index)
{
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
method.Body.Instructions[index].OpCode = OpCodes.Ldsfld;
method.Body.Instructions[index].Operand = Decryptor;
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, ldcI4Value));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Callvirt, method.Module.Import(typeof(Func<int, int>).GetMethod("Invoke"))));
index -= 2;
}
public FieldDef CreateProperField(TypeDef type)
{
TypeDef typeDef = ModuleDefMD.Load(typeof(FuncMutation).Module).ResolveTypeDef(MDToken.ToRID(typeof(FuncMutation).MetadataToken));
FieldDef fieldDef = typeDef.Fields.FirstOrDefault((FieldDef x) => x.Name == "prao");
fieldDef.DeclaringType = null;
type.Fields.Add(fieldDef);
MethodDef methodDef = typeDef.FindMethod("RET");
methodDef.DeclaringType = null;
type.Methods.Add(methodDef);
MethodDef methodDef2 = type.FindOrCreateStaticConstructor();
methodDef2.Body.Instructions.Insert(0, new Instruction(OpCodes.Ldnull));
methodDef2.Body.Instructions.Insert(1, new Instruction(OpCodes.Ldftn, methodDef));
methodDef2.Body.Instructions.Insert(2, new Instruction(OpCodes.Newobj, type.Module.Import(typeof(Func<int, int>).GetConstructors().First())));
methodDef2.Body.Instructions.Insert(3, new Instruction(OpCodes.Stsfld, fieldDef));
methodDef2.Body.Instructions.Insert(4, new Instruction(OpCodes.Nop));
return fieldDef;
}
public void Prepare(TypeDef type)
{
Decryptor = CreateProperField(type);
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
@@ -0,0 +1,18 @@
using System;
namespace Obfuscator.Obfuscator.Mutation2;
public class FuncMutation
{
public static readonly Func<int, int> prao;
public static int CharToInt(char shi)
{
return shi;
}
public static int RET(int i)
{
return i;
}
}
+34
View File
@@ -0,0 +1,34 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class Mul : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
int num = Methods.Random.Next(1, (int)((double)ldcI4Value / 1.5));
int num2 = ldcI4Value / num;
while (num * num2 != ldcI4Value)
{
num = Methods.Random.Next(1, (int)((double)ldcI4Value / 1.5));
num2 = ldcI4Value / num;
}
method.Body.Instructions[index].OpCode = OpCodes.Ldc_I4;
method.Body.Instructions[index].Operand = num2;
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, num));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Mul));
index++;
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
@@ -0,0 +1,56 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Mutation2;
public class MulToShift : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
if (!method.Body.Instructions[index - 1].IsLdcI4() || !method.Body.Instructions[index - 2].IsLdcI4())
{
return;
}
int ldcI4Value = method.Body.Instructions[index - 2].GetLdcI4Value();
int ldcI4Value2 = method.Body.Instructions[index - 1].GetLdcI4Value();
if (ldcI4Value2 < 3)
{
return;
}
Local local = new Local(method.Module.CorLibTypes.Int32);
method.Body.Variables.Add(local);
method.Body.Instructions.Insert(0, new Instruction(OpCodes.Stloc, local));
method.Body.Instructions.Insert(0, new Instruction(OpCodes.Ldc_I4, ldcI4Value));
index += 2;
method.Body.Instructions[index - 2].OpCode = OpCodes.Ldloc;
method.Body.Instructions[index - 2].Operand = local;
method.Body.Instructions[index - 1].OpCode = OpCodes.Nop;
method.Body.Instructions[index].OpCode = OpCodes.Nop;
int num = 0;
for (int num2 = ldcI4Value2; num2 > 0; num2 >>= 1)
{
if ((num2 & 1) == 1 && num != 0)
{
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldloc, local));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, num));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Shl));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Add));
}
num++;
}
if ((ldcI4Value2 & 1) == 0)
{
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldloc, local));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Sub));
}
}
public bool Supported(Instruction instr)
{
return instr.OpCode == OpCodes.Mul;
}
}
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using dnlib.DotNet;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class Mutation2
{
private static List<iMutation> Tasks = new List<iMutation>
{
new Abs(),
new VariableMutation(),
new ComparerMutation(),
new MulToShift()
};
public static void Execute(ModuleDef Module)
{
foreach (TypeDef type in Module.Types)
{
foreach (iMutation task in Tasks)
{
task.Prepare(type);
}
for (int i = 0; i < type.Methods.Count; i++)
{
MethodDef methodDef = type.Methods[i];
if (!methodDef.HasBody || methodDef.IsConstructor)
{
continue;
}
methodDef.Body.SimplifyBranches();
for (int j = 0; j < methodDef.Body.Instructions.Count; j++)
{
iMutation iMutation2 = Tasks[Methods.Random.Next(Tasks.Count)];
if (iMutation2.Supported(methodDef.Body.Instructions[j]))
{
iMutation2.Process(methodDef, ref j);
}
}
}
}
}
}
@@ -0,0 +1,34 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class StringLen : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
if (method.DeclaringType == method.Module.GlobalType)
{
index--;
return;
}
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
int num = Methods.Random.Next(4, 15);
string operand = Methods.GenerateString((byte)num);
method.Body.Instructions[index].OpCode = OpCodes.Ldc_I4;
method.Body.Instructions[index].Operand = ldcI4Value - num;
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldstr, operand));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Call, method.Module.Import(typeof(string).GetMethod("get_Length"))));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Add));
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
+27
View File
@@ -0,0 +1,27 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Mutation2;
public class Sub : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
int num = Methods.Random.Next((int)((double)ldcI4Value / 1.5));
method.Body.Instructions[index].OpCode = OpCodes.Ldc_I4;
method.Body.Instructions[index].Operand = ldcI4Value + num;
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Ldc_I4, num));
method.Body.Instructions.Insert(++index, new Instruction(OpCodes.Sub));
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
+19
View File
@@ -0,0 +1,19 @@
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Mutation2;
public class Utils
{
public static bool CheckArithmetic(Instruction instruction)
{
if (!instruction.IsLdcI4())
{
return false;
}
if (instruction.GetLdcI4Value() <= 1)
{
return false;
}
return true;
}
}
@@ -0,0 +1,27 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Mutation2;
public class VariableMutation : iMutation
{
public void Prepare(TypeDef type)
{
}
public void Process(MethodDef method, ref int index)
{
int ldcI4Value = method.Body.Instructions[index].GetLdcI4Value();
Local local = new Local(method.Module.CorLibTypes.Int32);
method.Body.Variables.Add(local);
method.Body.Instructions.Insert(0, new Instruction(OpCodes.Stloc, local));
method.Body.Instructions.Insert(0, new Instruction(OpCodes.Ldc_I4, ldcI4Value));
index += 2;
method.Body.Instructions[index] = new Instruction(OpCodes.Ldloc, local);
}
public bool Supported(Instruction instr)
{
return Utils.CheckArithmetic(instr);
}
}
@@ -0,0 +1,13 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Mutation2;
public interface iMutation
{
void Process(MethodDef method, ref int index);
void Prepare(TypeDef type);
bool Supported(Instruction instr);
}