diff options
Diffstat (limited to 'tools/trace_to_text/deobfuscate_profile.cc')
-rw-r--r-- | tools/trace_to_text/deobfuscate_profile.cc | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/tools/trace_to_text/deobfuscate_profile.cc b/tools/trace_to_text/deobfuscate_profile.cc index bc1173031..b6e8b8c29 100644 --- a/tools/trace_to_text/deobfuscate_profile.cc +++ b/tools/trace_to_text/deobfuscate_profile.cc @@ -17,33 +17,70 @@ #include <stdio.h> #include "perfetto/base/logging.h" -#include "perfetto/ext/base/file_utils.h" #include "perfetto/ext/base/scoped_file.h" -#include "perfetto/ext/base/string_splitter.h" -#include "perfetto/ext/base/utils.h" +#include "perfetto/profiling/deobfuscator.h" #include "perfetto/trace_processor/trace_processor.h" -#include "src/profiling/deobfuscator.h" #include "tools/trace_to_text/deobfuscate_profile.h" #include "tools/trace_to_text/utils.h" namespace perfetto { namespace trace_to_text { +namespace { + +bool ParseFile(profiling::ProguardParser* p, FILE* f) { + std::vector<std::string> lines; + size_t n = 0; + char* line = nullptr; + ssize_t rd = 0; + bool success = true; + do { + rd = getline(&line, &n, f); + // Do not read empty line that terminates the output. + if (rd > 1) { + // Remove newline character. + PERFETTO_DCHECK(line[rd - 1] == '\n'); + line[rd - 1] = '\0'; + success = p->AddLine(line); + } + } while (rd > 1 && success); + free(line); + return success; +} +} // namespace int DeobfuscateProfile(std::istream* input, std::ostream* output) { base::ignore_result(input); base::ignore_result(output); - auto maybe_map = profiling::GetPerfettoProguardMapPath(); - if (maybe_map.empty()) { + auto maybe_map = GetPerfettoProguardMapPath(); + if (!maybe_map) { PERFETTO_ELOG("No PERFETTO_PROGUARD_MAP specified."); return 1; } - if (!profiling::ReadProguardMapsToDeobfuscationPackets( - maybe_map, [output](const std::string& trace_proto) { - *output << trace_proto; - })) { + base::ScopedFstream f(fopen(maybe_map->c_str(), "r")); + if (!f) { + PERFETTO_ELOG("Failed to open %s", maybe_map->c_str()); + return 1; + } + profiling::ProguardParser parser; + if (!ParseFile(&parser, *f)) { + PERFETTO_ELOG("Failed to parse %s", maybe_map->c_str()); return 1; } + std::map<std::string, profiling::ObfuscatedClass> obfuscation_map = + parser.ConsumeMapping(); + + trace_processor::Config config; + std::unique_ptr<trace_processor::TraceProcessor> tp = + trace_processor::TraceProcessor::CreateInstance(config); + + if (!ReadTrace(tp.get(), input)) + PERFETTO_FATAL("Failed to read trace."); + tp->NotifyEndOfFile(); + DeobfuscateDatabase(tp.get(), obfuscation_map, + [output](const std::string& packet_proto) { + WriteTracePacket(packet_proto, output); + }); return 0; } |