Skip to main content

hooking/
lib.rs

1pub mod asm;
2pub mod error;
3pub mod hooks;
4pub mod mem;
5
6cfg_select! {
7    feature = "macros" => {
8        mod macros;
9
10        pub use hooking_macros::hook;
11        pub mod __macro_support {
12            pub use super::macros::*;
13        }
14    }
15    _ => {}
16}
17
18pub use hooks::{Hook, HookData, HookWriter};
19pub(crate) const ORIGINAL_FN_CHECKSUM_MAGIC: usize = 0xDEADBEEFCAFEBABE;
20pub fn original_function_ptr() -> Option<core::ptr::NonNull<core::ffi::c_void>> {
21    let mut orig_addr: *mut core::ffi::c_void = core::ptr::null_mut();
22    let mut checksum = 0usize;
23    unsafe {
24        core::arch::asm!(
25        "nop",
26        lateout("r10") orig_addr,
27        lateout("r11") checksum,
28        );
29
30        ((orig_addr as usize ^ ORIGINAL_FN_CHECKSUM_MAGIC) == checksum)
31            .then(|| core::ptr::NonNull::new_unchecked(orig_addr))
32    }
33}