Skip to content

Commit 5932fd3

Browse files
committed
Fix potential windows compatibility issues with BinDiff
1 parent 9874ba2 commit 5932fd3

5 files changed

Lines changed: 18 additions & 13 deletions

File tree

plugins/bindiff_similarity/diffview.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
#include "processor.h"
44

55
#include <third_party/zynamics/bindiff/differ.h>
6-
#include <filesystem>
76

8-
std::unique_ptr<BinDiffView> BinDiffView::FromFilePath(const std::filesystem::path& filePath)
7+
std::unique_ptr<BinDiffView> BinDiffView::FromFilePath(const std::string& filePath)
98
{
109
auto view = std::make_unique<BinDiffView>();
1110
security::bindiff::Instruction::Cache instrCache;
1211
auto status = security::bindiff::Read(
1312
filePath, &view->m_callGraph, &view->m_flowGraphs, &view->m_flowGraphInfos, &instrCache);
1413
if (!status.ok())
1514
{
16-
BinaryNinja::LogErrorF("Failed to read bindiff data from {}: {}", filePath.c_str(), status.message());
15+
BinaryNinja::LogErrorF("Failed to read bindiff data from {}: {}", filePath, status.message());
1716
return nullptr;
1817
}
1918
return view;

plugins/bindiff_similarity/diffview.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <third_party/zynamics/binexport/virtual_memory.h>
1010
#include <functional>
11+
#include <string>
1112

1213
class BinDiffView
1314
{
@@ -20,7 +21,7 @@ class BinDiffView
2021

2122
BinDiffView() = default;
2223

23-
static std::unique_ptr<BinDiffView> FromFilePath(const std::filesystem::path& filePath);
24+
static std::unique_ptr<BinDiffView> FromFilePath(const std::string& filePath);
2425

2526
// Generate a view from the given node, the nodes view must be available before calling.
2627
static std::unique_ptr<BinDiffView> FromSessionNode(

plugins/bindiff_similarity/plugin.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include <binaryninjaapi.h>
22

3-
#include <filesystem>
4-
53
#include "processor.h"
64
#include "provider.h"
75

@@ -11,14 +9,21 @@ namespace {
119
void ExportBinExport(BinaryView* view)
1210
{
1311
const std::string inputFilename = view->GetFile()->GetFilename();
14-
std::filesystem::path outputPath = inputFilename.empty() ? "export.BinExport" : inputFilename;
15-
outputPath.replace_extension(".BinExport");
12+
std::string outputPath = inputFilename.empty() ? "export.BinExport" : inputFilename;
13+
if (!inputFilename.empty())
14+
{
15+
const size_t separator = outputPath.find_last_of("/\\");
16+
const size_t filenameStart = separator == std::string::npos ? 0 : separator + 1;
17+
const size_t extension = outputPath.find_last_of('.');
18+
if ((extension != std::string::npos) && (extension > filenameStart))
19+
outputPath.resize(extension);
20+
outputPath += ".BinExport";
21+
}
1622

1723
if (IsUIEnabled())
1824
{
1925
std::string selectedPath;
20-
if (!GetSaveFileNameInput(
21-
selectedPath, "Export BinExport", "BinExport files (*.BinExport)", outputPath.string()))
26+
if (!GetSaveFileNameInput(selectedPath, "Export BinExport", "BinExport files (*.BinExport)", outputPath))
2227
return;
2328
outputPath = selectedPath;
2429
}
@@ -33,7 +38,7 @@ namespace {
3338
BinDiffProcessor processor(*view);
3439
for (const auto& function : view->GetAnalysisFunctionList())
3540
processor.AddFunction(*function);
36-
success = processor.Process(outputPath.string());
41+
success = processor.Process(outputPath);
3742
}
3843
if (!success && IsUIEnabled())
3944
{

vendor/bindiff

Submodule bindiff updated 1 file

0 commit comments

Comments
 (0)