diff options
author | David Sehr <sehr@google.com> | 2018-02-16 10:22:33 -0800 |
---|---|---|
committer | David Sehr <sehr@google.com> | 2018-02-16 14:45:23 -0800 |
commit | 999646d7f3b2ced25a995c020d19a55caf3c18d5 (patch) | |
tree | 870d9d5d33bca66f4891f66a0b53505508ebe009 /dexdump | |
parent | 0694a5527862fc76056458622759976fa41d4da6 (diff) | |
download | art-999646d7f3b2ced25a995c020d19a55caf3c18d5.tar.gz art-999646d7f3b2ced25a995c020d19a55caf3c18d5.tar.bz2 art-999646d7f3b2ced25a995c020d19a55caf3c18d5.zip |
Dex header cleanup and windows simplification
Remove a few unnecessary inclusions, move one missed header to
libdexfile. Also use android-base utilities for file loading in
dexdump2 and dexlist. (The utilities seem to work on Windows, where
mmap did not.)
Bug: 22322814
Test: make -j 50 test-art-host-gtest
Change-Id: I6e6de1895921f664a2280451b01e367649436200
Diffstat (limited to 'dexdump')
-rw-r--r-- | dexdump/dexdump.cc | 54 |
1 files changed, 13 insertions, 41 deletions
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc index 8778b129c5..61a1209ed1 100644 --- a/dexdump/dexdump.cc +++ b/dexdump/dexdump.cc @@ -34,19 +34,14 @@ #include "dexdump.h" -#include <fcntl.h> #include <inttypes.h> #include <stdio.h> -#include <sys/mman.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <iostream> #include <memory> #include <sstream> #include <vector> +#include "android-base/file.h" #include "android-base/logging.h" #include "android-base/stringprintf.h" @@ -1879,34 +1874,6 @@ static void processDexFile(const char* fileName, } } -static bool openAndMapFile(const char* fileName, - const uint8_t** base, - size_t* size, - std::string* error_msg) { - int fd = open(fileName, O_RDONLY); - if (fd < 0) { - *error_msg = "open failed"; - return false; - } - struct stat st; - if (fstat(fd, &st) < 0) { - *error_msg = "stat failed"; - return false; - } - *size = st.st_size; - if (*size == 0) { - *error_msg = "size == 0"; - return false; - } - void* addr = mmap(nullptr /*addr*/, *size, PROT_READ, MAP_PRIVATE, fd, 0 /*offset*/); - if (addr == MAP_FAILED) { - *error_msg = "mmap failed"; - return false; - } - *base = reinterpret_cast<const uint8_t*>(addr); - return true; -} - /* * Processes a single file (either direct .dex or indirect .zip/.jar/.apk). */ @@ -1918,17 +1885,22 @@ int processFile(const char* 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 uint8_t* base = nullptr; - size_t size = 0; - std::string error_msg; - if (!openAndMapFile(fileName, &base, &size, &error_msg)) { - LOG(ERROR) << error_msg; + std::string content; + // TODO: add an api to android::base to read a std::vector<uint8_t>. + if (!android::base::ReadFileToString(fileName, &content)) { + LOG(ERROR) << "ReadFileToString failed"; return -1; } const DexFileLoader dex_file_loader; + std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - if (!dex_file_loader.OpenAll( - base, size, fileName, /*verify*/ true, kVerifyChecksum, &error_msg, &dex_files)) { + if (!dex_file_loader.OpenAll(reinterpret_cast<const uint8_t*>(content.data()), + content.size(), + fileName, + /*verify*/ true, + kVerifyChecksum, + &error_msg, + &dex_files)) { // Display returned error message to user. Note that this error behavior // differs from the error messages shown by the original Dalvik dexdump. LOG(ERROR) << error_msg; |