18

A Java decompiler turns a .class file back into a .java file. While decompiled code is not perfect (no comments, sometimes obfuscated names, etc.), it can be useful during hacking competitions, or to liberate your data locked by proprietary software, or to satisfy curiosity.

There are a few Open Source decompilers around, but I am not really satisfied by any, as the ones I tried crashed on huge Java projects, or produced non-optimal variable names, or used code formatting that does not conform to the Java Code Conventions.

The decompiler should be able to understand and cleanly show all recent concepts (for instance generics).

  • I use jad together with the eclipse plugin jadclipse. It helps to get an impression about what is going on and shouldn't depend on project size, as it only decompiles a single class. – Jens Piegsa Feb 5 '14 at 1:18
  • @JensPiegsa: jad is not open source, and is not maintained despite bugs. – Nicolas Raoul Feb 5 '14 at 4:16
  • 2
    Plesae include list of decompilers you considered and why they are not upto the mark. – Jayan Mar 8 '14 at 6:01
4

I used CFR and output looks good. It understands generics, formatting is clean. Not sure if naming (local variable ) can be better. Here is an example which shows the naming problem.

See output from java.util.ArrayDequeue(

private void doubleCapacity() {
        int n;
        assert (this.head == this.tail);
        int n2 = this.head;
        int n3 = this.elements.length;
        int n4 = n3 - n2;
        if ((n = n3 << 1) < 0) {
            throw new IllegalStateException("Sorry, deque too big");
        }
        Object[] arrobject = new Object[n];
        System.arraycopy(this.elements, n2, arrobject, 0, n4);
        System.arraycopy(this.elements, 0, arrobject, n4, n2);
        this.elements = arrobject;
        this.head = 0;
        this.tail = n3;
    }

Compare that against original

private void doubleCapacity() {
    assert head == tail;
    int p = head;
    int n = elements.length;
    int r = n - p; // number of elements to the right of p
    int newCapacity = n << 1;
    if (newCapacity < 0)
        throw new IllegalStateException("Sorry, deque too big");
    Object[] a = new Object[newCapacity];
    System.arraycopy(elements, p, a, 0, r);
    System.arraycopy(elements, 0, a, r, p);
    elements = (E[])a;
    head = 0;
    tail = n;
}

Getting a context based name will be out of scope for most decompilers.

The author has link to his friends project, procyon, opensource. It has own comparison page. From the page...

The Procyon decompiler handles language enhancements from Java 5 and beyond that most other decompilers don't. It also excels in areas where others fall short. Procyon in particular does well with:

Enum declarations
Enum and String switch statements (only tested against javac 1.7 so far)
Local classes (both anonymous and named)
Annotations
Java 8 Lambdas and method references (i.e., the :: operator).
  • Unfortunately CFR is not open source :-/ See benf.org/other/cfr/faq.html "I'm not going to publish the source until it's a bit more polished". Only the binary is under MIT license, so it is not open source. – Nicolas Raoul Apr 28 '17 at 3:19
-2

I used Java Decompiler by Emmanuel Dupuy. For me it is a good decompiler for jar files. I got the source code. I used the windows GUI version to decompile the jar file.

  • Easy to use
  • Navigation and Search function
  • show the tree of the jar project

For me it was a good solution and it is very quick.

  • 3
    Thanks for the effort, but it is not open source. en.wikipedia.org/wiki/Java_Decompiler – Nicolas Raoul Feb 8 '14 at 12:28
  • Oh sorry, I saw your question and did not consider that you need an open Source version. – Irgendw Pointer Feb 9 '14 at 8:47
  • 1
    @NicolasRaoul Why the need for open-source if you have a decompiler? :) – Drux Apr 13 '14 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.