Recursive Java Decompiler
Often we encounter situations where the only solution to a certain Java problem is to decompile the contents of
an entire JAR file, edit the resulting the source, rebuild and repackage before using.
I searched a lot for decompilers which could recursively decompile multiple class files while preserving the package
hierarchy, but in vain. So, I thought of writing a Windows batch script myself, to do what I was looking for. This
script is also known as JAR decompiler or recursive JAD.
I have used JAD for decompilation. JAD is an excellent decompiler which can be downloaded from the author's
website, http://www.kpdus.com/jad.html. It provides an
executable, jad.exe which has various options to run the decompiler.
The following steps outline how to make use of the Recursive Decompiler Utility to successfully decompile a
huge set of class files.
-
Download decompile.zip and extract the contents into a path on the file system that doesn't contain spaces. Eg. D:\decompile.
-
You should be able to see a directory structure as shown below.
-
Extract the contents of the JAR file you would want to be recursively decompiled, into the folder decompile\classes.
You may use any the command "jar -xvf <jar> <dir>" or any of the popular file compression softwares such as WinZip
or WinRar to do the same.
-
Make sure the decompile\src folder is empty.
-
Run decompile.bat.
-
The utility decompiles each of the .class file found in classes directory and places the .java files under the src directory. This
operation preserves the original class hierarchy.
Now you can edit the code, recompile, rebuild, repackage and start using it!
Note: Because this utility uses some advanced batch scripting commands, it works only on Windows XP or higher operating systems.
What others say
This is good.. great stuff. Thanks. I am not good at batch scripting, but is handling spaces in the folder
structure a big problem?
Thanks Sriram. If paths were directly used in batch files without any manipulations, it would have worked well
and fine. However, in this batch script, I'm manipulating the path in the for loop to trim the ".class"
extension so that I could use a ".java" one. While doing this, I was facing some problems if I hadn't placed
the script in a path without spaces.
Great job, BUT I firstly executed the batch file from <C:>. Any *.class file existing on my harddrive
was going to be deleted. Is there a possibility to exit the batch if "cd src" (or any other command) fails?
hi,
i'm trying to do decompile some folder structure it is giving jad.exe error and in cammand prompt it showing
Not all exception handlers will be in the method main resolved
Couldn't fully decompile method main
please help me Adresh..
thanks & regards
shivu..
@M. Rettkowski
That sounds scary! I will try to do something about it. Thanks.
@shivananda
This error is something which JAD itself throws and is unfortunately, out of my scope.
Try replacing the jad.exe with the latest one from the author's website. It might help.
Here's the link:
http://www.kpdus.com/jad.html
@Adarsh R
U R great! That really helped a lot, I already had had to do with
jad, but it had always been a torture to decompile complicated
packages;)
@shivananda
I replaced jad with a newer one I already had worked with. Works
better, but if You look at jad's Author's site, You will find out,
there are certain limits not only to jad but to reverse engineering
in general.
This bat-file work like a charm. But i think the space problem in paths can be avoided.
i just modified your bat like this :
@echo off
echo Copying .class files...
xcopy /Q /E /Y classes src
cd src
echo Decompiling .class files into .java files...
::for /R src %%a in (*.class) do jad -d %%~dpa -o -s .java "%%a"
..\jad.exe -r -o -sjava -d . ./**/*.class
echo Deleting .class files...
::cd src
del /S /Q *.class
cd..
pause
ie, after copying all class-files from classes-folder give 'cd src'. then issue this command '..\jad.exe -r -o
-sjava -d . ./**/*.class' to recursively decompile (- option of JAD [restore package directory structure]).
this is working fine.
sunil
Thanks a lot Sunil for the changes. I will soon update the distributable.
I am very glad to know that you considered my suggestion. Also i am planning to make a Swing UI to do this recursive
JAR decompilation (so, one can specify JAR file and destination directory and just say 'Decompile').
Adarsh,
I landed on your page via Google & I must tell you that you have saved countless hours in my busy schedule !
I have posted a link to your page on my Blog !
Keep us the good work!
Thanks,
Sandeep
Awesome!It helped me a lot.
Thank you very much for you work.
Jo
Adarsh,
I\'m attempting to use your decompiler to decompile version 1.5 class files. I\'m getting this error for each file:
Parsing H:\jscape\src\com\jscape\n.class...The class file version is 49.0 (only 45.3 and 46.0 are supported)
JavaClassFileParseException: Class file version mismatch
Do you have any suggestions how to avoid this? Thanks for sharing the decompiler and thanks for you help.
Daren, this error is owing to the fact that the original Jad (which this script uses) cannot support Java 1.5
completely as of today. I'm afraid, there's no solution for this.