Frida Android:挂钩 StringBuilder 并仅打印来自特定 class 的数据
Frida Android: Hook StringBuilder and print data only from a specific class
我已经使用此代码
将 StringBuilder class 方法挂钩到 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;
};
});
此代码正在打印大量不相关的数据。我只想打印来自特定 class/method 的数据。如何实现?
谢谢
我还没有测试代码,但下面的代码应该可以工作:
同时挂钩使用您感兴趣的 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;
};
});
我已经使用此代码
将 StringBuilder class 方法挂钩到 StringJava.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;
};
});
此代码正在打印大量不相关的数据。我只想打印来自特定 class/method 的数据。如何实现? 谢谢
我还没有测试代码,但下面的代码应该可以工作:
同时挂钩使用您感兴趣的 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;
};
});