pub struct Hook { /* private fields */ }Expand description
An installed inline hook that redirects a target function to a detour.
The hook overwrites the first few bytes of the target function with a jump to the detour. A trampoline is allocated nearby containing the original instructions and a jump back, allowing the detour to call the original.
The hook is automatically removed when dropped.
Implementations§
Source§impl Hook
impl Hook
Sourcepub unsafe fn install(target: *const u8, detour: *const u8) -> Result<Self>
pub unsafe fn install(target: *const u8, detour: *const u8) -> Result<Self>
Install an inline hook at target, redirecting calls to detour.
Returns a Hook whose trampoline can be used
to call the original function.
§Safety
targetmust point to the start of a callable function in executable memory.detourmust be a function with the same calling convention and signature.- No thread may be executing the first 14 bytes of
targetduring this call.
Sourcepub fn trampoline(&self) -> *const u8
pub fn trampoline(&self) -> *const u8
Returns a pointer to the trampoline that calls the original function.
Transmute this to the original function’s type to call it:
ⓘ
let original: extern "C" fn(i32) -> i32 = std::mem::transmute(hook.trampoline());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Hook
impl RefUnwindSafe for Hook
impl Unpin for Hook
impl UnsafeUnpin for Hook
impl UnwindSafe for Hook
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