Skip to content

Commit 2be7b54

Browse files
committed
Add GetPathInProject() to core API
1 parent 2cd19b8 commit 2be7b54

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

binaryninjaapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,6 +2878,7 @@ namespace BinaryNinja {
28782878

28792879
Ref<Project> GetProject() const;
28802880
std::string GetPathOnDisk() const;
2881+
std::string GetPathInProject() const;
28812882
bool ExistsOnDisk() const;
28822883
std::string GetName() const;
28832884
std::string GetDescription() const;

binaryninjacore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,7 @@ extern "C"
40374037
BINARYNINJACOREAPI void BNFreeProjectFile(BNProjectFile* file);
40384038
BINARYNINJACOREAPI void BNFreeProjectFileList(BNProjectFile** files, size_t count);
40394039
BINARYNINJACOREAPI char* BNProjectFileGetPathOnDisk(BNProjectFile* file);
4040+
BINARYNINJACOREAPI char* BNProjectFileGetPathInProject(BNProjectFile* file);
40404041
BINARYNINJACOREAPI bool BNProjectFileExistsOnDisk(BNProjectFile* file);
40414042
BINARYNINJACOREAPI char* BNProjectFileGetName(BNProjectFile* file);
40424043
BINARYNINJACOREAPI bool BNProjectFileSetName(BNProjectFile* file, const char* name);

examples/triage/fileinfo.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,18 @@ FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv)
7272
this->m_layout->setVerticalSpacing(1);
7373

7474
const auto view = bv->GetParentView() ? bv->GetParentView() : bv;
75-
const auto filePath = bv->GetFile()->GetOriginalFilename();
75+
76+
const auto file = bv->GetFile();
77+
const auto filePath = file->GetOriginalFilename();
7678
this->addCopyableField("Path: ", filePath.c_str());
7779

80+
// If triage view is opened from a project, show both actual filepath and path relative to project
81+
if (const auto fileProjectRef = file->GetProjectFile())
82+
{
83+
const auto projectFilePath = file->GetProjectFile()->GetPathInProject();
84+
this->addCopyableField("Path in project: ", projectFilePath.c_str());
85+
}
86+
7887
const auto fileSize = QString::number(view->GetLength(), 16).prepend("0x");
7988
this->addCopyableField("Size: ", fileSize);
8089

project.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,14 @@ std::string ProjectFile::GetPathOnDisk() const
552552
return result;
553553
}
554554

555+
std::string ProjectFile::GetPathInProject() const
556+
{
557+
char* path = BNProjectFileGetPathInProject(m_object);
558+
std::string result = path;
559+
BNFreeString(path);
560+
return result;
561+
}
562+
555563

556564
bool ProjectFile::ExistsOnDisk() const
557565
{

0 commit comments

Comments
 (0)