然后找到并hook一个方法:
findAndHookMethod(类.class,"函数名",参数1.class,...,钩子);
比如要hook一下TextView的setText方法,该方法需要一个参数,类型为CharSequece,那么就写
findAndHookMethod(TextView.class,"setText",CharSequence.class,hooksend);
注意如果有参数是int等基本类型,不能写int.class,应该写Integer.TYPE。
如果要hook的是构造函数,就用findAndHookConstructor(类.class,参数1.class,...,钩子)。比如EditText的一个构造函数
findAndHookConstructor(EditText.class,Context.class,AttributeSet.class,hooket)。
这样就可以在方法调用之前先进行一些操作,比如篡改其参数,在方法调用之后再执行一些操作,比如获取返回值。如图的代码首先判断这个被hook到的TextView是不是气泡,如果是,就获取方法的参数,进行一些处理后,如果处理成功,就把参数篡改为处理后的结果。
![](https://imgsa.baidu.com/forum/w%3D580/sign=835c8fe306f431adbcd243317b37ac0f/b444fd1f4134970a01a57a5e9fcad1c8a6865d07.jpg)