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++;
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #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 + (System.Math.Abs(y) * -1));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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