How do I "decompile" Java class files? [closed]
Asked Answered
C

19

556

What program can I use to decompile a class file? Will I actually get Java code, or is it just JVM assembly code?

On Java performance questions on this site I often see responses from people who have "decompiled" the Java class file to see how the compiler optimizes certain things.

Chon answered 7/11, 2008 at 16:0 Comment(2)
The art of "decompiling" can also be thought upon as reverse engineering. Although sometimes when reverse engineering something you don't always have access to binaries.Lorrimor
No one mentioned bytecodeviewer.com, which can decompile to java source and to bytecode (for java source is based on JAD).Sloven
N
588

Update February 2016:

www.javadecompilers.com lists JAD as being:

the most popular Java decompiler, but primarily of this age only. Written in C++, so very fast.
Outdated, unsupported and does not decompile correctly Java 5 and later

So your mileage may vary with recent jdk (7, 8).

The same site list other tools.

And javadecompiler, as noted by Salvador Valencia in the comments (Sept 2017), offers a SaaS where you upload the .class file to the cloud and it returns you the decompiled code.


Original answer: Oct. 2008

  • The final release of JSR 176, defining the major features of J2SE 5.0 (Java SE 5), has been published on September 30, 2004.
  • The lastest Java version supported by JAD, the famous Java decompiler written by Mr. Pavel Kouznetsov, is JDK 1.3.
  • Most of the Java decompilers downloadable today from the Internet, such as “DJ Java Decompiler” or “Cavaj Java Decompiler”, are powered by JAD: they can not display Java 5 sources.

Java Decompiler (Yet another Fast Java decompiler) has:

  • Explicit support for decompiling and analyzing Java 5+ “.class” files.
  • A nice GUI:

screenshot

It works with compilers from JDK 1.1.8 up to JDK 1.7.0, and others (Jikes, JRockit, etc.).

It features an online live demo version that is actually fully functional! You can just drop a jar file on the page and see the decompiled source code without installing anything.

Ne answered 7/11, 2008 at 16:18 Comment(12)
+1 It's worth mentioning that it's also modularized, so the core (implemented in C++) can be leveraged elsewhere.Brutus
jd-gui-0.3.3 also available hereCover
+1 for the info! If Java decompilers are so damn easy, how does one go about protecting his IP? Is there an obfuscation technique to work around these decompilers?Windproof
@Windproof I suppose there is, when I look at stackoverflow.com/search?q=[java]+obfuscationNe
In case one installed the Eclipse java decompiler plugin on Eclipse Juno, and Eclipse started hanging on Marketplace DND Initialization forcing to kill the whole process: removing the jd.*.jar from Eclipse plugins directory just fixed it for me.Cabbage
If you don't like using the jd-gui, you can follow these instructions and generate the folder hierarchy for the code: https://mcmap.net/q/48251/-batch-decompiling-of-java-files-with-jd-guiNormative
@Windproof the same way you protect your IP in any language or platform - good lawyers. DRM is only a bandaid.Numen
There are only some small shortages (e.g. some types are not recovered), but overall is this an excellent tool, VonCDeane
JD-GUI project is outdated and long dead.Disrespectful
It now offers SaaS where you upload the .class file to the cloud and it returns you the decompiled code. Worked for a simple POJO.Glib
@SalvadorValencia Thank you. I have included your comment in the answer for more visibility.Ne
@Salvador Valencia Please add sources.Beograd
G
101

There are a few decompilers out there... A quick search yields:

  1. Procyon: open-source (Apache 2) and actively developed
  2. Krakatau: open-source (GPLv3) and actively developed
  3. CFR: open-source (MIT) and actively developed
  4. JAD
  5. DJ Java Decompiler
  6. Mocha

And many more.

These produce Java code. Java comes with something that lets you see JVM byte code (javap).

Gaza answered 7/11, 2008 at 16:3 Comment(3)
May I also add, that Procyon, CFR, JAD and DJ are available as a web-service: javadecompilers.comPersse
kpdus.com/jad.html is some AD linkOvereager
Thanks @marcinj, I found another link that has links to download it.Gaza
L
51

To see Java source code check some decompiler. Go search for jad.

If you want to see bytecodes, just use javap which comes with the JDK.

Leckie answered 7/11, 2008 at 16:3 Comment(1)
I'd recommend one of the open-source decompilers instead, as they are actively developed. Use Procyon, the CFR decompiler or Krakatau (Python) instead.Hay
G
29

I tried several, and Procyon seemed to work the best for me. It's under active development and supports many features of the latest versions of Java.

These are the others I tried:

  • CFR
    • Promising, but often failed method decompilation. I'll be keeping my eye on this one. Also actively developed with support for the latest Java features.
  • Krakatau
    • Takes a different approach in that it tries to output equivalent Java code instead of trying to reconstruct the original source, which has the potential of making it better for obfuscated code. From my testing it was roughly on par with Procyon, but still nice to have something different. I did have to use the -skip command-line flag so it wouldn't stop on errors. Actively developed, and interestingly enough it's written in Python.
  • JD-GUI
  • JAD
    • Worked, but only supports Java 1.4 and below. Also available as an Eclipse plugin. No longer under development.
Geniality answered 2/10, 2013 at 19:0 Comment(1)
Note that the IGNORE_EXCEPTIONS thing has now been changed to the command line flag -skip.Numen
I
18

I use JAD Decompiler.

There is an Eclipse plugin for it, jadeclipse. It is pretty nice.

Imaginable answered 7/11, 2008 at 16:7 Comment(0)
H
14

