Friday, December 02, 2005

Java Decompilers

Good... Bad... I'm the guy with the gun.
- Ash, Army of Darkness

Sometimes you need to pull out the tools of the trade that are a little controvercial, like Java decompilers. In some cases, usually do to poor documentation on a closed system, it is the only way to get the details that you need. I ran into such a case recently, and did some searching.

After trying out a few decomilers I settled on Jad, for two reasons. First, it didn't have a problem decomiling some files that Mocha choked on. Second, there is an Eclipse plug-in for it, which is my IDE of choice.

The following is based on my experience with installing Jad on Windows XP, and Eclipse 3.1.

Installing Jad is easy. Just go to the Jad site, download the distribution for your platform (I am using WinXP), and unzip the archive somewhere on your PC. From here you can use the Jad stand-alone executable. I also added the path to the Jad executable to my Windows path, but I don't think that this is required for using the Eclipse plug-in.

Next you need to download JadClipse plugin. I tried using the latest release, which is at the time of this writing 3.2, but it didn't work for me. I then tried version 3.1 which worked like a charm. So if one doesn't work, then try the ohter.

Place the downloaded JadClipse jar file into your Eclipse plug-ins directory, then start Eclipse from the command line using the -clean switch (e.g. "eclipse -clean"). From here you should see JadClipse show up in the Eclipse preferences under the Java category. You will need to set the path to the Jad executable before it will work.

Once this was done I was able to click on any .class file attached to my project, and the source code would be displayed in the editor view. This works even when you select a class that is part of a jar file in your project classpath. Note that this isn't the same exact code as was originally written. For example, variables will have different names, and there will be no Java comments.

If this doesn't work, perhaps because you are using an older version of eclipse, you can find another tutorial on DevX. If you want information on other decompilers, I also found a nice How-To by Al Dav.

No comments: