Java Decompiler

Decompiler is to reverse engineer source code from object code. A decompiler for java should get the respective source file from its Java binary class file.
Java decompiler world is in mess, yes it really looks like kid’s mud play. To our surprise, it is difficult to find a decent Java decompiler in the whole web world.

JAva Decompiler (JAD – No longer maintained)

When we say decompiler for Java, it is almost synonymous to JAD. JAD was/is the popular Java decompiler we can find. Very long back, when I started learning Java, I remember using JAD, may be with JDK1.2 or so. It was very popular and almost the only tool for Java class decompilation.
We may find lots and lots of software tools claiming to be Java decompilers. But if we dig deep then we can find that 90% of them are just the user interface and the underlying engine will be JAD decompiler.
JAD is copright software by Pavel Kouznetsov. JAD was written in C++ and its first version was released before 1999 and its last stable release version was to provide support for JDK 1.4.
JAD does not support JDK 1.5 and later. It is no longer developed or maintained. If you still want to get a feel of JAD, download its last official stable version 1.5.8g using the below link. I have hosted it as a mirror. This is a copyrighted software by Pavel Kouznetsov and cannot be bundled with any commercial software.
Download JAD – jad158g.win – for Windows

DJ Java Decompiler (UI for JAD)

In that case, what is DJ Java decompiler? DJ Java decompiler is GUI for JAD and provided by Atanas Neshkov. Its last stable version was released on August 2011. Since JAD is no longer maintained, it does not make sense to use DJ Java decompiler either as it is just the UI for JAD.

Java Decompiler Options

I can hear you shouting. JAD cannot be used and DJ too is also just an UI for JAD, so what are the options we have for decompiler in Java? We couldn’t find anything other than these!
There are couple of options for decompiler for Java which looks promising,
  1. JD Java Decompiler
  2. Procyon
These are the two options that are alive and maintained as of now and promises support for latest versions of Java.

1. JD Java Decompiler

Let us first explore JD Java decompiler project and do some simple Java class decompilations. JD-gui is a light weight application with a sleek user interface.
I wrote a simple Java factorial program to test JD Java decompiler and that program is as follows:

Java Factorial Sample

package com.javapapers.java;
 
import java.util.Scanner;
 
public class JavaFactorial {
  public static void main(String args[]) {
    int n, factorial = 1;
    System.out.print("Factorial of: ");
    Scanner input = null;
    try {
      input = new Scanner(System.in);
      n = input.nextInt();
    } finally {
      input.close();
    }
    if (n < 0)
      System.out.println("Try greater than 0.");
    else {
      for (int i = 1; i <= n; i++)
        factorial = factorial * i;
      System.out.println("Factorial " + n + " = " + factorial);
    }
  }
}

Decompiled Java Source

Following is the screen shot of both the Java factorial source in Eclipse IDE and its decompiled source using JD-gui Java decompiler. It is simple and easy, just open the .class Java binary file using the gui and it works clean.
JD Decompiled Java Class

Decompile Java using Eclipse (JD-Eclipse plugin)

No Java tool is complete unless it provides a plugin for Eclipse IDE. Eclipse is the most popular Java IDE.
JD Java decompiler provides a plugin for Eclipse IDE, so that we can decompile a Java class file within the Eclipse IDE itself.
Install the JD-Eclipse plugin as shown in the next screen shot.
Install JD Decompile Eclipse
JD Java decompile Eclipse plugin will take some good time to install, may be you should have a big coffee during the time. On a side note, Eclipse should still refine its plugin installation process. Once installed a java class file can be just opened and decompiled on the go.

2. Procyon Decompiler for Java

Procyon Java Decompiler is by mstrobel and hosted in Bitbucket. Procyon is a suite of tools containing lot more than the Java decompiler. It is very actively under development (I noticed a commit in Bitbucket during writing this article). Procyon is early in its development, he is just started and not offers a complete version yet. Still why I chose to give a coverage is primarily for two reasons,
  1. almost no one is actively working in this Java world for decompilers (at least as far as I know) – Procyon is actively developed
  2. Procyon Java Decompiler is open source
Let us wish him success on this Java decompiler project.

0 comments:

Post a Comment