MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / cookieDumpDex

Method cookieDumpDex

Bcore/src/main/cpp/DexDump.cpp:211–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211void DexDump::cookieDumpDex(JNIEnv *env, jlong cookie, jstring dir, jboolean fix) {
212 if (beginOffset == -2) {
213 init(env);
214 }
215 if (beginOffset == -1) {
216 ALOGD("dumpDex not support!");
217 return;
218 }
219 char magic[8] = {0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0x00};
220 auto base = reinterpret_cast<char *>(cookie);
221 auto begin = *(size_t *) (base + beginOffset * sizeof(size_t));
222 if (!PointerCheck::check(reinterpret_cast<void *>(begin))) {
223 return;
224 }
225 auto dirC = env->GetStringUTFChars(dir, 0);
226
227 auto dexSizeOffset = ((unsigned long) begin) + 0x20;
228 int size = *(size_t *) dexSizeOffset;
229
230 void *buffer = malloc(size);
231 if (buffer) {
232 memcpy(buffer, reinterpret_cast<const void *>(begin), size);
233 // fix magic
234 memcpy(buffer, magic, sizeof(magic));
235
236 const bool kVerifyChecksum = false;
237 const bool kVerify = true;
238 const art_lkchan::DexFileLoader dex_file_loader;
239 std::string error_msg;
240 std::vector<std::unique_ptr<const art_lkchan::DexFile>> dex_files;
241 if (!dex_file_loader.OpenAll(reinterpret_cast<const uint8_t *>(buffer),
242 size,
243 "",
244 kVerify,
245 kVerifyChecksum,
246 &error_msg,
247 &dex_files)) {
248 // Display returned error message to user. Note that this error behavior
249 // differs from the error messages shown by the original Dalvik dexdump.
250 ALOGE("Open dex error %s", error_msg.c_str());
251 return;
252 }
253
254 if (fix) {
255 fixCodeItem(env, dex_files[0].get(), begin);
256 }
257 char path[1024];
258 sprintf(path, "%s/cookie_%d.dex", dirC, size);
259 auto fd = open(path, O_CREAT | O_WRONLY, 0600);
260 ssize_t w = write(fd, buffer, size);
261 fsync(fd);
262 if (w > 0) {
263 ALOGE("cookie dump dex ======> %s", path);
264 } else {
265 remove(path);
266 }
267 close(fd);
268 free(buffer);

Callers

nothing calls this directly

Calls 5

fixCodeItemFunction · 0.85
OpenAllMethod · 0.80
c_strMethod · 0.80
initFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected