反编译JVM语言
是否可以将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,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:
for
replaced bywhile
, ...)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.
这不一定是可能的。例如,一种语言可能会以不可逆的方式破坏其名称。此外,它还可以将源语言的不同构造映射到单个 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.
嗯,我能想到的就只有编译器优化和注释的问题了。注释不会保留在字节码中(值得庆幸的是),并且编译器可能会更改源代码以获得更好的性能,而且这似乎是可能的。
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.