コード例 #1
0
ファイル: InstructionGroups.cs プロジェクト: xHeaven/Isolated
        public void Scramble(out InstructionGroups incGroups)
        {
            InstructionGroups instructionGroups = new InstructionGroups();

            foreach (InstructionGroup item in this)
            {
                instructionGroups.Insert(InstructionGroups.r.Next(0, instructionGroups.Count), item);
            }
            incGroups = instructionGroups;
        }
コード例 #2
0
ファイル: controlflow.cs プロジェクト: xHeaven/Isolated
        public static void processMethod1(MethodDef method)
        {
            method.Body.SimplifyBranches();
            InstructionGroups instructionGroups = new InstructionGroups();
            InstructionGroup  instructionGroup  = new InstructionGroup();
            int  num  = 0;
            int  num2 = 0;
            bool flag = false;

            foreach (Instruction instruction in method.Body.Instructions)
            {
                int num3 = 0;
                int num4;
                instruction.CalculateStackUsage(out num4, out num3);
                instructionGroup.Add(instruction);
                num2 += num4 - num3;
                if (num4 == 0 && instruction.OpCode != OpCodes.Nop && (num2 == 0 || instruction.OpCode == OpCodes.Ret))
                {
                    if (!flag)
                    {
                        InstructionGroup instructionGroup2 = new InstructionGroup();
                        instructionGroup2.ID        = num++;
                        instructionGroup2.nextGroup = instructionGroup2.ID + 1;
                        instructionGroups.Add(instructionGroup2);
                        instructionGroup2           = new InstructionGroup();
                        instructionGroup2.ID        = num++;
                        instructionGroup2.nextGroup = instructionGroup2.ID + 1;
                        instructionGroups.Add(instructionGroup2);
                        flag = true;
                    }
                    instructionGroup.ID        = num++;
                    instructionGroup.nextGroup = instructionGroup.ID + 1;
                    instructionGroups.Add(instructionGroup);
                    instructionGroup = new InstructionGroup();
                }
            }
            if (instructionGroups.Count == 1)
            {
                return;
            }
            InstructionGroup last = instructionGroups.getLast();

            instructionGroups.Scramble(out instructionGroups);
            method.Body.Instructions.Clear();
            Local local = new Local(controlflow.asm.CorLibTypes.Int32);

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

            method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4_0));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Stloc, local));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Br, instruction3));
            method.Body.Instructions.Add(instruction2);
            foreach (InstructionGroup instructionGroup3 in instructionGroups)
            {
                if (instructionGroup3 != last)
                {
                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldloc, local));
                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4, instructionGroup3.ID));
                    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 item in instructionGroup3)
                    {
                        method.Body.Instructions.Add(item);
                    }
                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4, instructionGroup3.nextGroup));
                    method.Body.Instructions.Add(Instruction.Create(OpCodes.Stloc, local));
                    method.Body.Instructions.Add(instruction4);
                }
            }
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldloc, local));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4, instructionGroups.Count - 1));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Ceq));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Brfalse, instruction3));
            method.Body.Instructions.Add(Instruction.Create(OpCodes.Br, last[0]));
            method.Body.Instructions.Add(instruction3);
            foreach (Instruction item2 in last)
            {
                method.Body.Instructions.Add(item2);
            }
            method.Body.OptimizeBranches();
            method.Body.OptimizeMacros();
        }