Exemple #1
0
 public void InjectInCatchBlock(MethodDefinition method, MethodCodeInjectingCodeProviderArgument codeProviderArgument, ILogger logger, MethodInjectionPlace injectionPlace)
 {
     Inject(
         method,
         codeProviderArgument,
         logger, injectionPlace,
         (body, newInstruction, call) => body.AddInstructionsInCatchBlock(newInstruction, call));
 }
Exemple #2
0
        public void Inject(MethodDefinition method, MethodCodeInjectingCodeProviderArgument codeProviderArgument, ILogger logger, MethodInjectionPlace injectionPlace, CustomInstructionsInjection injectNewInstructions)
        {
            var callInfoCollection = codeProvider.GetCallInfo(codeProviderArgument, method.Module);

            if (!method.HasBody)
            {
                throw new ArgumentException("Method does not contain body.");
            }

            logger.Notice($"Injecting method call before exit of method '{method.FullName}'.");

            newInstructions.Clear();

            if (injectionPlace == MethodInjectionPlace.InCatchBlock)
            {
                GenerateInstructionsForInjectedCallInTryCatchBlock(method, newInstructions, callInfoCollection[0].MethodReferenceToBeCalled, callInfoCollection[0].CallArguments);
            }
            else
            {
                GenerateInstructionsForInjectedCall(newInstructions, callInfoCollection[0].MethodReferenceToBeCalled, callInfoCollection[0].CallArguments);
            }

            foreach (var callInfo in callInfoCollection)
            {
                injectNewInstructions(method.Body, newInstructions, callInfo.MethodReferenceToBeCalled.Resolve());
            }
        }
Exemple #3
0
 public void InjectBeforeExit(MethodDefinition method, MethodCodeInjectingCodeProviderArgument codeProviderArgument, ILogger logger, MethodInjectionPlace injectionPlace)
 {
     Inject(
         method,
         codeProviderArgument,
         logger, injectionPlace,
         (body, newInstruction, call) => body.AddInstructionsBeforeExit(newInstructions));
 }