FileMetadata

Struct FileMetadata 

Source
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

Source

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.

Source

pub fn with_file_path(path: &Path) -> Ref<Self>

Build a FileMetadata with the given path.

Source

pub fn close(&self)

Closes the FileMetadata allowing any BinaryView parented to it to be freed.

Source

pub fn session_id(&self) -> SessionId

An id unique to this FileMetadata, mostly used for associating logs with a specific file.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn mark_modified(&self)

Marks the file as modified such that we can prompt to save the database on close.

Source

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.

Source

pub fn is_analysis_changed(&self) -> bool

Source

pub fn is_database_backed(&self) -> bool

Checks to see if the database exists for the file.

Source

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.

Source

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:

Source

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:

Source

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:

Source

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:

Source

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:

Source

pub fn undo(&self)

Source

pub fn redo(&self)

Source

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.

Source

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”.

Source

pub fn current_offset(&self) -> u64

The current offset navigated to within the FileMetadata::current_view.

Source

pub fn navigate_to(&self, view: &str, offset: u64) -> Result<(), ()>

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");
Source

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");
Source

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”.

Source

pub fn project_file(&self) -> Option<Ref<ProjectFile>>

Get the ProjectFile for the FileMetadata.

Source

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.

Source

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.

Source

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.

Source

pub fn open_database_for_configuration( &self, file: &Path, ) -> Result<Ref<BinaryView>, ()>

Source

pub fn open_database(&self, file: &Path) -> Result<Ref<BinaryView>, ()>

Source

pub fn open_database_with_progress<P: ProgressCallback>( &self, file: &Path, progress: P, ) -> Result<Ref<BinaryView>, ()>

Source

pub fn database(&self) -> Option<Ref<Database>>

Get the database attached to this file.

Only available if this file is a database, or has called FileMetadata::create_database.

Trait Implementations§

Source§

impl Debug for FileMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for FileMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for FileMetadata

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FileMetadata

Source§

fn eq(&self, other: &FileMetadata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToOwned for FileMetadata

Source§

type Owned = Ref<FileMetadata>

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl Eq for FileMetadata

Source§

impl Send for FileMetadata

Source§

impl StructuralPartialEq for FileMetadata

Source§

impl Sync for FileMetadata

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more