pub struct VTable {
pub begin: RawVTable,
pub size: usize,
}
Fields§
§begin: RawVTable
§size: usize
Implementations§
Source§impl VTable
impl VTable
pub unsafe fn new(vtable: RawVTable) -> Self
Sourcepub unsafe fn new_with_size(vtable: RawVTable, size: usize) -> Self
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}
pub unsafe fn count_methods_raw(vtable: RawVTable) -> usize
pub unsafe fn as_slice(&self) -> &[Method] ⓘ
Trait Implementations§
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> 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