Loading tools/aapt2/cmd/Dump.cpp +28 −10 Original line number Diff line number Diff line Loading @@ -251,19 +251,12 @@ int DumpConfigsCommand::Dump(LoadedApk* apk) { } int DumpPackageNameCommand::Dump(LoadedApk* apk) { xml::Element* manifest_el = apk->GetManifest()->root.get(); if (!manifest_el) { GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest"); Maybe<std::string> package_name = GetPackageName(apk); if (!package_name) { return 1; } xml::Attribute* attr = manifest_el->FindAttribute({}, "package"); if (!attr) { GetDiagnostics()->Error(DiagMessage() << "No package name"); return 1; } GetPrinter()->Println(StringPrintf("%s", attr->value.c_str())); GetPrinter()->Println(package_name.value()); return 0; } Loading @@ -283,6 +276,31 @@ int DumpStringsCommand::Dump(LoadedApk* apk) { return 0; } int DumpStyleParentCommand::Dump(LoadedApk* apk) { Maybe<std::string> package_name = GetPackageName(apk); if (!package_name) { return 1; } const auto target_style = ResourceName(package_name.value(), ResourceType::kStyle, style_); const auto table = apk->GetResourceTable(); if (!table) { GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table"); return 1; } Maybe<ResourceTable::SearchResult> target = table->FindResource(target_style); if (!target) { GetDiagnostics()->Error( DiagMessage() << "Target style \"" << target_style.entry << "\" does not exist"); return 1; } Debug::PrintStyleGraph(table, target_style); return 0; } int DumpTableCommand::Dump(LoadedApk* apk) { if (apk->GetApkFormat() == ApkFormat::kProto) { GetPrinter()->Println("Proto APK"); Loading tools/aapt2/cmd/Dump.h +31 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,21 @@ class DumpApkCommand : public Command { return diag_; } Maybe<std::string> GetPackageName(LoadedApk* apk) { xml::Element* manifest_el = apk->GetManifest()->root.get(); if (!manifest_el) { GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest."); return Maybe<std::string>(); } xml::Attribute* attr = manifest_el->FindAttribute({}, "package"); if (!attr) { GetDiagnostics()->Error(DiagMessage() << "No package name."); return Maybe<std::string>(); } return attr->value; } /** Perform the dump operation on the apk. */ virtual int Dump(LoadedApk* apk) = 0; Loading Loading @@ -164,6 +179,21 @@ class DumpStringsCommand : public DumpApkCommand { int Dump(LoadedApk* apk) override; }; /** Prints the graph of parents of a style in an APK. */ class DumpStyleParentCommand : public DumpApkCommand { public: explicit DumpStyleParentCommand(text::Printer* printer, IDiagnostics* diag) : DumpApkCommand("styleparents", printer, diag) { SetDescription("Print the parents of a style in an APK."); AddRequiredFlag("--style", "The name of the style to print", &style_); } int Dump(LoadedApk* apk) override; private: std::string style_; }; class DumpTableCommand : public DumpApkCommand { public: explicit DumpTableCommand(text::Printer* printer, IDiagnostics* diag) Loading Loading @@ -220,6 +250,7 @@ class DumpCommand : public Command { AddOptionalSubcommand(util::make_unique<DumpPackageNameCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpPermissionsCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpStringsCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpStyleParentCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpTableCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpXmlStringsCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpXmlTreeCommand>(printer, diag_)); Loading Loading
tools/aapt2/cmd/Dump.cpp +28 −10 Original line number Diff line number Diff line Loading @@ -251,19 +251,12 @@ int DumpConfigsCommand::Dump(LoadedApk* apk) { } int DumpPackageNameCommand::Dump(LoadedApk* apk) { xml::Element* manifest_el = apk->GetManifest()->root.get(); if (!manifest_el) { GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest"); Maybe<std::string> package_name = GetPackageName(apk); if (!package_name) { return 1; } xml::Attribute* attr = manifest_el->FindAttribute({}, "package"); if (!attr) { GetDiagnostics()->Error(DiagMessage() << "No package name"); return 1; } GetPrinter()->Println(StringPrintf("%s", attr->value.c_str())); GetPrinter()->Println(package_name.value()); return 0; } Loading @@ -283,6 +276,31 @@ int DumpStringsCommand::Dump(LoadedApk* apk) { return 0; } int DumpStyleParentCommand::Dump(LoadedApk* apk) { Maybe<std::string> package_name = GetPackageName(apk); if (!package_name) { return 1; } const auto target_style = ResourceName(package_name.value(), ResourceType::kStyle, style_); const auto table = apk->GetResourceTable(); if (!table) { GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table"); return 1; } Maybe<ResourceTable::SearchResult> target = table->FindResource(target_style); if (!target) { GetDiagnostics()->Error( DiagMessage() << "Target style \"" << target_style.entry << "\" does not exist"); return 1; } Debug::PrintStyleGraph(table, target_style); return 0; } int DumpTableCommand::Dump(LoadedApk* apk) { if (apk->GetApkFormat() == ApkFormat::kProto) { GetPrinter()->Println("Proto APK"); Loading
tools/aapt2/cmd/Dump.h +31 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,21 @@ class DumpApkCommand : public Command { return diag_; } Maybe<std::string> GetPackageName(LoadedApk* apk) { xml::Element* manifest_el = apk->GetManifest()->root.get(); if (!manifest_el) { GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest."); return Maybe<std::string>(); } xml::Attribute* attr = manifest_el->FindAttribute({}, "package"); if (!attr) { GetDiagnostics()->Error(DiagMessage() << "No package name."); return Maybe<std::string>(); } return attr->value; } /** Perform the dump operation on the apk. */ virtual int Dump(LoadedApk* apk) = 0; Loading Loading @@ -164,6 +179,21 @@ class DumpStringsCommand : public DumpApkCommand { int Dump(LoadedApk* apk) override; }; /** Prints the graph of parents of a style in an APK. */ class DumpStyleParentCommand : public DumpApkCommand { public: explicit DumpStyleParentCommand(text::Printer* printer, IDiagnostics* diag) : DumpApkCommand("styleparents", printer, diag) { SetDescription("Print the parents of a style in an APK."); AddRequiredFlag("--style", "The name of the style to print", &style_); } int Dump(LoadedApk* apk) override; private: std::string style_; }; class DumpTableCommand : public DumpApkCommand { public: explicit DumpTableCommand(text::Printer* printer, IDiagnostics* diag) Loading Loading @@ -220,6 +250,7 @@ class DumpCommand : public Command { AddOptionalSubcommand(util::make_unique<DumpPackageNameCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpPermissionsCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpStringsCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpStyleParentCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpTableCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpXmlStringsCommand>(printer, diag_)); AddOptionalSubcommand(util::make_unique<DumpXmlTreeCommand>(printer, diag_)); Loading