Can Java break / label statements be used as “goto” in bytecode obfuscation?

I'm trying to decompile some Java Class file, I encountered some code in which tags are used in a way that doesn't think they can be used I don't know if this is the decompiler's mistake of misunderstanding labels, or if the code is deliberately confused in this way In other words, can such labels be used in Java bytecode?

Note that the label appears after the relevant break statement, not before it It almost seems to be used as a goto rather than a tag to get out of a loop There are no loops, so I'm a little confused about how they should be used here

What happened here? I marked 3 Tags in the comments (####)

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.

Solution

Goto bytecode instruction (yes, it's actually called "goto") is used to implement break and other structures

Goto's own specification only limits the target to the same method as the goto instruction

4.10. Many other constraints are defined in verification of class files, especially checking code, which describes how to verify the actual bytecode of the method

I doubt that you can use goto to generate inconsistent interpretations of local variables and operand stacks. For example, the target instruction is required to be compatible with the source instruction, but my actual specification is written in Prolog. I will be grateful if someone gets the relevant points to ensure this

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>