Example #1
0
        private void PatchMethod(ModuleDefinition moduleDefinition, MethodDefinition methodDefinition)
        {
            if (!methodDefinition.HasBody)
            {
                return;
            }

            var ilProcessor = methodDefinition.Body.GetILProcessor();

            foreach (var instruction in methodDefinition.Body.Instructions.Where(instruction =>
                                                                                 _instructionInjector.IdentifyInstruction(instruction)).ToList())
            {
                _instructionInjector.InjectInstruction(ilProcessor, instruction, moduleDefinition);
            }
        }
        private List <ValidationResult> ValidateMethod(ModuleDefinition moduleDefinition, MethodDefinition methodDefinition)
        {
            var result = new List <ValidationResult>();

            if (!methodDefinition.HasBody)
            {
                return(result);
            }

            foreach (var instruction in methodDefinition.Body.Instructions.Where(instruction =>
                                                                                 _instructionInjector.IdentifyInstruction(instruction)).ToList())
            {
                if (_instructionInjector.ValidateInstruction(moduleDefinition, instruction))
                {
                    continue;
                }
                result.Add(new MethodCallInjectionValidationResult(
                               $"{_instructionInjector.GetType()} validation failed.").WithInfo(methodDefinition.Name,
                                                                                                methodDefinition.DeclaringType.Namespace, methodDefinition.DeclaringType.FullName, null));
            }

            return(result);
        }