android_mem_kit/
hooking.rs1use std::ffi::c_void;
2
3unsafe extern "C" {
4 fn DobbyHook(ptr: *mut c_void, handler: *mut c_void, original: *mut *mut c_void) -> i32;
5}
6
7pub unsafe fn attach(target: usize, replacement: usize) -> Result<usize, String> {
9 let mut original_ptr: *mut c_void = std::ptr::null_mut();
10
11 let ret = unsafe {
12 DobbyHook(
13 target as *mut c_void,
14 replacement as *mut c_void,
15 &mut original_ptr
16 )
17 };
18
19 if ret == 0 {
20 Ok(original_ptr as usize)
21 } else {
22 Err("Failed to hook function".to_string())
23 }
24}