Exemple #1
0
        public Arithmetic(ModuleDef moduleDef)
        {
            moduleDef1 = moduleDef;
            Generator generator = new Generator();

            foreach (TypeDef tDef in moduleDef.Types)
            {
                foreach (MethodDef mDef in tDef.Methods)
                {
                    if (!mDef.HasBody)
                    {
                        continue;
                    }
                    if (mDef.DeclaringType.IsGlobalModuleType)
                    {
                        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++;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public override ArithmeticVT Arithmetic(Instruction instruction, ModuleDef module)
        {
            Generator generator = new Generator();

            if (!ArithmeticUtils.CheckArithmetic(instruction))
            {
                return(null);
            }
            ArithmeticEmulator arithmeticEmulator = new ArithmeticEmulator(instruction.GetLdcI4Value(), ArithmeticUtils.GetY(instruction.GetLdcI4Value()), ArithmeticTypes);

            return(new ArithmeticVT(new Value(arithmeticEmulator.GetValue(), arithmeticEmulator.GetY()), new Token(OpCodes.Sub), ArithmeticTypes));
        }
Exemple #3
0
        public override ArithmeticVT Arithmetic(Instruction instruction, ModuleDef module)
        {
            Generator generator = new Generator();

            if (!ArithmeticUtils.CheckArithmetic(instruction))
            {
                return(null);
            }
            List <ArithmeticTypes> arithmeticTypes = new List <ArithmeticTypes>()
            {
                ArithmeticTypes.Add, ArithmeticTypes.Sub
            };
            ArithmeticEmulator 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));
        }