summaryrefslogtreecommitdiff
path: root/rust/src/filemetadata.rs
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2021-05-03 18:45:19 -0400
committerKyleMiles <krm504@nyu.edu>2021-05-11 16:49:24 -0400
commiteb7a52bf4bd3b19c22f2eadda444ab045c674fe3 (patch)
tree2395d577d410908b5d0291682660dac2017c7e97 /rust/src/filemetadata.rs
parent5731e612900bed0d542421e00e64324dbac9367e (diff)
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
Diffstat (limited to 'rust/src/filemetadata.rs')
-rw-r--r--rust/src/filemetadata.rs45
1 files changed, 42 insertions, 3 deletions
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<S: BnStrCompatible>(
+ &mut self,
+ filename: S,
+ ) -> Result<Ref<BinaryView>, ()> {
+ 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<S: BnStrCompatible>(
+ &mut self,
+ filename: S,
+ ) -> Result<Ref<BinaryView>, ()> {
+ 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,
*/