118 lines
5.1 KiB
C#
118 lines
5.1 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: MindLated.Protection.Arithmetic.Arithmetic
|
|
// Assembly: Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
|
// MVID: 33673F0A-7F43-4A2B-BC08-8E59A15CB7DA
|
|
// Assembly location: C:\Users\Admin\Desktop\Sheet RAT 2.5\Server.exe
|
|
|
|
using dnlib.DotNet;
|
|
using dnlib.DotNet.Emit;
|
|
using MindLated.Protection.Arithmetic.Functions;
|
|
using MindLated.Protection.Arithmetic.Functions.Maths;
|
|
using MindLated.Protection.Arithmetic.Utils;
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
//#nullable disable
|
|
namespace MindLated.Protection.Arithmetic {
|
|
|
|
public static class Arithmetic
|
|
{
|
|
private static ModuleDef _moduleDef1;
|
|
public static readonly List<Function> Tasks = new List<Function>()
|
|
{
|
|
(Function) new Add(),
|
|
(Function) new Sub(),
|
|
(Function) new Div(),
|
|
(Function) new Mul(),
|
|
(Function) new Xor(),
|
|
(Function) new Abs(),
|
|
(Function) new Log(),
|
|
(Function) new Log10(),
|
|
(Function) new Sin(),
|
|
(Function) new Cos(),
|
|
(Function) new Floor(),
|
|
(Function) new Round(),
|
|
(Function) new Tan(),
|
|
(Function) new Tanh(),
|
|
(Function) new Sqrt(),
|
|
(Function) new Ceiling(),
|
|
(Function) new Truncate()
|
|
};
|
|
|
|
public static void Execute(ModuleDef module)
|
|
{
|
|
MindLated.Protection.Arithmetic.Arithmetic._moduleDef1 = module;
|
|
MindLated.Protection.Arithmetic.Generator.Generator generator = new MindLated.Protection.Arithmetic.Generator.Generator();
|
|
foreach (TypeDef type in (IEnumerable<TypeDef>) module.Types)
|
|
{
|
|
foreach (MethodDef method in (IEnumerable<MethodDef>) type.Methods)
|
|
{
|
|
if (method.HasBody && !method.DeclaringType.IsGlobalModuleType)
|
|
{
|
|
for (int index = 0; index < method.Body.Instructions.Count; ++index)
|
|
{
|
|
if (ArithmeticUtils.CheckArithmetic(method.Body.Instructions[index]))
|
|
{
|
|
if (method.Body.Instructions[index].GetLdcI4Value() < 0)
|
|
{
|
|
List<Instruction> body = MindLated.Protection.Arithmetic.Arithmetic.GenerateBody(MindLated.Protection.Arithmetic.Arithmetic.Tasks[generator.Next(5)].Arithmetic(method.Body.Instructions[index], module));
|
|
method.Body.Instructions[index].OpCode = OpCodes.Nop;
|
|
foreach (Instruction instruction in body)
|
|
{
|
|
method.Body.Instructions.Insert(index + 1, instruction);
|
|
++index;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<Instruction> body = MindLated.Protection.Arithmetic.Arithmetic.GenerateBody(MindLated.Protection.Arithmetic.Arithmetic.Tasks[generator.Next(MindLated.Protection.Arithmetic.Arithmetic.Tasks.Count)].Arithmetic(method.Body.Instructions[index], module));
|
|
method.Body.Instructions[index].OpCode = OpCodes.Nop;
|
|
foreach (Instruction instruction in body)
|
|
{
|
|
method.Body.Instructions.Insert(index + 1, instruction);
|
|
++index;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static List<Instruction> GenerateBody(ArithmeticVt arithmeticVTs)
|
|
{
|
|
List<Instruction> body = new List<Instruction>();
|
|
if (MindLated.Protection.Arithmetic.Arithmetic.IsArithmetic(arithmeticVTs.GetArithmetic()))
|
|
{
|
|
body.Add(new Instruction(OpCodes.Ldc_R8, (object) arithmeticVTs.GetValue().GetX()));
|
|
body.Add(new Instruction(OpCodes.Ldc_R8, (object) arithmeticVTs.GetValue().GetY()));
|
|
if (arithmeticVTs.GetToken().GetOperand() != null)
|
|
body.Add(new Instruction(OpCodes.Call, arithmeticVTs.GetToken().GetOperand()));
|
|
body.Add(new Instruction(arithmeticVTs.GetToken().GetOpCode()));
|
|
body.Add(new Instruction(OpCodes.Call, (object) MindLated.Protection.Arithmetic.Arithmetic._moduleDef1.Import((MethodBase) typeof (Convert).GetMethod("ToInt32", new Type[1]
|
|
{
|
|
typeof (double)
|
|
}))));
|
|
}
|
|
else if (MindLated.Protection.Arithmetic.Arithmetic.IsXor(arithmeticVTs.GetArithmetic()))
|
|
{
|
|
body.Add(new Instruction(OpCodes.Ldc_I4, (object) (int) arithmeticVTs.GetValue().GetX()));
|
|
body.Add(new Instruction(OpCodes.Ldc_I4, (object) (int) arithmeticVTs.GetValue().GetY()));
|
|
body.Add(new Instruction(arithmeticVTs.GetToken().GetOpCode()));
|
|
body.Add(new Instruction(OpCodes.Conv_I4));
|
|
}
|
|
return body;
|
|
}
|
|
|
|
private static bool IsArithmetic(ArithmeticTypes arithmetic)
|
|
{
|
|
return arithmetic == ArithmeticTypes.Add || arithmetic == ArithmeticTypes.Sub || arithmetic == ArithmeticTypes.Div || arithmetic == ArithmeticTypes.Mul || arithmetic == ArithmeticTypes.Abs || arithmetic == ArithmeticTypes.Log || arithmetic == ArithmeticTypes.Log10 || arithmetic == ArithmeticTypes.Truncate || arithmetic == ArithmeticTypes.Sin || arithmetic == ArithmeticTypes.Cos || arithmetic == ArithmeticTypes.Floor || arithmetic == ArithmeticTypes.Round || arithmetic == ArithmeticTypes.Tan || arithmetic == ArithmeticTypes.Tanh || arithmetic == ArithmeticTypes.Sqrt || arithmetic == ArithmeticTypes.Ceiling;
|
|
}
|
|
|
|
private static bool IsXor(ArithmeticTypes arithmetic) => arithmetic == ArithmeticTypes.Xor;
|
|
}
|
|
}
|