From 193298e485806659814ef8bf0d791012b9d00e10 Mon Sep 17 00:00:00 2001 From: "Takacs, Philipp" Date: Thu, 15 Jan 2026 14:33:02 +0100 Subject: [PATCH] add emu_run --- crates/unicorn/src/ffi.rs | 6 ++++++ crates/unicorn/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/unicorn/src/ffi.rs b/crates/unicorn/src/ffi.rs index a553020..89bf0c3 100644 --- a/crates/unicorn/src/ffi.rs +++ b/crates/unicorn/src/ffi.rs @@ -97,6 +97,12 @@ extern "C" { timeout: u64, count: libc::size_t, ) -> uc_error; + pub fn uc_emu_run( + engine: uc_handle, + until: u64, + timeout: u64, + count: libc::size_t, + ) -> uc_error; pub fn uc_emu_stop(engine: uc_handle) -> uc_error; pub fn uc_hook_add( engine: uc_handle, diff --git a/crates/unicorn/src/lib.rs b/crates/unicorn/src/lib.rs index 4ee1237..6cd458d 100644 --- a/crates/unicorn/src/lib.rs +++ b/crates/unicorn/src/lib.rs @@ -1236,6 +1236,22 @@ impl<'a, D> Unicorn<'a, D> { unsafe { uc_emu_start(self.get_handle(), begin, until, timeout, count as _) }.into() } + /// Emulate machine code starting from the current instruction pointer. + /// + /// The emulation stops if `until` is hit. `timeout` specifies a duration in microseconds + /// after which the emulation is stopped (infinite execution if set to 0). `count` is the + /// maximum number of instructions to emulate (emulate all the available instructions if + /// set to 0). + pub fn emu_start( + &mut self, + begin: u64, + until: u64, + timeout: u64, + count: usize, + ) -> Result<(), uc_error> { + unsafe { uc_emu_run(self.get_handle(), until, timeout, count as _) }.into() + } + /// Stop the emulation. /// /// This is usually called from callback function in hooks.