Skip to content

Commit

Permalink
Shorter generated function names, unify address rendering
Browse files Browse the repository at this point in the history
- Skip leading zeroes `sub_00401245` -> `sub_401245`, like IDA Pro and
  Binary Ninja
- Generate all function names and addresses from a single place
- Drive-by: Fix comparison in `HumanReadableDuration()`

PiperOrigin-RevId: 482440847
Change-Id: Ifbf59d3aa54d79a998b8a3f4d553c86201b4c4e6
  • Loading branch information
cblichmann authored and copybara-github committed Oct 20, 2022
1 parent 1eb75b8 commit 893e090
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions call_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <cassert>

#include "third_party/absl/log/log.h"
#include "third_party/absl/strings/ascii.h"
#include "third_party/absl/strings/escaping.h"
#include "third_party/absl/strings/str_cat.h"
#include "third_party/absl/strings/string_view.h"
#include "third_party/zynamics/bindiff/flow_graph.h"
Expand All @@ -28,6 +26,7 @@
namespace security::bindiff {

using binexport::FormatAddress;
using binexport::FormatFunctionName;

namespace {

Expand Down Expand Up @@ -121,7 +120,7 @@ absl::Status CallGraph::Read(const BinExport2& proto,
}
if (!(vertex.flags_ & VERTEX_NAME)) {
// Provide a dummy name for display.
vertex.name_ = absl::StrCat("sub_", FormatAddress(vertex.address_));
vertex.name_ = FormatFunctionName(vertex.address_);
}

if (proto_vertex.type() == BinExport2::CallGraph::Vertex::LIBRARY) {
Expand Down
2 changes: 1 addition & 1 deletion call_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class CallGraph {
void SetStub(Vertex vertex, bool stub);

// Does this vertex have a real, i.e. user supplied, name? Binaries without
// symbols often have auto generated names like "sub_baadf00d".
// symbols often have auto generated names like "sub_BAADF00D".
bool HasRealName(Vertex vertex) const;

// Returns the pair<edge,true> if the edge could be found or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static String getFunctionName(final BinExport2.CallGraph.Vertex vertex)
if (!name.isEmpty()) {
return name;
}
return String.format("sub_%08X", vertex.getAddress());
return String.format("sub_%X", vertex.getAddress());
}

private static EJumpType toJumpType(final BinExport2.FlowGraph.Edge.Type type) {
Expand Down

0 comments on commit 893e090

Please sign in to comment.