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 double GetValue(List <ArithmeticTypes> arithmetics) { var generator = new Generator.Generator(); var 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); }