2011-10-07 167 views
5

我已经给出了一些古老的不受支持的第三方供应商代码在客户的jar文件中,我试图对其进行反向工程,所以我重新实现了它用于连接的相同协议到服务器。在反编译的代码中导致问题导致问题

我已经反编译它,其中一个类似乎有标签和goto语句。我的编译器在这方面引发了一个棘手的问题,因为据我了解,goto在Java中不受支持。

我不能在所有的代码后,由于IP问题,但这里是它的要点(我已经把注释中的编译器错误):

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

据我所知,线跟随冒号是标签,但我不明白这里出了什么问题。

与转到该行正在测试用于真正,所以我可以只是删除标签,因为它们是这里无关紧要,但我不明白这是什么行表示:

local; 

还是这个:

JVM INSTR ret 12; 

任何解释此协议的援助将不胜感激。

+1

如果您的反编译器声称将JVM字节码转换为Java,但它输出的代码不是有效的Java,那么这不是您的反编译器中的错误吗? – Raedwald

+0

挑剔的注意事项:注意逆向工程第三方供应商代码 - 甚至发布它 - 它可能不被供应商允许:/ – Christian

+0

我认为我尽可能混淆了代码... –

回答

4

你使用的是什么反编译器?试试另一个,它可能会产生更好的代码。我对JD-GUI有很好的体验。除此之外,看看字节码。

+0

感谢使用JD反编译它-GUI,它看起来很好。我正在使用DJ-Decompiler http://members.fortunecity.com/neshkov/dj.html –

2

说实话,有了这样的问题,你最好直接看字节码。在类文件上尝试javap -c,然后查看该方法内实际发生了什么。

6

你看到的是字节码的工件,你的反编译器无法正确处理,正如它看起来那样。对于〔实施例

_L2: 
    String x; 
    String y; 

    ... 

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

可能已经像

do { 
    String x; 
    String y; 

    ... 

} while (true); 

但反编译器无法(或没有活动TRY)到这些部件拼凑在一起正确。同样,

JVM INSTR ret 12 

似乎是一些操作码的渲染,反编译器没有正确理解。我不知道,local可能是什么。