public override ArithmeticVT Arithmetic(Instruction instruction, ModuleDef module) { if (!ArithmeticUtils.CheckArithmetic(instruction)) return null; var arithmeticTypes = new List<ArithmeticTypes> { ArithmeticTypes.Add, ArithmeticTypes.Sub }; var arithmeticEmulator = new ArithmeticEmulator(instruction.GetLdcI4Value(), ArithmeticUtils.GetY(instruction.GetLdcI4Value()), ArithmeticTypes); return (new ArithmeticVT(new Value(arithmeticEmulator.GetValue(arithmeticTypes), arithmeticEmulator.GetY()), new Token(ArithmeticUtils.GetOpCode(arithmeticEmulator.GetType), module.Import(ArithmeticUtils.GetMethod(ArithmeticTypes))), ArithmeticTypes)); }
public static void Execute(ModuleDef moduleDef) { moduleDef1 = moduleDef; var generator = new Generator.Generator(); foreach (var tDef in moduleDef.Types) { foreach (var mDef in tDef.Methods) { if (!mDef.HasBody) { continue; } if (mDef.DeclaringType.IsGlobalModuleType) { continue; } for (var i = 0; i < mDef.Body.Instructions.Count; i++) { if (!ArithmeticUtils.CheckArithmetic(mDef.Body.Instructions[i])) { continue; } if (mDef.Body.Instructions[i].GetLdcI4Value() < 0) { var iFunction = Tasks[generator.Next(5)]; var lstInstr = GenerateBody(iFunction.Arithmetic(mDef.Body.Instructions[i], moduleDef)); if (lstInstr == null) { continue; } mDef.Body.Instructions[i].OpCode = OpCodes.Nop; foreach (var instr in lstInstr) { mDef.Body.Instructions.Insert(i + 1, instr); i++; } } else { var iFunction = Tasks[generator.Next(Tasks.Count)]; var lstInstr = GenerateBody(iFunction.Arithmetic(mDef.Body.Instructions[i], moduleDef)); if (lstInstr == null) { continue; } mDef.Body.Instructions[i].OpCode = OpCodes.Nop; foreach (var instr in lstInstr) { mDef.Body.Instructions.Insert(i + 1, instr); i++; } } } } } }
public override ArithmeticVT Arithmetic(Instruction instruction, ModuleDef module) { if (!ArithmeticUtils.CheckArithmetic(instruction)) { return(null); } var arithmeticEmulator = new ArithmeticEmulator(instruction.GetLdcI4Value(), ArithmeticUtils.GetY(instruction.GetLdcI4Value()), ArithmeticTypes); return(new ArithmeticVT(new Value(arithmeticEmulator.GetValue(), arithmeticEmulator.GetY()), new Token(OpCodes.Div), ArithmeticTypes)); }
public override ArithmeticVT Arithmetic(Instruction instruction, ModuleDef module) { Generator.Generator generator = new Generator.Generator(); if (!ArithmeticUtils.CheckArithmetic(instruction)) { return(null); } ArithmeticEmulator arithmeticEmulator = new ArithmeticEmulator(instruction.GetLdcI4Value(), generator.Next(), ArithmeticTypes); return(new ArithmeticVT(new Value(arithmeticEmulator.GetValue(), arithmeticEmulator.GetY()), new Token(OpCodes.Xor), ArithmeticTypes)); }
public Arithmetic(ModuleDef moduleDef) { moduleDef1 = moduleDef; Generator.Generator generator = new Generator.Generator(); foreach (TypeDef tDef in moduleDef.Types) { foreach (MethodDef mDef in tDef.Methods) { if (!mDef.HasBody) { continue; } for (int i = 0; i < mDef.Body.Instructions.Count; i++) { if (ArithmeticUtils.CheckArithmetic(mDef.Body.Instructions[i])) { if (mDef.Body.Instructions[i].GetLdcI4Value() < 0) { iFunction iFunction = Tasks[generator.Next(5)]; List <Instruction> lstInstr = GenerateBody(iFunction.Arithmetic(mDef.Body.Instructions[i], moduleDef)); if (lstInstr == null) { continue; } mDef.Body.Instructions[i].OpCode = OpCodes.Nop; foreach (Instruction instr in lstInstr) { mDef.Body.Instructions.Insert(i + 1, instr); i++; } } else { iFunction iFunction = Tasks[generator.Next(Tasks.Count)]; List <Instruction> lstInstr = GenerateBody(iFunction.Arithmetic(mDef.Body.Instructions[i], moduleDef)); if (lstInstr == null) { continue; } mDef.Body.Instructions[i].OpCode = OpCodes.Nop; foreach (Instruction instr in lstInstr) { mDef.Body.Instructions.Insert(i + 1, instr); i++; } } } } } } }
void IProtector.ProtectionPhase(Context krawk) { Generator.Generator generator = new Generator.Generator(); foreach (TypeDef tDef in krawk.ManifestModule.Types) { foreach (MethodDef mDef in tDef.Methods) { if (!mDef.HasBody) { continue; } for (int i = 0; i < mDef.Body.Instructions.Count; i++) { if (ArithmeticUtils.CheckArithmetic(mDef.Body.Instructions[i])) { if (mDef.Body.Instructions[i].GetLdcI4Value() < 0) { iFunction iFunction = Tasks[generator.Next(5)]; List <Instruction> lstInstr = GenerateBody(iFunction.Arithmetic(mDef.Body.Instructions[i], krawk.ManifestModule), krawk); if (lstInstr == null) { continue; } mDef.Body.Instructions[i].OpCode = OpCodes.Nop; foreach (Instruction instr in lstInstr) { mDef.Body.Instructions.Insert(i + 1, instr); i++; } } else { iFunction iFunction = Tasks[generator.Next(Tasks.Count)]; List <Instruction> lstInstr = GenerateBody(iFunction.Arithmetic(mDef.Body.Instructions[i], krawk.ManifestModule), krawk); if (lstInstr == null) { continue; } mDef.Body.Instructions[i].OpCode = OpCodes.Nop; foreach (Instruction instr in lstInstr) { mDef.Body.Instructions.Insert(i + 1, instr); i++; } } } } } } }