public MethodRefHook(MethodBase intercepted, MethodInfo custom_method, MethodHookFlags hook_flags = MethodHookFlags.None) : base(intercepted, custom_method, MethodHookType.RunBefore, hook_flags) { if (hook_flags == MethodHookFlags.CanSkipOriginal) { throw new NotImplementedException("RefHook does not yet support Skipping. Want that feature? Leave me a note, so i may actually implement it :)"); } }
protected UnmutableMethodModification(MethodBase intercepted, MethodInfo customMethod, MethodHookType hookType = MethodHookType.RunAfter, MethodHookFlags hookFlags = MethodHookFlags.None) { HookType = hookType; InterceptedMethod = intercepted; CustomMethod = customMethod; HookFlags = hookFlags; Validate(); }
public UnmutableMethodModification(MethodBase intercepted, MethodInfo custom_method, MethodHookType hook_type = MethodHookType.RunAfter, MethodHookFlags hook_flags = MethodHookFlags.None) { HookType = hook_type; InterceptedMethod = intercepted; CustomMethod = custom_method; HookFlags = hook_flags; Validate_1_NoInformationMissing(); Validate_2_Accessibility(); Validate_3_SpecialCases(); Validate_4_ParameterLayout(); Validate_5_ReturnType(); }
public MethodAddVirtual(Type modifyingType, MethodInfo virtual_method, MethodInfo custom_method, MethodHookType type = MethodHookType.RunAfter, MethodHookFlags flags = MethodHookFlags.None) : base(virtual_method, custom_method, type, flags) { ModifyingType = modifyingType; if (ModifyingType == null) throw new ArgumentException("No target type specified!"); if (!virtual_method.DeclaringType.IsAssignableFrom(modifyingType)) throw new ArgumentException("Given Type [" + ModifyingType.FullName + "] is not a child of target [" + virtual_method.DeclaringType + "]!"); base.Validate_4_ParameterLayout(); if (modifyingType .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Select(m => m.GetBaseDefinition()) .Contains(virtual_method.GetBaseDefinition())) { if (virtual_method.DeclaringType == modifyingType) { throw new ArgumentException("Can't add a new virtual override method [" + virtual_method.Name + "]. Type [" + modifyingType.FullName + "] appears to already have such one. May just use a hook?"); } } else { throw new NotImplementedException("This part hopefully isn't necessary ever :p"); /* * MAKE SURE THAT WE HAVE THE REF TO ACTUAL BASE FUNCTION WE MODIFY ... required to to base.ourfunc(); * var tMeth = modifyingType .GetMethods(); var virtParamTypes = virtual_method.GetParameters().Select(p => p.ParameterType); var similarMethods = modifyingType .GetMethods() .Where(f => f.Name == virtual_method.Name && f.ReturnType == virtual_method.ReturnType && f.IsStatic == virtual_method.IsStatic && f.GetParameters().Select(p => p.ParameterType).SequenceEqual(virtParamTypes) ); if (similarMethods.Count() > 0) throw new ArgumentException("Can't add a new virtual override method [" + virtual_method.Name + "]. Type [" + modifyingType.FullName + "] appears to already have such one. May just use a hook?"); */ } }
public MethodAddVirtual(Type modifyingType, MethodInfo virtual_method, MethodInfo custom_method, MethodHookType type = MethodHookType.RunAfter, MethodHookFlags flags = MethodHookFlags.None) : base(virtual_method, custom_method, type, flags) { ModifyingType = modifyingType; if (ModifyingType == null) { throw new ArgumentException("No target type specified!"); } if (!virtual_method.DeclaringType.IsAssignableFrom(modifyingType)) { throw new ArgumentException("Given Type [" + ModifyingType.FullName + "] is not a child of target [" + virtual_method.DeclaringType + "]!"); } base.Validate_4_ParameterLayout(); if (modifyingType .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Select(m => m.GetBaseDefinition()) .Contains(virtual_method.GetBaseDefinition())) { if (virtual_method.DeclaringType == modifyingType) { throw new ArgumentException("Can't add a new virtual override method [" + virtual_method.Name + "]. Type [" + modifyingType.FullName + "] appears to already have such one. May just use a hook?"); } } else { throw new NotImplementedException("This part hopefully isn't necessary ever :p"); /* * MAKE SURE THAT WE HAVE THE REF TO ACTUAL BASE FUNCTION WE MODIFY ... required to to base.ourfunc(); * * var tMeth = modifyingType * .GetMethods(); * var virtParamTypes = virtual_method.GetParameters().Select(p => p.ParameterType); * var similarMethods = modifyingType * .GetMethods() * .Where(f => f.Name == virtual_method.Name * && f.ReturnType == virtual_method.ReturnType * && f.IsStatic == virtual_method.IsStatic * && f.GetParameters().Select(p => p.ParameterType).SequenceEqual(virtParamTypes) * ); * if (similarMethods.Count() > 0) * throw new ArgumentException("Can't add a new virtual override method [" + virtual_method.Name + "]. Type [" + modifyingType.FullName + "] appears to already have such one. May just use a hook?"); */ } }
public InterceptMethodAttribute(MethodBase interceptedMethod) { InterceptedMethod = interceptedMethod; HookType = MethodHookType.RunAfter; HookFlags = MethodHookFlags.None; }
public MethodHook(MethodBase intercepted, MethodInfo custom_method, MethodHookType hook_type = MethodHookType.RunAfter, MethodHookFlags hook_flags = MethodHookFlags.None) : base(intercepted, custom_method, hook_type, hook_flags) { }
public HookInjector(Injector injector, MethodDefinition originalMethod, MethodReference customMethodReference, MethodHookType hookType, MethodHookFlags hookFlags) { Injector = injector; OriginalMethod = originalMethod; CustomMethodReference = customMethodReference; HookType = hookType; HookFlags = hookFlags; GenericArguments = new TypeReference[originalMethod.GenericParameters.Count]; if (originalMethod.HasGenericParameters) { //throw new NotImplementedException("Hooking generic instances? Never tested it yet. Contact creator, pls!"); for (var i = 0; i < originalMethod.GenericParameters.Count; i++) { GenericArguments[i] = originalMethod.GenericParameters[i]; } } originalMethod.Body.SimplifyMacros(); ILGen = OriginalMethod.Body.GetILProcessor(); }
public CustomLoadArgsHookInjector(Injector inj, List<Tuple<OpCode, byte?>> instructionData, MethodDefinition methodBase, MethodReference methodInfo, MethodHookType methodHookType, MethodHookFlags methodHookFlags) : base(inj, methodBase, methodInfo, methodHookType, methodHookFlags) { this.instructionData = instructionData; }
private void InjectInstanceHook( MethodDefinition originalMethod, MethodReference customMethodReference, MethodHookType hookType, MethodHookFlags hookFlags) { var hooker = new HookInjector(this, originalMethod, customMethodReference, hookType, hookFlags); hooker.Inject(); }
protected void InjectStaticHook( MethodDefinition originalMethod, MethodReference customMethodReference, MethodHookType hookType, MethodHookFlags hookFlags) { var hooker = new HookInjector(this, originalMethod, customMethodReference, hookType, hookFlags); hooker.Inject(); }