Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT2_DUMP_H |
| 18 | #define AAPT2_DUMP_H |
| 19 | |
| 20 | #include "Command.h" |
| 21 | #include "Debug.h" |
| 22 | |
| 23 | namespace aapt { |
| 24 | |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 25 | /** Command the contents of files generated from the compilation stage. */ |
| 26 | class DumpAPCCommand : public Command { |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 27 | public: |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 28 | explicit DumpAPCCommand(IDiagnostics* diag) : Command("apc"), diag_(diag) { |
| 29 | SetDescription("Print the contents of the AAPT2 Container (APC) generated fom compilation."); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 30 | AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.", |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 31 | &no_values_); |
| 32 | AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | int Action(const std::vector<std::string>& args) override; |
| 36 | |
| 37 | private: |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 38 | IDiagnostics* diag_; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 39 | bool verbose_ = false; |
| 40 | bool no_values_ = false; |
| 41 | }; |
| 42 | |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 43 | /** Prints every configuration used by a resource in an APK. */ |
| 44 | class DumpConfigsCommand : public Command { |
| 45 | public: |
| 46 | explicit DumpConfigsCommand(IDiagnostics* diag) : Command("configurations"), diag_(diag) { |
| 47 | SetDescription("Print every configuration used by a resource in the APK."); |
| 48 | } |
| 49 | |
| 50 | int Action(const std::vector<std::string>& args) override; |
| 51 | |
| 52 | private: |
| 53 | IDiagnostics* diag_; |
| 54 | }; |
| 55 | |
| 56 | /** Prints the contents of the resource table string pool in the APK. */ |
| 57 | class DumpStringsCommand : public Command { |
| 58 | public: |
| 59 | explicit DumpStringsCommand(IDiagnostics* diag) : Command("strings"), diag_(diag) { |
| 60 | SetDescription("Print the contents of the resource table string pool in the APK."); |
| 61 | } |
| 62 | |
| 63 | int Action(const std::vector<std::string>& args) override; |
| 64 | |
| 65 | private: |
| 66 | IDiagnostics* diag_; |
| 67 | }; |
| 68 | |
| 69 | /** Prints the contents of the resource table from the APK. */ |
| 70 | class DumpTableCommand : public Command { |
| 71 | public: |
| 72 | explicit DumpTableCommand(IDiagnostics* diag) : Command("resources"), diag_(diag) { |
| 73 | SetDescription("Print the contents of the resource table from the APK."); |
| 74 | AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.", |
| 75 | &no_values_); |
| 76 | AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_); |
| 77 | } |
| 78 | |
| 79 | int Action(const std::vector<std::string>& args) override; |
| 80 | |
| 81 | private: |
| 82 | IDiagnostics* diag_; |
| 83 | bool verbose_ = false; |
| 84 | bool no_values_ = false; |
| 85 | }; |
| 86 | |
| 87 | /** Prints the string pool of a compiled xml in an APK. */ |
| 88 | class DumpXmlStringsCommand : public Command { |
| 89 | public: |
| 90 | explicit DumpXmlStringsCommand(IDiagnostics* diag) : Command("xmlstrings"), diag_(diag) { |
| 91 | SetDescription("Print the string pool of a compiled xml in an APK."); |
| 92 | AddRequiredFlagList("--file", "A compiled xml file to print", &files_); |
| 93 | } |
| 94 | |
| 95 | int Action(const std::vector<std::string>& args) override; |
| 96 | |
| 97 | private: |
| 98 | IDiagnostics* diag_; |
| 99 | std::vector<std::string> files_; |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | /** Prints the tree of a compiled xml in an APK. */ |
| 104 | class DumpXmlTreeCommand : public Command { |
| 105 | public: |
| 106 | explicit DumpXmlTreeCommand(IDiagnostics* diag) : Command("xmltree"), diag_(diag) { |
| 107 | SetDescription("Print the tree of a compiled xml in an APK."); |
| 108 | AddRequiredFlagList("--file", "A compiled xml file to print", &files_); |
| 109 | } |
| 110 | |
| 111 | int Action(const std::vector<std::string>& args) override; |
| 112 | |
| 113 | private: |
| 114 | IDiagnostics* diag_; |
| 115 | std::vector<std::string> files_; |
| 116 | }; |
| 117 | |
Todd Kennedy | 908b7fc | 2018-08-24 10:11:21 -0700 | [diff] [blame^] | 118 | /** Prints the contents of the resource table from the APK. */ |
| 119 | class DumpPackageNameCommand : public Command { |
| 120 | public: |
| 121 | explicit DumpPackageNameCommand(IDiagnostics* diag) : Command("packagename"), diag_(diag) { |
| 122 | SetDescription("Print the package name of the APK."); |
| 123 | } |
| 124 | |
| 125 | int Action(const std::vector<std::string>& args) override; |
| 126 | |
| 127 | private: |
| 128 | IDiagnostics* diag_; |
| 129 | }; |
| 130 | |
| 131 | /** The default dump command. Performs no action because a subcommand is required. */ |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 132 | class DumpCommand : public Command { |
| 133 | public: |
| 134 | explicit DumpCommand(IDiagnostics* diag) : Command("dump", "d"), diag_(diag) { |
| 135 | AddOptionalSubcommand(util::make_unique<DumpAPCCommand>(diag_)); |
| 136 | AddOptionalSubcommand(util::make_unique<DumpConfigsCommand>(diag_)); |
Todd Kennedy | 908b7fc | 2018-08-24 10:11:21 -0700 | [diff] [blame^] | 137 | AddOptionalSubcommand(util::make_unique<DumpPackageNameCommand>(diag_)); |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 138 | AddOptionalSubcommand(util::make_unique<DumpStringsCommand>(diag_)); |
| 139 | AddOptionalSubcommand(util::make_unique<DumpTableCommand>(diag_)); |
| 140 | AddOptionalSubcommand(util::make_unique<DumpXmlStringsCommand>(diag_)); |
| 141 | AddOptionalSubcommand(util::make_unique<DumpXmlTreeCommand>(diag_)); |
| 142 | } |
| 143 | |
| 144 | int Action(const std::vector<std::string>& args) override; |
| 145 | |
| 146 | private: |
| 147 | IDiagnostics* diag_; |
| 148 | }; |
| 149 | |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 150 | }// namespace aapt |
| 151 | |
| 152 | #endif //AAPT2_DUMP_H |