From 551a16e36d89ca23ede9d3b7727cc41ca8b40b08 Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Mon, 24 May 2021 17:50:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D64=E4=BD=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?dump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bcore/src/main/jni/DexDump.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Bcore/src/main/jni/DexDump.cpp b/Bcore/src/main/jni/DexDump.cpp index 5863b20..3c5d58f 100644 --- a/Bcore/src/main/jni/DexDump.cpp +++ b/Bcore/src/main/jni/DexDump.cpp @@ -64,24 +64,26 @@ void DexDump::dumpDex(JNIEnv *env, jlong cookie, jstring dir) { auto dirC = env->GetStringUTFChars(dir, 0); auto dexSizeOffset = ((unsigned long ) begin) + 0x20; - size_t size = *(size_t *) dexSizeOffset; + int size = *(size_t *) dexSizeOffset; auto buffer = malloc(size); - memcpy(buffer, reinterpret_cast(begin), size); - // fix magic - memcpy(buffer, magic, sizeof(magic)); + if (buffer) { + memcpy(buffer, reinterpret_cast(begin), size); + // fix magic + memcpy(buffer, magic, sizeof(magic)); - char path[1024]; - 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); - if (w > 0) { - ALOGD("dump dex ======> %s", path); - } else { - remove(path); + char path[1024]; + 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); + if (w > 0) { + ALOGD("dump dex ======> %s", path); + } else { + remove(path); + } + close(fd); + free(buffer); + env->ReleaseStringUTFChars(dir, dirC); } - close(fd); - free(buffer); - env->ReleaseStringUTFChars(dir, dirC); }