[英]Goto statements in decompiled code causing issues
我已经在客户的jar文件中给了一些古老的不受支持的第三方供应商代码,我正在尝试对其进行逆向工程,因此我重新实现了用于连接服务器的相同协议。
我已经反编译了它,其中一个类似乎有标签和goto语句。 我的编译器在这方面投入了大量的东西,因为我理解它在Java中不支持goto。
由于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;
}
我知道冒号后面的行是标签,但我不明白这里出了什么问题。
带goto的行正在测试为true所以我可以删除标签,因为它们在这里无关紧要,但我不明白这条线的含义:
local;
或这个:
JVM INSTR ret 12;
任何解释这一点的协助都将非常受欢迎。
您所看到的是字节码的工件,您的反编译器无法正确处理它。 例如
_L2:
String x;
String y;
...
if(true) goto _L2; else goto _L1;
_L1:
可能是这样的
do {
String x;
String y;
...
} while (true);
但反编译器无法(或没有事件尝试)将这些部分正确地拼凑在一起。 同样地,
JVM INSTR ret 12
似乎是一些操作码的渲染,反编译器没有正确理解。 我不知道, local
可能是什么。
你用的反编译器是什么? 尝试另一个,它可能会产生更好的代码。 我对JD-GUI有很好的经验。 除此之外,请查看字节码。
说实话,对于这类问题,您最好直接查看字节码。 在类文件上尝试javap -c
,看看该方法内部实际发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.