Open
Description
use unicorn_engine::unicorn_const::{Arch, Mode, Permission, SECOND_SCALE};
use unicorn_engine::{Unicorn, UcHookId};
static mut STEP_HOOK: Option<UcHookId> = None;
fn step_hook(uc: &mut Unicorn<()>, _addr: u64, _size: u32) {
unsafe {
if let Some(step_hook) = STEP_HOOK {
uc.remove_hook(step_hook)
.expect("Failed to remove step hook");
STEP_HOOK = None
}
}
}
fn main() {
let x86_code = [
0x48, 0xB8, 0xEF, 0xBE, 0xAD, 0xDE, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x05,
];
let mut uc = unicorn_engine::Unicorn::new(Arch::X86, Mode::MODE_32)
.expect("failed to initialize unicorn instance");
assert_eq!(uc.mem_map(0x1000, 0x4000, Permission::ALL), Ok(()));
assert_eq!(uc.mem_write(0x1000, &x86_code), Ok(()));
unsafe {
STEP_HOOK = Some(
uc.add_code_hook(1, 0, step_hook)
.expect("Failed to add code hook"),
)
}
let _ = uc.emu_start(
0x1000,
(0x1000 + x86_code.len()) as u64,
10 * SECOND_SCALE,
0,
);
}
Refer #1543.
Metadata
Metadata
Assignees
Labels
No labels