Exemplo n.º 1
0
        void createExitBranch(BasicBlock deadCodeBasicBlock)
        {
            // Exit the function at this dead code block while also returning a sane local as return value.
            var exitBranch = new ExitBranchTarget();

            exitBranch.sourceBasicBlock   = deadCodeBasicBlock;
            deadCodeBasicBlock.exitBranch = exitBranch;

            if (methodCfg.method.Type.ToString() != "System.Void")
            {
                var locals = getSuitableLocals(methodCfg.method.Type.ToString());
                if (locals.Count() == 0)
                {
                    // TODO: Actually support the return here (e.g., by adding proper locals).
                    throw new ArgumentException("Cannot yet handle creation of exit branches for non-void methods without" +
                                                " suitable locals.");
                }

                int index = prng.Next(locals.Count());
                var local = methodCfg.method.Body.LocalVariables.ElementAt(index);

                deadCodeBasicBlock.operations.Add(createNewOperation(OperationCode.Ldloc, local));
            }

            deadCodeBasicBlock.operations.Add(createNewOperation(OperationCode.Ret));
        }
Exemplo n.º 2
0
        public CodeMutator(IModule module, PeReader.DefaultHost host, Log.Log logger, Random prng, MethodCfg methodCfg,
                           CfgManipulator manipulator, bool debugging = false)
        {
            this.host        = host;
            this.logger      = logger;
            this.module      = module;
            this.prng        = prng;
            this.methodCfg   = methodCfg;
            this.debugging   = debugging;
            this.manipulator = manipulator;

            returnBlock = new BasicBlock();
            var exitBranch = new ExitBranchTarget();

            returnBlock.exitBranch = exitBranch;
            returnBlock.operations.Add(createNewOperation(OperationCode.Ret));

            methodCfg.basicBlocks.Add(returnBlock);
        }