diff --git a/differ.cc b/differ.cc index 9aaff28b..86dc8fdf 100644 --- a/differ.cc +++ b/differ.cc @@ -50,7 +50,7 @@ using ::security::binexport::FormatAddress; // Return the immediate children of the call graph node denoted by // address. Skip nodes that have already been matched. void GetUnmatchedChildren(const CallGraph& call_graph, CallGraph::Vertex vertex, - absl::Nonnull children) { + FlowGraphs* absl_nonnull children) { for (auto [edge_it, edge_end] = boost::out_edges(vertex, call_graph.GetGraph()); edge_it != edge_end; ++edge_it) { @@ -73,7 +73,7 @@ void GetUnmatchedChildren(const CallGraph& call_graph, CallGraph::Vertex vertex, // Returns the immediate parents of the call graph node denoted by address. // Skips nodes that have already been matched. void GetUnmatchedParents(const CallGraph& call_graph, CallGraph::Vertex vertex, - absl::Nonnull parents) { + FlowGraphs* absl_nonnull parents) { for (auto [edge_it, edge_end] = boost::in_edges(vertex, call_graph.GetGraph()); edge_it != edge_end; ++edge_it) { @@ -96,8 +96,8 @@ void GetUnmatchedParents(const CallGraph& call_graph, CallGraph::Vertex vertex, // Adds empty flow graphs to all call graph vertices that don't already have one // attached (for example for DLL stub functions). Returns an error if a flow // graph already exists for a call graph vertex. -absl::Status AddSubsToCallGraph(absl::Nonnull call_graph, - absl::Nonnull flow_graphs) { +absl::Status AddSubsToCallGraph(CallGraph* absl_nonnull call_graph, + FlowGraphs* absl_nonnull flow_graphs) { for (auto [it, end] = boost::vertices(call_graph->GetGraph()); it != end; ++it) { const CallGraph::Vertex vertex = *it; @@ -120,10 +120,9 @@ absl::Status AddSubsToCallGraph(absl::Nonnull call_graph, absl::Status SetupGraphsFromProto( const BinExport2& proto, const std::string& filename, - absl::Nonnull call_graph, - absl::Nonnull flow_graphs, - absl::Nullable flow_graph_infos, - absl::Nonnull instruction_cache) { + CallGraph* absl_nonnull call_graph, FlowGraphs* absl_nonnull flow_graphs, + FlowGraphInfos* absl_nullable flow_graph_infos, + Instruction::Cache* absl_nonnull instruction_cache) { NA_RETURN_IF_ERROR(call_graph->Read(proto, filename)); for (const auto& proto_flow_graph : proto.flow_graph()) { if (proto_flow_graph.basic_block_index_size() == 0) { @@ -156,10 +155,10 @@ absl::Status SetupGraphsFromProto( } absl::Status Read(const std::string& filename, - absl::Nonnull call_graph, - absl::Nonnull flow_graphs, - absl::Nullable flow_graph_infos, - absl::Nonnull instruction_cache) { + CallGraph* absl_nonnull call_graph, + FlowGraphs* absl_nonnull flow_graphs, + FlowGraphInfos* absl_nullable flow_graph_infos, + Instruction::Cache* absl_nonnull instruction_cache) { call_graph->Reset(); DeleteFlowGraphs(flow_graphs); if (flow_graph_infos) { @@ -183,7 +182,7 @@ absl::Status Read(const std::string& filename, flow_graph_infos, instruction_cache); } -void DeleteFlowGraphs(absl::Nullable flow_graphs) { +void DeleteFlowGraphs(FlowGraphs* absl_nullable flow_graphs) { if (!flow_graphs) { return; } @@ -195,9 +194,9 @@ void DeleteFlowGraphs(absl::Nullable flow_graphs) { } ScopedCleanup::ScopedCleanup( - absl::Nullable flow_graphs1, - absl::Nullable flow_graphs2, - absl::Nullable instruction_cache) + FlowGraphs* absl_nullable flow_graphs1, + FlowGraphs* absl_nullable flow_graphs2, + Instruction::Cache* absl_nullable instruction_cache) : flow_graphs1_(flow_graphs1), flow_graphs2_(flow_graphs2), instruction_cache_(instruction_cache) {} @@ -210,13 +209,13 @@ ScopedCleanup::~ScopedCleanup() { } } -void ResetMatches(absl::Nonnull flow_graphs) { +void ResetMatches(FlowGraphs* absl_nonnull flow_graphs) { for (auto* flow_graph : *flow_graphs) { flow_graph->ResetMatches(); } } -void Diff(absl::Nonnull context, +void Diff(MatchingContext* absl_nonnull context, const MatchingSteps& call_graph_steps, const MatchingStepsFlowGraph& basic_block_steps) { // The outer loop controls the rigorousness for initial matching while the @@ -289,13 +288,13 @@ void Diff(absl::Nonnull context, ClassifyChanges(context); } -void Count(const FlowGraph& flow_graph, absl::Nonnull counts) { +void Count(const FlowGraph& flow_graph, Counts* absl_nonnull counts) { FlowGraphs flow_graphs; CHECK(flow_graphs.insert(&const_cast(flow_graph)).second); Count(flow_graphs, counts); } -void Count(const FlowGraphs& flow_graphs, absl::Nonnull counts) { +void Count(const FlowGraphs& flow_graphs, Counts* absl_nonnull counts) { uint64_t num_functions = 0; uint64_t num_basic_blocks = 0; uint64_t num_instructions = 0; @@ -413,8 +412,8 @@ double GetConfidence(const Histogram& histogram, Confidences* confidences) { void GetCountsAndHistogram(const FlowGraphs& flow_graphs1, const FlowGraphs& flow_graphs2, const FixedPoints& fixed_points, - absl::Nonnull histogram, - absl::Nonnull counts) { + Histogram* absl_nonnull histogram, + Counts* absl_nonnull counts) { Counts counts1; Counts counts2; Count(flow_graphs1, &counts1); diff --git a/differ.h b/differ.h index 2e228348..236a76d8 100644 --- a/differ.h +++ b/differ.h @@ -39,15 +39,15 @@ using Confidences = absl::btree_map; // Main entry point to the differ, runs the core algorithm and produces a // (partial) matching between the two inputs. -void Diff(absl::Nonnull context, +void Diff(MatchingContext* absl_nonnull context, const MatchingSteps& call_graph_steps, const MatchingStepsFlowGraph& basic_block_steps); class ScopedCleanup { public: - ScopedCleanup(absl::Nullable flow_graphs1, - absl::Nullable flow_graphs2, - absl::Nullable instruction_cache); + ScopedCleanup(FlowGraphs* absl_nullable flow_graphs1, + FlowGraphs* absl_nullable flow_graphs2, + Instruction::Cache* absl_nullable instruction_cache); ~ScopedCleanup(); private: @@ -56,18 +56,18 @@ class ScopedCleanup { Instruction::Cache* instruction_cache_; }; -void DeleteFlowGraphs(absl::Nullable flow_graphs); +void DeleteFlowGraphs(FlowGraphs* absl_nullable flow_graphs); // Removes all fixed point assignments from flow graphs so they can be used // again for a different comparison. -void ResetMatches(absl::Nonnull flow_graphs); +void ResetMatches(FlowGraphs* absl_nonnull flow_graphs); // Loads a .BinExport file into the internal data structures. absl::Status Read(const std::string& filename, - absl::Nonnull call_graph, - absl::Nonnull flow_graphs, - absl::Nullable flow_graph_infos, - absl::Nonnull instruction_cache); + 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, @@ -86,14 +86,14 @@ double GetConfidence(const Histogram& histogram, Confidences* confidences); void GetCountsAndHistogram(const FlowGraphs& flow_graphs1, const FlowGraphs& flow_graphs2, const FixedPoints& fixed_points, - absl::Nonnull histogram, - absl::Nonnull counts); + Histogram* absl_nonnull histogram, + Counts* absl_nonnull counts); // Collects various statistics (no of instructions/edges/basic blocks). -void Count(const FlowGraphs& flow_graphs, absl::Nonnull counts); -void Count(const FlowGraph& flow_graph, absl::Nonnull counts); -void Count(const FixedPoint& fixed_point, absl::Nonnull counts, - absl::Nonnull histogram); +void Count(const FlowGraphs& flow_graphs, Counts* absl_nonnull counts); +void Count(const FlowGraph& flow_graph, Counts* absl_nonnull counts); +void Count(const FixedPoint& fixed_point, Counts* absl_nonnull counts, + Histogram* absl_nonnull histogram); } // namespace security::bindiff