0

我已使用此代码将 StringBuilder 类方法挂钩到字符串

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;
  };

});

此代码正在打印大量不相关的数据。我只想打印来自特定类/方法的数据。如何实现?谢谢

4

1 回答 1

3

我没有测试过代码,但以下应该可以工作:

还要挂钩使用您感兴趣的 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;
  };

});
于 2020-02-07T15:43:36.250 回答