diff options
Diffstat (limited to 'tools/aapt2/dump/Dump.cpp')
-rw-r--r-- | tools/aapt2/dump/Dump.cpp | 91 |
1 files changed, 56 insertions, 35 deletions
diff --git a/tools/aapt2/dump/Dump.cpp b/tools/aapt2/dump/Dump.cpp index 56b9f9a3e081..88c6f64f5510 100644 --- a/tools/aapt2/dump/Dump.cpp +++ b/tools/aapt2/dump/Dump.cpp @@ -20,6 +20,7 @@ #include "io/ZipArchive.h" #include "process/IResourceTableConsumer.h" #include "proto/ProtoSerialize.h" +#include "unflatten/BinaryResourceParser.h" #include "util/Files.h" #include "util/StringPiece.h" @@ -44,18 +45,9 @@ void dumpCompiledFile(const pb::CompiledFile& pbFile, const void* data, size_t l << "Source: " << file->source << "\n"; } -void dumpCompiledTable(const pb::ResourceTable& pbTable, const Source& source, - IAaptContext* context) { - std::unique_ptr<ResourceTable> table = deserializeTableFromPb(pbTable, source, - context->getDiagnostics()); - if (!table) { - return; - } - - Debug::printTable(table.get()); -} - void tryDumpFile(IAaptContext* context, const std::string& filePath) { + std::unique_ptr<ResourceTable> table; + std::string err; std::unique_ptr<io::ZipFileCollection> zip = io::ZipFileCollection::create(filePath, &err); if (zip) { @@ -75,37 +67,62 @@ void tryDumpFile(IAaptContext* context, const std::string& filePath) { return; } - std::unique_ptr<ResourceTable> table = deserializeTableFromPb( + table = deserializeTableFromPb( pbTable, Source(filePath), context->getDiagnostics()); - if (table) { - DebugPrintTableOptions debugPrintTableOptions; - debugPrintTableOptions.showSources = true; - Debug::printTable(table.get(), debugPrintTableOptions); + if (!table) { + return; } } - return; - } - Maybe<android::FileMap> file = file::mmapPath(filePath, &err); - if (!file) { - context->getDiagnostics()->error(DiagMessage(filePath) << err); - return; + if (!table) { + file = zip->findFile("resources.arsc"); + if (file) { + std::unique_ptr<io::IData> data = file->openAsData(); + if (!data) { + context->getDiagnostics()->error(DiagMessage(filePath) + << "failed to open resources.arsc"); + return; + } + + table = util::make_unique<ResourceTable>(); + BinaryResourceParser parser(context, table.get(), Source(filePath), + data->data(), data->size()); + if (!parser.parse()) { + return; + } + } + } } - android::FileMap* fileMap = &file.value(); + if (!table) { + Maybe<android::FileMap> file = file::mmapPath(filePath, &err); + if (!file) { + context->getDiagnostics()->error(DiagMessage(filePath) << err); + return; + } + + android::FileMap* fileMap = &file.value(); - // Try as a compiled table. - pb::ResourceTable pbTable; - if (pbTable.ParseFromArray(fileMap->getDataPtr(), fileMap->getDataLength())) { - dumpCompiledTable(pbTable, Source(filePath), context); - return; + // Try as a compiled table. + pb::ResourceTable pbTable; + if (pbTable.ParseFromArray(fileMap->getDataPtr(), fileMap->getDataLength())) { + table = deserializeTableFromPb(pbTable, Source(filePath), context->getDiagnostics()); + } + + if (!table) { + // Try as a compiled file. + CompiledFileInputStream input(fileMap->getDataPtr(), fileMap->getDataLength()); + if (const pb::CompiledFile* pbFile = input.CompiledFile()) { + dumpCompiledFile(*pbFile, input.data(), input.size(), Source(filePath), context); + return; + } + } } - // Try as a compiled file. - CompiledFileInputStream input(fileMap->getDataPtr(), fileMap->getDataLength()); - if (const pb::CompiledFile* pbFile = input.CompiledFile()) { - dumpCompiledFile(*pbFile, input.data(), input.size(), Source(filePath), context); - return; + if (table) { + DebugPrintTableOptions debugPrintTableOptions; + debugPrintTableOptions.showSources = true; + Debug::printTable(table.get(), debugPrintTableOptions); } } @@ -120,8 +137,8 @@ public: return nullptr; } - const std::u16string& getCompilationPackage() override { - static std::u16string empty; + const std::string& getCompilationPackage() override { + static std::string empty; return empty; } @@ -142,6 +159,10 @@ public: mVerbose = val; } + int getMinSdkVersion() override { + return 0; + } + private: StdErrDiagnostics mDiagnostics; bool mVerbose = false; |