#[cfg(target_os = "linux")]
mod example {
use hooking::mini_hook;
#[mini_hook(method = "getpid")]
extern "C" fn offset_getpid() -> std::ffi::c_int {
let original = unsafe { offset_getpid::original_function().expect("the hook was created") };
original() + 1_000_000
}
pub fn main() {
println!("before hooking: pid {}", std::process::id());
unsafe { offset_getpid::enable_hook().unwrap() };
println!("hooked: pid {}", std::process::id());
unsafe { offset_getpid::disable_hook().unwrap() };
println!("unhooked: pid {}", std::process::id());
}
}
#[cfg(target_os = "linux")]
fn main() {
example::main();
}
#[cfg(not(target_os = "linux"))]
fn main() {
println!("this example needs linux");
}