Ejemplo n.º 1
0
        /// <summary>
        /// Remove all instances of codeBlockToFind from instructions.
        /// </summary>
        /// <param name="codeBlockToFind">Code block to remove for in instructions list</param>
        /// <remarks>This method removes entry nop and void return from codeBlockToFind statements</remarks>
        public void RemoveCodeBlock(MethodInfo codeBlockToRemove)
        {
            List <CodeInstruction> instructionsToFind = MethodToILInstructions(codeBlockToRemove);

            instructionsToFind = MethodCleaner.RemoveEntryAndReturn(instructionsToFind);

            ReplaceInstancesInList(instructionsToFind, new List <CodeInstruction>());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Replaces all instances of codeBlockToFind with replacementCodeBlock.
        /// </summary>
        /// <param name="codeBlockToFind"></param>
        /// <param name="replacementCodeBlock"></param>
        public void ReplaceAllCodeBlocks(MethodInfo codeBlockToFind, MethodInfo replacementCodeBlock)
        {
            List <CodeInstruction> instructionsToFind     = MethodToILInstructions(codeBlockToFind);
            List <CodeInstruction> instructionReplacement = MethodToILInstructions(replacementCodeBlock);

            instructionsToFind     = MethodCleaner.RemoveEntryAndReturn(instructionsToFind);
            instructionReplacement = MethodCleaner.RemoveEntryAndReturn(instructionReplacement);

            ReplaceInstancesInList(instructionsToFind, instructionReplacement);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Places additional CodeBlock statements before all instances of codeBlockToFind statements.
        /// </summary>
        /// <param name="codeBlockToFind">Code block to search for in instructions list</param>
        /// <param name="additionCodeBlock">Code block to add in instructions list</param>
        /// <remarks>This method removes entry nop and void return from additionCodeBlock statements</remarks>
        public void AddCodeBlockBefore(MethodInfo codeBlockToFind, MethodInfo additionCodeBlock)
        {
            List <CodeInstruction> instructionsToFind  = MethodToILInstructions(codeBlockToFind);
            List <CodeInstruction> instructionAddition = MethodToILInstructions(additionCodeBlock);

            instructionsToFind  = MethodCleaner.RemoveEntryAndReturn(instructionsToFind);
            instructionAddition = MethodCleaner.RemoveEntryAndReturn(instructionAddition);

            instructionAddition.InsertRange(0, instructionsToFind);

            ReplaceInstancesInList(instructionsToFind, instructionAddition);
        }