我使用此代码将 StringBuilder 类方法挂接到 String
Java.perform(function() {
const StringBuilder = Java.use('java.lang.StringBuilder');
StringBuilder.toString.implementation = function() {
var res = this.toString();
var tmp = "";
if (res !== null) {
tmp = res.toString().replace("/n", "");
console.log(tmp);
}
return res;
};
});
这段代码正在打印大量不相关的数据。我只想打印来自特定类/方法的数据。如何实现? 谢谢
我还没有测试代码,但以下内容应该可以工作:
还要钩住使用您感兴趣的 StringBuilder.toString(( 的特定方法,并设置一个变量,以便在您使用该方法时启用 StringBuilder 挂钩代码:
var sbActivate = false;
Java.perform(function() {
const StringBuilder = Java.use('java.lang.StringBuilder');
StringBuilder.toString.implementation = function() {
var res = this.toString();
if (sbActivate) {
var tmp = "";
if (res !== null) {
tmp = res.toString().replace("/n", "");
console.log(tmp);
}
}
return res;
};
});
Java.perform(function() {
const someclass = Java.use('<the specific class you are interested in>');
someclass.someMethod.implementation = function() {
sbActivate = true;
var res = this.someMethod();
sbActivate = false;
return res;
};
});