Java Decompiler HOW-TO <!-- chapt change Java Decompiler HOW-TO --> <author>Al Dev (Alavoor Vasudevan) <htmlurl url="mailto:alavoor[AT]yahoo.com" name="alavoor[AT]yahoo.com"> <date>v4.5, 20 Sep 2002 <abstract> This document will help you to de-compile the Java class programs. This documents gives a list of decompilers which can reverse engineer the Java class files and generate the Java source code files. Thie is very helpful if you do not have the Java source code file and have only the Java class files. The information in this document applies to all the operating sytems where Java language/Java VM runs. </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <!-- ******************************************* ************ End of Section *************** ******************************************* <chapt>Introduction --> <sect>Introduction <p> <bf> (The latest version of this document is at <url url="http://www.milkywaygalaxy.freeservers.com">. You may want to check there for changes). </bf> Java compiler compiles the Java source code files (*.java) into binaries files (*.class). You would use the Java de-compiler to convert java class files into source code files (*.java). Java de-compiler is very useful especially if you have *.class files and you do not have access to the source code. Some vendors do not ship the source code for java class files, in which case you use the java decompiler to look at the source code. See also the "javap" command from Sun Microsystems. This command is available as soon as you install the JDK from Sun Microsystems. At unix prompt type - <code> bash$ javap -help bash$ javap -c <filename>.class </code> The following are the list of Java decompilers available - <itemize> <item> Free "Jad" Java Decompiler at <url url="http://www.geocities.com/SiliconValley/Bridge/8617/jad.html#general"> and at <url url="http://www.geocities.com/SiliconValley/Bridge/8617/jad.html#gui"> <p> <item> List of Decompilers, disassemblers and obfuscators are at <url url="http://dmoz.org/Computers/Programming/Languages/Java"> <p> <item> Free "Mocha" Java Decompiler at <url url="http://www.brouhaha.com/~eric/computers"> and download at <url url="http://www.brouhaha.com/~eric/computers/mocha-b1.zip"> <p> <item> "DeCafe Pro" from DeCafe, France at <url url="http://decafe.hypermart.net/index.htm"> <p> <item> "SourceTech Java decompiler" from Source Tech corp at <url url="http://www.srctec.com"> and at <url url="http://members.tripod.com/~SourceTec/jasmine.htm"> <p> <item> "SourceAgain" from Ahpah corp at <url url="http://www.ahpah.com"> <p> <item> "Class Cracker" from Mayon Software, Australia at <url url="http://www.tip.net.au/~mayon/classcracker/ccorder.html"> and at <url url="http://www.pcug.org.au/~mayon"> <p> <item> "IceBreaker" from BreakerTech corp, U.K. at <url url="http://www.breakertech.com"> and at <url url="http://www.breakertech.com/breaker/ice/ice.html#download"> <p> <item> "NMI Java decompiler" from NMI at <url url="http://njcv.htmlplanet.com"> and at <url url="http://njcv.htmlplanet.com/njcv.html"> <p> <item> DJ Java Decompiler at <url name="DJ decompiler" url="http://members.fortunecity.com/neshkov/dj.html"> or at the <url name="Download.com" url="http://download.com.com/3000-2417-10146169.html?tag=must"> <p> <item> Google <url url="http://directory.google.com/Top/Computers/Programming/Languages/Java/Development_Tools/Translators/Decompilers_and_Disassemblers/?tc=1"> <p> <item> SureShot <url url="http://www.bysoft.se/sureshot/cavaj/index.html"> and <url url="http://www.bysoft.se/sureshot/jcavaj/index.html"> </itemize> <!-- ******************************************* ************ End of Section *************** ******************************************* <chapt> How can I trust Java Decompiler ??!! --> <sect> How can I trust Java Decompiler ??!! <p> For 100% assurance you need a <bf>SCIENTIFIC</bf> way to validate and trust the Java Decompiler program. The method described in this section will enable the decompiler program to be accepted as "trust-worthy" and reliable. In order to verify that the decompiler program is regenerating the Java source-code properly, use the following technique - Generate the class file from the generated source code using the compiler - <code> bash$ mv myprogram.class myprogram_orig.class bash$ javac myprogram.java </code> Now use the unix 'diff' command to compare the two class files - <code> bash$ diff myprogram.class myprogram_orig.class </code> Both these files <bf>MUST BE IDENTICAL</bf>. This verifies that decompiler program is working perfectly. On DOS or Windows 95 you may want to use the free <url name="Cygnus" url="http://www.cygnus.com"> Cygwin 'diff' or 'MKS' utilities. This step gives 100% guarantee and 100% quality assurance and life term or long term <bf>WARRANTY</bf> on decompiler programs. It is strongly recommended that you do these steps every time you run decompiler programs. <!-- ******************************************* ************ End of Section *************** ******************************************* <chapt change> Related URLs --> <sect> Related URLs <p> Visit following locators which are related to Java - <itemize> <item> <url url="http://www.linuxdoc.org/HOWTO/Enterprise-Java-for-Linux-HOWTO.html"> <item> <url url="http://www.linuxdoc.org/HOWTO/Java-CGI-HOWTO.html"> <item> <url url="http://www.linuxdoc.org/HOWTO/JavaStation-HOWTO/index.html"> <item> <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html" name="Vim color text editor for Java, C++, C"> <item> <url url="http://metalab.unc.edu/LDP/HOWTO/C-C++Beautifier-HOWTO.html" name="Beautifier HOWTO for Java and C++ programs"> <item> <url url="http://metalab.unc.edu/LDP/HOWTO/C++Programming-HOWTO.html" name="C++ Programming HOWTO has support for Java like String objects"> <item> Linux goodies main site is at <url url="http://www.milkywaygalaxy.freeservers.com"> Mirror sites are at - <url url="http://aldev0.webjump.com">, <url name="angelfire" url="http://www.angelfire.com/country/aldev0">, <url name="geocities" url="http://www.geocities.com/alavoor/index.html">, <url name="virtualave" url="http://aldev0.virtualave.net">, <url name="50megs" url="http://aldev0.50megs.com">, <url name="theglobe" url="http://members.theglobe.com/aldev1/index.html">, <url name="NBCi" url="http://members.nbci.com/alavoor">, <url name="Terrashare" url="http://aldev.terrashare.com">, <url name="Fortunecity" url="http://members.fortunecity.com/aldev">, <url name="Freewebsites" url="http://aldev.freewebsites.com">, <url name="Tripod" url="http://members.tripod.lycos.com/aldev">, <url name="Spree" url="http://members.spree.com/technology/aldev">, <url name="Escalix" url="http://www.escalix.com/freepage/aldev">, <url name="Httpcity" url="http://www.httpcity.com/aldev/index.html">, <url name="Freeservers" url="http://aldev.freeservers.com">. </itemize> <!-- ******************************************* ************ End of Section *************** ******************************************* <chapt change> Other Formats of this Document --> <sect> Other Formats of this Document <p> This document is published in 14 different formats namely - DVI, Postscript, Latex, Adobe Acrobat PDF, LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages, single HTML file, SGML (Linuxdoc format), SGML (Docbook format), MS WinHelp format. This howto document is located at - <itemize> <item> <url url="http://www.linuxdoc.org"> and click on HOWTOs and search for howto document name using CTRL+f or ALT+f within the web-browser. </itemize> You can also find this document at the following mirrors sites - <itemize> <item> <url url="http://www.caldera.com/LDP/HOWTO"> <item> <url url="http://www.linux.ucla.edu/LDP"> <item> <url url="http://www.cc.gatech.edu/linux/LDP"> <item> <url url="http://www.redhat.com/mirrors/LDP"> <item> Other mirror sites near you (network-address-wise) can be found at <url url="http://www.linuxdoc.org/mirrors.html"> select a site and go to directory /LDP/HOWTO/xxxxx-HOWTO.html </itemize> <itemize> <item> You can get this HOWTO document as a single file tar ball in HTML, DVI, Postscript or SGML formats from - <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO/other-formats/"> and <url url="http://www.linuxdoc.org/docs.html#howto"> <p> <item>Plain text format is in: <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO"> and <url url="http://www.linuxdoc.org/docs.html#howto"> <p> <item>Single HTML file format is in: <url url="http://www.linuxdoc.org/docs.html#howto"> <p> Single HTML file can be created with command (see man sgml2html) - sgml2html -split 0 xxxxhowto.sgml <p> <item>Translations to other languages like French, German, Spanish, Chinese, Japanese are in <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO"> and <url url="http://www.linuxdoc.org/docs.html#howto"> Any help from you to translate to other languages is welcome. </itemize> The document is written using a tool called "SGML-Tools" which can be got from - <url url="http://www.sgmltools.org"> Compiling the source you will get the following commands like <itemize> <item>sgml2html xxxxhowto.sgml (to generate html file) <item>sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file) <item>sgml2rtf xxxxhowto.sgml (to generate RTF file) <item>sgml2latex xxxxhowto.sgml (to generate latex file) </itemize> <!-- ******************************************* ************ End of Section *************** ******************************************* --> <sect1> Acrobat PDF format <label id="acrobatpdf"> <p> PDF file can be generated from postscript file using either acrobat <bf>distill</bf> or <bf>Ghostscript</bf>. And postscript file is generated from DVI which in turn is generated from LaTex file. You can download distill software from <url url="http://www.adobe.com">. Given below is a sample session: <code> bash$ man sgml2latex bash$ sgml2latex filename.sgml bash$ man dvips bash$ dvips -o filename.ps filename.dvi bash$ distill filename.ps bash$ man ghostscript bash$ man ps2pdf bash$ ps2pdf input.ps output.pdf bash$ acroread output.pdf & </code> Or you can use Ghostscript command <bf>ps2pdf</bf>. ps2pdf is a work-alike for nearly all the functionality of Adobe's Acrobat Distiller product: it converts PostScript files to Portable Document Format (PDF) files. <bf>ps2pdf</bf> is implemented as a very small command script (batch file) that invokes Ghostscript, selecting a special "output device" called <bf>pdfwrite</bf>. In order to use ps2pdf, the pdfwrite device must be included in the makefile when Ghostscript was compiled; see the documentation on building Ghostscript for details. <!-- ******************************************* ************ End of Section *************** ******************************************* --> <sect1> Convert Linuxdoc to Docbook format <label id="linuxdoc2docbook"> <p> This document is written in linuxdoc SGML format. The Docbook SGML format supercedes the linuxdoc format and has lot more features than linuxdoc. The linuxdoc is very simple and is easy to use. To convert linuxdoc SGML file to Docbook SGML use the program <bf>ld2db.sh</bf> and some perl scripts. The ld2db output is not 100% clean and you need to use the <bf>clean_ld2db.pl</bf> perl script. You may need to manually correct few lines in the document. <itemize> <item> Download ld2db program from <url url="http://www.dcs.gla.ac.uk/~rrt/docbook.html"> or from <url name="Milkyway Galaxy site" url="http://www.milkywaygalaxy.freeservers.com"> <item> Download the cleanup_ld2db.pl perl script from from <url name="Milkyway Galaxy site" url="http://www.milkywaygalaxy.freeservers.com"> </itemize> The ld2db.sh is not 100% clean, you will get lots of errors when you run <code> bash$ ld2db.sh file-linuxdoc.sgml db.sgml bash$ cleanup.pl db.sgml > db_clean.sgml bash$ gvim db_clean.sgml bash$ docbook2html db.sgml </code> And you may have to manually edit some of the minor errors after running the perl script. For e.g. you may need to put closing tag < /Para> for each < Listitem> <!-- ******************************************* ************ End of Section *************** ******************************************* --> <sect1> Convert to MS WinHelp format <label id="mswinhelp"> <p> You can convert the SGML howto document to Microsoft Windows Help file, first convert the sgml to html using: <code> bash$ sgml2html xxxxhowto.sgml (to generate html file) bash$ sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file) </code> Then use the tool <url name="HtmlToHlp" url="http://javadocs.planetmirror.com/htmltohlpe.html">. You can also use sgml2rtf and then use the RTF files for generating winhelp files. <!-- ******************************************* ************ End of Section *************** ******************************************* --> <sect1> Reading various formats <label id="readformats"> <p> In order to view the document in dvi format, use the xdvi program. The xdvi program is located in tetex-xdvi*.rpm package in Redhat Linux which can be located through ControlPanel | Applications | Publishing | TeX menu buttons. To read dvi document give the command - <tscreen><verb> xdvi -geometry 80x90 howto.dvi man xdvi </verb></tscreen> And resize the window with mouse. To navigate use Arrow keys, Page Up, Page Down keys, also you can use 'f', 'd', 'u', 'c', 'l', 'r', 'p', 'n' letter keys to move up, down, center, next page, previous page etc. To turn off expert menu press 'x'. You can read postscript file using the program 'gv' (ghostview) or 'ghostscript'. The ghostscript program is in ghostscript*.rpm package and gv program is in gv*.rpm package in Redhat Linux which can be located through ControlPanel | Applications | Graphics menu buttons. The gv program is much more user friendly than ghostscript. Also ghostscript and gv are available on other platforms like OS/2, Windows 95 and NT, you view this document even on those platforms. <itemize> <item>Get ghostscript for Windows 95, OS/2, and for all OSes from <url url="http://www.cs.wisc.edu/~ghost"> </itemize> To read postscript document give the command - <tscreen><verb> gv howto.ps ghostscript howto.ps </verb></tscreen> You can read HTML format document using Netscape Navigator, Microsoft Internet explorer, Redhat Baron Web browser or any of the 10 other web browsers. You can read the latex, LyX output using LyX a X-Windows front end to latex. <!-- ******************************************* ************ End of Section *************** ******************************************* <chapt> Copyright --> <sect> Copyright <p> Copyright policy is GNU/GPL as per LDP (Linux Documentation project). LDP is a GNU/GPL project. Additional requests are - you retain the author's name, email address and this copyright notice on all the copies. If you make any changes or additions to this document then you should intimate all the authors of this document. <!-- ******************************************* ************ End of Section *************** ******************************************* --> </article>