diff options
| author | Alexander Khosrowshahi <alexk@vector35.com> | 2025-06-30 14:56:41 -0400 |
|---|---|---|
| committer | Alexander Khosrowshahi <alexk@vector35.com> | 2025-07-03 13:47:57 -0400 |
| commit | 2be7b54b7bc7a0e46408b228ee55bbb4fe342e6c (patch) | |
| tree | 8c55b55ccaef570f6388411d7f990dbcc6a710ab | |
| parent | 2cd19b867772f15d87eaee9560b94a9fd9ba13e4 (diff) | |
Add GetPathInProject() to core API
| -rw-r--r-- | binaryninjaapi.h | 1 | ||||
| -rw-r--r-- | binaryninjacore.h | 1 | ||||
| -rw-r--r-- | examples/triage/fileinfo.cpp | 11 | ||||
| -rw-r--r-- | project.cpp | 8 |
4 files changed, 20 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 66f40fac..0c86e026 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2878,6 +2878,7 @@ namespace BinaryNinja { Ref<Project> GetProject() const; std::string GetPathOnDisk() const; + std::string GetPathInProject() const; bool ExistsOnDisk() const; std::string GetName() const; std::string GetDescription() const; diff --git a/binaryninjacore.h b/binaryninjacore.h index 215cd6b2..e25b1b8f 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -4037,6 +4037,7 @@ extern "C" BINARYNINJACOREAPI void BNFreeProjectFile(BNProjectFile* file); BINARYNINJACOREAPI void BNFreeProjectFileList(BNProjectFile** files, size_t count); BINARYNINJACOREAPI char* BNProjectFileGetPathOnDisk(BNProjectFile* file); + BINARYNINJACOREAPI char* BNProjectFileGetPathInProject(BNProjectFile* file); BINARYNINJACOREAPI bool BNProjectFileExistsOnDisk(BNProjectFile* file); BINARYNINJACOREAPI char* BNProjectFileGetName(BNProjectFile* file); BINARYNINJACOREAPI bool BNProjectFileSetName(BNProjectFile* file, const char* name); diff --git a/examples/triage/fileinfo.cpp b/examples/triage/fileinfo.cpp index 3250feae..b521b892 100644 --- a/examples/triage/fileinfo.cpp +++ b/examples/triage/fileinfo.cpp @@ -72,9 +72,18 @@ FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv) this->m_layout->setVerticalSpacing(1); const auto view = bv->GetParentView() ? bv->GetParentView() : bv; - const auto filePath = bv->GetFile()->GetOriginalFilename(); + + const auto file = bv->GetFile(); + const auto filePath = file->GetOriginalFilename(); this->addCopyableField("Path: ", filePath.c_str()); + // If triage view is opened from a project, show both actual filepath and path relative to project + if (const auto fileProjectRef = file->GetProjectFile()) + { + const auto projectFilePath = file->GetProjectFile()->GetPathInProject(); + this->addCopyableField("Path in project: ", projectFilePath.c_str()); + } + const auto fileSize = QString::number(view->GetLength(), 16).prepend("0x"); this->addCopyableField("Size: ", fileSize); diff --git a/project.cpp b/project.cpp index da4ee88d..6cb76a02 100644 --- a/project.cpp +++ b/project.cpp @@ -552,6 +552,14 @@ std::string ProjectFile::GetPathOnDisk() const return result; } +std::string ProjectFile::GetPathInProject() const +{ + char* path = BNProjectFileGetPathInProject(m_object); + std::string result = path; + BNFreeString(path); + return result; +} + bool ProjectFile::ExistsOnDisk() const { |
