var manActivity=Java.use("com.kanxue.algorithmbase.MainActivity"); var res= manActivity.encodeFromJni_71(input) console.log("input:",input,"output:",res);
然后是主动调用函数
1 2 3 4 5 6 7 8 9 10 11
//主动调用静态函数 var FridaActivity2 = Java.use("com.kanxue.algorithmbase.MainActivity"); FridaActivity2.setStatic_bool_var(); //主动调用非静态函数 Java.choose("com.example.androiddemo.Activity.FridaActivity2", { onMatch: function (instance) { instance.setBool_var(); }, onComplete: function () { } });
var InnerClasses = Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses"); console.log(InnerClasses); InnerClasses.check1.implementation = function () { returntrue; };
根据条件判断动态hook多个函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
var class_name = "com.example.androiddemo.Activity.FridaActivity4$InnerClasses"; var InnerClasses = Java.use(class_name); var all_methods = InnerClasses.class.getDeclaredMethods(); for (var i = 0; i < all_methods.length; i++) { var method = (all_methods[i]); var methodStr = method.toString(); var substring = methodStr.substr(methodStr.indexOf(class_name) + class_name.length + 1); var methodname = substring.substr(0, substring.indexOf("(")); console.log(methodname); InnerClasses[methodname].implementation = function () { console.log("hook_mul_function:", this); returntrue; } }
functionwrite_reg_dat2() { //把C函数定义为NativeFunction来写文件 var addr_fopen = Module.findExportByName("libc.so", "fopen"); var addr_fputs = Module.findExportByName("libc.so", "fputs"); var addr_fclose = Module.findExportByName("libc.so", "fclose");
console.log("addr_fopen:", addr_fopen, "addr_fputs:", addr_fputs, "addr_fclose:", addr_fclose); var fopen = new NativeFunction(addr_fopen, "pointer", ["pointer", "pointer"]); var fputs = new NativeFunction(addr_fputs, "int", ["pointer", "pointer"]); var fclose = new NativeFunction(addr_fclose, "int", ["pointer"]);
var filename = Memory.allocUtf8String("/sdcard/reg.dat"); var open_mode = Memory.allocUtf8String("w+"); var file = fopen(filename, open_mode); console.log("fopen file:", file);
var buffer = Memory.allocUtf8String("EoPAoY62@ElRD"); var ret = fputs(buffer, file); console.log("fputs ret:", ret);
fclose(file); }
将指针以字符串的方式打印
1 2 3 4 5
functionprint_string(addr) { var base_hello_jni = Module.findBaseAddress("libhello-jni.so"); var addr_str = base_hello_jni.add(addr); console.log("addr:", addr, " ", ptr(addr_str).readCString()); }
functionhook_gettimeofday() { var addr_gettimeofday = Module.findExportByName(null, "gettimeofday"); var gettimeofday = new NativeFunction(addr_gettimeofday, "int", ["pointer", "pointer"]);
var source = [ 'struct timeval {', ' int tv_sec;', ' int tv_usec;', '};', 'void modify_time(struct timeval* tv, int tv_sec, int tv_usec) {', ' tv->tv_sec = tv_sec;', ' tv->tv_usec = tv_usec;', '}', ].join('\n');
var cm = new CModule(source); var modify_time = new NativeFunction(cm.modify_time, 'void', ["pointer", "int", "int"]);
Interceptor.replace(addr_gettimeofday, new NativeCallback(function (ptr_tz, ptr_tzp) {
var result = gettimeofday(ptr_tz, ptr_tzp); if (result == 0) { console.log("hook gettimeofday:", ptr_tz, ptr_tzp, result); //modify_time(ptr_tz, 0xAAAA, 0xBBBB); var t = newInt32Array(ArrayBuffer.wrap(ptr_tz, 8)); t[0] = 0xAAAA; t[1] = 0xBBBB; console.log(hexdump(ptr_tz)); } return result; }, "int", ["pointer", "pointer"])); }