dobby-hook-core 0.1.2

Dobby-like low-level inline hook core in Rust
Documentation

dobby-hook-core

crates.io docs.rs License

dobby-hook-core is the low-level inline hook core used by dobby-hook.

  • Backends: Windows x86_64, Unix x86_64/aarch64
  • Public API: hook / destroy / code_patch / resolve_symbol

Most users should start with dobby-hook unless you explicitly need the low-level primitives.

Install

cargo add dobby-hook-core

Minimal Usage

use core::ffi::c_void;

#[inline(never)]
fn target_add(x: i32) -> i32 {
    x + 1
}

#[inline(never)]
fn detour_add(x: i32) -> i32 {
    x + 100
}

fn main() -> dobby_hook_core::Result<()> {
    unsafe {
        // EN: `hook` returns a trampoline pointer for calling the original.
        // CN: `hook` 返回 trampoline 指针用于调用原函数。
        let trampoline = dobby_hook_core::hook(
            target_add as *const () as *mut c_void,
            detour_add as *const () as *mut c_void,
        )?;

        let _ = trampoline;
        dobby_hook_core::destroy(target_add as *const () as *mut c_void)?;
    }
    Ok(())
}

Safety

All hook APIs are unsafe by nature. You must ensure correct ABI/signature, address validity, and be careful with concurrency.

This crate is inspired by jmpews/Dobby (not affiliated).