xhook_rs/
lib.rs

1use std::ffi::CString;
2
3pub fn xhook_register(pathname_regex_str: &str, symbol: &str, new_func: *const u8) {
4    let pathname_regex_str = CString::new(pathname_regex_str).unwrap();
5    let symbol = CString::new(symbol).unwrap();
6    unsafe {
7        xhook_sys::xhook_register(
8            pathname_regex_str.as_ptr(),
9            symbol.as_ptr(),
10            new_func as *mut ::std::os::raw::c_void,
11            std::ptr::null_mut(),
12        );
13    }
14}
15
16pub fn xhook_refresh(is_async: i32) -> i32 {
17    unsafe { xhook_sys::xhook_refresh(is_async) }
18}
19
20pub fn xhook_ignore(pathname_regex_str: &str, symbol: Option<&str>) -> i32 {
21    let pathname_regex_str = CString::new(pathname_regex_str).unwrap();
22    match symbol {
23        Some(sym ) => {
24            let symbol = CString::new(sym).unwrap();
25            unsafe { xhook_sys::xhook_ignore(pathname_regex_str.as_ptr(), symbol.as_ptr()) }
26        },
27        None => {
28            unsafe { xhook_sys::xhook_ignore(pathname_regex_str.as_ptr(), std::ptr::null()) }
29        }
30    }
31
32}
33
34pub fn xhook_clear() {
35    unsafe { xhook_sys::xhook_clear() }
36}
37pub fn xhook_enable_debug(flag: i32) {
38    unsafe { xhook_sys::xhook_enable_debug(flag) }
39}
40pub fn xhook_enable_sigsegv_protection(flag: i32) {
41    unsafe { xhook_sys::xhook_enable_sigsegv_protection(flag) }
42}