pub struct FileMetadata { /* private fields */ }Expand description
File metadata provides information about a file in the context of Binary Ninja. It contains no
analysis information, only information useful for identifying a file, such as the FileMetadata::file_path.
Another responsibility of the FileMetadata is to own the available BinaryViews for the
file, such as the “Raw” view and any other views that may be created for the file.
Important: Because FileMetadata holds a strong reference to the BinaryViews and those
views hold a strong reference to the file metadata, to end the cyclic reference a call to the
FileMetadata::close is required.
Implementations§
Source§impl FileMetadata
impl FileMetadata
Sourcepub fn new() -> Ref<Self>
pub fn new() -> Ref<Self>
Create an empty FileMetadata with no associated file path.
Unless you are creating an ephemeral file with no backing, prefer FileMetadata::with_file_path.
Sourcepub fn with_file_path(path: &Path) -> Ref<Self>
pub fn with_file_path(path: &Path) -> Ref<Self>
Build a FileMetadata with the given path.
Sourcepub fn close(&self)
pub fn close(&self)
Closes the FileMetadata allowing any BinaryView parented to it to be freed.
Sourcepub fn session_id(&self) -> SessionId
pub fn session_id(&self) -> SessionId
An id unique to this FileMetadata, mostly used for associating logs with a specific file.
Sourcepub fn file_path(&self) -> PathBuf
pub fn file_path(&self) -> PathBuf
The path to the FileMetadata on disk.
This will not point to the original file on disk, in the event that the file was saved as a BNDB. When a BNDB is opened, the FileMetadata will contain the file path to the database.
If you need the original binary file path, use FileMetadata::original_file_path instead.
If you just want a name to present to the user, use FileMetadata::display_name.
Sourcepub fn display_name(&self) -> String
pub fn display_name(&self) -> String
The display name of the file. Useful for presenting to the user. Can differ from the original
name of the file and can be overridden with FileMetadata::set_display_name.
Sourcepub fn set_display_name(&self, name: &str)
pub fn set_display_name(&self, name: &str)
Set the display name of the file.
This can be anything and will not be used for any purpose other than presentation.
Sourcepub fn original_file_path(&self) -> Option<PathBuf>
pub fn original_file_path(&self) -> Option<PathBuf>
The path to the original file on disk, if any.
It may not be present if the BNDB was saved without it or cleared via FileMetadata::clear_original_file_path.
If this FileMetadata is a database within a project, it may not have a “consumable” original
file path. Instead, this might return the path to the on disk file path of the project file that
this database was created from, for projects you should query through FileMetadata::project_file.
Only prefer this over FileMetadata::file_path if you require the original binary location.
Sourcepub fn set_original_file_path(&self, path: &Path)
pub fn set_original_file_path(&self, path: &Path)
Set the original file path inside the database. Useful if it has since been cleared from the database, or you have moved the original file.
Sourcepub fn clear_original_file_path(&self)
pub fn clear_original_file_path(&self)
Clear the original file path inside the database. This is useful since the original file path may be sensitive information you wish to not share with others.
Sourcepub fn virtual_path(&self) -> Option<String>
pub fn virtual_path(&self) -> Option<String>
The non-filesystem path that describes how this file was derived from the container transform system, detailing the sequence of transform steps and selection names.
NOTE: Returns None if this FileMetadata was not processed by the transform system and
does not differ from that of the “physical” file path reported by FileMetadata::file_path.
Sourcepub fn set_virtual_path(&self, path: &str)
pub fn set_virtual_path(&self, path: &str)
Sets the non-filesystem path that describes how this file was derived from the container transform system.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Whether the file is currently flagged as modified.
When this returns true, the UI will prompt to save the database on close, as well as display
a dot in the files tab.
Sourcepub fn mark_modified(&self)
pub fn mark_modified(&self)
Marks the file as modified such that we can prompt to save the database on close.
Sourcepub fn mark_saved(&self)
pub fn mark_saved(&self)
Marks the file as saved such that FileMetadata::is_modified and FileMetadata::is_analysis_changed
will return false and the undo buffer associated with this FileMetadata will be updated.
pub fn is_analysis_changed(&self) -> bool
Sourcepub fn is_database_backed(&self) -> bool
pub fn is_database_backed(&self) -> bool
Checks to see if the database exists for the file.
Sourcepub fn is_database_backed_for_view_type(&self, view_type: &str) -> bool
pub fn is_database_backed_for_view_type(&self, view_type: &str) -> bool
Checks to see if the file metadata has a Database, and then checks to see if the view_type
is available.
NOTE: Passing an empty string will simply check if the database exists.
Sourcepub fn run_undoable_transaction<F: FnOnce() -> Result<T, E>, T, E>(
&self,
func: F,
) -> Result<T, E>
pub fn run_undoable_transaction<F: FnOnce() -> Result<T, E>, T, E>( &self, func: F, ) -> Result<T, E>
Runs a failable function where the failure state will revert any undo actions that occurred during the time of the function’s execution.
NOTE: This will commit or undo any actions that occurred on any thread as this state is not thread local.
NOTE: This is NOT thread safe, if you are holding any locks that might be held by both the main thread and the thread executing this function, you can deadlock. You should also never call this function on multiple threads at a time. See the following issues:
Sourcepub fn begin_undo_actions(&self, anonymous_allowed: bool) -> String
pub fn begin_undo_actions(&self, anonymous_allowed: bool) -> String
Creates a new undo entry, any undo actions after this will be added to this entry.
NOTE: This is NOT thread safe, if you are holding any locks that might be held by both the main thread and the thread executing this function, you can deadlock. You should also never call this function on multiple threads at a time. See the following issues:
Sourcepub fn commit_undo_actions(&self, id: &str)
pub fn commit_undo_actions(&self, id: &str)
Commits the undo entry with the id to the undo buffer.
NOTE: This is NOT thread safe, if you are holding any locks that might be held by both the main thread and the thread executing this function, you can deadlock. You should also never call this function on multiple threads at a time. See the following issues:
Sourcepub fn revert_undo_actions(&self, id: &str)
pub fn revert_undo_actions(&self, id: &str)
Reverts the undo actions committed in the undo entry.
NOTE: This is NOT thread safe, if you are holding any locks that might be held by both the main thread and the thread executing this function, you can deadlock. You should also never call this function on multiple threads at a time. See the following issues:
Sourcepub fn forget_undo_actions(&self, id: &str)
pub fn forget_undo_actions(&self, id: &str)
Forgets the undo actions committed in the undo entry.
NOTE: This is NOT thread safe, if you are holding any locks that might be held by both the main thread and the thread executing this function, you can deadlock. You should also never call this function on multiple threads at a time. See the following issues:
pub fn undo(&self)
pub fn redo(&self)
Sourcepub fn raw_view(&self) -> Ref<BinaryView>
pub fn raw_view(&self) -> Ref<BinaryView>
Retrieve the raw view for the file, this should always be present.
The “Raw” view is a special BinaryView that holds data required for updating and creating
Databases such as the view and load settings.
Sourcepub fn current_view(&self) -> String
pub fn current_view(&self) -> String
The current view for the file.
For example, opening a PE file and navigating to the linear view will return “Linear:PE”.
Sourcepub fn current_offset(&self) -> u64
pub fn current_offset(&self) -> u64
The current offset navigated to within the FileMetadata::current_view.
Navigate to an offset for a specific view.
§Example
use binaryninja::file_metadata::FileMetadata;
file.navigate_to("Linear:Raw", 0x0).expect("Linear:Raw should always be present");Sourcepub fn view_of_type(&self, view: &str) -> Option<Ref<BinaryView>>
pub fn view_of_type(&self, view: &str) -> Option<Ref<BinaryView>>
Get the BinaryView for the view type.
§Example
use binaryninja::file_metadata::FileMetadata;
file.view_of_type("Raw").expect("Raw type should always be present");Sourcepub fn view_types(&self) -> Array<BnString>
pub fn view_types(&self) -> Array<BnString>
The BinaryViewTypes associated with this file.
For example, opening a PE binary will have the following: “Raw”, “PE”.
Sourcepub fn project_file(&self) -> Option<Ref<ProjectFile>>
pub fn project_file(&self) -> Option<Ref<ProjectFile>>
Get the ProjectFile for the FileMetadata.
Sourcepub fn create_database(
&self,
file_path: impl AsRef<Path>,
settings: &SaveSettings,
) -> bool
pub fn create_database( &self, file_path: impl AsRef<Path>, settings: &SaveSettings, ) -> bool
Create a database for the file and its views at file_path.
NOTE: Calling this while analysis is running will flag the next load of the database to regenerate the current analysis.
Sourcepub fn create_database_with_progress<P: ProgressCallback>(
&self,
file_path: impl AsRef<Path>,
settings: &SaveSettings,
progress: P,
) -> bool
pub fn create_database_with_progress<P: ProgressCallback>( &self, file_path: impl AsRef<Path>, settings: &SaveSettings, progress: P, ) -> bool
Create a database for the file and its views at file_path, with a progress callback.
NOTE: Calling this while analysis is running will flag the next load of the database to regenerate the current analysis.
Sourcepub fn save_auto_snapshot(&self) -> bool
pub fn save_auto_snapshot(&self) -> bool
Save a new snapshot of the current file.
NOTE: Calling this while analysis is running will flag the next load of the database to regenerate the current analysis.