反编译代码中的 Goto 语句导致问题

发布于 2024-12-08 19:36:16 字数 1511 浏览 0 评论 0原文

客户在 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;

任何解释这一点的帮助都是最重要的赞赏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So尛奶瓶 2024-12-15 19:36:16

您所看到的是字节码的伪影,您的反编译器似乎无法正确处理它们。例如,

_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 可能是什么。

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.

太傻旳人生 2024-12-15 19:36:16

你用什么反编译器?尝试另一种,它可能会产生更好的代码。我在 JD-GUI 方面获得了很好的体验。除此之外,看看字节码。

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.

浅忆流年 2024-12-15 19:36:16

老实说,对于此类问题,您最好直接查看字节码。在类文件上尝试 javap -c 并查看该方法内部实际发生了什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文