diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-05-12 00:52:51 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-05-12 00:52:51 -0400 |
| commit | a73d6e7cca0da2b9ec1f31095ab9026a2bcf81fe (patch) | |
| tree | 84dfeac464cba81409ba03c316616d2e430a12c7 /rust | |
| parent | 21da3f95b00431f4d10d8b5e67ee402bffde129c (diff) | |
Rust API : Add filemetadata::FileMetadata::create_database and filemetadata::FileMetadata::save_auto_snapshot
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/filemetadata.rs | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/rust/src/filemetadata.rs b/rust/src/filemetadata.rs index 8ba25387..11f8cb98 100644 --- a/rust/src/filemetadata.rs +++ b/rust/src/filemetadata.rs @@ -15,7 +15,9 @@ use binaryninjacore_sys::{ BNBeginUndoActions, BNCloseFile, + BNCloseProject, BNCommitUndoActions, + BNCreateDatabase, BNCreateFileMetadata, BNFileMetadata, BNFreeFileMetadata, @@ -27,13 +29,16 @@ use binaryninjacore_sys::{ BNIsBackedByDatabase, //BNSetFileMetadataNavigationHandler, BNIsFileModified, + BNIsProjectOpen, BNMarkFileModified, BNMarkFileSaved, BNNavigate, BNNewFileReference, BNOpenDatabaseForConfiguration, BNOpenExistingDatabase, + BNOpenProject, BNRedo, + BNSaveAutoSnapshot, BNSetFilename, BNUndo, }; @@ -43,6 +48,8 @@ use crate::binaryview::BinaryView; use crate::rc::*; use crate::string::*; +use std::ptr; + #[derive(PartialEq, Eq, Hash)] pub struct FileMetadata { pub(crate) handle: *mut BNFileMetadata, @@ -91,7 +98,7 @@ impl FileMetadata { } } - pub fn is_modified(&self) -> bool { + pub fn modified(&self) -> bool { unsafe { BNIsFileModified(self.handle) } } @@ -101,16 +108,16 @@ impl FileMetadata { } } - pub fn is_analysis_changed(&self) -> bool { - unsafe { BNIsAnalysisChanged(self.handle) } - } - pub fn mark_saved(&self) { unsafe { BNMarkFileSaved(self.handle); } } + pub fn is_analysis_changed(&self) -> bool { + unsafe { BNIsAnalysisChanged(self.handle) } + } + pub fn is_database_backed<S: BnStrCompatible>(&self, view_type: S) -> bool { let view_type = view_type.as_bytes_with_nul(); @@ -175,6 +182,29 @@ impl FileMetadata { } } + pub fn create_database<S: BnStrCompatible>(&self, filename: S) -> bool { + let filename = filename.as_bytes_with_nul(); + let raw = "Raw"; + + unsafe { + BNCreateDatabase( + BNGetFileViewOfType(self.handle, raw.as_ptr() as *mut _), + filename.as_ref().as_ptr() as *mut _, + ptr::null_mut() as *mut _, + ) + } + } + + pub fn save_auto_snapshot(&self) -> bool { + let raw = "Raw"; + unsafe { + BNSaveAutoSnapshot( + BNGetFileViewOfType(self.handle, raw.as_ptr() as *mut _), + ptr::null_mut() as *mut _, + ) + } + } + pub fn open_database_for_configuration<S: BnStrCompatible>( &self, filename: S, @@ -210,6 +240,20 @@ impl FileMetadata { Ok(unsafe { BinaryView::from_raw(view) }) } } + + pub fn open_project(&self) -> bool { + unsafe { BNOpenProject(self.handle) } + } + + pub fn close_project(&self) { + unsafe { + BNCloseProject(self.handle); + } + } + + pub fn is_project_open(&self) -> bool { + unsafe { BNIsProjectOpen(self.handle) } + } } impl ToOwned for FileMetadata { |
