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
+52
View File
@@ -0,0 +1,52 @@
using System;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.IntProtect;
internal class Int
{
public static void Execute(ModuleDef moduleDef)
{
foreach (TypeDef type in moduleDef.GetTypes())
{
if (type.IsGlobalModuleType)
{
continue;
}
foreach (MethodDef method in type.Methods)
{
if (!method.HasBody)
{
continue;
}
for (int i = 0; i < method.Body.Instructions.Count; i++)
{
if (method.Body.Instructions[i].IsLdcI4())
{
int num = new Random(Guid.NewGuid().GetHashCode()).Next();
int num2 = new Random(Guid.NewGuid().GetHashCode()).Next();
int value = num ^ num2;
Instruction instruction = OpCodes.Nop.ToInstruction();
Local local = new Local(method.Module.ImportAsTypeSig(typeof(int)));
method.Body.Variables.Add(local);
method.Body.Instructions.Insert(i + 1, OpCodes.Stloc.ToInstruction(local));
method.Body.Instructions.Insert(i + 2, Instruction.Create(OpCodes.Ldc_I4, method.Body.Instructions[i].GetLdcI4Value() - 4));
method.Body.Instructions.Insert(i + 3, Instruction.Create(OpCodes.Ldc_I4, num));
method.Body.Instructions.Insert(i + 4, Instruction.Create(OpCodes.Ldc_I4, value));
method.Body.Instructions.Insert(i + 5, Instruction.Create(OpCodes.Xor));
method.Body.Instructions.Insert(i + 6, Instruction.Create(OpCodes.Ldc_I4, num2));
method.Body.Instructions.Insert(i + 7, Instruction.Create(OpCodes.Bne_Un, instruction));
method.Body.Instructions.Insert(i + 8, Instruction.Create(OpCodes.Ldc_I4, 2));
method.Body.Instructions.Insert(i + 9, OpCodes.Stloc.ToInstruction(local));
method.Body.Instructions.Insert(i + 10, Instruction.Create(OpCodes.Sizeof, method.Module.Import(typeof(float))));
method.Body.Instructions.Insert(i + 11, Instruction.Create(OpCodes.Add));
method.Body.Instructions.Insert(i + 12, instruction);
i += 12;
}
}
method.Body.SimplifyBranches();
}
}
}
}
@@ -0,0 +1,105 @@
using System;
using System.Security.Cryptography;
using System.Text;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Obfuscator.Obfuscator.IntProtect;
internal static class IntEncoding
{
private static readonly RandomNumberGenerator csp = RandomNumberGenerator.Create();
public static int Next(int minValue = 0, int maxValue = int.MaxValue)
{
if (minValue >= maxValue)
{
throw new ArgumentOutOfRangeException("minValue");
}
long num = (long)maxValue - (long)minValue;
long num2 = uint.MaxValue / num * num;
uint num3;
do
{
num3 = RandomUInt();
}
while (num3 >= num2);
return (int)(minValue + num3 % num);
}
public static string GenerateRandomString(int length)
{
byte[] bytes = RandomBytes(length);
return Encoding.UTF7.GetString(bytes).Replace("\0", ".").Replace("\n", ".")
.Replace("\r", ".");
}
public static int GetRandomStringLength()
{
return Next(30, 120);
}
public static int GetRandomInt32()
{
return BitConverter.ToInt32(RandomBytes(4), 0);
}
private static uint RandomUInt()
{
return BitConverter.ToUInt32(RandomBytes(4), 0);
}
private static byte[] RandomBytes(int bytes)
{
byte[] array = new byte[bytes];
csp.GetBytes(array);
return array;
}
public static void Execute(ModuleDef moduleDef)
{
IMethod method = moduleDef.Import(typeof(Math).GetMethod("Abs", new Type[1] { typeof(int) }));
IMethod method2 = moduleDef.Import(typeof(Math).GetMethod("Min", new Type[2]
{
typeof(int),
typeof(int)
}));
foreach (TypeDef type in moduleDef.Types)
{
if (type.IsGlobalModuleType)
{
continue;
}
foreach (MethodDef method3 in type.Methods)
{
if (!method3.HasBody)
{
continue;
}
for (int i = 0; i < method3.Body.Instructions.Count; i++)
{
if (method3.Body.Instructions[i].Operand is int num && num > 0)
{
method3.Body.Instructions.Insert(i + 1, OpCodes.Call.ToInstruction(method));
int num2 = Next(8, GetRandomStringLength());
if (num2 % 2 != 0)
{
num2++;
}
for (int j = 0; j < num2; j++)
{
method3.Body.Instructions.Insert(i + j + 1, Instruction.Create(OpCodes.Neg));
}
if (num < int.MaxValue)
{
method3.Body.Instructions.Insert(i + 1, OpCodes.Ldc_I4.ToInstruction(int.MaxValue));
method3.Body.Instructions.Insert(i + 2, OpCodes.Call.ToInstruction(method2));
}
i += num2 + 2;
}
}
method3.Body.SimplifyBranches();
}
}
}
}