A Rust wrapper for the MinHook library.
Unlike other detouring crates, this crate does not require nightly.
Add this to your Cargo.toml
:
toml
[dependencies]
minhook = "0.3.0"
This example shows how to create a hook for a function, and also call the original function.
```rust use minhook::{MinHook, MH_STATUS};
fn main() -> Result<(), MHSTATUS> { // Create a hook for the test function let return0addr = unsafe { MinHook::createhook(return0 as _, return1 as _)? };
// Enable the hook
unsafe { MinHook::enable_all_hooks()? };
// Call the detoured test function
assert_eq!(return_0(), 1);
// Transmute the original test function address to a function pointer
let return_0_orig = unsafe { std::mem::transmute::<_, fn() -> i32>(return_0_addr) };
// Call the original test function
assert_eq!(return_0_orig(), 0);
Ok(())
}
fn return_0() -> i32 { 0 }
fn return_1() -> i32 { 1 } ```
This project is licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).
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.