minhook

Crates.iominhook
lib.rsminhook
version
sourcesrc
created_at2023-04-11 08:01:23.755923+00
updated_at2025-03-02 17:59:09.472097+00
descriptionA Rust wrapper for MinHook, a minimalistic x86/x64 API hooking library for Windows.
homepagehttps://github.com/Jakobzs/minhook
repositoryhttps://github.com/Jakobzs/minhook
max_upload_size
id835872
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Jakob (Jakobzs)

documentation

https://jakobzs.github.io/minhook/minhook

README

minhook

Rust Crates.io rustdoc

A Rust wrapper for the MinHook library.

Usage

Add this to your Cargo.toml:

[dependencies]
minhook = "0.7.1"

Example

This example shows how to create a hook for a function, and also call the original function.

use minhook::{MinHook, MH_STATUS};

fn main() -> Result<(), MH_STATUS> {
    // Create a hook for the return_0 function, detouring it to return_1
    let return_0_address = unsafe { MinHook::create_hook(return_0 as _, return_1 as _)? };

    // Enable the hook
    unsafe { MinHook::enable_all_hooks()? };

    // Call the detoured return_0 function, it should return 1
    assert_eq!(return_0(), 1);

    // Transmute the original return_0 function address to a function pointer
    let return_0_original = unsafe { std::mem::transmute::<_, fn() -> i32>(return_0_address) };

    // Call the original return_0 function
    assert_eq!(return_0_original(), 0);

    Ok(())
}

fn return_0() -> i32 {
    0
}

fn return_1() -> i32 {
    1
}

License

This project is licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.

Commit count: 34

cargo fmt