pub struct RawHook { /* private fields */ }
Implementations§
Source§impl RawHook
impl RawHook
Sourcepub unsafe fn new(
struct_vtable_field_ptr: *mut RawVTable,
original_vtable: Option<VTable>,
) -> Self
pub unsafe fn new( struct_vtable_field_ptr: *mut RawVTable, original_vtable: Option<VTable>, ) -> Self
Examples found in repository?
examples/copy_raw.rs (lines 39-42)
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}
Sourcepub unsafe fn is_enabled(&self) -> bool
pub unsafe fn is_enabled(&self) -> bool
Examples found in repository?
examples/copy_raw.rs (line 49)
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}
Sourcepub unsafe fn enable(&mut self) -> bool
pub unsafe fn enable(&mut self) -> bool
Examples found in repository?
examples/copy_raw.rs (line 66)
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}
Sourcepub unsafe fn disable(&mut self) -> bool
pub unsafe fn disable(&mut self) -> bool
Examples found in repository?
examples/copy_raw.rs (line 86)
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}
Sourcepub unsafe fn replace_method(
&mut self,
index: usize,
our_method: Method,
) -> Option<()>
pub unsafe fn replace_method( &mut self, index: usize, our_method: Method, ) -> Option<()>
Examples found in repository?
examples/copy_raw.rs (line 64)
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 restore_method(&mut self, index: usize) -> Option<()>
pub unsafe fn restore_all(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawHook
impl RefUnwindSafe for RawHook
impl !Send for RawHook
impl !Sync for RawHook
impl Unpin for RawHook
impl UnwindSafe for RawHook
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