diff options
-rw-r--r-- | dexdump/dexdump.cc | 36 | ||||
-rw-r--r-- | dexdump/dexdump.h | 1 | ||||
-rw-r--r-- | dexdump/dexdump_main.cc | 11 | ||||
-rw-r--r-- | dexdump/dexdump_test.cc | 5 |
4 files changed, 48 insertions, 5 deletions
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc index 7e4c1a68d3..b273a5c768 100644 --- a/dexdump/dexdump.cc +++ b/dexdump/dexdump.cc @@ -1902,6 +1902,37 @@ static void dumpCallSite(const DexFile* pDexFile, u4 idx) { } /* + * Used to decide if we want to print or skip a string from string_ids + */ +static int isPrintable(const char* s) { + for (size_t i = 0; i < strlen(s); i++) { + if (!isprint((s[i]))) { + return false; + } + } + return true; +} + +/* + * Show all printable string in the string_ids section + */ +static void dumpStrings(const DexFile* pDexFile) { + const DexFile::Header& pHeader = pDexFile->GetHeader(); + fprintf(gOutFile, "\nDisplaying %u strings from string_ids:\n", pHeader.string_ids_size_); + + for (uint32_t i = 0; i < pHeader.string_ids_size_; i++) { + dex::StringIndex idx = static_cast<dex::StringIndex>(i); + const char* string = pDexFile->StringDataByIdx(idx); + if (!isPrintable(string)) { + string = "skipped (not printable)"; + } + fprintf(gOutFile, " string[%06u] - '%s'\n", i, string); + } + + fprintf(gOutFile, "\n"); +} + +/* * Dumps the requested sections of the file. */ static void processDexFile(const char* fileName, @@ -1920,6 +1951,11 @@ static void processDexFile(const char* fileName, dumpFileHeader(pDexFile); } + // Strings. + if (gOptions.showAllStrings) { + dumpStrings(pDexFile); + } + // Iterate over all classes. char* package = nullptr; const u4 classDefsSize = pDexFile->GetHeader().class_defs_size_; diff --git a/dexdump/dexdump.h b/dexdump/dexdump.h index 7226ca0fc9..ec101d5b6d 100644 --- a/dexdump/dexdump.h +++ b/dexdump/dexdump.h @@ -51,6 +51,7 @@ struct Options { bool verbose; OutputFormat outputFormat; const char* outputFileName; + bool showAllStrings; }; /* Prototypes. */ diff --git a/dexdump/dexdump_main.cc b/dexdump/dexdump_main.cc index fed2ba7282..821d98f775 100644 --- a/dexdump/dexdump_main.cc +++ b/dexdump/dexdump_main.cc @@ -39,8 +39,9 @@ static const char* gProgName = "dexdump"; */ static void usage() { LOG(ERROR) << "Copyright (C) 2007 The Android Open Source Project\n"; - LOG(ERROR) << gProgName << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-j] [-l layout] [-n]" - " [-o outfile] dexfile...\n"; + LOG(ERROR) << gProgName + << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-j] [-l layout] [-n]" + " [-s] [-o outfile] dexfile...\n"; LOG(ERROR) << " -a : display annotations"; LOG(ERROR) << " -c : verify checksum and exit"; LOG(ERROR) << " -d : disassemble code sections"; @@ -53,6 +54,7 @@ static void usage() { LOG(ERROR) << " -l : output layout, either 'plain' or 'xml'"; LOG(ERROR) << " -n : don't display debug information"; LOG(ERROR) << " -o : output file name (defaults to stdout)"; + LOG(ERROR) << " -s : display all strings from string_ids header section"; } /* @@ -67,7 +69,7 @@ int dexdumpDriver(int argc, char** argv) { // Parse all arguments. while (true) { - const int ic = getopt(argc, argv, "acdefghijl:no:"); + const int ic = getopt(argc, argv, "acdefghijl:no:s"); if (ic < 0) { break; // done } @@ -115,6 +117,9 @@ int dexdumpDriver(int argc, char** argv) { case 'o': // output file gOptions.outputFileName = optarg; break; + case 's': // display all strings + gOptions.showAllStrings = true; + break; default: wantUsage = true; break; diff --git a/dexdump/dexdump_test.cc b/dexdump/dexdump_test.cc index 91ab1871de..0ab5182a55 100644 --- a/dexdump/dexdump_test.cc +++ b/dexdump/dexdump_test.cc @@ -67,8 +67,9 @@ TEST_F(DexDumpTest, BadFlagCombination) { TEST_F(DexDumpTest, FullPlainOutput) { std::string error_msg; - ASSERT_TRUE(Exec({"-d", "-f", "-h", "-l", "plain", "-o", "/dev/null", - dex_file_}, &error_msg)) << error_msg; + ASSERT_TRUE( + Exec({"-d", "-f", "-h", "-s", "-l", "plain", "-o", "/dev/null", dex_file_}, &error_msg)) + << error_msg; } TEST_F(DexDumpTest, XMLOutput) { |