wicked-waifus-win-patch/src/interceptor.rs

51 lines
1.1 KiB
Rust
Raw Normal View History

2024-08-27 22:41:40 +00:00
use ilhook::x64::{
CallbackOption, HookFlags, HookPoint, HookType, Hooker, JmpBackRoutine, RetnRoutine,
};
pub struct Interceptor {
pub hooks: Vec<HookPoint>,
}
impl Interceptor {
pub const fn new() -> Self {
Self { hooks: Vec::new() }
}
#[allow(dead_code)]
pub unsafe fn attach(
&mut self,
addr: usize,
routine: JmpBackRoutine,
) -> Result<(), ilhook::HookError> {
let hooker = Hooker::new(
addr,
HookType::JmpBack(routine),
CallbackOption::None,
0,
HookFlags::empty(),
);
let hook_point = hooker.hook()?;
self.hooks.push(hook_point);
Ok(())
}
pub unsafe fn replace(
&mut self,
addr: usize,
routine: RetnRoutine,
) -> Result<(), ilhook::HookError> {
let hooker = Hooker::new(
addr,
HookType::Retn(routine),
CallbackOption::None,
0,
HookFlags::empty(),
);
let hook_point = hooker.hook()?;
self.hooks.push(hook_point);
Ok(())
}
}