Merge pull request #1575 from n1tram1/dev

Fix rust binding for insn_in hook callback
This commit is contained in:
lazymio 2022-04-03 00:42:45 +02:00 committed by GitHub
commit ec808c94a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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(()));
}