302

Does anyone know of a free decompiler that can decompile an entire Jar file instead of a single class? I have a problem with sub classes like name$1.class name$2.class name.class

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
StoneHeart
  • 14,122
  • 31
  • 65
  • 83
  • 137
    Remember two more things: 1) The mere mention of a decompiler will cause the "holier than thou's" to come out and make value judgements about your motives despite having no idea what your planned use is, so be careful who you talk to. 2) The fancy JavaDecompiler will give you an excellent rendition of the code, well laid out and easy to read - missing only comments. It is astoundingly good, recovering a JAR file which had long lost source complete with variable names. Of course we don't obfuscate our in-house JAR files. – Andrew Feb 09 '10 at 03:32
  • See also remarks in post [Choose and test java decompiler](http://stackoverflow.com/questions/3898391). – dma_k Jan 02 '12 at 12:19
  • 9
    I've stopped by this thread so many times when I needed to study how someone accomplished something for a Bukkit plugin... That comment always leaves me with a smile. I wish I could upvote it every time I stop by. – Jane Panda Apr 03 '12 at 19:45
  • [SecureTeam Java Decompiler](http://secureteam.net/Java-Decompiler.aspx) can do that. – SecureTeam Software Nov 19 '13 at 11:44
  • Simple online decompiler if you don't want to download any software. http://www.javadecompilers.com/ – Nick Graham Nov 11 '16 at 19:27
  • This shouldn't be closed as the decompilers playground changes dynamically. Currently, the best is probably [FernFlower](https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine). If you're looking for an easy solution, download [Windup](http://windup.jboss.org/) and run it's command-line version on your .jar. It will decompile using FernFlower, with support up to Java 8 (jad only suports up to Java 1.3, JavaDecompiler up to Java 1.5 IIRC), with a fallback to Procyon if FernFlower fails. – Ondra Žižka Feb 08 '17 at 23:34

8 Answers8

328

2009: JavaDecompiler can do a good job with a jar: since 0.2.5, All files, in JAR files, are displayed.

http://java.decompiler.free.fr/sites/default/screenshots/screenshot1.png

See also the question "How do I “decompile” Java class files?".

The JD-Eclipse doesn't seem to have changed since late 2009 though (see Changes).
So its integration with latest Eclipse (3.8, 4.2+) might be problematic.

JD-Core is actively maintained.

Both are the result of the fantastic work of (SO user) Emmanuel Dupuy.


2018: A more modern option, mentioned in the comments by David Kennedy Araujo:

JetBrains/intellij-community/plugins/java-decompiler/engine

Fernflower is the first actually working analytical decompiler for Java and probably for a high-level programming language in general.

java -jar fernflower.jar [-<option>=<value>]* [<source>]+ <destination>

java -jar fernflower.jar -hes=0 -hdc=0 c:\Temp\binary\ -e=c:\Java\rt.jar c:\Temp\source\

See also How to decompile to java files intellij idea for a command working with recent IntelliJ IDEA.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 5
    fyi, java decompiler works on windows, mac and linux. – yanokwa Sep 13 '11 at 20:56
  • 4
    @AlexS nice :) Next step: version control (http://stackoverflow.com/questions/59561/what-tools-techniques-can-benefit-a-solo-developer) And then Continuous Integration (http://stackoverflow.com/questions/130592/is-continuous-integration-important-for-a-solo-developer) – VonC Apr 19 '12 at 11:13
  • Anyone get the eclipse plugin to work anymore with the latest eclipse and jdk7? I tried but I get a download error. JD-Gui works but jd-eclipse seems to fail for me... – Stephane Grenier Nov 06 '12 at 06:51
  • @StephaneGrenier I didn't test it recently. That could be a question in its own (detailed with the OS, Eclipse version, and screenshot of the error message you got, or the Eclipse log view). Java-Decompiler maintainer Emmanuel Dupuy (http://stackoverflow.com/users/37785/emmanuel-dupuy) could answer. – VonC Nov 06 '12 at 06:59
  • so with plugin for Eclipse how can I view code for a specific jar in Package Explorer? – Nikolay Kuznetsov Dec 21 '12 at 14:01
  • 3
    With Java Decompiler you can open the JAR file and go to File, Save All Sources. It saves all class files into java files =D – Akira Yamamoto Apr 02 '13 at 22:54
  • 2
    Please remember that it makes errors too. I have a class with a Member variable and it moved it to the parameter of a function, destroying the effect of the code. Watch out, it will get you. – CharlesW Feb 14 '14 at 18:56
  • jd.benow.ca is currently down. However, the Internet Archive has a snapshot of it from January: https://web.archive.org/web/20140105052622/http://jd.benow.ca/ – sfuqua Mar 21 '14 at 14:04
  • @CharlesW I think this was an optimisation done by the compiler, not by the decompiler... – Peter Wippermann Feb 11 '15 at 14:16
  • Is there any way to prevent from my code to be decompiled ? If I store sensitive information inside the CLASS files – Pini Cheyni Apr 21 '16 at 13:00
  • Doesn't work if you only have Java 8 installed on your system. – aroth May 11 '17 at 08:34
  • 2
    JD is a good starting point but fail to decompile complex code. A good alternative is use https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine – David Kennedy Jun 29 '18 at 15:21
  • @DavidKennedyAraujo Thank you. I have included your comment in the answer for more visibility. – VonC Jun 29 '18 at 15:24
  • 1
    Is there a download location for fernflower.jar? – Saftpresse99 Sep 12 '18 at 10:18
  • @Saftpresse99 Maybe http://www.javadecompilers.com/? or https://github.com/fesh0r/fernflower (but requiring a compilation) – VonC Sep 12 '18 at 11:34
40

First of all, it's worth remembering that all Java archive files (.jar/.war/etc...) are all basically just fancy.zip files, with a few added manifests and metadata.

Second, to tackle this problem I personally use several tools which handle this problem on all levels:

  • Jad + Jadclipse while working in IDE for decompiling .class files
  • WinRAR, my favorite compression tool natively supports Java archives (again, see first paragraph).
  • Beyond Compare, my favorite diff tool, when configured correctly can do on-the-fly comparisons between any archive file, including jars. Well worth a try.

The advantage of all the aforementioned, is that I do not need to hold any other external tool which clutters my work environment. Everything I will ever need from one of those files can be handled inside my IDE or diffed with other files natively.

bakoyaro
  • 2,502
  • 3
  • 33
  • 56
Yuval Adam
  • 149,388
  • 85
  • 287
  • 384
36

If you happen to have both a bash shell and jad:

JAR=(your jar file name)
unzip -d $JAR.tmp $JAR
pushd $JAR.tmp
for f in `find . -name '*.class'`; do
    jad -d $(dirname $f) -s java -lnc $f
done
popd

I might be a tiny, tiny bit off with that, but it should work more or less as advertised. You should end up with $JAR.tmp containing your decompiled files.

Chris R
  • 16,477
  • 22
  • 97
  • 163
27

I have had reasonable success with a tool named (frustratingly) "JD: Java Decompiler".

I have found it better than most decompilers when dealing with classes compiled for Java 5 and higher. Unfortunately, it can still have some hiccups where JAD would normally succeed.

Gowtham Gopalakrishnan
  • 9,485
  • 11
  • 41
  • 60
Adam Paynter
  • 44,176
  • 30
  • 143
  • 162
12

Something like:

jar -xf foo.jar && find . -iname "*.class" | xargs /opt/local/bin/jad -r

maybe?

cybertoast
  • 121
  • 1
  • 2
  • 1
    I've used jad for a while and needed a quick way to extract and decompile a whole jar. Thanks, this helped immensely. – Alper Akture Jul 27 '12 at 17:50
5

Insert the following into decompile.jar.sh

# Usage: decompile.jar.sh some.jar [-d]

# clean target folders
function clean_target {
  rm -rf $unjar $src $jad_log
}

# clean all debug stuff
function clean_stuff {
  rm -rf $unjar $jad_log
}

# the main function
function work {
  jar=$1
  unjar=`basename $jar.unjar`
  src=`basename $jar.src`
  jad_log=jad.log

  clean_target

  unzip -q $jar -d $unjar
  jad -d $src -ff -r -lnc -o -s java $unjar/**/*.class > $jad_log 2>&1

  if [ ! $debug ]; then
    clean_stuff
  fi

  if [ -d $src ] 
    then
      echo "$jar has been decompiled to $src"
    else
      echo "Got some problems check output or run in debug mode"
  fi
}

function usage {
  echo "This script extract and decompile JAR file"
  echo "Usage: $0 some.jar [-d]"
  echo "    where: some.jar is the target to decompile"
  echo "    use -d for debug mode"
}

# check params
if [ -n "$1" ]
  then
    if [ "$2" == "-d" ]; then
      debug=true
      set -x
    fi
    work $1
  else
    usage
fi
  • chmod +x decomplie.jar.sh //executable
  • ln -s ./decomplie.jar.s /usr/bin/dj

Ready to use, just type dj your.jar and you will get your.jar.src folder with sources. Use -d option for debug mode.

merzod
  • 51
  • 1
  • 1
  • Thanks, but had to change "jad" to "./jad" on line 23 and run "bash decompile.jar.sh foo.jar -d" as I did not want to pollute my bin folder – Sam Mar 02 '15 at 10:55
  • any recompiler ? recompiles jad files into jar ? – N Jay Jun 23 '15 at 00:14
1

You extract it and then use jad against the dir.

yanchenko
  • 53,981
  • 33
  • 142
  • 163
1

Note: This solution only works for Mac and *nix users.

I also tried to find Jad with no luck. My quick solution was to download MacJad that contains jad. Once you downloaded it you can find jad in [where-you-downloaded-macjad]/MacJAD/Contents/Resources/jad.

Joel S
  • 468
  • 5
  • 17