Struct minhook::Hook [] [src]

pub struct Hook<T: Function> {
    // some fields omitted
}

A hook that is destroyed when it goes out of scope.

Methods

impl<T: Function> Hook<T>
[src]

unsafe fn create<D>(target: T, detour: D) -> Result<Hook<T>> where T: HookableWith<D>, D: Function

Create a new hook given a target function and a compatible detour function.

The hook is disabled by default. Even when this function is succesful, there is no guaranteee that the detour function will actually get called when the target function gets called. An invocation of the target function might for example get inlined in which case it is impossible to hook at runtime.

Safety

The given target function type must uniquely match the actual target function. This means two things: the given target function type has to be correct, but also there can not be two function pointers with different signatures pointing to the same code location. This last situation can for example happen when the Rust compiler or LLVM decide to merge multiple functions with the same code into one.

unsafe fn create_api<M, D>(target_module: M, target_function: FunctionId, detour: D) -> Result<Hook<T>> where M: AsRef<OsStr>, T: HookableWith<D>, D: Function

Create a new hook given the name of the module, the name of the function symbol and a compatible detour function.

The module has to be loaded before this function is called. This function does not attempt to load the module first. The hook is disabled by default.

Safety

The target module must remain loaded in memory for the entire duration of the hook.

See create() for more safety requirements.

fn trampoline(&self) -> T::Unsafe

Returns a pointer to the trampoline function.

Calling the returned function is unsafe because it will point to invalid memory after the hook is destroyed.

fn enable(&self) -> Result<()>

Enables this hook.

Consider using a HookQueue if you want to enable/disable a large amount of hooks at once.

fn disable(&self) -> Result<()>

Disables this hook.

Consider using a HookQueue if you want to enable/disable a large amount of hooks at once.

Trait Implementations

impl<T: Debug + Function> Debug for Hook<T>
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<T: Function> Drop for Hook<T>
[src]

fn drop(&mut self)

A method called when the value goes out of scope. Read more

impl<T: Function> Sync for Hook<T>
[src]

impl<T: Function> Send for Hook<T>
[src]