function hookTest2(){ Java.perform(function(){ //根据导出函数名打印地址 var helloAddr = Module.findExportByName("lib52pojie.so","Java_com_zj_wuaipojie_util_SecurityUtil_vipLevel"); if(helloAddr != null){ Interceptor.attach(helloAddr,{ //onEnter里可以打印和修改参数 onEnter: function(args){ //args传入参数 var JNIEnv = Java.vm.getEnv(); var originalStrPtr = JNIEnv.getStringUtfChars(args[2], null).readCString(); console.log("参数:", originalStrPtr); var modifiedContent = "至尊"; var newJString = JNIEnv.newStringUtf(modifiedContent); args[2] = newJString; }, //onLeave里可以打印和修改返回值 onLeave: function(retval){ //retval返回值 var returnedJString = Java.cast(retval, Java.use('java.lang.String')); console.log("返回值:", returnedJString.toString()); var JNIEnv = Java.vm.getEnv(); var modifiedContent = "无敌"; var newJString = JNIEnv.newStringUtf(modifiedContent); retval.replace(newJString); } }) } }) }
5.SO基址的获取方式
1 2 3
var moduleAddr1 = Process.findModuleByName("lib52pojie.so").base; var moduleAddr2 = Process.getModuleByName("lib52pojie.so").base; var moduleAddr3 = Module.findBaseAddress("lib52pojie.so");
functionhook_dlopen() { var dlopen = Module.findExportByName(null, "dlopen"); Interceptor.attach(dlopen, { onEnter: function (args) { var so_name = args[0].readCString(); if (so_name.indexOf("lib52pojie.so") >= 0) this.call_hook = true; }, onLeave: function (retval) { if (this.call_hook) hookTest2(); } }); // 高版本Android系统使用android_dlopen_ext var android_dlopen_ext = Module.findExportByName(null, "android_dlopen_ext"); Interceptor.attach(android_dlopen_ext, { onEnter: function (args) { var so_name = args[0].readCString(); if (so_name.indexOf("lib52pojie.so") >= 0) this.call_hook = true; }, onLeave: function (retval) { if (this.call_hook) hookTest2(); } }); }
8.借助IDA脚本实现一键式hook
通过MyIDAFrida直接生成,默认应该只适用于attach模式
粘贴到文件,之后也是通过的方式启动
1
frida -U wuaipojie -l .\idahook.js
通过java层修改
1 2 3 4 5 6 7 8 9 10
//定义一个名为hookTest1的函数 function hookTest1(){ let SecurityUtil = Java.use("com.zj.wuaipojie.util.SecurityUtil"); SecurityUtil["checkVip"].implementation = function () { console.log(`SecurityUtil.checkVip is called`); let result = this["checkVip"](); console.log(`SecurityUtil.checkVip result=${result}`); return true; }; }