Struct VTable

Source
pub struct VTable {
    pub begin: RawVTable,
    pub size: usize,
}

Fields§

§begin: RawVTable§size: usize

Implementations§

Source§

impl VTable

Source

pub unsafe fn new(vtable: RawVTable) -> Self

Source

pub unsafe fn new_with_size(vtable: RawVTable, size: usize) -> Self

Examples found in repository?
examples/copy_raw.rs (line 38)
31fn main() {
32    unsafe {
33        /* The same classes, but one is our victim, and the other is unaffected. */
34        let mut victim_cpp_class = CppClass::default();
35        let unaffected_cpp_class = CppClass::default();
36
37        /* Setting up raw hook */
38        let original_vtable = vtable_hook::VTable::new_with_size(victim_cpp_class.vtable as _, 1);
39        let mut raw_hook = vtable_hook::hook::copy::raw::RawHook::new(
40            &mut victim_cpp_class.vtable as *mut _ as _,
41            Some(original_vtable),
42        );
43        eprintln!("Raw hook: {raw_hook:#?}");
44
45        /* Hooks are unset now, let's test that its true */
46        eprintln!("-- Hook is disabled -- ");
47        eprintln!(
48            "victim_cpp_class's raw_hook is_enabled {}",
49            raw_hook.is_enabled()
50        );
51        eprintln!(
52            "victim_cpp_class foo() result = {}",
53            (victim_cpp_class.vtable.read().foo)(&victim_cpp_class)
54        );
55        eprintln!(
56            "unaffected_cpp_class foo() result = {}",
57            (unaffected_cpp_class.vtable.read().foo)(&unaffected_cpp_class)
58        );
59        /* victim_cpp_class's raw_hook is_enabled false
60         * victim_cpp_class foo() result = 0
61         * unaffected_cpp_class foo() result = 0 */
62
63        /* Replacing foo inside raw_hook */
64        raw_hook.replace_method(0, foo_hooked as _);
65        /* Replacing victim_cpp_class's VTable */
66        raw_hook.enable();
67        /* Testing */
68        eprintln!("-- Hook is enabled -- ");
69        eprintln!(
70            "victim_cpp_class's raw_hook is_enabled {}",
71            raw_hook.is_enabled()
72        );
73        eprintln!(
74            "victim_cpp_class foo() result = {}",
75            (victim_cpp_class.vtable.read().foo)(&victim_cpp_class)
76        );
77        eprintln!(
78            "unaffected_cpp_class foo() result = {}",
79            (unaffected_cpp_class.vtable.read().foo)(&unaffected_cpp_class)
80        );
81        /* victim_cpp_class's raw_hook is_enabled true
82         * victim_cpp_class foo() result = 1
83         * unaffected_cpp_class foo() result = 0 */
84
85        /* Restoring victim_cpp_class's VTable */
86        raw_hook.disable();
87        /* NOTE: raw_hook's foo method still points to our function,
88         * but we have restored original VTable inside victim_cpp_class
89         * To restore methods inside raw_hook use raw_hook.restore_method()
90         * or raw_hook.restore_all() */
91        eprintln!("-- Hook is disabled -- ");
92        eprintln!(
93            "victim_cpp_class's raw_hook is_enabled {}",
94            raw_hook.is_enabled()
95        );
96        eprintln!(
97            "victim_cpp_class foo() result = {}",
98            (victim_cpp_class.vtable.read().foo)(&victim_cpp_class)
99        );
100        eprintln!(
101            "unaffected_cpp_class foo() result = {}",
102            (unaffected_cpp_class.vtable.read().foo)(&unaffected_cpp_class)
103        );
104        /* victim_cpp_class's raw_hook is_enabled false
105         * victim_cpp_class foo() result = 0
106         * unaffected_cpp_class foo() result = 0 */
107    }
108}
Source

pub unsafe fn count_methods_raw(vtable: RawVTable) -> usize

Source

pub unsafe fn as_slice(&self) -> &[Method]

Trait Implementations§

Source§

impl Clone for VTable

Source§

fn clone(&self) -> VTable

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VTable

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for VTable

§

impl RefUnwindSafe for VTable

§

impl !Send for VTable

§

impl !Sync for VTable

§

impl Unpin for VTable

§

impl UnwindSafe for VTable

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.