protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
 {
     foreach (ModuleDef module in parameters.Targets.OfType <ModuleDef>())
     {
         CFHelper cFHelper = new CFHelper();
         foreach (TypeDef type in module.Types)
         {
             foreach (MethodDef method in type.Methods)
             {
                 if (method.HasBody && method.Body.Instructions.Count > 0 && !method.IsConstructor)
                 {
                     if (!cFHelper.HasUnsafeInstructions(method))
                     {
                         if (DnlibUtils2.Simplify(method))
                         {
                             Blockss blocks = cFHelper.GetBlocks(method);
                             if (blocks.blocks.Count != 1)
                             {
                                 Run(cFHelper, method, blocks, context);
                             }
                             DnlibUtils2.Optimize(method);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void Run(CFHelper cFHelper, MethodDef method, Blocks blocks, ConfuserContext context)
        {
            blocks.Scramble(out blocks);
            method.Body.Instructions.Clear();
            Local local = new Local(context.CurrentModule.CorLibTypes.Int32);

            method.Body.Variables.Add(local);
            Instruction target = Instruction.Create(OpCodes.Nop);
            Instruction instr  = Instruction.Create(OpCodes.Br, target);

            foreach (Instruction instruction in cFHelper.Calc(0))
            {
                method.Body.Instructions.Add(instruction);
            }

            method.Body.Instructions.Add(Instruction.Create(OpCodes.Stloc, local));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Br, instr));
            method.Body.Instructions.Add(target);
            foreach (Block block in blocks.blocks)
            {
                if (block != blocks.getBlock((blocks.blocks.Count - 1)))
                {
                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldloc, local));
                    foreach (Instruction instruction in cFHelper.Calc(block.ID))
                    {
                        method.Body.Instructions.Add(instruction);
                    }

                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Ceq));
                    Instruction instruction4 = Instruction.Create(OpCodes.Nop);
                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Brfalse, instruction4));
                    foreach (Instruction instruction in block.instructions)
                    {
                        method.Body.Instructions.Add(instruction);
                    }

                    foreach (Instruction instruction in cFHelper.Calc(block.nextBlock))
                    {
                        method.Body.Instructions.Add(instruction);
                    }

                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Stloc, local));
                    method.Body.Instructions.Add(instruction4);
                }
            }
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldloc, local));
            foreach (Instruction instruction in cFHelper.Calc(blocks.blocks.Count - 1))
            {
                method.Body.Instructions.Add(instruction);
            }

            method.Body.Instructions.Add(Instruction.Create(OpCodes.Ceq));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Brfalse, instr));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Br, blocks.getBlock((blocks.blocks.Count - 1)).instructions[0]));
            method.Body.Instructions.Add(instr);
            foreach (Instruction lastBlock in blocks.getBlock((blocks.blocks.Count - 1)).instructions)
            {
                method.Body.Instructions.Add(lastBlock);
            }
        }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            var other = obj as Person2;

            if (null == other)
            {
                return(false);
            }
            return(CFHelper.AreEqual(_name, other._name));
        }
Ejemplo n.º 4
0
        public ERROR Loadmovies()
        {
            try
            {
                movieList = (List <Movie>)CFHelper.LoadData(Application.dataPath + "/ModuleRemote/movieConfig.xml", typeof(List <Movie>));
            }
            catch (System.Exception e)
            {
                Remote.Instance().Log(e.ToString());
                return(ERROR.EXCEPTION);
            }

            return(ERROR.OK);
        }
Ejemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         List <Movie> list = new List <Movie>();
         list.Add(new Movie
         {
             Name = "m1",
             Path = Application.dataPath + @"/ModuleRemote/Resources/captain.jpg"
         });
         list.Add(new Movie
         {
             Name = "m2",
             Path = Application.dataPath + @"/ModuleRemote/Resources/ironman.jpg"
         });
         list.Add(new Movie
         {
             Name = "m3",
             Path = Application.dataPath + @"/ModuleRemote/Resources/spider.jpg"
         });
         CFHelper.SaveData(Application.dataPath + @"/movieConfig.xml", list);
         Debug.Log("done");
     }
 }
Ejemplo n.º 6
0
    public static string WhoIsWinner(List <string> piecesPositionList)
    {
        // retrun "Red" or "Yellow" or "Draw"
        Console.WriteLine(string.Join("\n", piecesPositionList.ToArray()));
        CFHelper game  = new CFHelper();
        Regex    regex = new Regex(@"^(?<c>[a-g])_(?<p>Red|Yellow)", RegexOptions.IgnoreCase | RegexOptions.Compiled);

        foreach (var ln in piecesPositionList)
        {
            Match match;
            if ((match = regex.Match(ln)).Success)
            {
                char   ch  = Char.ToUpper(match.Groups["c"].Value[0]);
                Player p   = (Player)Enum.Parse(typeof(Player), match.Groups["p"].Value, true);
                Player res = game.DropAndCheck(ch, p);
                if (res == Player.Red || res == Player.Yellow)
                {
                    return(res.ToString());
                }
            }
        }

        /*
         * Player[,] board = game.GetBoard();
         * StringBuilder buffer = new StringBuilder();
         * for (int i = 0; i < board.GetLength(0); i++)
         * {
         *      for (int j = 0; j < board.GetLength(1); j++)
         *      {
         *              buffer.Append(' ').Append(board[i, j].ToString()[0]);
         *      }
         *      buffer.Append('\n');
         * }
         * Console.WriteLine(buffer.ToString());
         * for (int i = 0; i < board.GetLength(0); i++)
         * {
         *      for (int j = 0; j < board.GetLength(1); j++)
         *      {
         *              Player p;
         *              if (j < (board.GetLength(1) - 3))
         *              {
         *                      // check row
         *                      p = CFHelper.CheckRow(i, j, board);
         *                      if (p == Player.Red || p == Player.Yellow)
         *                              return p.ToString();
         *                      if (i < (board.GetLength(0) - 3))
         *                      {
         *                              // check column, check diag fwd
         *                              p = CFHelper.CheckCol(i, j, board);
         *                              if (p == Player.Red || p == Player.Yellow)
         *                                      return p.ToString();
         *                              p = CFHelper.CheckDiagFwd(i, j, board);
         *                              if (p == Player.Red || p == Player.Yellow)
         *                                      return p.ToString();
         *                      }
         *              }
         *              if (i < (board.GetLength(0) - 3) && j >= 3)
         *              {
         *                      // check diag back
         *                      p = CFHelper.CheckDiagBack(i, j, board);
         *                      if (p == Player.Red || p == Player.Yellow)
         *                              return p.ToString();
         *              }
         *      }
         * }
         */
        return("Draw");
    }