summaryrefslogtreecommitdiffstats
path: root/dexdump
diff options
context:
space:
mode:
authorDavid Sehr <sehr@google.com>2018-01-19 11:08:51 -0800
committerDavid Sehr <sehr@google.com>2018-01-22 20:50:17 +0000
commit5a1f6294919206d117662925ff2ad7cd0802721d (patch)
tree3414edb24e5a834207551a3b172d37552cbe2a55 /dexdump
parent5577295109a8af9f5bd31430670e5cbbc1a1e079 (diff)
downloadart-5a1f6294919206d117662925ff2ad7cd0802721d.tar.gz
art-5a1f6294919206d117662925ff2ad7cd0802721d.tar.bz2
art-5a1f6294919206d117662925ff2ad7cd0802721d.zip
Build dexdump2 and dexlist without libart
Finally, flesh out libdexfile enough that it can replace libart for use in dexdump2. Bug: 22322814 Test: make -j 50 dexdump2 dexlist dexdump2 -d fb/base.apk dexlist fb/base.apk Change-Id: Ibf9a1cd642cd473eea0b2208d72b4768aaa17f02
Diffstat (limited to 'dexdump')
-rw-r--r--dexdump/Android.bp27
-rw-r--r--dexdump/dexdump.cc48
-rw-r--r--dexdump/dexdump_main.cc10
3 files changed, 59 insertions, 26 deletions
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index 4916d643c6..eca08448bc 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -14,33 +14,38 @@
// TODO(ajcbik): rename dexdump2 into dexdump when Dalvik version is removed
-art_cc_binary {
- name: "dexdump2",
- host_supported: true,
+
+cc_defaults {
+ name: "dexdump_defaults",
srcs: [
"dexdump_cfg.cc",
"dexdump_main.cc",
"dexdump.cc",
],
cflags: ["-Wall", "-Werror"],
+ // TODO: fix b/72216369 and remove the need for this.
+ include_dirs: [
+ "art/runtime" // dex utils.
+ ],
+}
+
+art_cc_binary {
+ name: "dexdump2",
+ defaults: ["dexdump_defaults"],
+ host_supported: true,
shared_libs: [
- "libart",
+ "libdexfile",
"libbase",
],
}
art_cc_binary {
name: "dexdumps",
+ defaults: ["dexdump_defaults"],
host_supported: true,
device_supported: false,
- srcs: [
- "dexdump_cfg.cc",
- "dexdump_main.cc",
- "dexdump.cc",
- ],
- cflags: ["-Wall", "-Werror"],
static_libs: [
- "libart",
+ "libdexfile",
"libbase",
] + art_static_dependencies,
target: {
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc
index 1518e1d205..16cb302a84 100644
--- a/dexdump/dexdump.cc
+++ b/dexdump/dexdump.cc
@@ -34,8 +34,13 @@
#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>
@@ -44,7 +49,6 @@
#include "android-base/stringprintf.h"
-#include "dex/art_dex_file_loader.h"
#include "dex/code_item_accessors-no_art-inl.h"
#include "dex/dex_file-inl.h"
#include "dex/dex_file_exception_helpers.h"
@@ -1868,6 +1872,34 @@ 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).
*/
@@ -1879,12 +1911,18 @@ 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;
- // TODO: Use DexFileLoader when that is implemented.
- const ArtDexFileLoader dex_file_loader;
+ if (!openAndMapFile(fileName, &base, &size, &error_msg)) {
+ fputs(error_msg.c_str(), stderr);
+ fputc('\n', stderr);
+ return -1;
+ }
+ const DexFileLoader dex_file_loader;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- if (!dex_file_loader.Open(
- fileName, fileName, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) {
+ if (!dex_file_loader.OpenAll(
+ base, 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.
fputs(error_msg.c_str(), stderr);
diff --git a/dexdump/dexdump_main.cc b/dexdump/dexdump_main.cc
index 382b551a1a..2247e7a7e6 100644
--- a/dexdump/dexdump_main.cc
+++ b/dexdump/dexdump_main.cc
@@ -28,12 +28,6 @@
#include <string.h>
#include <unistd.h>
-#include <android-base/logging.h>
-
-#include <base/logging.h> // For InitLogging.
-#include "mem_map.h"
-#include "runtime.h"
-
namespace art {
static const char* gProgName = "dexdump";
@@ -61,10 +55,6 @@ static void usage(void) {
* Main driver of the dexdump utility.
*/
int dexdumpDriver(int argc, char** argv) {
- // Art specific set up.
- InitLogging(argv, Runtime::Abort);
- MemMap::Init();
-
// Reset options.
bool wantUsage = false;
memset(&gOptions, 0, sizeof(gOptions));