Skip to content

IDA plugin: fix result save/load for same-named binaries - #92

Open
xeropresence wants to merge 2 commits into
google:mainfrom
xeropresence:fix/same-name-binexport-collision
Open

xeropresence wants to merge 2 commits into
google:mainfrom
xeropresence:fix/same-name-binexport-collision

Conversation

@xeropresence

Copy link
Copy Markdown

Problem

Diffing two databases with the same basename (e.g. v1/app.exe.i64 vs v2/app.exe.i64) produces a broken result
file:

  • WriteResults copies both .BinExport sidecars next to the .BinDiff by basename; the secondary overwrites the
    primary.
  • DatabaseReader::Read resolves <dir>/<file.filename>.BinExport per side; with identical filename columns, the
    secondary export is loaded as both call graphs.

Loading such a result then shows the "original file hash … is different from the primary one in the result file"
warning, and all primary addresses are resolved against the wrong call graph.

Fix

  • ida/main_plugin.cc (ExportIdbs): when both IDB stems are equal, export as <stem>_primary.BinExport /
    <stem>_secondary.BinExport — the same convention the Java UI uses
    (NewDiffImplementation.createUniqueExportFileName). This flows through CallGraph::GetFilename() into the
    file.filename column, so save, load, and the UI all resolve distinct sidecars. Non-colliding names are unchanged.
  • database_writer.cc (DatabaseReader::Read): fail with a FailedPrecondition if primary and secondary would
    resolve to the same .BinExport, instead of silently loading one file twice.

Notes

Result files already saved with colliding names cannot be repaired (the primary sidecar is gone); re-diff and save
again.

Diffing two databases with the same basename (e.g. two versions of the
same binary in different directories) wrote both .BinExport sidecars to
the same path next to the result file, so the secondary overwrote the
primary. Loading the result then read the secondary export as both call
graphs and reported a hash mismatch against the open IDB.

Name the exports <stem>_primary.BinExport / <stem>_secondary.BinExport in
that case, following the convention already used by the BinDiff UI
(NewDiffImplementation.createUniqueExportFileName). The names flow through
CallGraph::GetFilename() into the file.filename column, so save, load and
the UI resolve distinct sidecars.
DatabaseReader::Read resolves <dir>/<file.filename>.BinExport per side. If
both filenames are equal, one export has necessarily overwritten the other,
so fail with an actionable error instead of silently loading the same file
for both sides.
@google-cla

google-cla Bot commented Sep 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant