From 7873e6074087f6b66cc4fc78054e8f8653333a92 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Wed, 10 Nov 2021 04:21:30 +0100 Subject: [PATCH] reverted unfinished commit --- bindings/rust/src/ffi.rs | 6 +++--- bindings/rust/src/lib.rs | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bindings/rust/src/ffi.rs b/bindings/rust/src/ffi.rs index 2cf7faf9..300e1220 100644 --- a/bindings/rust/src/ffi.rs +++ b/bindings/rust/src/ffi.rs @@ -80,12 +80,12 @@ extern "C" { pub struct UcHook<'a, D: 'a, F: 'a> { pub callback: F, - pub uc: Unicorn, + pub uc: Unicorn<'a, D>, } -pub trait IsUcHook {} +pub trait IsUcHook<'a> {} -impl<'a, D, F> IsUcHook for UcHook<'a, D, F> {} +impl<'a, D, F> IsUcHook<'a> for UcHook<'a, D, F> {} pub extern "C" fn code_hook_proxy( uc: uc_handle, diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index f96b795f..7b5c35c6 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -77,15 +77,16 @@ impl Drop for Context { } } -pub struct UnicornInner { +pub struct UnicornInner<'a, D> { pub uc: uc_handle, pub arch: Arch, /// to keep ownership over the hook for this uc instance's lifetime - pub hooks: Vec<(ffi::uc_hook, Box)>, + pub hooks: Vec<(ffi::uc_hook, Box + 'a>)>, + pub data: D, } /// Drop UC -impl Drop for UnicornInner { +impl<'a, D> Drop for UnicornInner<'a, D> { fn drop(&mut self) { if !self.uc.is_null() { unsafe { ffi::uc_close(self.uc) }; @@ -95,25 +96,25 @@ impl Drop for UnicornInner { } /// A Unicorn emulator instance. -pub struct Unicorn { - inner: Rc>>, +pub struct Unicorn<'a, D: 'a> { + inner: Rc>>, } -impl<'a> Unicorn<'a> { +impl<'a> Unicorn<'a, ()> { /// Create a new instance of the unicorn engine for the specified architecture /// and hardware mode. - pub fn new(arch: Arch, mode: Mode) -> Result, uc_error> { + pub fn new(arch: Arch, mode: Mode) -> Result, uc_error> { Self::new_with_data(arch, mode, ()) } } -impl<'a, D> Unicorn<'a> +impl<'a, D> Unicorn<'a, D> where D: 'a, { /// Create a new instance of the unicorn engine for the specified architecture /// and hardware mode. - pub fn new_with_data(arch: Arch, mode: Mode, data: D) -> Result, uc_error> { + pub fn new_with_data(arch: Arch, mode: Mode, data: D) -> Result, uc_error> { let mut handle = core::ptr::null_mut(); let err = unsafe { ffi::uc_open(arch, mode, &mut handle) }; if err == uc_error::OK {