mod common;
use dobby_rs_framework::prelude::*;
fn main() -> dobby_rs_framework::Result<()> {
common::init_example_logging();
#[cfg(unix)]
let hooks: Vec<HookDef> = vec![make_hook(
"puts",
"puts_cfg",
common::detours::unix::detour_puts
as unsafe extern "C" fn(*const core::ffi::c_char) -> core::ffi::c_int,
)];
#[cfg(windows)]
let hooks: Vec<HookDef> = vec![make_hook_simple(
"GetCurrentProcessId",
common::detours::windows::detour_get_current_process_id
as unsafe extern "system" fn() -> u32,
)];
let mut session: HookSession = unsafe {
install_inline_hooks(InlineHooksConfig {
lib_name: common::DEMO_LIB,
hooks,
extra_action: Some(Box::new(|m: &ModuleHandle| {
let sym = if cfg!(windows) {
"GetCurrentProcessId"
} else {
"puts"
};
common::resolve_and_print(m, sym)
})),
})?
};
unsafe { session.unhook_all()? };
Ok(())
}