Skip to content

Commit

Permalink
Add an option for disabling dex file verifier.
Browse files Browse the repository at this point in the history
Useful for boot classpath dex files, that may contain
hidden api flags.

bug: 73879013
Test: dexdump2 -b -d out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar

Change-Id: I38513c357473a751ad826c6974c0b3eefd04bfea
  • Loading branch information
Nicolas Geoffray committed Mar 1, 2018
1 parent e58709d commit c1d8caa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions dexdump/dexdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1882,10 +1882,11 @@ int processFile(const char* fileName) {
fprintf(gOutFile, "Processing '%s'...\n", fileName);
}

// If the file is not a .dex file, the function tries .zip/.jar/.apk files,
// all of which are Zip archives with "classes.dex" inside.
const bool kVerifyChecksum = !gOptions.ignoreBadChecksum;
const bool kVerify = !gOptions.disableVerifier;
std::string content;
// If the file is not a .dex file, the function tries .zip/.jar/.apk files,
// all of which are Zip archives with "classes.dex" inside.
// TODO: add an api to android::base to read a std::vector<uint8_t>.
if (!android::base::ReadFileToString(fileName, &content)) {
LOG(ERROR) << "ReadFileToString failed";
Expand All @@ -1897,7 +1898,7 @@ int processFile(const char* fileName) {
if (!dex_file_loader.OpenAll(reinterpret_cast<const uint8_t*>(content.data()),
content.size(),
fileName,
/*verify*/ true,
kVerify,
kVerifyChecksum,
&error_msg,
&dex_files)) {
Expand Down
1 change: 1 addition & 0 deletions dexdump/dexdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct Options {
bool disassemble;
bool exportsOnly;
bool ignoreBadChecksum;
bool disableVerifier;
bool showAnnotations;
bool showCfg;
bool showFileHeaders;
Expand Down
8 changes: 6 additions & 2 deletions dexdump/dexdump_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static const char* gProgName = "dexdump";
*/
static void usage(void) {
LOG(ERROR) << "Copyright (C) 2007 The Android Open Source Project\n";
LOG(ERROR) << gProgName << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-l layout] [-o outfile]"
LOG(ERROR) << gProgName << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-j] [-l layout] [-o outfile]"
" dexfile...\n";
LOG(ERROR) << " -a : display annotations";
LOG(ERROR) << " -c : verify checksum and exit";
Expand All @@ -49,6 +49,7 @@ static void usage(void) {
LOG(ERROR) << " -g : display CFG for dex";
LOG(ERROR) << " -h : display file header details";
LOG(ERROR) << " -i : ignore checksum failures";
LOG(ERROR) << " -j : disable dex file verification";
LOG(ERROR) << " -l : output layout, either 'plain' or 'xml'";
LOG(ERROR) << " -o : output file name (defaults to stdout)";
}
Expand All @@ -64,7 +65,7 @@ int dexdumpDriver(int argc, char** argv) {

// Parse all arguments.
while (1) {
const int ic = getopt(argc, argv, "acdefghil:o:");
const int ic = getopt(argc, argv, "acdefghijl:o:");
if (ic < 0) {
break; // done
}
Expand Down Expand Up @@ -93,6 +94,9 @@ int dexdumpDriver(int argc, char** argv) {
case 'i': // continue even if checksum is bad
gOptions.ignoreBadChecksum = true;
break;
case 'j': // disable dex file verification
gOptions.disableVerifier = true;
break;
case 'l': // layout
if (strcmp(optarg, "plain") == 0) {
gOptions.outputFormat = OUTPUT_PLAIN;
Expand Down

0 comments on commit c1d8caa

Please sign in to comment.