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
@@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Obfuscator.Obfuscator.Proxy;
public static class EnumerableExtensions
{
public static T Random<T>(this IEnumerable<T> input)
{
return EnumerableHelper.Random(input);
}
}
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Obfuscator.Obfuscator.Proxy;
public static class EnumerableHelper
{
private static readonly Random R;
static EnumerableHelper()
{
R = new Random();
}
public static TE Random<TE>(IEnumerable<TE> input)
{
TE[] array = (input as TE[]) ?? input.ToArray();
return array.ElementAt(R.Next(array.Length));
}
}
+120
View File
@@ -0,0 +1,120 @@
using System.Linq;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Proxy;
public class ProxyCall
{
private static bool Analyse(ModuleDef module, MethodDef method)
{
if (method.FullName.ToLower().Contains("get_") || method.FullName.ToLower().Contains("get_"))
{
return false;
}
if (method.FullName.ToLower().Contains("datetime"))
{
return false;
}
if (method.Attributes.ToString().Replace("PrivateScope", "").Contains("Private"))
{
method.Attributes = MethodAttributes.Public | MethodAttributes.Static;
}
for (int i = 0; i < method.Body.Instructions.Count(); i++)
{
if (method.Body.Instructions[i].OpCode == OpCodes.Call && method.Body.Instructions[i].Operand is MethodDef)
{
MethodAttributes attributes = ((MethodDef)method.Body.Instructions[i].Operand).Attributes;
if (attributes.ToString().Contains("Private") || !attributes.ToString().Contains("Static"))
{
return false;
}
}
else if (method.Body.Instructions[i].OpCode == OpCodes.Ldsfld && method.Body.Instructions[i].Operand is FieldDef)
{
FieldAttributes attributes2 = ((FieldDef)method.Body.Instructions[i].Operand).Attributes;
if (attributes2.ToString().Contains("Private") || !attributes2.ToString().Contains("Static"))
{
return false;
}
}
}
return true;
}
public static void Execute(ModuleDef module)
{
for (int i = 0; i < Methods.Random.Next(4, 8); i++)
{
foreach (TypeDef type in module.Types)
{
if (type.IsGlobalModuleType)
{
continue;
}
MethodDef[] array = type.Methods.ToArray();
foreach (MethodDef methodDef in array)
{
if (!methodDef.HasBody)
{
continue;
}
for (int k = 0; k < methodDef.Body.Instructions.Count; k++)
{
if (methodDef.Body.Instructions[k].OpCode != OpCodes.Call)
{
continue;
}
try
{
if (!(methodDef.Body.Instructions[k].Operand is MethodDef))
{
continue;
}
MethodDef methodDef2 = methodDef.Body.Instructions[k].Operand as MethodDef;
if (!Analyse(module, methodDef2) || methodDef2.Parameters.Count > 4)
{
continue;
}
MethodDefUser methodDefUser = new MethodDefUser(Methods.GenerateString(16), methodDef2.MethodSig, methodDef2.ImplAttributes, methodDef2.Attributes);
methodDefUser.Body = methodDef2.Body;
foreach (ParamDef paramDef in methodDef2.ParamDefs)
{
methodDefUser.ParamDefs.Add(new ParamDefUser(Methods.GenerateString(10), paramDef.Sequence));
}
CilBody cilBody = new CilBody();
cilBody.Instructions.Add(OpCodes.Nop.ToInstruction());
for (int l = 0; l < methodDef2.Parameters.Count; l++)
{
switch (l)
{
case 0:
cilBody.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
break;
case 1:
cilBody.Instructions.Add(OpCodes.Ldarg_1.ToInstruction());
break;
case 2:
cilBody.Instructions.Add(OpCodes.Ldarg_2.ToInstruction());
break;
case 3:
cilBody.Instructions.Add(OpCodes.Ldarg_3.ToInstruction());
break;
}
}
cilBody.Instructions.Add(OpCodes.Call.ToInstruction(methodDefUser));
cilBody.Instructions.Add(OpCodes.Nop.ToInstruction());
cilBody.Instructions.Add(OpCodes.Ret.ToInstruction());
methodDef2.Body = cilBody;
type.Methods.Add(methodDefUser);
}
catch
{
}
}
}
}
}
}
}
+57
View File
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Proxy;
public static class ProxyInt
{
public static void Execute(ModuleDef module)
{
foreach (TypeDef type in module.GetTypes())
{
if (type.IsGlobalModuleType)
{
continue;
}
foreach (MethodDef method in type.Methods)
{
if (!method.HasBody)
{
continue;
}
IList<Instruction> instructions = method.Body.Instructions;
for (int i = 0; i < instructions.Count; i++)
{
if (method.Body.Instructions[i].IsLdcI4())
{
MethodImplAttributes implFlags = MethodImplAttributes.IL;
MethodAttributes flags = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig;
MethodDefUser methodDefUser = new MethodDefUser(Methods.GenerateString(), MethodSig.CreateStatic(module.CorLibTypes.Int32), implFlags, flags);
module.GlobalType.Methods.Add(methodDefUser);
methodDefUser.Body = new CilBody();
methodDefUser.Body.Variables.Add(new Local(module.CorLibTypes.Int32));
methodDefUser.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4, instructions[i].GetLdcI4Value()));
methodDefUser.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
instructions[i].OpCode = OpCodes.Call;
instructions[i].Operand = methodDefUser;
}
else if (method.Body.Instructions[i].OpCode == OpCodes.Ldc_R4)
{
MethodImplAttributes implFlags2 = MethodImplAttributes.IL;
MethodAttributes flags2 = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig;
MethodDefUser methodDefUser2 = new MethodDefUser(Methods.GenerateString(), MethodSig.CreateStatic(module.CorLibTypes.Double), implFlags2, flags2);
module.GlobalType.Methods.Add(methodDefUser2);
methodDefUser2.Body = new CilBody();
methodDefUser2.Body.Variables.Add(new Local(module.CorLibTypes.Double));
methodDefUser2.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_R4, (float)method.Body.Instructions[i].Operand));
methodDefUser2.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
instructions[i].OpCode = OpCodes.Call;
instructions[i].Operand = methodDefUser2;
}
}
}
}
}
}
+155
View File
@@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.Linq;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.Proxy;
public static class ProxyMeth
{
public static Random rand = new Random();
public static List<MemberRef> MemberRefList = new List<MemberRef>();
public static void ScanMemberRef(ModuleDef module)
{
foreach (TypeDef type in module.Types)
{
foreach (MethodDef method in type.Methods)
{
if (!method.HasBody || !method.Body.HasInstructions)
{
continue;
}
for (int i = 0; i < method.Body.Instructions.Count - 1; i++)
{
if (method.Body.Instructions[i].OpCode != OpCodes.Call)
{
continue;
}
try
{
MemberRef memberRef = (MemberRef)method.Body.Instructions[i].Operand;
if (!memberRef.HasThis)
{
MemberRefList.Add(memberRef);
}
}
catch
{
}
}
}
}
}
public static MethodDef GenerateSwitch(MemberRef original, ModuleDef md)
{
try
{
List<TypeSig> list = original.MethodSig.Params.ToList();
list.Add(md.CorLibTypes.Int32);
MethodImplAttributes implFlags = MethodImplAttributes.IL;
MethodAttributes flags = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig;
MethodDef methodDef = new MethodDefUser($"ProxyMeth{rand.Next(0, int.MaxValue)}", MethodSig.CreateStatic(original.MethodSig.RetType, list.ToArray()), implFlags, flags)
{
Body = new CilBody()
};
methodDef.Body.Variables.Add(new Local(md.CorLibTypes.Int32));
methodDef.Body.Variables.Add(new Local(md.CorLibTypes.Int32));
methodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
List<Instruction> list2 = new List<Instruction>();
Instruction instruction = new Instruction(OpCodes.Switch);
methodDef.Body.Instructions.Add(instruction);
Instruction instruction2 = new Instruction(OpCodes.Br_S);
methodDef.Body.Instructions.Add(instruction2);
for (int i = 0; i < 5; i++)
{
for (int j = 0; j <= original.MethodSig.Params.Count - 1; j++)
{
methodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg, methodDef.Parameters[j]));
if (j == 0)
{
list2.Add(Instruction.Create(OpCodes.Ldarg, methodDef.Parameters[j]));
}
}
Instruction item = Instruction.Create(OpCodes.Ldc_I4, i);
methodDef.Body.Instructions.Add(item);
methodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
}
Instruction instruction3 = Instruction.Create(OpCodes.Ldnull);
methodDef.Body.Instructions.Add(instruction3);
methodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
instruction2.Operand = instruction3;
instruction.Operand = list2;
return methodDef;
}
catch
{
return null;
}
}
public static void Execute(ModuleDef module)
{
ScanMemberRef(module);
foreach (TypeDef type in module.GetTypes())
{
if (type.IsGlobalModuleType)
{
continue;
}
MethodDef[] array = type.Methods.ToArray();
foreach (MethodDef methodDef in array)
{
if (!methodDef.HasBody || methodDef.Name.Contains("ProxyMeth"))
{
continue;
}
IList<Instruction> instructions = methodDef.Body.Instructions;
for (int j = 0; j < instructions.Count; j++)
{
if (methodDef.Body.Instructions[j].OpCode != OpCodes.Call)
{
continue;
}
try
{
MemberRef original = (MemberRef)methodDef.Body.Instructions[j].Operand;
if (original.HasThis)
{
continue;
}
MethodDef methodDef2 = GenerateSwitch(original, module);
methodDef.DeclaringType.Methods.Add(methodDef2);
instructions[j].OpCode = OpCodes.Call;
instructions[j].Operand = methodDef2;
int value = rand.Next(0, 5);
for (int k = 0; k < methodDef2.Body.Instructions.Count - 1; k++)
{
if (methodDef2.Body.Instructions[k].OpCode != OpCodes.Ldc_I4)
{
continue;
}
if (string.Compare(methodDef2.Body.Instructions[k].Operand.ToString(), value.ToString(), StringComparison.Ordinal) != 0)
{
methodDef2.Body.Instructions[k].OpCode = OpCodes.Call;
methodDef2.Body.Instructions[k].Operand = MemberRefList.Where((MemberRef m) => m.MethodSig.Params.Count == original.MethodSig.Params.Count).ToList().Random();
}
else
{
methodDef2.Body.Instructions[k].OpCode = OpCodes.Call;
methodDef2.Body.Instructions[k].Operand = original;
}
}
methodDef.Body.Instructions.Insert(j, Instruction.CreateLdcI4(value));
}
catch
{
}
}
}
}
}
}
@@ -0,0 +1,42 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Obfuscator.Helper;
namespace Obfuscator.Obfuscator.Proxy;
internal class ProxyString
{
public static void Execute(ModuleDef module)
{
foreach (TypeDef type in module.GetTypes())
{
if (type.IsGlobalModuleType)
{
continue;
}
foreach (MethodDef method in type.Methods)
{
if (!method.HasBody)
{
continue;
}
foreach (Instruction instruction in method.Body.Instructions)
{
if (instruction.OpCode == OpCodes.Ldstr)
{
MethodImplAttributes implFlags = MethodImplAttributes.IL;
MethodAttributes flags = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig;
MethodDefUser methodDefUser = new MethodDefUser(Methods.GenerateString(), MethodSig.CreateStatic(module.CorLibTypes.String), implFlags, flags);
module.GlobalType.Methods.Add(methodDefUser);
methodDefUser.Body = new CilBody();
methodDefUser.Body.Variables.Add(new Local(module.CorLibTypes.String));
methodDefUser.Body.Instructions.Add(Instruction.Create(OpCodes.Ldstr, instruction.Operand.ToString()));
methodDefUser.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
instruction.OpCode = OpCodes.Call;
instruction.Operand = methodDefUser;
}
}
}
}
}
}