|
|
|
@ -16,8 +16,6 @@ |
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
static int beginOffset = -2; |
|
|
|
|
static int sizeOffset = -2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void init(JNIEnv *env) { |
|
|
|
|
jlongArray emptyCookie = VmCore::loadEmptyDex(env); |
|
|
|
@ -25,7 +23,7 @@ void init(JNIEnv *env) { |
|
|
|
|
if (env->ExceptionCheck() == JNI_TRUE) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
jlong* long_data = env->GetLongArrayElements(emptyCookie, nullptr); |
|
|
|
|
jlong *long_data = env->GetLongArrayElements(emptyCookie, nullptr); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < arrSize; ++i) { |
|
|
|
|
jlong cookie = long_data[i]; |
|
|
|
@ -36,8 +34,7 @@ void init(JNIEnv *env) { |
|
|
|
|
for (int ii = 0; ii < 10; ++ii) { |
|
|
|
|
auto value = *(size_t *) (dex + ii * sizeof(size_t)); |
|
|
|
|
if (value == 1872) { |
|
|
|
|
sizeOffset = ii; |
|
|
|
|
beginOffset = sizeOffset - 1; |
|
|
|
|
beginOffset = ii - 1; |
|
|
|
|
// auto dexBegin = *(size_t *) (dex + beginOffset * sizeof(size_t));
|
|
|
|
|
// HexDump(reinterpret_cast<char *>(dexBegin), 10, 0);
|
|
|
|
|
env->ReleaseLongArrayElements(emptyCookie, long_data, 0); |
|
|
|
@ -47,34 +44,36 @@ void init(JNIEnv *env) { |
|
|
|
|
} |
|
|
|
|
env->ReleaseLongArrayElements(emptyCookie, long_data, 0); |
|
|
|
|
beginOffset = -1; |
|
|
|
|
sizeOffset = -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DexDump::dumpDex(JNIEnv *env, jlong cookie, jstring dir) { |
|
|
|
|
if (beginOffset == -2 || sizeOffset == -2) { |
|
|
|
|
if (beginOffset == -2) { |
|
|
|
|
init(env); |
|
|
|
|
} |
|
|
|
|
if (beginOffset == -1 || sizeOffset == -1) { |
|
|
|
|
if (beginOffset == -1) { |
|
|
|
|
ALOGD("dumpDex not support!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
char magic[8] = {0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0x00}; |
|
|
|
|
auto base = reinterpret_cast<char *>(cookie); |
|
|
|
|
auto begin = *(size_t *) (base + beginOffset * sizeof(size_t)); |
|
|
|
|
auto size = *(size_t *) (base + sizeOffset * sizeof(size_t)); |
|
|
|
|
// auto size = *(size_t *) (base + sizeOffset * sizeof(size_t));
|
|
|
|
|
if (!PointerCheck::check(reinterpret_cast<void *>(begin))) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto dirC = env->GetStringUTFChars(dir, 0); |
|
|
|
|
|
|
|
|
|
auto dexSizeOffset = ((unsigned long ) begin) + 0x20; |
|
|
|
|
size_t size = *(size_t *) dexSizeOffset; |
|
|
|
|
|
|
|
|
|
auto buffer = malloc(size); |
|
|
|
|
memcpy(buffer, reinterpret_cast<const void *>(begin), size); |
|
|
|
|
// fix magic
|
|
|
|
|
memcpy(buffer, magic, sizeof(magic)); |
|
|
|
|
|
|
|
|
|
char path[1024]; |
|
|
|
|
sprintf(path, "%s/dex_%ld.dex", dirC, size); |
|
|
|
|
sprintf(path, "%s/dex_%d.dex", dirC, size); |
|
|
|
|
auto fd = open(path, O_CREAT | O_WRONLY, 0600); |
|
|
|
|
ssize_t w = write(fd, buffer, size); |
|
|
|
|
fsync(fd); |
|
|
|
|