Skip to main content

original_function_ptr

Function original_function_ptr 

Source
pub fn original_function_ptr() -> Option<NonNull<c_void>>
Examples found in repository?
examples/write_hook_table.rs (line 15)
12unsafe extern "C" fn hook(a: i32, b: i32) -> i32 {
13    let original_add: extern "C" fn(a: i32, b: i32) -> i32 = unsafe {
14        std::mem::transmute(
15            hooking::original_function_ptr()
16                .expect("invoked from hook")
17                .as_ptr(),
18        )
19    };
20
21    println!("Hooked with params: ({a}, {b})");
22
23    original_add(5, 6)
24}
More examples
Hide additional examples
examples/macros.rs (line 12)
7unsafe extern "C" fn hooked_puts(s: *const i8) -> c_int {
8    let param_s = unsafe { CStr::from_ptr(s) };
9
10    let original_puts: extern "C" fn(*const i8) -> c_int = unsafe {
11        std::mem::transmute(
12            hooking::original_function_ptr()
13                .expect("called from hook")
14                .as_ptr(),
15        )
16    };
17
18    println!(
19        "Hooked function param: {:?} | Original fn restore jump: {:?}",
20        param_s, original_puts
21    );
22
23    original_puts(c"Yes, im hooked!".as_ptr())
24}
examples/hook_puts.rs (line 10)
5unsafe extern "C" fn hooked_puts(s: *const i8) {
6    let param_s = unsafe { CStr::from_ptr(s) };
7
8    let original_puts: extern "C" fn(*const i8) = unsafe {
9        std::mem::transmute(
10            hooking::original_function_ptr()
11                .expect("invoked from hook")
12                .as_ptr(),
13        )
14    };
15
16    println!(
17        "Hooked function param: {:?} | Original fn restore jump: {:?}",
18        param_s, original_puts
19    );
20
21    original_puts(c"Call original puts restore detour".as_ptr());
22}
examples/hook_msgboxa.rs (line 22)
14unsafe extern "C" fn hook_destination(
15    _: *mut std::ffi::c_void,
16    lp_text: *const i8,
17    lp_caption: *const i8,
18    _: u32,
19) -> i32 {
20    let original_msgbox: extern "C" fn(*mut std::ffi::c_void, *const i8, *const i8, u32) -> i32 = unsafe {
21        std::mem::transmute(
22            hooking::original_function_ptr()
23                .expect("invoked from hook")
24                .as_ptr(),
25        )
26    };
27
28    println!(
29        "Called with title: {:?} | Body: {:?}",
30        unsafe { CStr::from_ptr(lp_text) },
31        unsafe { CStr::from_ptr(lp_caption) }
32    );
33
34    original_msgbox(
35        std::ptr::null_mut(),
36        c"msgbox was hooked!".as_ptr(),
37        c"Intercepted hook".as_ptr(),
38        0,
39    )
40}