Show / Hide Table of Contents

Class Hook<T>

Manages a hook which can be used to intercept a call to native function. This class is basically a thin wrapper around the LocalHook type to provide helper functions.

Inheritance
System.Object
Hook<T>
Implements
System.IDisposable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Dalamud.Hooking
Assembly: Dalamud.dll
Syntax
public sealed class Hook<T> : IDisposable, IDalamudHook where T : Delegate
Type Parameters
Name Description
T

Delegate type to represents a function prototype. This must be the same prototype as original function do.

Constructors

| Improve this Doc View Source

Hook(IntPtr, Delegate, Object)

Initializes a new instance of the Hook<T> class. Hook is not activated until Enable() method is called.

Declaration
public Hook(IntPtr address, Delegate detour, object callbackParam = null)
Parameters
Type Name Description
System.IntPtr address

A memory address to install a hook.

System.Delegate detour

Callback function. Delegate must have a same original function prototype.

System.Object callbackParam

A callback object which can be accessed within the detour.

Properties

| Improve this Doc View Source

Address

Gets a memory address of the target function.

Declaration
public IntPtr Address { get; }
Property Value
Type Description
System.IntPtr
Exceptions
Type Condition
System.ObjectDisposedException

Hook is already disposed.

| Improve this Doc View Source

IsDisposed

Gets a value indicating whether or not the hook has been disposed.

Declaration
public bool IsDisposed { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

IsEnabled

Gets a value indicating whether or not the hook is enabled.

Declaration
public bool IsEnabled { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

Original

Gets a delegate function that can be used to call the actual function as if function is not hooked yet.

Declaration
public T Original { get; }
Property Value
Type Description
T
Exceptions
Type Condition
System.ObjectDisposedException

Hook is already disposed.

Methods

| Improve this Doc View Source

Disable()

Stops intercepting a call to the function.

Declaration
public void Disable()
| Improve this Doc View Source

Dispose()

Remove a hook from the current process.

Declaration
public void Dispose()
| Improve this Doc View Source

Enable()

Starts intercepting a call to the function.

Declaration
public void Enable()
| Improve this Doc View Source

FromSymbol(String, String, Delegate, Object)

Creates a hook. Hooking address is inferred by calling to GetProcAddress() function. Hook is not activated until Enable() method is called.

Declaration
public static Hook<T> FromSymbol(string moduleName, string exportName, Delegate detour, object callbackParam = null)
Parameters
Type Name Description
System.String moduleName

A name of the module currently loaded in the memory. (e.g. ws2_32.dll).

System.String exportName

A name of the exported function name (e.g. send).

System.Delegate detour

Callback function. Delegate must have a same original function prototype.

System.Object callbackParam

A callback object which can be accessed within the detour.

Returns
Type Description
Hook<T>

The hook with the supplied parameters.

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX