示例#1
0
        public NativeDetour(MethodBase method, IntPtr from, IntPtr to, ref NativeDetourConfig config)
        {
            Method = method;

            if (!(OnDetour?.InvokeWhileTrue(this, method, from, to) ?? true))
            {
                return;
            }
            IsValid = true;

            Data = DetourHelper.Native.Create(from, to, null);

            // Backing up the original function only needs to happen once.
            if (!config.SkipILCopy)
            {
                method?.TryCreateILCopy(out _BackupMethod);
            }

            // BackupNative is required even if BackupMethod is present to undo the detour.
            _BackupNative = DetourHelper.Native.MemAlloc(Data.Size);

            if (!config.ManualApply)
            {
                Apply();
            }
        }
示例#2
0
        public NativeDetour(MethodBase method, IntPtr from, IntPtr to, ref NativeDetourConfig config)
        {
            if (from == to)
            {
                throw new InvalidOperationException($"Cannot detour from a location to itself! (from: {from:X16} to: {to:X16} method: {method})");
            }

            method = method?.GetIdentifiable();
            Method = method;

            if (!(OnDetour?.InvokeWhileTrue(this, method, from, to) ?? true))
            {
                return;
            }
            IsValid = true;

            _Data = DetourHelper.Native.Create(from, to, null);

            // Backing up the original function only needs to happen once.
            if (!config.SkipILCopy)
            {
                method?.TryCreateILCopy(out _BackupMethod);
            }

            // BackupNative is required even if BackupMethod is present to undo the detour.
            _BackupNative = DetourHelper.Native.MemAlloc(_Data.Size);

            if (!config.ManualApply)
            {
                Apply();
            }
        }
示例#3
0
 public NativeDetour(MethodBase from, IntPtr to, NativeDetourConfig config)
     : this(from, from.Pin().GetNativeStart(), to, ref config)
 {
     _Pinned.Add(from);
 }
示例#4
0
 public NativeDetour(IntPtr from, IntPtr to, NativeDetourConfig config)
     : this(null, from, to, ref config)
 {
 }
示例#5
0
 public NativeDetour(MethodBase method, IntPtr from, IntPtr to, NativeDetourConfig config)
     : this(method, from, to, ref config)
 {
 }
示例#6
0
 public NativeDetour(Delegate from, Delegate to, NativeDetourConfig config)
     : this(from.Method, to.Method, ref config)
 {
 }
示例#7
0
 public NativeDetour(IntPtr from, Delegate to, ref NativeDetourConfig config)
     : this(from, to.Method, ref config)
 {
 }
示例#8
0
 public NativeDetour(Delegate from, IntPtr to, ref NativeDetourConfig config)
     : this(from.Method, to, ref config)
 {
 }
示例#9
0
 public NativeDetour(MethodBase from, MethodBase to, NativeDetourConfig config)
     : this(from, DetourHelper.Runtime.GetDetourTarget(from, to).Pin().GetNativeStart(), ref config)
 {
     _Pinned.Add(to);
 }
示例#10
0
 public NativeDetour(IntPtr from, MethodBase to, NativeDetourConfig config)
     : this(from, to.Pin().GetNativeStart(), ref config)
 {
     _Pinned.Add(to);
 }
示例#11
0
 public NativeDetour(MethodBase from, IntPtr to, NativeDetourConfig config)
     : this(from, from.GetNativeStart(), to, ref config)
 {
 }
示例#12
0
 public NativeDetour(MethodBase from, MethodBase to, ref NativeDetourConfig config)
     : this(from, DetourHelper.Runtime.GetDetourTarget(from, to).GetNativeStart(), ref config)
 {
 }
示例#13
0
 public NativeDetour(IntPtr from, MethodBase to, NativeDetourConfig config)
     : this(from, to.GetNativeStart(), ref config)
 {
 }