2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * Main driver of the dexdump utility.
18 * This is a re-implementation of the original dexdump utility that was
19 * based on Dalvik functions in libdex into a new dexdump that is now
20 * based on Art functions in libart instead. The output is identical to
21 * the original for correct DEX files. Error messages may differ, however.
22 * Also, ODEX files are no longer supported.
36 static const char* gProgName = "dexdump";
41 static void usage(void) {
42 fprintf(stderr, "Copyright (C) 2007 The Android Open Source Project\n\n");
43 fprintf(stderr, "%s: [-c] [-d] [-e] [-f] [-h] [-i] [-l layout] [-o outfile]"
44 " [-t tempfile] dexfile...\n", gProgName);
45 fprintf(stderr, "\n");
46 fprintf(stderr, " -c : verify checksum and exit\n");
47 fprintf(stderr, " -d : disassemble code sections\n");
48 fprintf(stderr, " -e : display exported items only\n");
49 fprintf(stderr, " -f : display summary information from file header\n");
50 fprintf(stderr, " -g : dump CFG for dex\n");
51 fprintf(stderr, " -h : display file header details\n");
52 fprintf(stderr, " -i : ignore checksum failures\n");
53 fprintf(stderr, " -l : output layout, either 'plain' or 'xml'\n");
54 fprintf(stderr, " -o : output file name (defaults to stdout)\n");
55 fprintf(stderr, " -t : temp file name (defaults to /sdcard/dex-temp-*)\n");
59 * Main driver of the dexdump utility.
61 int dexdumpDriver(int argc, char** argv) {
62 // Art specific set up.
67 bool wantUsage = false;
68 memset(&gOptions, 0, sizeof(gOptions));
69 gOptions.verbose = true;
71 // Parse all arguments.
73 const int ic = getopt(argc, argv, "cdefghil:t:o:");
78 case 'c': // verify the checksum then exit
79 gOptions.checksumOnly = true;
81 case 'd': // disassemble Dalvik instructions
82 gOptions.disassemble = true;
84 case 'e': // exported items only
85 gOptions.exportsOnly = true;
87 case 'f': // dump outer file header
88 gOptions.showFileHeaders = true;
93 case 'h': // dump section headers, i.e. all meta-data
94 gOptions.showSectionHeaders = true;
96 case 'i': // continue even if checksum is bad
97 gOptions.ignoreBadChecksum = true;
100 if (strcmp(optarg, "plain") == 0) {
101 gOptions.outputFormat = OUTPUT_PLAIN;
102 } else if (strcmp(optarg, "xml") == 0) {
103 gOptions.outputFormat = OUTPUT_XML;
104 gOptions.verbose = false;
109 case 't': // temp file, used when opening compressed Jar
110 gOptions.tempFileName = optarg;
112 case 'o': // output file
113 gOptions.outputFileName = optarg;
121 // Detect early problems.
122 if (optind == argc) {
123 fprintf(stderr, "%s: no file specified\n", gProgName);
126 if (gOptions.checksumOnly && gOptions.ignoreBadChecksum) {
127 fprintf(stderr, "Can't specify both -c and -i\n");
135 // Open alternative output file.
136 if (gOptions.outputFileName) {
137 gOutFile = fopen(gOptions.outputFileName, "w");
139 fprintf(stderr, "Can't open %s\n", gOptions.outputFileName);
144 // Process all files supplied on command line.
146 while (optind < argc) {
147 result |= processFile(argv[optind++]);
154 int main(int argc, char** argv) {
155 return art::dexdumpDriver(argc, argv);