VmtHook

Struct VmtHook 

Source
pub struct VmtHook { /* private fields */ }
Expand description

a single VMT entry hook (modifies vtable directly)

this affects all objects of the class. use ShadowVmt for instance-specific hooking.

Implementations§

Source§

impl VmtHook

Source

pub unsafe fn new( object: *const (), index: usize, detour: usize, ) -> Result<Self>

create and install a VMT hook

§Arguments
  • object - pointer to the C++ object (or any pointer to a vptr)
  • index - index of the virtual function in the vtable
  • detour - address of the detour function
§Safety

The object pointer must point to a valid C++ object with a vtable. The index must be a valid vtable index for that class.

§Example
// hook the 3rd virtual function (index 2)
let hook = unsafe { VmtHook::new(object_ptr, 2, my_detour as usize)? };
let original: fn() = unsafe { std::mem::transmute(hook.original()) };
Source

pub fn new_at_vtable(vtable: usize, index: usize, detour: usize) -> Result<Self>

create and install a VMT hook at a known vtable address

§Arguments
  • vtable - address of the vtable
  • index - index of the virtual function
  • detour - address of the detour function
Source

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

install the hook

Source

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

remove the hook

Source

pub fn is_active(&self) -> bool

check if hook is active

Source

pub fn original(&self) -> usize

get the original function pointer

Source

pub fn detour(&self) -> usize

get the detour function pointer

Source

pub fn vtable_entry(&self) -> usize

get the vtable entry address

Source

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

set whether to auto-restore on drop

Source

pub fn leak(self)

leak the hook

Source

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

restore and consume

Trait Implementations§

Source§

impl Drop for VmtHook

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for VmtHook

Source§

impl Sync for VmtHook

Auto Trait Implementations§

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.