diff options
| -rw-r--r-- | binaryninjaapi.h | 14 | ||||
| -rw-r--r-- | binaryninjacore.h | 5 | ||||
| -rw-r--r-- | filemetadata.cpp | 15 | ||||
| -rw-r--r-- | python/filemetadata.py | 19 | ||||
| -rw-r--r-- | ui/filecontext.h | 1 |
5 files changed, 53 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 5c73fe9a..3a2a7941 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3803,6 +3803,20 @@ namespace BinaryNinja { */ void SetVirtualPath(const std::string& path); + /*! Get the display name for the file. For container entries, this returns the synthesized name + representing the extracted artifact. For normal files, this returns the filename. + + \return The display name for UI purposes (tab titles, save dialogs, etc.) + */ + std::string GetDisplayName() const; + + /*! Set the display name for the file. This is typically used for container entries to store + a synthesized name representing the extracted artifact. + + \param name The display name to set + */ + void SetDisplayName(const std::string& name); + /*! Whether the file has unsaved modifications \return Whether the file has unsaved modifications diff --git a/binaryninjacore.h b/binaryninjacore.h index 228b1745..c2db1132 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,7 +37,7 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 155 +#define BN_CURRENT_CORE_ABI_VERSION 156 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and @@ -4451,6 +4451,9 @@ extern "C" BINARYNINJACOREAPI char* BNGetVirtualPath(BNFileMetadata* file); BINARYNINJACOREAPI void BNSetVirtualPath(BNFileMetadata* file, const char* path); + BINARYNINJACOREAPI char* BNGetDisplayName(BNFileMetadata* file); + BINARYNINJACOREAPI void BNSetDisplayName(BNFileMetadata* file, const char* name); + BINARYNINJACOREAPI BNProjectFile* BNGetProjectFile(BNFileMetadata* file); BINARYNINJACOREAPI void BNSetProjectFile(BNFileMetadata* file, BNProjectFile* pfile); diff --git a/filemetadata.cpp b/filemetadata.cpp index 3ce82521..18c30591 100644 --- a/filemetadata.cpp +++ b/filemetadata.cpp @@ -144,6 +144,21 @@ void FileMetadata::SetVirtualPath(const string& path) } +string FileMetadata::GetDisplayName() const +{ + char* str = BNGetDisplayName(m_object); + string result = str; + BNFreeString(str); + return result; +} + + +void FileMetadata::SetDisplayName(const string& name) +{ + BNSetDisplayName(m_object, name.c_str()); +} + + bool FileMetadata::IsModified() const { return BNIsFileModified(m_object); diff --git a/python/filemetadata.py b/python/filemetadata.py index 810d4d17..23965ac9 100644 --- a/python/filemetadata.py +++ b/python/filemetadata.py @@ -224,6 +224,25 @@ class FileMetadata: core.BNSetVirtualPath(self.handle, str(value)) @property + def display_name(self) -> str: + """ + ``display_name`` is the synthesized name for UI display purposes. + + For container entries, this contains a virtual filename representing the extracted artifact (e.g., "/path/to/entry"). + For normal files, this equals ``filename``. + + Use this property for tab titles, save dialog defaults, and other UI display purposes. + Use ``filename`` for the actual physical file path that can be reopened. + + .. note:: For normal files, ``filename`` == ``virtual_path`` == ``display_name``. For container files, ``filename`` is the container path, ``virtual_path`` is the transform chain, and ``display_name`` is the extracted entry name. + """ + return core.BNGetDisplayName(self.handle) + + @display_name.setter + def display_name(self, value: str) -> None: + core.BNSetDisplayName(self.handle, str(value)) + + @property def modified(self) -> bool: """Boolean result of whether the file is modified (Inverse of 'saved' property) (read/write)""" return core.BNIsFileModified(self.handle) diff --git a/ui/filecontext.h b/ui/filecontext.h index 53b108f5..6a8c1d51 100644 --- a/ui/filecontext.h +++ b/ui/filecontext.h @@ -65,6 +65,7 @@ class BINARYNINJAUIAPI FileContext : public FileContextBase, public BinaryNinja: FileMetadataRef getMetadata() const { return m_file; } QString getFilename() const { return m_filename; } void setFilename(QString newName) { m_filename = newName; } + QString getDisplayName() const; ViewFrame* getCurrentViewFrame() const { return m_currentViewFrame; } QString getTabName(QWidget* widget); QString getShortFileName(QWidget* widget); |
