#[hook]Expand description
The primary macro for defining a hook.
This attribute macro transforms a standard Rust function into a
hook handler and automatically generates a constructor to register
the hook with the global HOOK_REGISTRY.
§Parameters
kind: (Optional) The type of hook to apply."retn"(Default): A function-level hook. Injectscall_original!(...)."jmp_back": An inline hook that returns to the next instruction."jmp_to_ret": An inline hook that jumps to a dynamic address."jmp_to_addr": An inline hook that jumps to a fixed address.
symbol: (Optional) The name of the symbol to hook.offset: (Optional) The address offset from the binary’s base address.dest: (Required for"jmp_to_addr") The destination offset to jump to.
§Examples
§Function Hook (retn)
ⓘ
use prehook::hook;
#[hook(kind = "retn", symbol = "check_license")]
fn my_hook(key: i32) -> i32 {
let result = call_original!(key);
if result == 0 { 1 } else { result }
}§Inline Hook (jmp_back)
ⓘ
use prehook::hook;
#[hook(kind = "jmp_back", offset = 0x1234)]
fn my_inline_hook(reg: &mut Registers) {
println!("RAX: 0x{:x}", reg.rax);
}