Skip to content

Commit

Permalink
added tests for rust vmt hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbo committed May 28, 2024
1 parent 1a74b68 commit 9f8ca5f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bindings/rust/tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libmem::{
get_thread_ex, get_thread_process, hook_code, hook_code_ex, is_process_alive, load_module,
load_module_ex, pattern_scan, pattern_scan_ex, prot_memory, prot_memory_ex, read_memory,
read_memory_ex, set_memory, set_memory_ex, sig_scan, sig_scan_ex, unhook_code, unhook_code_ex,
unload_module, unload_module_ex, write_memory, write_memory_ex, Address, Arch, Bits, Prot,
unload_module, unload_module_ex, write_memory, write_memory_ex, Address, Arch, Bits, Prot, Vmt,
};

fn some_function(num: i32, c: char) {
Expand Down Expand Up @@ -378,4 +378,22 @@ fn main() {
unhook_code_ex(&target_process, wait_message_addr, target_tramp).unwrap();

println!("================================");

struct Dummy {
vtable: [fn(i32, char); 1],
}
let dummy_object = Dummy {
vtable: [some_function],
};

let mut vmt = Vmt::new(dummy_object.vtable.as_ptr() as Address);
unsafe { vmt.get_original::<fn(i32, char)>(0)(1, '2') };
println!();

unsafe { vmt.hook(0, hk_some_function as Address) };
dummy_object.vtable[0](69, 'W');
println!();

unsafe { vmt.unhook(0) };
dummy_object.vtable[0](42, '0');
}

0 comments on commit 9f8ca5f

Please sign in to comment.