$ frida-ls-devices Id Type Name ---------------- ------ ---------------- locallocal Local System t49dbutgc6wgizuw usb Redmi Note 8 Pro socket remote Local Socket
voidfun(int x , int y ){ Log.d("Sum" , String.valueOf(x+y)); }
}
可以看到,app的作用就是每1秒种输出50和30的和。
使用adb查看日志:
1 2 3 4 5 6 7 8
$ adb logcat | grep Sum 11-26 21:26:23.234 3245 3245 D Sum : 80 11-26 21:26:24.234 3245 3245 D Sum : 80 11-26 21:26:25.235 3245 3245 D Sum : 80 11-26 21:26:26.235 3245 3245 D Sum : 80 11-26 21:26:27.236 3245 3245 D Sum : 80 11-26 21:26:28.237 3245 3245 D Sum : 80 11-26 21:26:29.237 3245 3245 D Sum : 80
11-26 21:44:47.875 2420 2420 D Sum : 80 11-26 21:44:48.375 2420 2420 D Sum : 80 11-26 21:44:48.875 2420 2420 D Sum : 80 11-26 21:44:49.375 2420 2420 D Sum : 80 11-26 21:44:49.878 2420 2420 D Sum : 7 11-26 21:44:50.390 2420 2420 D Sum : 7 11-26 21:44:50.904 2420 2420 D Sum : 7 11-26 21:44:51.408 2420 2420 D Sum : 7
$ python loader.py Script loaded successfully Inside java perform function Java.Use.Successfully! {u'columnNumber': 1, u'description': u"Error: fun(): has more than one overload, use .overload(<signature>) to choose from:\n\t.overload('java.lang.String')\n\t.overload('int', 'int')", u'fileName': u'frida/node_modules/frida-java/lib/class-factory.js', u'lineNumber': 2233, u'type': u'error', u'stack': u"Error: fun(): has more than one overload, use .overload(<signature>) to choose from:\n\t.overload('java.lang.String')\n\t.overload('int', 'int')\n at throwOverloadError (frida/node_modules/frida-java/lib/class-factory.js:2233)\n at frida/node_modules/frida-java/lib/class-factory.js:1468\n at x (/script1.js:14)\n at frida/node_modules/frida-java/lib/vm.js:43\n at M (frida/node_modules/frida-java/index.js:347)\n at frida/node_modules/frida-java/index.js:299\n at frida/node_modules/frida-java/lib/vm.js:43\n at frida/node_modules/frida-java/index.js:279\n at /script1.js:15"} None
//定位类 var my_class = Java.use("com.example.test.MainActivity"); console.log("Java.Use.Successfully!");//定位类成功!
//在这里更改类的方法的实现(implementation) my_class.fun.overload("int", "int").implementation = function(x, y){ //打印替换前的参数 console.log( "original call: fun("+ x + ", " + y + ")"); //把参数替换成2和5,依旧调用原函数 var ret_value = this.fun(2, 5); return ret_value; }
var string_class = Java.use("java.lang.String"); //获取String类型
my_class.fun.overload("java.lang.String").implementation = function(x){ console.log("*************************************"); var my_string = string_class.$new("My TeSt String#####"); //new一个新字符串 console.log("Original arg: " + x ); var ret = this.fun(my_string); // 用新的参数替换旧的参数,然后调用原函数获取结果 console.log("Return value: "+ ret); console.log("*************************************"); return ret; }; });
这里处理了两个方法的重载,运行结果:
1 2 3 4 5 6 7 8
08-14 16:09:39.539 10591 10591 D ROYSUE.Sum: 80 08-14 16:09:39.539 10591 10591 D ROYSUE.string: lowercase me!!!!!!!!! 08-14 16:09:40.580 10591 10591 D ROYSUE.Sum: 7 08-14 16:09:40.610 10591 10591 D ROYSUE.string: my test string##### 08-14 16:09:41.653 10591 10591 D ROYSUE.Sum: 7 08-14 16:09:41.658 10591 10591 D ROYSUE.string: my test string##### 08-14 16:09:42.700 10591 10591 D ROYSUE.Sum: 7 08-14 16:09:42.705 10591 10591 D ROYSUE.string: my test string#####
$ python loader.py [*] PID: 11467 Script loaded successfully Inside java perform function Java.Use.Successfully! Found instance: com.example.test.MainActivity@f1cb759 Result of secret func: @@@###@@@ original call: fun(50, 30) ************************************* Original arg: LoWeRcAsE Me!!!!!!!!! Return value: my test string##### *************************************
$ python l3.py Script loaded successfully Enter command: 1: Exit 2: Call secret function choice:2 Found instance: com.example.test.MainActivity@f1cb759 Result of secret func: @@@###@@@LoWeRcAsE Me!!!!!!!!! Enter command: 1: Exit 2: Call secret function choice:2 Found instance: com.example.test.MainActivity@f1cb759 Result of secret func: @@@###@@@LoWeRcAsE Me!!!!!!!!!LoWeRcAsE Me!!!!!!!!!LoWeRcAsE Me!!!!!!!!!LoWeRcAsE Me!!!!!!!!!LoWeRcAsE Me!!!!!!!!! Enter command: 1: Exit 2: Call secret function choice:1