Show / Hide Table of Contents

    Class NativeDetour

    A "raw" native detour, acting as a wrapper around NativeDetourData with a few helpers. Only one NativeDetour for a method to detour from can exist at any given time. NativeDetours cannot be layered. If you don't need the trampoline generator or any of the management helpers, use DetourManager.Native directly. Unless you're writing your own detour manager or need to detour native functions, it's better to create instances of Detour instead.

    Inheritance
    System.Object
    NativeDetour
    Implements
    IDetour
    System.IDisposable
    Namespace: MonoMod.RuntimeDetour
    Assembly: MonoMod.RuntimeDetour.dll
    Syntax
    public class NativeDetour : Object, IDetour, IDisposable

    Constructors

    NativeDetour(Delegate, Delegate)

    Declaration
    public NativeDetour(Delegate from, Delegate to)
    Parameters
    Type Name Description
    System.Delegate from
    System.Delegate to

    NativeDetour(Delegate, Delegate, NativeDetourConfig)

    Declaration
    public NativeDetour(Delegate from, Delegate to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Delegate from
    System.Delegate to
    NativeDetourConfig config

    NativeDetour(Delegate, Delegate, ref NativeDetourConfig)

    Declaration
    public NativeDetour(Delegate from, Delegate to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Delegate from
    System.Delegate to
    NativeDetourConfig config

    NativeDetour(Delegate, IntPtr)

    Declaration
    public NativeDetour(Delegate from, IntPtr to)
    Parameters
    Type Name Description
    System.Delegate from
    System.IntPtr to

    NativeDetour(Delegate, IntPtr, NativeDetourConfig)

    Declaration
    public NativeDetour(Delegate from, IntPtr to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Delegate from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(Delegate, IntPtr, ref NativeDetourConfig)

    Declaration
    public NativeDetour(Delegate from, IntPtr to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Delegate from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(IntPtr, Delegate)

    Declaration
    public NativeDetour(IntPtr from, Delegate to)
    Parameters
    Type Name Description
    System.IntPtr from
    System.Delegate to

    NativeDetour(IntPtr, Delegate, NativeDetourConfig)

    Declaration
    public NativeDetour(IntPtr from, Delegate to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.IntPtr from
    System.Delegate to
    NativeDetourConfig config

    NativeDetour(IntPtr, Delegate, ref NativeDetourConfig)

    Declaration
    public NativeDetour(IntPtr from, Delegate to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.IntPtr from
    System.Delegate to
    NativeDetourConfig config

    NativeDetour(IntPtr, IntPtr)

    Declaration
    public NativeDetour(IntPtr from, IntPtr to)
    Parameters
    Type Name Description
    System.IntPtr from
    System.IntPtr to

    NativeDetour(IntPtr, IntPtr, NativeDetourConfig)

    Declaration
    public NativeDetour(IntPtr from, IntPtr to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.IntPtr from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(IntPtr, IntPtr, ref NativeDetourConfig)

    Declaration
    public NativeDetour(IntPtr from, IntPtr to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.IntPtr from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(IntPtr, MethodBase)

    Declaration
    public NativeDetour(IntPtr from, MethodBase to)
    Parameters
    Type Name Description
    System.IntPtr from
    System.Reflection.MethodBase to

    NativeDetour(IntPtr, MethodBase, NativeDetourConfig)

    Declaration
    public NativeDetour(IntPtr from, MethodBase to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.IntPtr from
    System.Reflection.MethodBase to
    NativeDetourConfig config

    NativeDetour(IntPtr, MethodBase, ref NativeDetourConfig)

    Declaration
    public NativeDetour(IntPtr from, MethodBase to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.IntPtr from
    System.Reflection.MethodBase to
    NativeDetourConfig config

    NativeDetour(MethodBase, IntPtr)

    Declaration
    public NativeDetour(MethodBase from, IntPtr to)
    Parameters
    Type Name Description
    System.Reflection.MethodBase from
    System.IntPtr to

    NativeDetour(MethodBase, IntPtr, NativeDetourConfig)

    Declaration
    public NativeDetour(MethodBase from, IntPtr to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Reflection.MethodBase from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(MethodBase, IntPtr, ref NativeDetourConfig)

    Declaration
    public NativeDetour(MethodBase from, IntPtr to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Reflection.MethodBase from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(MethodBase, IntPtr, IntPtr)

    Declaration
    public NativeDetour(MethodBase method, IntPtr from, IntPtr to)
    Parameters
    Type Name Description
    System.Reflection.MethodBase method
    System.IntPtr from
    System.IntPtr to

    NativeDetour(MethodBase, IntPtr, IntPtr, NativeDetourConfig)

    Declaration
    public NativeDetour(MethodBase method, IntPtr from, IntPtr to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Reflection.MethodBase method
    System.IntPtr from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(MethodBase, IntPtr, IntPtr, ref NativeDetourConfig)

    Declaration
    public NativeDetour(MethodBase method, IntPtr from, IntPtr to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Reflection.MethodBase method
    System.IntPtr from
    System.IntPtr to
    NativeDetourConfig config

    NativeDetour(MethodBase, MethodBase)

    Declaration
    public NativeDetour(MethodBase from, MethodBase to)
    Parameters
    Type Name Description
    System.Reflection.MethodBase from
    System.Reflection.MethodBase to

    NativeDetour(MethodBase, MethodBase, NativeDetourConfig)

    Declaration
    public NativeDetour(MethodBase from, MethodBase to, NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Reflection.MethodBase from
    System.Reflection.MethodBase to
    NativeDetourConfig config

    NativeDetour(MethodBase, MethodBase, ref NativeDetourConfig)

    Declaration
    public NativeDetour(MethodBase from, MethodBase to, ref NativeDetourConfig config)
    Parameters
    Type Name Description
    System.Reflection.MethodBase from
    System.Reflection.MethodBase to
    NativeDetourConfig config

    Fields

    Data

    Declaration
    public readonly NativeDetourData Data
    Field Value
    Type Description
    NativeDetourData

    Method

    Declaration
    public readonly MethodBase Method
    Field Value
    Type Description
    System.Reflection.MethodBase

    OnDetour

    Declaration
    public static Func<NativeDetour, MethodBase, IntPtr, IntPtr, bool> OnDetour
    Field Value
    Type Description
    System.Func<NativeDetour, System.Reflection.MethodBase, System.IntPtr, System.IntPtr, System.Boolean>

    OnGenerateTrampoline

    Declaration
    public static Func<NativeDetour, MethodBase, MethodBase> OnGenerateTrampoline
    Field Value
    Type Description
    System.Func<NativeDetour, System.Reflection.MethodBase, System.Reflection.MethodBase>

    OnUndo

    Declaration
    public static Func<NativeDetour, bool> OnUndo
    Field Value
    Type Description
    System.Func<NativeDetour, System.Boolean>

    Properties

    IsApplied

    Declaration
    public bool IsApplied { get; }
    Property Value
    Type Description
    System.Boolean

    IsValid

    Declaration
    public bool IsValid { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    Apply()

    Apply the native detour. This can be done automatically when creating an instance.

    Declaration
    public void Apply()

    Dispose()

    Undo and free this temporary detour.

    Declaration
    public void Dispose()

    Free()

    Free the detour's data without undoing it. This makes any further operations on this detour invalid.

    Declaration
    public void Free()

    GenerateTrampoline(MethodBase)

    Generate a new DynamicMethod with which you can invoke the previous state. If the NativeDetour holds a reference to a managed method, a copy of the original method is returned. If the NativeDetour holds a reference to a native function, an "undo-call-redo" trampoline with a matching signature is returned.

    Declaration
    public MethodBase GenerateTrampoline(MethodBase signature = null)
    Parameters
    Type Name Description
    System.Reflection.MethodBase signature
    Returns
    Type Description
    System.Reflection.MethodBase

    GenerateTrampoline<T>()

    Generate a new delegate with which you can invoke the previous state. If the NativeDetour holds a reference to a managed method, a copy of the original method is returned. If the NativeDetour holds a reference to a native function, an "undo-call-redo" trampoline with a matching signature is returned.

    Declaration
    public T GenerateTrampoline<T>()
        where T : Delegate
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    Undo()

    Undo the native detour without freeing the detour native data, allowing you to reapply it later.

    Declaration
    public void Undo()

    Implements

    IDetour
    System.IDisposable
    Back to top Yet another C# modding swiss army knife.