1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| var soName = "libDexHelper-x86.so";
function getPackageName() { var pkg = "unknown"; try { Java.perform(function () { var ActivityThread = Java.use("android.app.ActivityThread"); var app = ActivityThread.currentApplication(); if (app) { pkg = app.getApplicationContext().getPackageName(); } }); } catch (e) { console.log("[!] getPackageName failed:", e); } return pkg; }
function printJNIOnLoad(module) { try { var jni = Module.findExportByName( module.name, "JNI_OnLoad" );
if (!jni) { var symbols = module.enumerateSymbols();
for (var i = 0; i < symbols.length; i++) { if (symbols[i].name === "JNI_OnLoad") { jni = symbols[i].address; break; } } }
if (jni) { console.log("[+] JNI_OnLoad:", jni);
var offset = jni.sub(module.base);
console.log( "[+] JNI_OnLoad offset:", offset );
console.log( "[+] base + offset:", module.base.add(offset) ); } else { console.log("[!] JNI_OnLoad not found"); }
} catch (e) { console.log("[!] JNI_OnLoad lookup failed:", e); } }
function waitModule(cb) { var t = setInterval(function () { var m = Process.findModuleByName(soName); if (m) { clearInterval(t); console.log("[+] loaded:", soName); console.log("[+] base:", m.base); console.log("[+] size:", m.size); cb(m); } }, 100); }
function dumpSoStable(module) {
try { console.log("======================================"); console.log("[DUMP START]");
var pkg = getPackageName();
var dumpPath = "/data/data/" + pkg + "/" + module.name + ".stable.dump.so";
var dumpBuffer = Memory.alloc(module.size);
Memory.writeByteArray( dumpBuffer, new Uint8Array(module.size) );
var ranges = Process.enumerateRangesSync({ protection: 'r--', coalesce: true }).concat( Process.enumerateRangesSync({ protection: 'r-x', coalesce: true }), Process.enumerateRangesSync({ protection: 'rw-', coalesce: true }) );
var copied = 0;
ranges.forEach(function (range) { try {
if ( range.base.compare(module.base) < 0 || range.base.compare(module.base.add(module.size)) >= 0 ) return;
var offset = Number(range.base.sub(module.base)); if (offset < 0 || offset >= module.size) return;
var data = Memory.readByteArray(range.base, range.size); if (!data) return;
Memory.writeByteArray(dumpBuffer.add(offset), data); copied++;
} catch (e) { } });
console.log("[+] ranges copied:", copied);
var magic = new Uint8Array(Memory.readByteArray(dumpBuffer, 4));
if ( magic[0] === 0x7f && magic[1] === 0x45 && magic[2] === 0x4c && magic[3] === 0x46 ) { console.log("[OK] ELF MAGIC"); } else { console.log("[WARN] ELF BROKEN"); }
var file = new File(dumpPath, "wb"); file.write(Memory.readByteArray(dumpBuffer, module.size)); file.flush(); file.close();
console.log("======================================"); console.log("[DUMP SUCCESS]"); console.log("[PATH]:", dumpPath); console.log("======================================");
} catch (e) { console.log("[DUMP ERROR]", e); } }
waitModule(function (module) {
printJNIOnLoad(module);
setTimeout(function () { dumpSoStable(module); }, 1000);
});
|