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
impl VmtHook
Sourcepub unsafe fn new(
object: *const (),
index: usize,
detour: usize,
) -> Result<Self>
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 vtabledetour- 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()) };Sourcepub fn new_at_vtable(vtable: usize, index: usize, detour: usize) -> Result<Self>
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 vtableindex- index of the virtual functiondetour- address of the detour function
Sourcepub fn vtable_entry(&self) -> usize
pub fn vtable_entry(&self) -> usize
get the vtable entry address
Sourcepub fn set_auto_restore(&mut self, restore: bool)
pub fn set_auto_restore(&mut self, restore: bool)
set whether to auto-restore on drop
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VmtHook
impl RefUnwindSafe for VmtHook
impl Unpin for VmtHook
impl UnwindSafe for VmtHook
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