From 365c0f900d7805da94ed6e3bf193f56b122daa92 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 30 Jul 2026 06:38:14 -0700 Subject: [PATCH] Expose `SetupGraphsFromProto` in `differ.h` This change exposes `SetupGraphsFromProto` in the public BinDiff interface, allowing clients to load BinExport protos directly in memory. PiperOrigin-RevId: 956489672 Change-Id: Iab14193a0dc4f525d6de79e82bbc7841d287368c --- differ.cc | 18 ++++++++++++------ differ.h | 12 ++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/differ.cc b/differ.cc index 7c26bd17..6db9b8da 100644 --- a/differ.cc +++ b/differ.cc @@ -1,4 +1,4 @@ -// Copyright 2011-2024 Google LLC +// Copyright 2011-2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "third_party/absl/base/nullability.h" @@ -27,7 +28,6 @@ #include "third_party/absl/memory/memory.h" #include "third_party/absl/status/status.h" #include "third_party/absl/status/status_macros.h" -#include "third_party/absl/status/statusor.h" #include "third_party/absl/strings/str_cat.h" #include "third_party/zynamics/bindiff/call_graph.h" #include "third_party/zynamics/bindiff/change_classifier.h" @@ -103,15 +103,21 @@ absl::Status AddSubsToCallGraph(CallGraph* absl_nonnull call_graph, ++it) { const CallGraph::Vertex vertex = *it; const Address address = call_graph->GetAddress(vertex); - FlowGraph* flow_graph = call_graph->GetFlowGraph(vertex); - if (flow_graph) { + if (call_graph->GetFlowGraph(vertex)) { continue; } - flow_graph = new FlowGraph(call_graph, address); + std::unique_ptr flow_graph; + // Temporary try-catch block. A follow-up change will refactor to + // absl::StatusOr>. + try { + flow_graph = std::make_unique(call_graph, address); + } catch (const std::runtime_error& e) { + return absl::FailedPreconditionError(e.what()); + } call_graph->SetStub(vertex, true); call_graph->SetLibrary(vertex, true); - if (!flow_graphs->insert(flow_graph).second) { + if (!flow_graphs->insert(flow_graph.release()).second) { return absl::FailedPreconditionError( absl::StrCat("a flow graph exists at ", FormatAddress(address))); } diff --git a/differ.h b/differ.h index 236a76d8..34f85d62 100644 --- a/differ.h +++ b/differ.h @@ -1,4 +1,4 @@ -// Copyright 2011-2024 Google LLC +// Copyright 2011-2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -62,13 +62,21 @@ void DeleteFlowGraphs(FlowGraphs* absl_nullable flow_graphs); // again for a different comparison. void ResetMatches(FlowGraphs* absl_nonnull flow_graphs); -// Loads a .BinExport file into the internal data structures. +// Loads a .BinExport file into the internal data structures. Parses filename +// and then calls SetupGraphsFromProto with the contents of the file. absl::Status Read(const std::string& filename, CallGraph* absl_nonnull call_graph, FlowGraphs* absl_nonnull flow_graphs, FlowGraphInfos* absl_nullable flow_graph_infos, Instruction::Cache* absl_nonnull instruction_cache); +// Loads a .BinExport proto into the internal data structures. +absl::Status SetupGraphsFromProto( + const BinExport2& proto, const std::string& filename, + CallGraph* absl_nonnull call_graph, FlowGraphs* absl_nonnull flow_graphs, + FlowGraphInfos* absl_nullable flow_graph_infos, + Instruction::Cache* absl_nonnull instruction_cache); + // Gets the similarity score for two full binaries. double GetSimilarityScore(const CallGraph& call_graph1, const CallGraph& call_graph2,