java - Java break/label 语句可以在字节码混淆中充当 "goto"吗?

标签 java bytecode

我试图在反编译后对一些 Java .class 文件进行去混淆处理,但我遇到了部分代码,它以我认为无法使用的方式使用标签。我不知道这是反编译器误解标签的错误,还是代码被故意这样混淆了。也就是说,在Java字节码中可以这样使用标签吗?

请注意,标 checkout 现在相关的 break 语句之后,而不是之前。它几乎似乎是将它们用作 goto,而不是用于跳出循环的标签。也根本没有循环,所以我对它们应该如何在这里使用有点困惑。

这是怎么回事?我在评论中标记了 3 个标签 (###)

if (i != 96)
  {
    if ((i ^ 0xFFFFFFFF) != -98)
    {
      if (i == 98)
        break label417;  // ### Here are the three breaks... The relevant labels appear later in the code
      if (i != 99)
        break label540;
      if (!bool)
        break label461;
    }
  }
  else
  {
    if (localwb == this.localWB5)
    {
      if (this.localWB4 != null) {
          this.localWB4.a((byte)-92, this);
        if (!bool);
      }
      else
      {
          this.localWB6.a((byte)-9, this);
      }
      return true;
    }
    if (localwb == this.localWB4)
    {
        this.localWB6.a((byte)-59, this);
      return true;
    }
    if (this.localWB3 != localwb)
      break label540;
      this.localWB2.a((byte)-38, this);
    return true;
  }
  if (this.localWB6 == localwb)
  {
    if (this.localWB4 != null) {
        this.localWB4.a((byte)-122, this);
      if (!bool);
    }
    else {
        this.localWB5.a((byte)-63, this);
    }
    return true;
  }
  if (this.localWB4 == localwb)
  {
    this.localWB5.a((byte)-22, this);
    return true;
  }
  if ((this.localWB2 == localwb) && (this.localWB3.M))
  {
    this.localWB3.a((byte)-84, this);
    return true;
    label417:  //  ### The first label.  Note how this next if-statement has inaccessible code... if the above if-statement is true, it would have already returned true;  However, the label appears after the return statement, almost as if the label is being used as a goto.
    if (localwb == this.localWB2)
    {
        this.localWB6.a((byte)-86, this);
      return true;
    }
    if (this.localWB3 == localwb)
    {
      this.localWB5.a((byte)-31, this);
      return true;
      label461:  //  ###  The second label
      if ((this.localWB6 == localwb) || (this.localWB4 == localwb))
      {
          this.localWB2.a((byte)-60, this);
        return true;
      }
      if (localwb == this.localWB5)
      {
        if (this.localWB3.M)
        {
          this.localWB3.a((byte)-44, this);
          if (!bool);
        }
        else {
            this.localWB2.a((byte)-9, this);
        }
        return true;
      }
    }
  }
  label540:  //  ###  The final label.

最佳答案

goto bytecode instruction (是的,它实际上称为“goto”)用于实现 break 和其他构造。

goto 本身的规范将目标限制在与goto 指令相同的方法内。

4.10. Verification of class Files 中定义了许多其他约束,特别是在 Checking Code ,它描述了如何验证方法的实际字节码

怀疑您不能使用goto 产生局部变量和操作数堆栈的不一致解释,例如要求目标指令与源指令兼容指令,但我实际的规范是用 Prolog 编写的,如果有人能得到确保这一点的相关要点,我将不胜感激。

关于java - Java break/label 语句可以在字节码混淆中充当 "goto"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14496134/

相关文章:

java - 如何在DataTables中使用JSP/表达式语言显示数据?

java - 检查数组的范围

java - JVM 字节码浮点否定 : not allowed but possible?

java - 是否可以让 System ClassLoader 在运行时加载指定的 .class 文件?

java.lang.VerifyError 构造函数调用

annotations - 字节码注入(inject)发生在哪里?

java - Gradle 错误 "Cannot invoke method buildToolsVersion() on null object"

java - 运行时获取数据库信息

java - 为第三方创建/公开 Web 服务的设计决策

c++ - 从 C++ 类创建 LLVM 字节码