https://github.com/jakobzs/minhook
A Rust wrapper for the MinHook library
https://github.com/jakobzs/minhook
detour hook hooking minhook rust
Last synced: 2 months ago
JSON representation
A Rust wrapper for the MinHook library
- Host: GitHub
- URL: https://github.com/jakobzs/minhook
- Owner: Jakobzs
- License: mit
- Created: 2023-04-05T17:08:10.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-03-02T18:00:41.000Z (4 months ago)
- Last Synced: 2025-04-02T12:58:27.918Z (3 months ago)
- Topics: detour, hook, hooking, minhook, rust
- Language: Rust
- Homepage:
- Size: 32.2 KB
- Stars: 32
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minhook
[](https://github.com/Jakobzs/minhook/actions/workflows/rust.yml)
[](https://crates.io/crates/minhook)
[](https://jakobzs.github.io/minhook/minhook)A Rust wrapper for the [MinHook](https://github.com/TsudaKageyu/minhook) library.
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
minhook = "0.7.1"
```## Example
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<(), 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](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.