pub struct HookSession {
pub module: ModuleHandle,
pub installed: Vec<InstalledHook>,
}Fields§
§module: ModuleHandle§installed: Vec<InstalledHook>Implementations§
Source§impl HookSession
impl HookSession
Sourcepub unsafe fn unhook_all(&mut self) -> Result<()>
pub unsafe fn unhook_all(&mut self) -> Result<()>
Examples found in repository?
examples/inline_hooks_builder.rs (line 36)
10fn main() -> dobby_rs_framework::Result<()> {
11 // EN/CN: Keep this example tiny: install, then uninstall.
12
13 #[cfg(unix)]
14 let builder: InlineHooksBuilder<'_> = inline_hooks(common::DEMO_LIB)
15 .hook_alias(
16 "puts",
17 "puts",
18 common::detours::unix::detour_puts
19 as unsafe extern "C" fn(*const core::ffi::c_char) -> core::ffi::c_int,
20 )
21 .extra_action_fn(|m| common::resolve_and_print(m, "puts"));
22 #[cfg(unix)]
23 let mut session: HookSession = unsafe { builder.install()? };
24
25 #[cfg(windows)]
26 let builder: InlineHooksBuilder<'_> = inline_hooks(common::DEMO_LIB)
27 .hook_alias(
28 "GetTickCount",
29 "GetTickCount",
30 common::detours::windows::detour_get_tick_count as unsafe extern "system" fn() -> u32,
31 )
32 .extra_action_fn(|m| common::resolve_and_print(m, "GetTickCount"));
33 #[cfg(windows)]
34 let mut session: HookSession = unsafe { builder.install()? };
35
36 unsafe { session.unhook_all()? };
37 Ok(())
38}More examples
examples/inline_hooks_config.rs (line 46)
10fn main() -> dobby_rs_framework::Result<()> {
11 common::init_example_logging();
12
13 // EN: Build HookDef(s) using helpers.
14 // CN: 使用 helper 构造 HookDef。
15 #[cfg(unix)]
16 let hooks: Vec<HookDef> = vec![make_hook(
17 "puts",
18 "puts_cfg",
19 common::detours::unix::detour_puts
20 as unsafe extern "C" fn(*const core::ffi::c_char) -> core::ffi::c_int,
21 )];
22 #[cfg(windows)]
23 let hooks: Vec<HookDef> = vec![make_hook_simple(
24 "GetCurrentProcessId",
25 common::detours::windows::detour_get_current_process_id
26 as unsafe extern "system" fn() -> u32,
27 )];
28
29 let mut session: HookSession = unsafe {
30 install_inline_hooks(InlineHooksConfig {
31 lib_name: common::DEMO_LIB,
32 hooks,
33 extra_action: Some(Box::new(|m: &ModuleHandle| {
34 // EN: `ModuleHandle` is available here.
35 // CN: 这里可以拿到 `ModuleHandle`。
36 let sym = if cfg!(windows) {
37 "GetCurrentProcessId"
38 } else {
39 "puts"
40 };
41 common::resolve_and_print(m, sym)
42 })),
43 })?
44 };
45
46 unsafe { session.unhook_all()? };
47 Ok(())
48}Auto Trait Implementations§
impl Freeze for HookSession
impl RefUnwindSafe for HookSession
impl !Send for HookSession
impl !Sync for HookSession
impl Unpin for HookSession
impl UnsafeUnpin for HookSession
impl UnwindSafe for HookSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more