Procyon includes a decompiler. It is FOSS.

Hay answered 10/6, 2013 at 14:2 Comment(0)
B
13

Soot is an option for newer Java code. At least it has the advantage of still being recently maintained...

Also, Java Decompiler is a decompiler with both a stand-alone GUI and Eclipse integration.

Lastly, Jdec hasn't been mentioned, though it's not as polished as other options.

Brutus answered 18/9, 2009 at 23:53 Comment(1)
Do you know how to decompile a concrete class file with Soot? I'm not sure it's possible...Hay
F
12

JD-GUI is really good. You could just open a JAR file and browse through the code as if you are working on an IDE. Good stuff.

Formenti answered 1/7, 2011 at 9:33 Comment(0)
P
11

Here's a list of decompilers as of Feb 2015:

Procyon, open-source, https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler

CFR, free, no source-code available, http://www.benf.org/other/cfr/

JD, free for non-commercial use only, http://jd.benow.ca/

Fernflower, open-source, https://github.com/fesh0r/fernflower,

JAD – given here only for historical reason. Free, no source-code available, http://varaneckas.com/jad/ Outdated, unsupported and does not decompile correctly Java 5 and later.

You may test above-mentioned decompilers online, no installation required and make your own educated choice.

Java decompilers in the cloud: http://www.javadecompilers.com/

Persse answered 7/3, 2015 at 0:6 Comment(0)
H
10

There are a few programs you can use. You will get the actual Java code, but sometimes the code will have been obfuscated so methods are named by one letter or number or a random mix of letters and numbers.

DJ Decompiler Mocha

Heraclitus answered 7/11, 2008 at 16:4 Comment(0)
N
9

Most decompilers for Java are based on JAD. It's a great tool, but unfortunately hasn't been updated for a while and does not handle Java 1.5+ classes very well. I have not seen any tools that will properly handle 1.5+ classes.

Normalie answered 7/11, 2008 at 16:18 Comment(2)
here you go: I just posted an answer to your answer ;) JDK1.5 and more supported!Ne
"I have not seen any tools that will properly handle 1.5+ classes" - Procion,Fernflower,JDCore and CFR (this one handles Java 8!)Persse
W
6

Take a look at cavaj.

Whorl answered 7/11, 2008 at 16:2 Comment(1)
That also uses jad underneath.Brutus
M
6

All of the JAD links listed so far far seem to be broken, so I found this site. Works great (for Linux, at least)! On Ubuntu 11.10 I had to download the static one for whatever reason.

http://www.varaneckas.com/jad

Mcgraw answered 4/4, 2012 at 3:11 Comment(0)
F
5
  • JAD is one that works and is simple.

  • Also, if you just want to see the methods, use javap.

Fanning answered 13/3, 2011 at 5:41 Comment(0)
N
5

If you want to see how the Java compiler does certain things, you don't want decompilation, you want disassembly. Decompilation involves transforming the bytecode into Java source, meaning that a lot of low level information is lost, and if you're wondering about compiler optimization, this is probably the very information you're interested in.

Anyway, I happen to have written an open source Java disassembler. Unlike Javap, this works even on highly pathological classes, so you can see what obfuscation tools are doing to your classes as well. It can also do decompilation, though I wouldn't recommend it.

Numen answered 30/11, 2012 at 3:13 Comment(0)
H
4

JAD doesn't work for me (Ubuntu 11.10 issue) so I've moved forward and sopped on JODO. At least it has Open Java source code and been able to decompile my .class properly.

I recommend to check out 'branches/generic' branch first. The trunks is not stable.

Histrionism answered 25/6, 2013 at 17:52 Comment(1)
JODO is sporadically maintained while CFR and Procyon are actively developed and have JDK 8 support.Hay
K
4

On IntelliJ IDEA platform you can use Java Decompiler IntelliJ Plugin. It allows you to display all the Java sources during your debugging process, even if you do not have them all. It is based on the famous tools JD-GUI.

enter image description here

Klansman answered 4/8, 2015 at 9:4 Comment(5)
@NoOP's Are you a robot? Or just not paying attention to a subject of review?Klansman
Sorry for that, at first glance it seems like link only answer. Maybe you should add more details and also your answer only comply with question title not with content of question.Holter
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.Musa
@Chris have you tried the suggested solution? Have you even read the question?Klansman
@NoOP's sorry for being rude =( I am overwhelmed by the number of reviewers who don't pay attention.Klansman
A
1

For OSX I recommend: jarzilla or JD-GUI

They both allow you to view jar,war,etc. file content and decompiles any class files inside of them.

Jarzilla: https://code.google.com/p/jarzilla/
JD-GUI: http://jd.benow.ca/

Arva answered 18/6, 2015 at 16:54 Comment(0)
K
1

With AndroChef Java Decompiler you can decompile apk, dex, jar and java class-files. It's simple and easy. AndroChef JD is based on FernFlower. You can evaluate it in 10 free uses.

AndroChef supports Java language features like generics, enums and annotations. According to some studies, AndroChef Java Decompiler is able to decompile 98.04% of Java applications generated with traditional Java compilers - a very high recovery rate. It is simple but powerful tool that allows you to decompile Java and Dalvik bytecode (DEX, APK) into readable Java source.

Klansman answered 4/8, 2015 at 8:22 Comment(1)
@Dimitrius, please read answers carefully during a review. How do you imagine including a FernFlower or AndroChef here?Klansman

© 2022 - 2024 — McMap. All rights reserved.