Skip to content

sorrow404Null/dobby-rs

Repository files navigation

dobby-hook

English | 简体中文

crates.io docs.rs License

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.

Crates

  • dobby-hook: facade crate; core APIs by default, optional framework via feature
  • dobby-hook-core: low-level inline hook core (patch/relocate/trampoline)
  • dobby-rs-framework: framework crate used by the facade feature framework

In practice, you usually only depend on dobby-hook.

Install

Recommended (enable framework feature):

cargo add dobby-hook --features framework

Or in Cargo.toml:

[dependencies]
dobby-hook = { version = "0.1.4", features = ["framework"] }

Core only (no framework):

cargo add dobby-hook

Low-level core crate (if you really want only the core package):

cargo add dobby-hook-core

Quick Start (Framework)

Note: 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

Examples live in framework/examples/ and cover the whole framework surface:

  • logging.rs
  • static_hook_basic.rs
  • install_replace.rs
  • module_params.rs
  • symbols_aliases.rs
  • inline_hooks_builder.rs
  • inline_hooks_config.rs
  • macros.rs
  • common.rs (shared module for examples)

Run one:

cargo run -p dobby-rs-framework --example static_hook_basic

Supported Targets

Implemented backends (current workspace state):

  • Windows: x86_64
  • Unix: x86_64, aarch64

Safety

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

MSRV is defined by rust-version in each crate (dobby-rs/Cargo.toml, framework/Cargo.toml, dobby-hook/Cargo.toml).

License

This project is licensed under the Apache License 2.0.

  • License text: LICENSE
  • Attribution notice (if applicable): NOTICE

About

Rust inline-hook toolkit inspired by jmpews/Dobby: core patch/relocate/trampoline plus an optional framework (typed handles, static hooks, symbol/alias helpers). Targets Windows x86_64 and Unix x86_64/aarch64. Built with AI assistance. 🦀🔧

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages