Frida Hook Textview

Frida Hook Textview

本篇文章简单介绍下frida 如何hook TextView.

1: 编写frida脚本 .

Java.perform(function() {
var textView = Java.use(‘android.widget.TextView’);
textView.setText.overload(“java.lang.CharSequence”).implementation = function (x) {
console.log(“original text :”,x)
var text = ‘xxxx’
console.log(“new text :”,text)
return this.setText(text);
}
});

2: 运行

首先回顾frida-server 的运行:

adb shell 
cd /data/local/tmp 
su
chmod 777 frida-server
cd frida-server
chmod 777 data
./data

然后运行脚本:

frida -U -f com.tencent.mm -l /home/zh/workSpace/test/Xpose/app/src/main/java/com/zh/xpose/js/HookText.js

运行结果如下:

   ____
    / _  |   Frida 16.0.2 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to LEX820 (id=6b4a96b2)
Spawned `com.tencent.mm`. Resuming main thread!                         
[LEX820::com.tencent.mm ]-> original text : 微信
new text : xxxx
Error: setText(): argument types do not match any of:
	.overload('int')
	.overload('java.lang.CharSequence')
	.overload('int', 'android.widget.TextView$BufferType')
	.overload('java.lang.CharSequence', 'android.widget.TextView$BufferType')
        .overload('[C', 'int', 'int')
	.overload('java.lang.CharSequence', 'android.widget.TextView$BufferType', 'boolean', 'int')
    at X (frida/node_modules/frida-java-bridge/lib/class-factory.js:569)
    at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:973)
    at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:553)
    at <anonymous> (/home/zh/workSpace/test/Xpose/app/src/main/java/com/zh/xpose/js/HookText.js:18)
    at apply (native)
    at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:620)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/class-factory.js:598)

可以看到 已经监听到TextView的事件,并且取到textview的原文案了, 但是在settext()时出现错误了.

错误原因:

  1. 传递给setText方法的参数类型不匹配。它期望的参数类型是CharSequence,但传递的参数类型是未知的.

所以我们修改脚本:

Java.perform(function() {
  var textView = Java.use('android.widget.TextView');
  textView.setText.overload("java.lang.CharSequence").implementation = function (x) {
       var CharSequence = Java.use("java.lang.CharSequence");
       var String = Java.use("java.lang.String");
       console.log("original text :",x)
       var text = String.$new("xxxxx"); // 创建一个CharSequence对象
       console.log("new text :",text)
       return this.setText(text);
    }
});

重新运行: 这次没有出现错误,并且微信中的textview已经成功替换成了"xxxxx".

    ____
    / _  |   Frida 16.0.2 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to LEX820 (id=6b4a96b2)
Spawned `com.tencent.mm`. Resuming main thread!                         
[LEX820::com.tencent.mm ]-> original text : 微信
new text : xxxxx
original text : 微信
new text : xxxxx
original text : 
new text : xxxxx
original text : xxxxx
new text : xxxxx
original text : 用声音锁登录
new text : xxxxx
original text : 切换验证方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值