Loading tools/aapt2/Debug.cpp +35 −0 Original line number Diff line number Diff line Loading @@ -408,6 +408,41 @@ void Debug::DumpHex(const void* data, size_t len) { } } void Debug::DumpResStringPool(const android::ResStringPool* pool, text::Printer* printer) { using namespace android; if (pool->getError() == NO_INIT) { printer->Print("String pool is unitialized.\n"); return; } else if (pool->getError() != NO_ERROR) { printer->Print("String pool is corrupt/invalid.\n"); return; } SortedVector<const void*> uniqueStrings; const size_t N = pool->size(); for (size_t i=0; i<N; i++) { size_t len; if (pool->isUTF8()) { uniqueStrings.add(pool->string8At(i, &len)); } else { uniqueStrings.add(pool->stringAt(i, &len)); } } printer->Print(StringPrintf("String pool of %zd unique %s %s strings, %zd entries and %zd styles " "using %zd bytes:\n", uniqueStrings.size(), pool->isUTF8() ? "UTF-8" : "UTF-16", pool->isSorted() ? "sorted" : "non-sorted", N, pool->styleCount(), pool->bytes())); const size_t NS = pool->size(); for (size_t s=0; s<NS; s++) { String8 str = pool->string8ObjectAt(s); printer->Print(StringPrintf("String #%zd : %s\n", s, str.string())); } } namespace { class XmlPrinter : public xml::ConstVisitor { Loading tools/aapt2/Debug.h +1 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ struct Debug { static void PrintStyleGraph(ResourceTable* table, const ResourceName& target_style); static void DumpHex(const void* data, size_t len); static void DumpXml(const xml::XmlResource& doc, text::Printer* printer); static void DumpResStringPool(const android::ResStringPool* pool, text::Printer* printer); }; } // namespace aapt Loading tools/aapt2/LoadedApk.cpp +47 −0 Original line number Diff line number Diff line Loading @@ -257,6 +257,53 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table return true; } std::unique_ptr<xml::XmlResource> LoadedApk::LoadXml(const std::string& file_path, IDiagnostics* diag) { io::IFile* file = apk_->FindFile(file_path); if (file == nullptr) { diag->Error(DiagMessage() << "failed to find file"); return nullptr; } std::unique_ptr<xml::XmlResource> doc; if (format_ == ApkFormat::kProto) { std::unique_ptr<io::InputStream> in = file->OpenInputStream(); if (!in) { diag->Error(DiagMessage() << "failed to open file"); return nullptr; } io::ZeroCopyInputAdaptor adaptor(in.get()); pb::XmlNode pb_node; if (!pb_node.ParseFromZeroCopyStream(&adaptor)) { diag->Error(DiagMessage() << "failed to parse file as proto XML"); return nullptr; } std::string err; doc = DeserializeXmlResourceFromPb(pb_node, &err); if (!doc) { diag->Error(DiagMessage() << "failed to deserialize proto XML: " << err); return nullptr; } } else if (format_ == ApkFormat::kBinary) { std::unique_ptr<io::IData> data = file->OpenAsData(); if (!data) { diag->Error(DiagMessage() << "failed to open file"); return nullptr; } std::string err; doc = xml::Inflate(data->data(), data->size(), &err); if (!doc) { diag->Error(DiagMessage() << "failed to parse file as binary XML: " << err); return nullptr; } } return doc; } ApkFormat LoadedApk::DetermineApkFormat(io::IFileCollection* apk) { if (apk->FindFile(kApkResourceTablePath) != nullptr) { return ApkFormat::kBinary; Loading tools/aapt2/LoadedApk.h +6 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,10 @@ class LoadedApk { return apk_.get(); } ApkFormat GetApkFormat() { return format_; } const ResourceTable* GetResourceTable() const { return table_.get(); } Loading Loading @@ -106,6 +110,8 @@ class LoadedApk { const TableFlattenerOptions& options, FilterChain* filters, IArchiveWriter* writer, xml::XmlResource* manifest = nullptr); /** Loads the file as an xml document. */ std::unique_ptr<xml::XmlResource> LoadXml(const std::string& file_path, IDiagnostics* diag); private: DISALLOW_COPY_AND_ASSIGN(LoadedApk); Loading tools/aapt2/Main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class MainCommand : public Command { explicit MainCommand(IDiagnostics* diagnostics) : Command("aapt2"), diagnostics_(diagnostics) { AddOptionalSubcommand(util::make_unique<CompileCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<LinkCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<DumpCommand>()); AddOptionalSubcommand(util::make_unique<DumpCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<DiffCommand>()); AddOptionalSubcommand(util::make_unique<OptimizeCommand>()); AddOptionalSubcommand(util::make_unique<ConvertCommand>()); Loading Loading
tools/aapt2/Debug.cpp +35 −0 Original line number Diff line number Diff line Loading @@ -408,6 +408,41 @@ void Debug::DumpHex(const void* data, size_t len) { } } void Debug::DumpResStringPool(const android::ResStringPool* pool, text::Printer* printer) { using namespace android; if (pool->getError() == NO_INIT) { printer->Print("String pool is unitialized.\n"); return; } else if (pool->getError() != NO_ERROR) { printer->Print("String pool is corrupt/invalid.\n"); return; } SortedVector<const void*> uniqueStrings; const size_t N = pool->size(); for (size_t i=0; i<N; i++) { size_t len; if (pool->isUTF8()) { uniqueStrings.add(pool->string8At(i, &len)); } else { uniqueStrings.add(pool->stringAt(i, &len)); } } printer->Print(StringPrintf("String pool of %zd unique %s %s strings, %zd entries and %zd styles " "using %zd bytes:\n", uniqueStrings.size(), pool->isUTF8() ? "UTF-8" : "UTF-16", pool->isSorted() ? "sorted" : "non-sorted", N, pool->styleCount(), pool->bytes())); const size_t NS = pool->size(); for (size_t s=0; s<NS; s++) { String8 str = pool->string8ObjectAt(s); printer->Print(StringPrintf("String #%zd : %s\n", s, str.string())); } } namespace { class XmlPrinter : public xml::ConstVisitor { Loading
tools/aapt2/Debug.h +1 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ struct Debug { static void PrintStyleGraph(ResourceTable* table, const ResourceName& target_style); static void DumpHex(const void* data, size_t len); static void DumpXml(const xml::XmlResource& doc, text::Printer* printer); static void DumpResStringPool(const android::ResStringPool* pool, text::Printer* printer); }; } // namespace aapt Loading
tools/aapt2/LoadedApk.cpp +47 −0 Original line number Diff line number Diff line Loading @@ -257,6 +257,53 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table return true; } std::unique_ptr<xml::XmlResource> LoadedApk::LoadXml(const std::string& file_path, IDiagnostics* diag) { io::IFile* file = apk_->FindFile(file_path); if (file == nullptr) { diag->Error(DiagMessage() << "failed to find file"); return nullptr; } std::unique_ptr<xml::XmlResource> doc; if (format_ == ApkFormat::kProto) { std::unique_ptr<io::InputStream> in = file->OpenInputStream(); if (!in) { diag->Error(DiagMessage() << "failed to open file"); return nullptr; } io::ZeroCopyInputAdaptor adaptor(in.get()); pb::XmlNode pb_node; if (!pb_node.ParseFromZeroCopyStream(&adaptor)) { diag->Error(DiagMessage() << "failed to parse file as proto XML"); return nullptr; } std::string err; doc = DeserializeXmlResourceFromPb(pb_node, &err); if (!doc) { diag->Error(DiagMessage() << "failed to deserialize proto XML: " << err); return nullptr; } } else if (format_ == ApkFormat::kBinary) { std::unique_ptr<io::IData> data = file->OpenAsData(); if (!data) { diag->Error(DiagMessage() << "failed to open file"); return nullptr; } std::string err; doc = xml::Inflate(data->data(), data->size(), &err); if (!doc) { diag->Error(DiagMessage() << "failed to parse file as binary XML: " << err); return nullptr; } } return doc; } ApkFormat LoadedApk::DetermineApkFormat(io::IFileCollection* apk) { if (apk->FindFile(kApkResourceTablePath) != nullptr) { return ApkFormat::kBinary; Loading
tools/aapt2/LoadedApk.h +6 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,10 @@ class LoadedApk { return apk_.get(); } ApkFormat GetApkFormat() { return format_; } const ResourceTable* GetResourceTable() const { return table_.get(); } Loading Loading @@ -106,6 +110,8 @@ class LoadedApk { const TableFlattenerOptions& options, FilterChain* filters, IArchiveWriter* writer, xml::XmlResource* manifest = nullptr); /** Loads the file as an xml document. */ std::unique_ptr<xml::XmlResource> LoadXml(const std::string& file_path, IDiagnostics* diag); private: DISALLOW_COPY_AND_ASSIGN(LoadedApk); Loading
tools/aapt2/Main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class MainCommand : public Command { explicit MainCommand(IDiagnostics* diagnostics) : Command("aapt2"), diagnostics_(diagnostics) { AddOptionalSubcommand(util::make_unique<CompileCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<LinkCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<DumpCommand>()); AddOptionalSubcommand(util::make_unique<DumpCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<DiffCommand>()); AddOptionalSubcommand(util::make_unique<OptimizeCommand>()); AddOptionalSubcommand(util::make_unique<ConvertCommand>()); Loading