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;
             }
             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++;
                         }
                     }
                 }
             }
         }
     }
 }
예제 #2
0
        public double GetValue(List <ArithmeticTypes> arithmetics)
        {
            Generator.Generator generator  = new Generator.Generator();
            ArithmeticTypes     arithmetic = arithmetics[generator.Next(arithmetics.Count)];

            GetType = arithmetic;
            switch (ArithmeticTypes)
            {
            case ArithmeticTypes.Abs:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x + (Math.Abs(y) * -1));

                case ArithmeticTypes.Sub:
                    return(x - (Math.Abs(y) * -1));
                }
                return(-1);

            case ArithmeticTypes.Log:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Log(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Log(y)));
                }
                return(-1);

            case ArithmeticTypes.Log10:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Log10(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Log10(y)));
                }
                return(-1);

            case ArithmeticTypes.Sin:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Sin(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Sin(y)));
                }
                return(-1);

            case ArithmeticTypes.Cos:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Cos(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Cos(y)));
                }
                return(-1);

            case ArithmeticTypes.Floor:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Floor(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Floor(y)));
                }
                return(-1);

            case ArithmeticTypes.Round:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Round(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Round(y)));
                }
                return(-1);

            case ArithmeticTypes.Tan:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Tan(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Tan(y)));
                }
                return(-1);

            case ArithmeticTypes.Tanh:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Tanh(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Tanh(y)));
                }
                return(-1);

            case ArithmeticTypes.Sqrt:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Sqrt(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Sqrt(y)));
                }
                return(-1);

            case ArithmeticTypes.Ceiling:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Ceiling(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Ceiling(y)));
                }
                return(-1);

            case ArithmeticTypes.Truncate:
                switch (arithmetic)
                {
                case ArithmeticTypes.Add:
                    return(x - (Math.Truncate(y)));

                case ArithmeticTypes.Sub:
                    return(x + (Math.Truncate(y)));
                }
                return(-1);
            }
            return(-1);
        }