public static int InjectHooks(Dictionary <string, List <AttributeData> > attributes, AssemblyDefinition assemblyDefinition) { if (!attributes.ContainsKey(nameof(HookAttributes))) { return(0); } var injectedCorrectly = 0; foreach (var hook in attributes[nameof(HookAttributes)]) { hook.TargetData = Cecil.ConvertStringToClassAndMethod(hook.Attribute.ConstructorArguments[0].Value.ToString(), assemblyDefinition); if (hook.TargetData == null) { continue; } if (Cecil.Inject(hook.TargetData, hook)) { ++injectedCorrectly; } } return(injectedCorrectly); }
public static int InjectHooks(Dictionary <string, List <HookData> > attributes, AssemblyDefinition assembly, Dictionary <string, TypeDefinition> typeDefinitions) { if (!attributes.ContainsKey(nameof(AddCallHook))) { return(0); } int injectedCorrectly = 0; foreach (HookData hook in attributes[nameof(AddCallHook)]) { if (hook.Attribute.ConstructorArguments.Count > 0) { hook.TargetData = Cecil.ConvertStringToClassAndMethod(hook.Attribute.ConstructorArguments[0].Value.ToString(), assembly, typeDefinitions, hook); if (hook.TargetData != null && Cecil.Inject(hook.TargetData, hook)) { ++injectedCorrectly; } } } return(injectedCorrectly); }