pub struct StaticHook<F> { /* private fields */ }Implementations§
Source§impl<F: Copy> StaticHook<F>
impl<F: Copy> StaticHook<F>
Sourcepub fn set_before<C: Fn() + Send + Sync + 'static>(&self, cb: C)
pub fn set_before<C: Fn() + Send + Sync + 'static>(&self, cb: C)
Examples found in repository?
examples/static_hook_basic.rs (line 34)
29fn main() -> dobby_rs_framework::Result<()> {
30 common::init_example_logging();
31
32 // EN: Set optional callbacks (not required).
33 // CN: 设置可选回调(非必须)。
34 HOOK.set_before(|| log::info!("before"));
35 HOOK.set_after(|| log::info!("after"));
36
37 unsafe {
38 HOOK.install(
39 common::target_add as fn(i32) -> i32,
40 detour_add as fn(i32) -> i32,
41 )?;
42 }
43
44 let v = common::target_add(1);
45 println!("target_add(1) = {v}");
46
47 unsafe {
48 HOOK.uninstall()?;
49 }
50 Ok(())
51}Sourcepub fn set_after<C: Fn() + Send + Sync + 'static>(&self, cb: C)
pub fn set_after<C: Fn() + Send + Sync + 'static>(&self, cb: C)
Examples found in repository?
examples/static_hook_basic.rs (line 35)
29fn main() -> dobby_rs_framework::Result<()> {
30 common::init_example_logging();
31
32 // EN: Set optional callbacks (not required).
33 // CN: 设置可选回调(非必须)。
34 HOOK.set_before(|| log::info!("before"));
35 HOOK.set_after(|| log::info!("after"));
36
37 unsafe {
38 HOOK.install(
39 common::target_add as fn(i32) -> i32,
40 detour_add as fn(i32) -> i32,
41 )?;
42 }
43
44 let v = common::target_add(1);
45 println!("target_add(1) = {v}");
46
47 unsafe {
48 HOOK.uninstall()?;
49 }
50 Ok(())
51}Sourcepub fn call_before(&self)
pub fn call_before(&self)
Examples found in repository?
examples/static_hook_basic.rs (line 16)
13fn detour_add(x: i32) -> i32 {
14 // EN: Optional: run user callbacks.
15 // CN: 可选:执行用户的 before/after 回调。
16 HOOK.call_before();
17
18 // EN: Call the original implementation with modified arguments.
19 // CN: 修改参数后调用原函数。
20 let out = (HOOK.original())(x + 100);
21
22 HOOK.call_after();
23
24 // EN: Post-process return value.
25 // CN: 对返回值做二次处理。
26 out + 10
27}Sourcepub fn call_after(&self)
pub fn call_after(&self)
Examples found in repository?
examples/static_hook_basic.rs (line 22)
13fn detour_add(x: i32) -> i32 {
14 // EN: Optional: run user callbacks.
15 // CN: 可选:执行用户的 before/after 回调。
16 HOOK.call_before();
17
18 // EN: Call the original implementation with modified arguments.
19 // CN: 修改参数后调用原函数。
20 let out = (HOOK.original())(x + 100);
21
22 HOOK.call_after();
23
24 // EN: Post-process return value.
25 // CN: 对返回值做二次处理。
26 out + 10
27}Sourcepub unsafe fn install(&self, target: F, detour: F) -> Result<()>
pub unsafe fn install(&self, target: F, detour: F) -> Result<()>
Examples found in repository?
examples/static_hook_basic.rs (lines 38-41)
29fn main() -> dobby_rs_framework::Result<()> {
30 common::init_example_logging();
31
32 // EN: Set optional callbacks (not required).
33 // CN: 设置可选回调(非必须)。
34 HOOK.set_before(|| log::info!("before"));
35 HOOK.set_after(|| log::info!("after"));
36
37 unsafe {
38 HOOK.install(
39 common::target_add as fn(i32) -> i32,
40 detour_add as fn(i32) -> i32,
41 )?;
42 }
43
44 let v = common::target_add(1);
45 println!("target_add(1) = {v}");
46
47 unsafe {
48 HOOK.uninstall()?;
49 }
50 Ok(())
51}Sourcepub unsafe fn uninstall(&self) -> Result<()>
pub unsafe fn uninstall(&self) -> Result<()>
Examples found in repository?
examples/static_hook_basic.rs (line 48)
29fn main() -> dobby_rs_framework::Result<()> {
30 common::init_example_logging();
31
32 // EN: Set optional callbacks (not required).
33 // CN: 设置可选回调(非必须)。
34 HOOK.set_before(|| log::info!("before"));
35 HOOK.set_after(|| log::info!("after"));
36
37 unsafe {
38 HOOK.install(
39 common::target_add as fn(i32) -> i32,
40 detour_add as fn(i32) -> i32,
41 )?;
42 }
43
44 let v = common::target_add(1);
45 println!("target_add(1) = {v}");
46
47 unsafe {
48 HOOK.uninstall()?;
49 }
50 Ok(())
51}Sourcepub fn original(&self) -> F
pub fn original(&self) -> F
Examples found in repository?
examples/static_hook_basic.rs (line 20)
13fn detour_add(x: i32) -> i32 {
14 // EN: Optional: run user callbacks.
15 // CN: 可选:执行用户的 before/after 回调。
16 HOOK.call_before();
17
18 // EN: Call the original implementation with modified arguments.
19 // CN: 修改参数后调用原函数。
20 let out = (HOOK.original())(x + 100);
21
22 HOOK.call_after();
23
24 // EN: Post-process return value.
25 // CN: 对返回值做二次处理。
26 out + 10
27}Trait Implementations§
Auto Trait Implementations§
impl<F> !Freeze for StaticHook<F>
impl<F> RefUnwindSafe for StaticHook<F>where
F: RefUnwindSafe,
impl<F> Send for StaticHook<F>where
F: Send,
impl<F> Sync for StaticHook<F>where
F: Sync,
impl<F> Unpin for StaticHook<F>where
F: Unpin,
impl<F> UnsafeUnpin for StaticHook<F>
impl<F> UnwindSafe for StaticHook<F>where
F: UnwindSafe,
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