HookGuard

Struct HookGuard 

Source
pub struct HookGuard<A: Architecture> { /* private fields */ }
Expand description

RAII guard for an installed inline hook

when dropped, automatically restores the original function bytes unless leak() was called.

Implementations§

Source§

impl<A: Architecture> HookGuard<A>

Source

pub fn target(&self) -> usize

get the target (hooked) function address

Source

pub fn detour(&self) -> usize

get the detour function address

Source

pub fn trampoline(&self) -> Option<usize>

get the trampoline address (call this to invoke the original function)

returns None if no trampoline was allocated

Source

pub fn original_bytes(&self) -> &[u8]

get the original bytes that were overwritten

Source

pub fn will_auto_restore(&self) -> bool

check if auto-restore is enabled

Source

pub fn set_auto_restore(&mut self, restore: bool)

set whether to auto-restore on drop

Source

pub fn leak(self)

disable auto-restore and keep the hook active permanently

consumes the guard without restoring the original function. the trampoline memory is leaked and remains valid.

Source

pub fn restore(self) -> Result<()>

manually restore the original function

consumes the guard and restores the hooked function to its original state.

Source

pub fn disable(&mut self) -> Result<()>

temporarily disable the hook

restores original bytes but keeps the guard and trampoline alive for re-enabling later.

Source

pub fn enable(&mut self, hook_bytes: &[u8]) -> Result<()>

re-enable a previously disabled hook

writes the hook stub back to the target function.

Trait Implementations§

Source§

impl<A: Architecture> Drop for HookGuard<A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<A: Architecture> Send for HookGuard<A>

Source§

impl<A: Architecture> Sync for HookGuard<A>

Auto Trait Implementations§

§

impl<A> Freeze for HookGuard<A>

§

impl<A> RefUnwindSafe for HookGuard<A>
where A: RefUnwindSafe,

§

impl<A> Unpin for HookGuard<A>
where A: Unpin,

§

impl<A> UnwindSafe for HookGuard<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.