Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions differ.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,14 +20,14 @@
#include <fstream>
#include <ios>
#include <memory>
#include <stdexcept>
#include <string>

#include "third_party/absl/base/nullability.h"
#include "third_party/absl/log/check.h"
#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"
Expand Down Expand Up @@ -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<FlowGraph> flow_graph;
// Temporary try-catch block. A follow-up change will refactor to
// absl::StatusOr<std::unique_ptr<FlowGraph>>.
try {
flow_graph = std::make_unique<FlowGraph>(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)));
}
Expand Down
12 changes: 10 additions & 2 deletions differ.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Loading