选择并测试java反编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3898391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Choose and test java decompiler
提问by user471011
Now I'm trying to find the best java decompiler, I found these:
现在我试图找到最好的 Java 反编译器,我发现了这些:
- http://java.decompiler.free.fr/
- http://www.reversed-java.com/fernflower/
- http://dj.navexpress.com/
- http://cavaj-java-decompiler.en.softonic.com/
- http://java.decompiler.free.fr/
- http://www.reversed-java.com/fernflower/
- http://dj.navexpress.com/
- http://cavaj-java-decompiler.en.softonic.com/
With these decompilers I handle byte code of this class:
使用这些反编译器,我可以处理此类的字节码:
public class ss
{
public static void main(String args[])
{
try{
System.out.println("try");
}
catch(Exception e)
{
System.out.println("catch");
}
finally
{System.out.println("finally");}
}
}
and I got the following results:
我得到了以下结果:
fernflower:
蕨花:
public class ss {
public static void main(String[] var0) {
try {
System.out.println("try");
} catch (Exception var5) {
System.out.println("catch");
} finally {
System.out.println("finally");
}
}
}
DJ Java Decompiler:
DJ Java 反编译器:
import java.io.PrintStream;
public class ss
{
public ss()
{
}
public static void main(String args[])
{
System.out.println("try");
System.out.println("finally");
break MISSING_BLOCK_LABEL_50;
Exception exception;
exception;
System.out.println("catch");
System.out.println("finally");
break MISSING_BLOCK_LABEL_50;
Exception exception1;
exception1;
System.out.println("finally");
throw exception1;
}
}
cavaj:
卡瓦伊:
import java.io.PrintStream;
public class ss
{
public ss()
{
}
public static void main(String args[])
{
System.out.println("try");
System.out.println("finally");
break MISSING_BLOCK_LABEL_50;
Exception exception;
exception;
System.out.println("catch");
System.out.println("finally");
break MISSING_BLOCK_LABEL_50;
Exception exception1;
exception1;
System.out.println("finally");
throw exception1;
}
}
http://java.decompiler.free.fr/:
http://java.decompiler.free.fr/:
import java.io.PrintStream;
public class ss
{
public static void main(String[] paramArrayOfString)
{
try
{
System.out.println("try");
}
catch (Exception localException)
{
System.out.println("catch");
}
finally {
System.out.println("finally");
}
}
}
I see that the best result in decompiler: http://java.decompiler.free.fr/
我看到反编译器的最佳结果:http: //java.decompiler.free.fr/
To test, I wrote very simple code. What do you think, what code to write to test decompilers? Maybe the idea is to better than a try{} catch(){} finally{}?
为了测试,我编写了非常简单的代码。你怎么看,写什么代码来测试反编译器?也许这个想法比 try{} catch(){} finally{} 更好?
采纳答案by Justin Garrick
The code that you use to test should test the features available the in JDK used to compile the target class. For example, if you know that your target is written in Java 1.5, it is reasonable to assume that the code might include generics, so you will want to make sure that your chosen decompiler handles them properly. In my experience, the freely available decompilers tend to lag behind the JDK releases in terms of the features they support by 1-2 releases.
用于测试的代码应该测试 JDK 中用于编译目标类的可用功能。例如,如果您知道您的目标是用 Java 1.5 编写的,那么假设代码可能包含generics是合理的,因此您需要确保您选择的反编译器正确处理它们。根据我的经验,免费提供的反编译器在支持 1-2 个版本的功能方面往往落后于 JDK 版本。
Based on personal trial and error, JDtends to do the best job in general. However, if you're decompiling code that was written in 1.3 or lower, I'd also suggest you give JODEa try.
根据个人的反复试验,京东通常会做得最好。但是,如果您要反编译用 1.3 或更低版本编写的代码,我还建议您尝试使用JODE。
EDIT, 5 years later:
编辑,5 年后:
CFR, Procyon, and Fernflowerlead the way in this space.
CFR、Procyon和Fernflower在这个领域处于领先地位。
回答by Buhake Sindi
Ok, this is written from my mobile phone so bear with me.
好吧,这是用我的手机写的,请耐心等待。
1st of all, every java file codes are compiled in bytecode in their respective .classfile. This means that constants are stored AS IS
(hence strings can easily be retrieved) and variables are assigned to a register that is then put on a stack program execution when the JVM process the class file.
首先,每个java文件代码都在各自的.class文件中以字节码编译。这意味着存储常量AS IS
(因此可以轻松检索字符串)并将变量分配给寄存器,然后在 JVM 处理类文件时将其置于堆栈程序执行中。
The reason your exception block are not returned to the original code you've written is because of the way javac compiled & translated the code to java bytecode.
您的异常块没有返回到您编写的原始代码的原因是 javac 编译并将代码转换为 java 字节码的方式。
If you want to know which decompiler works best, write all java well known statements (for loop, if statement, while loop) with some expressions & see what best represent your original code.
如果您想知道哪种反编译器效果最好,请使用一些表达式编写所有 Java 众所周知的语句(for 循环、if 语句、while 循环),然后看看什么最能代表您的原始代码。
Good luck.
祝你好运。
回答by Stephen C
It looks like fernflower
and JD Java Decompilerare producing decompiled code that is as good as is possible for this particular testcase. The other two aren't doing a good job, IMO.
它看起来像fernflower
和JD的Java反编译器是生产反编译的代码是一样好,这个特定的测试用例是可能的。其他两个做得不好,IMO。
What do you think, what code to write to test decompilers?
你怎么看,写什么代码来测试反编译器?
- Write more complicated code using all available constructs.
- Try them out on some real code.
- Try them out on some real code that has been obfuscated.
- 使用所有可用的结构编写更复杂的代码。
- 在一些真实的代码上尝试一下。
- 在一些经过混淆的真实代码上试用它们。
When trying out code that you compile from source, experiment with different "-g" options, and with different Java compilers.
在尝试从源代码编译的代码时,尝试使用不同的“-g”选项和不同的 Java 编译器。
回答by Emmanuel Dupuy
For information, JD supports switch(enum), switch(string), assert statements and for-each loops.
有关信息,JD 支持 switch(enum)、switch(string)、assert 语句和 for-each 循环。
About the -g(javac) options,
关于 -g(javac) 选项,
- if you omit the line numbers, JD can not reconstruct the original flow of instructions : the types of loop can not be determinate, the multiple assigments can not be regenerate, and the algorithm used to realign source code can not work.
- if you omit the local variable data, JD can not, sometime, determine the exact range of variables. It's problematic.
- 如果省略行号,JD 无法重构原始指令流:无法确定循环类型,无法重新生成多个分配,用于重新对齐源代码的算法无法工作。
- 如果省略局部变量数据,JD 有时无法确定变量的确切范围。这是有问题的。
回答by Stiver
If you anticipate to get any meaningful results, you really should test with a bit more non-trivial code. Fernflower was created with the aim of handling highly unusual and obfuscated bytecode. Thus decompiling such simple snippets is no big deal. By the way, if you are interested in testing the stand-alone version of Fernflower drop me a note at fernflower(dot)decompiler(at)gmail(dot)com. Version 0.8.4 is now in semi-public beta (however not available on the website yet).
如果您希望获得任何有意义的结果,您确实应该使用更重要的代码进行测试。Fernflower 的创建目的是处理非常不寻常和混淆的字节码。因此,反编译这些简单的片段没什么大不了的。顺便说一句,如果您有兴趣测试 Fernflower 的独立版本,请在 fernflower(dot)decompiler(at)gmail(dot)com 上给我留言。0.8.4 版现在处于半公开测试阶段(但尚未在网站上提供)。
回答by vorburger
http://www.reversed-java.com/fernflower/, see my comparison on github.com /vorburger/ScratchApplet
http://www.reversed-java.com/fernflower/,请参阅我在 github.com /vorburger/ScratchApplet 上的比较
回答by Anant
I have been using http://java.decompiler.free.fr/for a long time now and found it to be the best one. In particular I used it to decompile a third-party jar and I was able to modify the source code as well with it.
我已经使用http://java.decompiler.free.fr/很长时间了,发现它是最好的。特别是我用它来反编译第三方 jar,我也能够用它修改源代码。
Its easy to use and the UI is also neat and clean.
它易于使用,用户界面也整洁干净。
Update: Java Decompiler is no longer available on http://java.decompiler.free.fr/. It has new link http://jd.benow.ca/from where it can be downloaded.
更新:http://java.decompiler.free.fr/ 上不再提供 Java Decompiler 。它有新的链接http://jd.benow.ca/ 可以从那里下载。
回答by GISNovis
It's been a while since any feedback to this thread. However since I found it and took the input seriously I feel it important to give an update.
已经有一段时间没有对此线程的任何反馈了。但是,自从我找到它并认真对待输入后,我觉得提供更新很重要。
I have used Java Decompiler Free with good success. However, recently I accidentally deleted quite a bit of code of a production J2EE application. assumed JD Free would handle it, but it doesn't handle generics at all. Plus there was code where it handled variable initialization totally wrong. What I ended up with was a total mess.
我已经成功地使用了 Java Decompiler Free。但是,最近我不小心删除了很多生产 J2EE 应用程序的代码。假设 JD Free 会处理它,但它根本不处理泛型。另外有代码在处理变量初始化时完全错误。我最终得到的是一团糟。
There may not be anything out there that will to the job correctly. In my case it's just another lesson in backup, backup, backup. I need a de-compiler that handles generics properly in order to do a mass recovery. But some accuracy of handling variables would also help. It is too much to ask a tool to spit out the original code. But what I have seen so far will compile but will not function properly, generics aside. So I suppose it's going to be a long week before Christmas!!
可能没有任何东西可以正确地完成工作。就我而言,这只是备份、备份、备份的又一课。我需要一个可以正确处理泛型的反编译器,以便进行大规模恢复。但是处理变量的一些准确性也会有所帮助。求一个工具吐出原代码也太过分了。但是到目前为止我所看到的可以编译但不能正常运行,除了泛型。所以我想这将是圣诞节前的漫长一周!!