Skip to main content

InlineHook

Struct InlineHook 

Source
pub struct InlineHook<F: FnPtr> { /* private fields */ }
Available on crate feature inline only.
Expand description

Type-safe and RAII (drop guard) wrapper of an inline hook.

Manages the lifetime of a detour hook, providing easy enable/disable and cleanup through RAII principles.

See inline module for details.

§Type Parameters

  • F: The function type being hooked.

Implementations§

Source§

impl<F: FnPtr> InlineHook<F>

Source

pub fn with_enabled(target: F, detour: F, enable: bool) -> Result<Self, HRESULT>

Creates a new InlineHookGuard and immediately applies the hook.

§Arguments
  • enable: Whether to enable the hook immediately (true = enable, false = disable)
  • target: Pointer to the target function to hook
  • detour: Pointer to the detour/hooked function
§Returns
  • Ok(InlineHookGuard) if hook creation succeeds
  • HRESULT error if hook creation fails
Source

pub const fn new_disabled(target: F, detour: F) -> Self

Creates a new InlineHookGuard without immediately enabling it.

§Arguments
  • target: Pointer to the target function to hook
  • detour: Pointer to the detour/hooked function
§Returns

InlineHookGuard with the hook not yet applied. Call enable() to apply it.

Source

pub fn new(target: F, detour: F) -> Result<Self, HRESULT>

Creates a new InlineHookGuard with the hook enabled.

§Arguments
  • target: Pointer to the target function to hook
  • detour: Pointer to the detour/hooked function
§Returns
  • Ok(InlineHookGuard) with the hook created and enabled
  • HRESULT error if hook creation fails
Source

pub fn set_enabled(&mut self, enable: bool) -> HRESULT

Enables or disables the hook.

§Arguments
  • enable: true to enable, false to disable
§Returns
  • HRESULT success or error code
Source

pub fn enable(&mut self) -> HRESULT

Enables the hook.

§Returns
  • Ok(()) if the hook is enabled successfully (or already enabled)
  • HRESULT error if enabling fails
Source

pub fn disable(&mut self) -> HRESULT

Disables the hook.

§Returns
  • Ok(()) if the hook is disabled successfully (or not enabled)
  • HRESULT error if disabling fails
Source

pub fn toggle(&mut self) -> HRESULT

Toggles the hook state (enabled -> disabled, disabled -> enabled).

§Returns
  • Ok(()) if toggle succeeds
  • HRESULT error if toggle fails
Source

pub fn is_enabled(&self) -> bool

Returns true if the hook is currently enabled.

Source

pub const fn target(&self) -> F

Returns the target function being hooked.

Source

pub fn is_target(&self, other: F) -> bool

Returns true if other is the same target function as this hook.

This is mainly for avoiding the warning if not using std::ptr::fn_addr_eq().

Source

pub const fn detour(&self) -> F

Returns the detour function that will be called when the hook is active.

Source

pub const fn trampoline(&self) -> F

Returns the trampoline function holding the original target implementation.

When the hook is enabled, calling target() redirects to detour(), while trampoline() provides access to the original target functionality.

Trait Implementations§

Source§

impl<F: Debug + FnPtr> Debug for InlineHook<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: FnPtr> Drop for InlineHook<F>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<F> Freeze for InlineHook<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for InlineHook<F>

§

impl<F> Send for InlineHook<F>

§

impl<F> Sync for InlineHook<F>

§

impl<F> Unpin for InlineHook<F>

§

impl<F> UnsafeUnpin for InlineHook<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for InlineHook<F>

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> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more