reverted unfinished commit

This commit is contained in:
Dominik Maier
2021-11-10 04:21:30 +01:00
parent a231440cf8
commit 7873e60740
2 changed files with 13 additions and 12 deletions

View File

@ -80,12 +80,12 @@ extern "C" {
pub struct UcHook<'a, D: 'a, F: 'a> { pub struct UcHook<'a, D: 'a, F: 'a> {
pub callback: F, 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<D, F>( pub extern "C" fn code_hook_proxy<D, F>(
uc: uc_handle, uc: uc_handle,

View File

@ -77,15 +77,16 @@ impl Drop for Context {
} }
} }
pub struct UnicornInner { pub struct UnicornInner<'a, D> {
pub uc: uc_handle, pub uc: uc_handle,
pub arch: Arch, pub arch: Arch,
/// to keep ownership over the hook for this uc instance's lifetime /// to keep ownership over the hook for this uc instance's lifetime
pub hooks: Vec<(ffi::uc_hook, Box<dyn ffi::IsUcHook>)>, pub hooks: Vec<(ffi::uc_hook, Box<dyn ffi::IsUcHook<'a> + 'a>)>,
pub data: D,
} }
/// Drop UC /// Drop UC
impl Drop for UnicornInner { impl<'a, D> Drop for UnicornInner<'a, D> {
fn drop(&mut self) { fn drop(&mut self) {
if !self.uc.is_null() { if !self.uc.is_null() {
unsafe { ffi::uc_close(self.uc) }; unsafe { ffi::uc_close(self.uc) };
@ -95,25 +96,25 @@ impl Drop for UnicornInner {
} }
/// A Unicorn emulator instance. /// A Unicorn emulator instance.
pub struct Unicorn { pub struct Unicorn<'a, D: 'a> {
inner: Rc<UnsafeCell<UnicornInner<'a>>>, inner: Rc<UnsafeCell<UnicornInner<'a, D>>>,
} }
impl<'a> Unicorn<'a> { impl<'a> Unicorn<'a, ()> {
/// Create a new instance of the unicorn engine for the specified architecture /// Create a new instance of the unicorn engine for the specified architecture
/// and hardware mode. /// and hardware mode.
pub fn new(arch: Arch, mode: Mode) -> Result<Unicorn<'a>, uc_error> { pub fn new(arch: Arch, mode: Mode) -> Result<Unicorn<'a, ()>, uc_error> {
Self::new_with_data(arch, mode, ()) Self::new_with_data(arch, mode, ())
} }
} }
impl<'a, D> Unicorn<'a> impl<'a, D> Unicorn<'a, D>
where where
D: 'a, D: 'a,
{ {
/// Create a new instance of the unicorn engine for the specified architecture /// Create a new instance of the unicorn engine for the specified architecture
/// and hardware mode. /// and hardware mode.
pub fn new_with_data(arch: Arch, mode: Mode, data: D) -> Result<Unicorn<'a>, uc_error> { pub fn new_with_data(arch: Arch, mode: Mode, data: D) -> Result<Unicorn<'a, D>, uc_error> {
let mut handle = core::ptr::null_mut(); let mut handle = core::ptr::null_mut();
let err = unsafe { ffi::uc_open(arch, mode, &mut handle) }; let err = unsafe { ffi::uc_open(arch, mode, &mut handle) };
if err == uc_error::OK { if err == uc_error::OK {