Skip to main content

Crate dobby_hook_core

Crate dobby_hook_core 

Source
Expand description

§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).

Enums§

Error

Constants§

VERSION

Functions§

code_patch
destroy
hook
import_table_replace
instrument
register_alloc_near_code_callback
resolve_symbol
set_near_trampoline
set_options
symbol_resolver

Type Aliases§

Result