反编译JVM语言

发布于 2024-11-02 05:53:52 字数 163 浏览 7 评论 0原文

是否可以将 Groovy、Scala 等 JVM 语言反编译为其初始形式?

如果我尝试反编译 4 行 Groovy 类,我会得到大约 20 行反编译的 Java 代码。

这更多的是一个理论问题,而不是一个实际问题,因为市场上没有这样的反编译器(据我所知)。

谢谢。

Is it possible to decompile JVM languages like Groovy, Scala to their initial form?

If I try and decompile a 4 line Groovy class I get about 20 lines of decompiled Java code.

It's more of a theoretical question than a practical one, cause there are no such decompilers on the market (not that I know of).

Thanks.

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

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

发布评论

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

评论(3

灵芸 2024-11-09 05:53:52

是的,Java 反编译器可以管理类似的保真度(意味着:代码看起来相似,但不一定相同)。

但是,您需要为每种语言提供专用的反编译器。

编辑:我想我需要澄清我期望的保真度水平:

  • 局部变量的名称可能会或可能不会重现
  • 循环类型可能会被错误解释(for替换为while,...)
  • 更一般地说:可以用两种类似的方式完成的事情可能会被误解
  • ...

所有这些都是反编译 Java 代码时也会发生的错误,仅仅是因为从字节码到Java源代码不是1:1的。

但是,如果您有专用的 Groovy 反编译器,那么我强烈怀疑它通过反编译已编译的 Groovy 代码可以生成比 Java 反编译器更具可读性的代码。

Yes, it's possible to a similar fidelity that a Java decompiler can manage (meaning: the code will look similar, but not necessarily identical).

You'd need a dedicated decompiler for each language, however.

Edit: I think I need to clarify what level of fidelity I'd expect:

  • The names of local variables may or may not be reproducable
  • Loop types might be mis-interpreted (for replaced by while, ...)
  • More general: Things that can be done in two similar ways might be mis-interpreted
  • ...

All of those are errors that also occur on decompiling Java code, simply because the association from byte code to Java source code is not 1:1.

However, if you have a dedicated Groovy decompiler, then I strongly suspect it to produce much more readable code from decompiling compiled Groovy code than a Java decompiler ever could.

金兰素衣 2024-11-09 05:53:52

这不一定是可能的。例如,一种语言可能会以不可逆的方式破坏其名称。此外,它还可以将源语言的不同构造映射到单个 java 语言构造。

然而,最重要的是,java 语言(相对于 JVM 字节码)不够强大,无法以具体化的方式对源语言的某些概念或结构进行编码。 Java 和 JVM 字节码已经是这种情况,后者无法表达泛型。

It is not necessarily possible. For example, a language could mangle it's names in a fashion that is not reversible. Also, it could map different constructs of the source language to a single java language construct.

Most impotantly, however, the java language (vs. the JVM bytecode) could not be powerful enough to encode certain concepts or constructs of the source language in such a way that they could be reified. This is already the case with Java and the JVM bytecode, where the latter is not capable of expressing generics.

拥抱影子 2024-11-09 05:53:52

嗯,我能想到的就只有编译器优化和注释的问题了。注释不会保留在字节码中(值得庆幸的是),并且编译器可能会更改源代码以获得更好的性能,而且这似乎是可能的。

Well, the only things that I can think of are the problems of compiler optimization and comments. Comments aren't preserved in the bytecode (thankfully) and the compiler may alter the source code for better performance, beside that it seems possible.

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