Expand description
In-process function hooking for the imping toolkit.
Installs typed function detours and code injections at arbitrary addresses
in the running process, and depends on nothing else in imping.
Relocation, near-memory allocation and thread-safe patching come from the
[detour] crate, wrapped behind this crate’s types.
§Examples
use imping_hook::Hook;
#[inline(never)]
extern "C" fn add(a: i32, b: i32) -> i32 { a + b }
extern "C" fn sub(a: i32, b: i32) -> i32 { a - b }
// SAFETY: `add` is a real function with the signature below, and `sub`
// shares it.
let hook = unsafe {
Hook::at(add as *const ())
.redirect(sub as extern "C" fn(i32, i32) -> i32)
.install()?
};
hook.enable()?;
assert_eq!(add(3, 2), 1);
assert_eq!(hook.original().call(3, 2), 5);§Main items
Hookredirects a function to another of the same signature and keeps the original callable. Its docs cover threads, batches and dropping.Injectionruns machine code, assembly or a register callback at an address, then the original code.scanfinds code by a byte pattern;Hook::scanandInjection::scanpatch what it finds.batchapplies many enables and disables with one thread suspension.Contextholds the registers a register callback sees.Errorlists everything that can fail.
Modules§
- asm
- Re-exports the assembler used by
InjectionBuilder::asm. - scan
- Finding code by a byte pattern.
Structs§
- Context
- The x86-64 registers at an injection site: general-purpose registers, flags, instruction pointer and SSE registers.
- Hook
- A typed function detour, and the RAII guard that owns it.
- Hook
Builder - A hook builder holding the target address, returned by
Hook::at. - Hook
Scan - A hook builder holding a byte pattern to find the target by, returned by
Hook::scan. - Hook
With - A hook builder holding the target and detour, returned by
HookBuilder::redirectandHookScan::redirect. - Injection
- A code injection, and the RAII guard that owns it.
- Injection
Builder - An injection builder holding the target address, returned by
Injection::at. - Injection
Scan - An injection builder holding a byte pattern to find the target by, returned
by
Injection::scan. - Injection
With - An injection builder holding the target and what to inject, returned by the
InjectionBuilderandInjectionScanmethods. - Original
- The original, unhooked function of a
Hook, borrowed from it. - OsError
- A failed operating system call, such as allocating or protecting memory or suspending a thread.
- Xmm
- The 128 bits of one SSE (
xmm) register.
Enums§
- Error
- Everything that can go wrong when finding, installing, enabling or disabling a hook.
Traits§
Functions§
- batch
- Runs
f, then applies the enables and disables it made on this thread in one transaction, so other threads are suspended once rather than per patch.
Type Aliases§
- Result
- The result of a hooking operation.