console.log("加载脚本成功!");
Java.perform(function x() {
//定位StringBuilder,StringBuffer类
const stringbuilder = Java.use("java.lang.StringBuilder");
const stringbuffer = Java.use("java.lang.StringBuffer");
//定位方法
const toString = "toString";
// 使用log类和Exception类产生堆栈
var jAndroidLog = Java.use("android.util.Log");
var jException = Java.use("java.lang.Exception");
stringbuilder[toString].implementation = function(){
//执行原逻辑
const result = this[toString]();
// 打印返回的字符串内容
console.log(result);
// 只有长度大于30时,才打印堆栈
if (result.length > 15) {
// 抛出异常。打印堆栈
console.log(jAndroidLog.getStackTraceString(jException.$new()));
}
//return出去
return result;
};
stringbuffer[toString].implementation = function() {
//执行原逻辑
const result = this[toString]();
// 打印返回的字符串内容
console.log(result);
// 只有长度大于30时,才打印堆栈
if (result.length > 30) {
// 抛出异常。打印堆栈
console.log(jAndroidLog.getStackTraceString(jException.$new()));
}
//return出去
return result;
}
});