Skip to content

Add BinDiff Similarity Provider (API) - #8387

Open
emesare wants to merge 5 commits into
devfrom
similarity/binary-similarity-bindiff-provider
Open

Add BinDiff Similarity Provider (API)#8387
emesare wants to merge 5 commits into
devfrom
similarity/binary-similarity-bindiff-provider

Conversation

@emesare

@emesare emesare commented Aug 4, 2026

Copy link
Copy Markdown
Member

Apart of https://github.com/Vector35/binaryninja/pull/1735 (Binary Similarity)
For a test_* build with this change see the above branch ^

Adds a first party integration with https://github.com/google/bindiff meant for simple structural (cfg) diffing and matching, supersedes the binexport plugin.

Screenshot 2026-08-02 at 10 05 46 PM

An example of the rendering performed giving the bindiff annotations.

The sister PR is found here: https://github.com/Vector35/binaryninja/pull/1743

Depends on:

{
public:
security::bindiff::CallGraph m_callGraph;
security::bindiff::FlowGraphs m_flowGraphs;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you're leaking memory here. BinDiffView needs a destructor.

~BinDiffView()
{
    security::bindiff::DeleteFlowGraphs(&m_flowGraphs);
}

FlowGraphs is defined as

using FlowGraphs = std::set<FlowGraph*, SortByAddress>;

Additionally copying should be disabled too or given explicit ownership semantics

BinDiffView(const BinDiffView&) = delete;
BinDiffView& operator=(const BinDiffView&) = delete;

for (const auto& match : pendingMatches)
{
const SimilarityResultId primaryResult =
results.AddResult(match.key.primary, match.key.secondary, match.similarity, 255);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions here:

  • Whats the reason these are getting Max confidence this seems wrong. Could you just store confidence in pendingMatches?
  • Please don't use magic values like this prefer named constants.

const int permissions = GetSegmentPermissions(*segment);

// Map the segment without reading its contents.
m_impl->m_flagSpace.AddMemoryBlock(segmentAddr, AddressSpace::MemoryBlock(segmentLen), permissions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be doing this for non-file backed segments which can be arbitrarily large. MemoryBlock will allocate a byte for every segmentLen.

primaryView.m_flowGraphs, secondaryView.m_flowGraphs, fixedPoints);

// TODO: Expose options for diffing.
security::bindiff::Diff(&context, security::bindiff::GetDefaultMatchingSteps(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking but it would be great if we could plumb our completion.IsStopRequested() into Diff as this is where I think the bulk of the time is going to be spent. Maybe its worth keeping track of this as a separate issue?


bool success;
{
BinDiffProcessor processor(*view);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking but I feel like this should really be done off the main thread with a progress callback. Perhaps another issue we should create.

Comment thread docs/guide/binexport.md
## Built-in similarity

The **Google BinDiff** provider can also compare binaries directly in a
[similarity session](./similarity.md), without first creating intermediate BinExport files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust similarity.md is in another PR?

@plafosse

Copy link
Copy Markdown
Member

I think the only two blocking requests are the memory exhaustion and the memory leak issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants