话不多言,直接上代码,注意点都在注释里面了
setTimeout(function() {
Java.perform(function() {
//加载EditText类
var editText = Java.use("android.widget.EditText");
//加载CharSequence类
var CharSequence = Java.use("java.lang.CharSequence");
//hook getText()方法,这里getText()返回的是Editable类,Editable又是继承自CharSequnce类,
//所以讲结果直接强转为CharSequence类。如果不做类型转换,这里console.log的输出结果就是[object, Object]
editText.getText.overload().implementation = function() {
var result = this.getText();
var resultStr = Java.cast(result, CharSequence);
console.log("result: " + resultStr);
return result;
};
});
});