2424
2525#include " third_party/absl/log/check.h"
2626#include " third_party/absl/log/log.h"
27- #include " third_party/absl/strings/ascii.h"
2827#include " third_party/absl/strings/str_cat.h"
2928#include " third_party/zynamics/binexport/call_graph.h"
29+ #include " third_party/zynamics/binexport/util/format.h"
30+
31+ using security::binexport::FormatAddress;
32+ using security::binexport::FormatFunctionName;
3033
3134int Function::instance_count_ = 0 ;
3235Function::StringCache Function::string_cache_;
@@ -48,19 +51,16 @@ Function::~Function() {
4851
4952void Function::Render (std::ostream* stream, const CallGraph& call_graph,
5053 const FlowGraph& flow_graph) const {
51- *stream << std::hex << std::setfill (' 0' ) << std::uppercase << std::setw (8 )
52- << GetEntryPoint () << " " << GetModuleName ()
54+ *stream << FormatAddress (GetEntryPoint ()) << " " << GetModuleName ()
5355 << (GetModuleName ().empty () ? " " : " ." ) << GetName (DEMANGLED) << " \n " ;
5456 for (const auto & basic_block_ptr : basic_blocks_) {
5557 basic_block_ptr->Render (stream, call_graph, flow_graph);
5658 *stream << " \n " ;
5759 }
5860
5961 for (const auto & edge : edges_) {
60- *stream << std::hex << std::setfill (' 0' ) << std::uppercase << std::setw (8 )
61- << edge.source << " -> " << std::hex << std::setfill (' 0' )
62- << std::uppercase << std::setw (8 ) << edge.target << " "
63- << edge.GetTypeName () << " \n " ;
62+ *stream << FormatAddress (edge.source ) << " -> "
63+ << FormatAddress (edge.target ) << " " << edge.GetTypeName () << " \n " ;
6464 }
6565 if (!edges_.empty ()) {
6666 *stream << " \n " ;
@@ -140,8 +140,7 @@ std::string Function::GetName(Name type) const {
140140 if (HasRealName ()) {
141141 return type == MANGLED || demangled_name_.empty () ? name_ : demangled_name_;
142142 }
143- return absl::StrCat (" sub_" , absl::AsciiStrToUpper (absl::StrCat (absl::Hex (
144- GetEntryPoint (), absl::kZeroPad8 ))));
143+ return FormatFunctionName (GetEntryPoint ());
145144}
146145
147146bool Function::HasRealName () const { return !name_.empty (); }
@@ -198,9 +197,8 @@ int Function::GetBasicBlockIndexForAddress(Address address) const {
198197 }
199198 }
200199
201- LOG (WARNING) << absl::StrCat (" No basic block for " ,
202- absl::Hex (address, absl::kZeroPad8 ), " in " ,
203- GetEntryPoint ());
200+ LOG (WARNING) << absl::StrCat (" No basic block for " , FormatAddress (address),
201+ " in " , GetEntryPoint ());
204202 return basic_blocks_.size ();
205203}
206204
0 commit comments