rust: return u32 from insn_in_hook callback

This commit is contained in:
Martin Schmidt 2022-03-26 15:41:37 +01:00
parent 966798fbf6
commit 9702e657a2
3 changed files with 4 additions and 2 deletions

View File

@ -181,7 +181,7 @@ pub extern "C" fn insn_in_hook_proxy<D, F>(
size: usize,
user_data: *mut UcHook<D, F>,
) where
F: FnMut(&mut crate::Unicorn<D>, u32, usize),
F: FnMut(&mut crate::Unicorn<D>, u32, usize) -> u32,
{
let user_data = unsafe { &mut *user_data };
debug_assert_eq!(uc, user_data.uc.get_handle());

View File

@ -758,7 +758,7 @@ impl<'a, D> Unicorn<'a, D> {
/// Add hook for x86 IN instruction.
pub fn add_insn_in_hook<F: 'a>(&mut self, callback: F) -> Result<ffi::uc_hook, uc_error>
where
F: FnMut(&mut Unicorn<D>, u32, usize),
F: FnMut(&mut Unicorn<D>, u32, usize) -> u32,
{
let mut hook_ptr = core::ptr::null_mut();
let mut user_data = Box::new(ffi::UcHook {

View File

@ -309,6 +309,7 @@ fn x86_insn_in_callback() {
let callback_insn = insn_cell.clone();
let callback = move |_: &mut Unicorn<()>, port: u32, size: usize| {
*callback_insn.borrow_mut() = InsnInExpectation(port, size);
42
};
let x86_code32: Vec<u8> = vec![0xe5, 0x10]; // IN eax, 0x10;
@ -332,6 +333,7 @@ fn x86_insn_in_callback() {
Ok(())
);
assert_eq!(expect, *insn_cell.borrow());
assert_eq!(emu.reg_read(RegisterX86::EAX), Ok(42));
assert_eq!(emu.remove_hook(hook), Ok(()));
}