From eb7a52bf4bd3b19c22f2eadda444ab045c674fe3 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Mon, 3 May 2021 18:45:19 -0400 Subject: Rust API : Better headless support; Introducing `binaryninja::open_view` and `binaryninja::open_view_with_options`, updated init/shutdown, script example, more setting support, and misc fixes --- rust/src/filemetadata.rs | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'rust/src/filemetadata.rs') diff --git a/rust/src/filemetadata.rs b/rust/src/filemetadata.rs index fa7d65e1..809abea4 100644 --- a/rust/src/filemetadata.rs +++ b/rust/src/filemetadata.rs @@ -31,6 +31,8 @@ use binaryninjacore_sys::{ BNMarkFileSaved, BNNavigate, BNNewFileReference, + BNOpenDatabaseForConfiguration, + BNOpenExistingDatabase, BNRedo, BNSetFilename, BNUndo, @@ -168,10 +170,49 @@ impl FileMetadata { if res.is_null() { Err(()) } else { - Ok(Ref::new(BinaryView::from_raw(res))) + Ok(BinaryView::from_raw(res)) } } } + + pub fn open_database_for_configuration( + &mut self, + filename: S, + ) -> Result, ()> { + let filename = filename.as_bytes_with_nul(); + unsafe { + let bv = + BNOpenDatabaseForConfiguration(self.handle, filename.as_ref().as_ptr() as *const _); + + if bv.is_null() { + Err(()) + } else { + Ok(BinaryView::from_raw(bv)) + } + } + } + + pub fn open_database( + &mut self, + filename: S, + ) -> Result, ()> { + let filename = filename.as_bytes_with_nul(); + let filename_ptr = filename.as_ref().as_ptr() as *mut _; + + let view = unsafe { BNOpenExistingDatabase(self.handle, filename_ptr) }; + + // TODO : add optional progress function + // let view = match progress_func { + // None => BNOpenExistingDatabase(self.handle, filename_ptr), + // _ => BNOpenExistingDatabaseWithProgress(self.handle, str(filename), None, ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, cur, total: progress_func(cur, total))) + // }; + + if view.is_null() { + Err(()) + } else { + Ok(unsafe { BinaryView::from_raw(view) }) + } + } } impl ToOwned for FileMetadata { @@ -197,6 +238,4 @@ unsafe impl RefCountable for FileMetadata { /* BNCreateDatabase, BNCreateDatabaseWithProgress, -BNOpenExistingDatabase, -BNOpenExistingDatabaseWithProgress, */ -- cgit v1.3.1