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
43 changes: 21 additions & 22 deletions differ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlowGraphs*> children) {
FlowGraphs* absl_nonnull children) {
for (auto [edge_it, edge_end] =
boost::out_edges(vertex, call_graph.GetGraph());
edge_it != edge_end; ++edge_it) {
Expand All @@ -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<FlowGraphs*> parents) {
FlowGraphs* absl_nonnull parents) {
for (auto [edge_it, edge_end] =
boost::in_edges(vertex, call_graph.GetGraph());
edge_it != edge_end; ++edge_it) {
Expand All @@ -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<CallGraph*> call_graph,
absl::Nonnull<FlowGraphs*> 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;
Expand All @@ -120,10 +120,9 @@ absl::Status AddSubsToCallGraph(absl::Nonnull<CallGraph*> call_graph,

absl::Status SetupGraphsFromProto(
const BinExport2& proto, const std::string& filename,
absl::Nonnull<CallGraph*> call_graph,
absl::Nonnull<FlowGraphs*> flow_graphs,
absl::Nullable<FlowGraphInfos*> flow_graph_infos,
absl::Nonnull<Instruction::Cache*> 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) {
Expand Down Expand Up @@ -156,10 +155,10 @@ absl::Status SetupGraphsFromProto(
}

absl::Status Read(const std::string& filename,
absl::Nonnull<CallGraph*> call_graph,
absl::Nonnull<FlowGraphs*> flow_graphs,
absl::Nullable<FlowGraphInfos*> flow_graph_infos,
absl::Nonnull<Instruction::Cache*> 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) {
Expand All @@ -183,7 +182,7 @@ absl::Status Read(const std::string& filename,
flow_graph_infos, instruction_cache);
}

void DeleteFlowGraphs(absl::Nullable<FlowGraphs*> flow_graphs) {
void DeleteFlowGraphs(FlowGraphs* absl_nullable flow_graphs) {
if (!flow_graphs) {
return;
}
Expand All @@ -195,9 +194,9 @@ void DeleteFlowGraphs(absl::Nullable<FlowGraphs*> flow_graphs) {
}

ScopedCleanup::ScopedCleanup(
absl::Nullable<FlowGraphs*> flow_graphs1,
absl::Nullable<FlowGraphs*> flow_graphs2,
absl::Nullable<Instruction::Cache*> 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) {}
Expand All @@ -210,13 +209,13 @@ ScopedCleanup::~ScopedCleanup() {
}
}

void ResetMatches(absl::Nonnull<FlowGraphs*> flow_graphs) {
void ResetMatches(FlowGraphs* absl_nonnull flow_graphs) {
for (auto* flow_graph : *flow_graphs) {
flow_graph->ResetMatches();
}
}

void Diff(absl::Nonnull<MatchingContext*> 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
Expand Down Expand Up @@ -289,13 +288,13 @@ void Diff(absl::Nonnull<MatchingContext*> context,
ClassifyChanges(context);
}

void Count(const FlowGraph& flow_graph, absl::Nonnull<Counts*> counts) {
void Count(const FlowGraph& flow_graph, Counts* absl_nonnull counts) {
FlowGraphs flow_graphs;
CHECK(flow_graphs.insert(&const_cast<FlowGraph&>(flow_graph)).second);
Count(flow_graphs, counts);
}

void Count(const FlowGraphs& flow_graphs, absl::Nonnull<Counts*> 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;
Expand Down Expand Up @@ -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*> histogram,
absl::Nonnull<Counts*> counts) {
Histogram* absl_nonnull histogram,
Counts* absl_nonnull counts) {
Counts counts1;
Counts counts2;
Count(flow_graphs1, &counts1);
Expand Down
32 changes: 16 additions & 16 deletions differ.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ using Confidences = absl::btree_map<std::string, double>;

// Main entry point to the differ, runs the core algorithm and produces a
// (partial) matching between the two inputs.
void Diff(absl::Nonnull<MatchingContext*> context,
void Diff(MatchingContext* absl_nonnull context,
const MatchingSteps& call_graph_steps,
const MatchingStepsFlowGraph& basic_block_steps);

class ScopedCleanup {
public:
ScopedCleanup(absl::Nullable<FlowGraphs*> flow_graphs1,
absl::Nullable<FlowGraphs*> flow_graphs2,
absl::Nullable<Instruction::Cache*> instruction_cache);
ScopedCleanup(FlowGraphs* absl_nullable flow_graphs1,
FlowGraphs* absl_nullable flow_graphs2,
Instruction::Cache* absl_nullable instruction_cache);
~ScopedCleanup();

private:
Expand All @@ -56,18 +56,18 @@ class ScopedCleanup {
Instruction::Cache* instruction_cache_;
};

void DeleteFlowGraphs(absl::Nullable<FlowGraphs*> 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<FlowGraphs*> 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<CallGraph*> call_graph,
absl::Nonnull<FlowGraphs*> flow_graphs,
absl::Nullable<FlowGraphInfos*> flow_graph_infos,
absl::Nonnull<Instruction::Cache*> 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,
Expand All @@ -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*> histogram,
absl::Nonnull<Counts*> 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*> counts);
void Count(const FlowGraph& flow_graph, absl::Nonnull<Counts*> counts);
void Count(const FixedPoint& fixed_point, absl::Nonnull<Counts*> counts,
absl::Nonnull<Histogram*> 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

Expand Down
Loading