English | 简体中文
Rust inline-hook core + a small framework inspired by jmpews/Dobby.
This repository is a Rust rewrite/wrapper of the ideas (not the code) of Dobby. It is not affiliated with the upstream Dobby project.
dobby-hook: facade crate; core APIs by default, optional framework via featuredobby-hook-core: low-level inline hook core (patch/relocate/trampoline)dobby-rs-framework: framework crate used by the facade featureframework
In practice, you usually only depend on dobby-hook.
Recommended (enable framework feature):
cargo add dobby-hook --features frameworkOr in Cargo.toml:
[dependencies]
dobby-hook = { version = "0.1.4", features = ["framework"] }Core only (no framework):
cargo add dobby-hookLow-level core crate (if you really want only the core package):
cargo add dobby-hook-coreNote: the prelude module is available when you enable the dependency feature framework.
use dobby_hook::prelude::*;
static HOOK: StaticHook<fn(i32) -> i32> = StaticHook::new();
#[inline(never)]
fn target_add(x: i32) -> i32 {
x + 1
}
#[inline(never)]
fn detour_add(x: i32) -> i32 {
// EN: Detour has the same signature, so you already have the arguments.
// CN: detour 和目标函数同签名,因此可以直接拿到参数。
let x2 = x + 100;
(HOOK.original())(x2) + 10
}
fn main() -> dobby_hook::Result<()> {
let _ = init_logging(LogOptions::default());
unsafe {
HOOK.install(target_add as fn(i32) -> i32, detour_add as fn(i32) -> i32)?;
}
println!("{}", target_add(1));
unsafe {
HOOK.uninstall()?;
}
Ok(())
}Examples live in framework/examples/ and cover the whole framework surface:
logging.rsstatic_hook_basic.rsinstall_replace.rsmodule_params.rssymbols_aliases.rsinline_hooks_builder.rsinline_hooks_config.rsmacros.rscommon.rs(shared module for examples)
Run one:
cargo run -p dobby-rs-framework --example static_hook_basicImplemented backends (current workspace state):
- Windows:
x86_64 - Unix:
x86_64,aarch64
Inline hooking patches executable code at runtime. Misuse can crash the process or cause undefined behavior.
- Treat hook install/uninstall APIs as
unsafe. - Ensure detour ABI/signature matches the target.
- Use
#[inline(never)]for demo targets. - Be careful with concurrency.
MSRV is defined by rust-version in each crate (dobby-rs/Cargo.toml, framework/Cargo.toml, dobby-hook/Cargo.toml).
This project is licensed under the Apache License 2.0.
- License text:
LICENSE - Attribution notice (if applicable):
NOTICE