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

Function handleDumpByDexFile

Bcore/src/main/cpp/DexDump.cpp:44–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42std::list<int> dumped;
43
44void handleDumpByDexFile(void *dex_file) {
45 char magic[8] = {0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0x00};
46 if (!PointerCheck::check(dex_file)) {
47 return;
48 }
49 auto dexFile = static_cast<art_lkchan::DexFile *>(dex_file);
50
51 int size = dexFile->Size();
52 list<int>::iterator iterator;
53 for (iterator = dumped.begin(); iterator != dumped.end(); ++iterator) {
54 int value = *iterator;
55 if (size == value) {
56 return;
57 }
58 }
59 void *buffer = malloc(size);
60 if (buffer) {
61 memcpy(buffer, dexFile->Begin(), size);
62 // fix magic
63 memcpy(buffer, magic, sizeof(magic));
64
65 const bool kVerifyChecksum = false;
66 const bool kVerify = true;
67 const art_lkchan::DexFileLoader dex_file_loader;
68 std::string error_msg;
69 std::vector<std::unique_ptr<const art_lkchan::DexFile>> dex_files;
70 if (!dex_file_loader.OpenAll(reinterpret_cast<const uint8_t *>(buffer),
71 size,
72 "",
73 kVerify,
74 kVerifyChecksum,
75 &error_msg,
76 &dex_files)) {
77 // Display returned error message to user. Note that this error behavior
78 // differs from the error messages shown by the original Dalvik dexdump.
79 ALOGE("Open dex error %s", error_msg.c_str());
80 return;
81 }
82
83 char path[1024];
84 sprintf(path, "%s/hook_%d.dex", dumpPath, size);
85 auto fd = open(path, O_CREAT | O_WRONLY, 0600);
86 ssize_t w = write(fd, buffer, size);
87 fsync(fd);
88 if (w > 0) {
89 ALOGE("hook dump dex ======> %s", path);
90 } else {
91 remove(path);
92 }
93 close(fd);
94 free(buffer);
95 dumped.push_back(size);
96 }
97}
98
99HOOK_JNI(int, kill, pid_t __pid, int __signal) {
100 ALOGE("hooked so kill");

Callers 1

HOOK_FUNFunction · 0.85

Calls 6

BeginMethod · 0.80
OpenAllMethod · 0.80
c_strMethod · 0.80
SizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected