开发者

Goto statements in decompiled code causing issues

I've been given some ancient unsupported third party vendor code in a jar file by a customer and I'm trying to reverse engineer it so I re-implement the same protocol it used to connect to a server.

I've decompiled it and one of the classes seems to have labels and goto statements in it. My compiler is throwing a hissy-fit at this because as I understand it goto is not supported in Java.

I can't post the all the code due to IP issues but here is the gist of it (I've put the compiler errors in the comments):

   private void methodName(InputType input)
        throws ConfigurationException
    {
    // initialization code here
_L2:
    String x; // The compiler is complaining that "String cannot be resolved to a variable" here
    String y; // This line is fine though.开发者_运维百科..
    // Some Code here

    x = <SOME VALUE> // Compiler complains about "x cannot be resolved to a variable" 
    y = <ANOTHER VALUE> // Compiler is fine with this.

    // Some more code
    if(true) goto _L2; else goto _L1 // Multiple issues here see following lines.
    // Syntax error on token "goto", throw expected
    // _L2 cannot be resolved to a variable
    // Syntax error on token "goto", { expected
    // Syntax error on token "goto", { expected

_L1: // Syntax error on token "goto", { expected
        local; // local cannot be resolved to a variable

        // Some more code

         JVM INSTR ret 12; // Multiple issues here see following lines.
         //  JVM INSTR ret 12;
         // Syntax error on token "ret", = expected

         return;
    }

I understand that the lines followed by a colon are Labels, but I don't understand what is going wrong here.

The line with the goto is testing for true so I could just remove the labels as they are irrelevant here, but I don't understand what this line means:

local;

Or this:

JVM INSTR ret 12;

Any assistance interpreting this would be most appreciated.


What you are seeing are artifacts of the byte-code, which your decompiler could not properly handle, as it seems. For exmaple

_L2:
    String x;
    String y;

    ... 

    if(true) goto _L2; else goto _L1;
_L1:

might have been something like

do {
    String x;
    String y; 

    ...

} while (true);

but the decompiler was not able (or didn't event try) to piece these parts properly together. Likewise, the

JVM INSTR ret 12

seems to be a rendering for some opcode, which the decompiler did not properly understand. I have no idea, what the local might be.


What decompiler are you using? Try another one, it might produce better code. I had pretty good experience with JD-GUI. Barring that, look at the bytecode.


To be honest, with this sort of issues you might be better off looking at the bytecodes directly. Try javap -c on the class file and see what actually goes on inside that method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