public static Hooker New(ModuleDefinition module, HookSubOptions options) { /* * These things have to be recreated for every module! * This is because a reference is specifically generated from a certain module and cannot be reused * by another module! */ // Fetch types and references TypeDefinition _hookRegistryType = options.HookRegistryType; // RuntimeMethodHandle gives us information about the hooked function. // By doing this import we FAIL EARLY if the Type could not be found. (headache prevention) // var rmhTypeRef = module.Import(typeof(RuntimeMethodHandle)); // Look for the HookRegistry.onCall(..) method var onCallMethod = _hookRegistryType.Methods.First(mi => mi.Name.Equals("OnCall")); var onCallMethodRef = module.Import(onCallMethod); // The (reference) name for in the manifest of the hooked library. The runtime loads all referenced libraries // into application domain. Once in application domain, methods and types can resolve. // var hrAssemblyName = AssemblyNameReference.Parse(options.HooksRegistryAssembly.FullName); // By adding a new reference (pointing to our HookRegistry assembly), we are certain // that Module can resolve the calls to our hooks. // MARK; CECIL DOES THIS FOR US // module.AssemblyReferences.Add(hrAssemblyName); var newObj = new Hooker { Module = module, onCallMethodRef = onCallMethodRef, }; return(newObj); }
public static Hooker New(ModuleDefinition module, HookSubOptions options) { /* * These things have to be recreated for every module! * This is because a reference is specifically generated from a certain module and cannot be reused * by another module! */ // Fetch types and references TypeDefinition _hookRegistryType = options.HookRegistryType; // Look for the HookRegistry.onCall(..) method var onCallMethod = _hookRegistryType.Methods.First(mi => mi.Name.Equals("OnCall")); var onCallMethodRef = module.Import(onCallMethod); var newObj = new Hooker { Module = module, onCallMethodRef = onCallMethodRef, }; return(newObj); }
public HookHelper(HookSubOptions options) { _options = options; HookTypes = new List <Type>(); }
public HookHelper(HookSubOptions options) { _options = options; }