pub struct Interceptor<'a> { /* private fields */ }
Expand description

Function hooking engine interface.

Implementations§

source§

impl<'a> Interceptor<'a>

source

pub fn obtain<'b>(_gum: &'b Gum) -> Interceptor<'_>
where 'b: 'a,

Obtain an Interceptor handle, ensuring that the runtime is properly initialized. This may be called as many times as needed, and results in a no-op if the Interceptor is already initialized.

source

pub fn attach<I: InvocationListener>( &mut self, f: NativePointer, listener: &mut I ) -> NativePointer

Available on crate feature invocation-listener only.

Attach a listener to the beginning of a function address.

§Safety

The provided address must point to the start of a function in a valid memory region.

source

pub fn attach_instruction<I: ProbeListener>( &mut self, instr: NativePointer, listener: &mut I ) -> NativePointer

Available on crate feature invocation-listener only.

Attach a listener to an instruction address.

§Safety

The provided address must point to a valid instruction.

source

pub fn detach(&mut self, listener: NativePointer)

Available on crate feature invocation-listener only.

Detach an attached listener.

§Safety

The listener must have been attached with Interceptor::attach().

source

pub fn replace( &mut self, function: NativePointer, replacement: NativePointer, replacement_data: NativePointer ) -> Result<NativePointer>

Replace a function with another function. The new function should have the same signature as the old one.

§Safety

Assumes that the provided function and replacement addresses are valid and point to the start of valid functions

source

pub fn replace_fast( &mut self, function: NativePointer, replacement: NativePointer ) -> Result<NativePointer>

Replace a function with another function. The new function should have the same signature as the old one. This implementation avoids the overhead of the re-entrancy checking and context push/pop of conventional interceptors returning the address of a simple trampoline and patching the original function with the provided replacement. This type is not interoperable with attach and requires the caller to pass any required data to the hook function themselves.

§Safety

Assumes that the provided function and replacement addresses are valid and point to the start of valid functions

source

pub fn revert(&mut self, function: NativePointer)

Reverts a function replacement for the given function, such that the implementation is the original function.

§Safety

Assumes that function is the start of a real function previously replaced uisng Interceptor::replace.

source

pub fn current_invocation() -> InvocationContext<'a>

Available on crate feature invocation-listener only.

Retrieve the current InvocationContext.

§Safety

Should only be called from within a hook or replacement function.

source

pub fn begin_transaction(&mut self)

Begin an Interceptor transaction. This may improve performance if applying many hooks.

§Safety

After placing hooks, the transaction must be ended with Interceptor::end_transaction().

source

pub fn end_transaction(&mut self)

End an Interceptor transaction. This must be called after placing hooks if in a transaction started with Interceptor::begin_transaction().

Auto Trait Implementations§

§

impl<'a> Freeze for Interceptor<'a>

§

impl<'a> RefUnwindSafe for Interceptor<'a>

§

impl<'a> !Send for Interceptor<'a>

§

impl<'a> !Sync for Interceptor<'a>

§

impl<'a> Unpin for Interceptor<'a>

§

impl<'a> UnwindSafe for Interceptor<'a>

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>,

§

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>,

§

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.