Beispiel #1
0
        protected UnmutableMethodModification(MethodBase intercepted, MethodInfo customMethod, MethodHookType hookType = MethodHookType.RunAfter, MethodHookFlags hookFlags = MethodHookFlags.None)
        {
            HookType          = hookType;
            InterceptedMethod = intercepted;
            CustomMethod      = customMethod;
            HookFlags         = hookFlags;

            Validate();
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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?");
                */
            }
        }
Beispiel #4
0
        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?");
                 */
            }
        }
Beispiel #5
0
 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)
 {
 }
Beispiel #6
0
 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)
 {
 }
Beispiel #7
0
 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();
 }
Beispiel #8
0
 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;
 }
Beispiel #9
0
 private void InjectInstanceHook(
     MethodDefinition originalMethod,
     MethodReference customMethodReference,
     MethodHookType hookType,
     MethodHookFlags hookFlags)
 {
     var hooker = new HookInjector(this, originalMethod, customMethodReference, hookType, hookFlags);
     hooker.Inject();
 }
Beispiel #10
0
 protected void InjectStaticHook(
   MethodDefinition originalMethod,
   MethodReference customMethodReference,
   MethodHookType hookType,
   MethodHookFlags hookFlags)
 {
     var hooker = new HookInjector(this, originalMethod, customMethodReference, hookType, hookFlags);
     hooker.Inject();
 }