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
| var addrNewStringUTF = null; var method02addr = null; function find_RegisterNatives() { var symbols = Module.enumerateSymbolsSync("libart.so"); var addrRegisterNatives = null; for (var i = 0; i < symbols.length; i++) { var symbol = symbols[i];
if (symbol.name.indexOf("art") >= 0 && symbol.name.indexOf("JNI") >= 0 && symbol.name.indexOf("NewStringUTF") >= 0 && symbol.name.indexOf("CheckJNI") < 0) { addrNewStringUTF = symbol.address; console.log("NewStringUTF is at ", symbol.address, symbol.name); } if (symbol.name.indexOf("art") >= 0 && symbol.name.indexOf("JNI") >= 0 && symbol.name.indexOf("RegisterNatives") >= 0 && symbol.name.indexOf("CheckJNI") < 0) { addrRegisterNatives = symbol.address; console.log("RegisterNatives is at ", symbol.address, symbol.name); hook_RegisterNatives(addrRegisterNatives) } }
} function hook_RegisterNatives(addrRegisterNatives) {
if (addrRegisterNatives != null) { Interceptor.attach(addrRegisterNatives, { onEnter: function (args) { console.log("[RegisterNatives] method_count:", args[3]); var env = args[0]; var java_class = args[1]; var class_name = Java.vm.tryGetEnv().getClassName(java_class);
var methods_ptr = ptr(args[2]);
var method_count = parseInt(args[3]); for (var i = 0; i < method_count; i++) { var name_ptr = Memory.readPointer(methods_ptr.add(i * Process.pointerSize * 3)); var sig_ptr = Memory.readPointer(methods_ptr.add(i * Process.pointerSize * 3 + Process.pointerSize)); var fnPtr_ptr = Memory.readPointer(methods_ptr.add(i * Process.pointerSize * 3 + Process.pointerSize * 2));
var name = Memory.readCString(name_ptr); var sig = Memory.readCString(sig_ptr); var find_module = Process.findModuleByAddress(fnPtr_ptr); console.log("[RegisterNatives] java_class:", class_name, "name:", name, "sig:", sig, "fnPtr:", fnPtr_ptr, " fnOffset:", ptr(fnPtr_ptr).sub(find_module.base), " callee:", DebugSymbol.fromAddress(this.returnAddress)); if (name.indexOf("decrypt") >= 0){ method02addr = fnPtr_ptr; var method01addr = Module.findExportByName("libroysue.so", "Java_com_roysue_easyso1_MainActivity_method01"); console.log("method01 address:", method02addr) console.log("method02 address:", method01addr) if(method02addr){ Interceptor.attach(method02addr, { onEnter: function(args){ console.log("method02 args[2] ==> ", Java.vm.getEnv().getStringUtfChars(args[2], null).readCString()) }, onLeave: function(retval){ console.log("method02 retval ==> ", Java.vm.getEnv().getStringUtfChars(retval, null).readCString()) } }) } } } } }); } }
function invoke_method01(contents){ var method01_addr = Module.findExportByName("libroysue.so", "Java_com_roysue_easyso1_MainActivity_method01") if(method01_addr && addrNewStringUTF){ console.log("method01_addr is =>",method01_addr) var method01 = new NativeFunction(method01_addr, 'pointer',['pointer','pointer','pointer']) var NewStringUTF = new NativeFunction(addrNewStringUTF, "pointer", ["pointer", "pointer"]); var result = null; Java.perform(function(){ var Jstring = NewStringUTF(Java.vm.getEnv(), Memory.allocUtf8String(contents)); result = method01(Java.vm.getEnv(), Jstring, Jstring) console.log("result is =>",result) console.log("result is ", Java.vm.getEnv().getStringUtfChars(result, null).readCString()) result = Java.vm.getEnv().getStringUtfChars(result, null).readCString(); }) return result; } } function invoke_method02(contents){ if(method02addr && addrNewStringUTF){ console.log("method02_addr is =>", method02addr) var method02 = new NativeFunction(method02addr, 'pointer',['pointer','pointer','pointer']) var NewStringUTF = new NativeFunction(addrNewStringUTF,'pointer',['pointer','pointer']) var result = null; Java.perform(function(){ var Jstring = NewStringUTF(Java.vm.getEnv(), Memory.allocUtf8String(contents)); result = method02(Java.vm.getEnv(), Jstring, Jstring) console.log("result is =>",result) console.log("result is ", Java.vm.getEnv().getStringUtfChars(result, null).readCString()) result = Java.vm.getEnv().getStringUtfChars(result, null).readCString(); }) return result; } }
rpc.exports = { invoke1:invoke_method01, invoke2:invoke_method02 } function main(){ find_RegisterNatives("libroysue.so") }
setImmediate(main)
|