Source Code Cross Referenced for ConsoleLauncher.java in  » Development » jdec » net » sf » jdec » main » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jdec » net.sf.jdec.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  ConsoleLauncher.java Copyright (c) 2006,07 Swaroop Belur
0003:         *
0004:         * This program is free software; you can redistribute it and/or
0005:         * modify it under the terms of the GNU General Public License
0006:         * as published by the Free Software Foundation; either version 2
0007:         * of the License, or (at your option) any later version.
0008:
0009:         * This program is distributed in the hope that it will be useful,
0010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:         * GNU General Public License for more details.
0013:
0014:         * You should have received a copy of the GNU General Public License
0015:         * along with this program; if not, write to the Free Software
0016:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0017:         *
0018:         */
0019:
0020:        package net.sf.jdec.main;
0021:
0022:        import java.awt.Color;
0023:        import java.awt.Font;
0024:        import java.io.BufferedInputStream;
0025:        import java.io.BufferedReader;
0026:        import java.io.BufferedWriter;
0027:        import java.io.DataInputStream;
0028:        import java.io.File;
0029:        import java.io.FileInputStream;
0030:        import java.io.FileNotFoundException;
0031:        import java.io.FileOutputStream;
0032:        import java.io.IOException;
0033:        import java.io.InputStream;
0034:        import java.io.InputStreamReader;
0035:        import java.io.OutputStreamWriter;
0036:        import java.util.ArrayList;
0037:        import java.util.Arrays;
0038:        import java.util.Enumeration;
0039:        import java.util.HashMap;
0040:        import java.util.Hashtable;
0041:        import java.util.Iterator;
0042:        import java.util.StringTokenizer;
0043:        import java.util.jar.JarEntry;
0044:        import java.util.jar.JarFile;
0045:        import java.util.zip.ZipEntry;
0046:
0047:        import javax.swing.JDialog;
0048:        import javax.swing.JFrame;
0049:        import javax.swing.JOptionPane;
0050:        import javax.swing.JTabbedPane;
0051:        import javax.swing.SwingUtilities;
0052:        import javax.swing.UIManager;
0053:
0054:        import net.sf.jdec.commonutil.StartupHelper;
0055:        import net.sf.jdec.config.Configuration;
0056:        import net.sf.jdec.constantpool.CPool;
0057:        import net.sf.jdec.constantpool.ClassDescription;
0058:        import net.sf.jdec.core.Decompiler;
0059:        import net.sf.jdec.core.Disassembler;
0060:        import net.sf.jdec.core.InnerClassTracker;
0061:        import net.sf.jdec.core.JvmUtil;
0062:        import net.sf.jdec.core.LocalVariable;
0063:        import net.sf.jdec.core.LocalVariableStructure;
0064:        import net.sf.jdec.core.LocalVariableTable;
0065:        import net.sf.jdec.core.InnerClassTracker.Node;
0066:        import net.sf.jdec.exceptions.ApplicationException;
0067:        import net.sf.jdec.exceptions.InvalidInputException;
0068:        import net.sf.jdec.exceptions.MalFormedClassException;
0069:        import net.sf.jdec.io.Reader;
0070:        import net.sf.jdec.io.Writer;
0071:        import net.sf.jdec.reflection.Behaviour;
0072:        import net.sf.jdec.reflection.ConstructorMember;
0073:        import net.sf.jdec.reflection.FieldMember;
0074:        import net.sf.jdec.reflection.JavaClass;
0075:        import net.sf.jdec.ui.core.JdecTree;
0076:        import net.sf.jdec.ui.core.Manager;
0077:        import net.sf.jdec.ui.core.UIObserver;
0078:        import net.sf.jdec.ui.main.UILauncher;
0079:        import net.sf.jdec.ui.util.UIUtil;
0080:        import net.sf.jdec.util.AllExceptionHandler;
0081:        import net.sf.jdec.util.ClassStructure;
0082:        import net.sf.jdec.util.Constants;
0083:        import net.sf.jdec.util.Util;
0084:
0085:        // import org.bb.projects.jdec.ui.core.JarTree;
0086:
0087:        /**
0088:         * @author sbelur
0089:         */
0090:        public class ConsoleLauncher {
0091:
0092:            private static boolean supportedVersion = true;
0093:
0094:            private static JavaClass clazzRef;
0095:
0096:            private static int magicNumber = -1;
0097:
0098:            static ArrayList tabChange = new ArrayList();
0099:
0100:            private static ArrayList inclList = new ArrayList();
0101:
0102:            private static ArrayList exclList = new ArrayList();
0103:
0104:            public ArrayList variablesPushedToFront = null;
0105:
0106:            public static boolean fatalErrorOccured = false;
0107:
0108:            public static ArrayList currentClassMethods = null;
0109:
0110:            public static ArrayList innerClassStructures = null;
0111:
0112:            private static boolean dontpvtmethods = false;
0113:
0114:            private static boolean dontstaticinit = false;
0115:
0116:            private static boolean dontsynth = false;
0117:
0118:            private static boolean dontshowemptyconst = false;
0119:
0120:            private static boolean dontshownative = false;
0121:
0122:            private static boolean dontshowabs = false;
0123:
0124:            private static boolean showconstfirst = true;
0125:
0126:            private static boolean showfieldsfirst = true;
0127:
0128:            private static boolean showextendsobject = false;
0129:
0130:            public static ArrayList allClassStructures = new ArrayList();
0131:
0132:            public static boolean currentIsInner = false;
0133:
0134:            public static HashMap method_names_signature = new HashMap();
0135:
0136:            public static HashMap classMethodMap = new HashMap();
0137:
0138:            public static HashMap classMethodRefMap = new HashMap();
0139:
0140:            public static HashMap method_names_methodref = new HashMap();
0141:
0142:            private static java.lang.String resultFileName = null;
0143:
0144:            public static String currentdecompiledtext = "";
0145:
0146:            private static InnerClassTracker.Node mainRoot = null;
0147:
0148:            private static InnerClassTracker.Node currentNode = null;
0149:
0150:            public static long l3 = -1;
0151:
0152:            private static int currentDepthLevel = 0;
0153:
0154:            public static ClassStructure mainClassStructure = null;
0155:
0156:            private static float version = -1;
0157:
0158:            public static void setResultFilePath(String res) {
0159:                resultFileName = res;
0160:
0161:            }
0162:
0163:            public static long getStartTime() {
0164:                return startTime;
0165:            }
0166:
0167:            public static long startTime;
0168:
0169:            static java.lang.String mesg = "";
0170:
0171:            /**
0172:             * @param args
0173:             */
0174:
0175:            public static void main(String[] args) {
0176:
0177:                startTime = System.currentTimeMillis();
0178:
0179:                try {
0180:
0181:                    /*
0182:                     * if(args==null || args.length==0) showHelp();
0183:                     */
0184:
0185:                    // For help ...No further processing
0186:                    if (args != null && (args.length > 0)) {
0187:                        if ((args[0].equalsIgnoreCase("help")
0188:                                || args[0].equalsIgnoreCase("/?") || args[0]
0189:                                .equalsIgnoreCase("-help"))) {
0190:                            showHelp();
0191:                        }
0192:                    }
0193:                    Configuration
0194:                            .init(new String[] { "config", "consolefilter" });
0195:
0196:                    new StartupHelper().start();
0197:
0198:                    // mesg="Parameters from Configuration.properties registered...\n";
0199:
0200:                    mesg += Configuration.userInput();
0201:                    Util.registerInputs(args);
0202:                    mesg += "Input Parameter(s) to Jdec registered ....\n";
0203:                    mesg += "User has Chosen to Run Jdec with option "
0204:                            + Configuration.getDecompileroption() + "\n";
0205:                    mesg += "Jdec will verify user specified input parameters...\n";
0206:                    System.out.println(mesg);
0207:
0208:                    verifyConfigProperties();
0209:
0210:                    String path = "";
0211:                    /*
0212:                     * if(Configuration.wasJarSpecified() &&
0213:                     * Configuration.wasSingleClassSpecified()) { mesg+="Jdec was
0214:                     * Provided options jar as well as input\n"; mesg+="Jdec will now
0215:                     * OVERRIDE jar option and will proceed to decompile the input
0216:                     * .class File specified \""+Configuration.getJavaClassFile()+"\"
0217:                     * ...\n\n"; if(Configuration.getDecompileroption().equals("jar")) {
0218:                     * Configuration.setDecompileroption("dc"); }
0219:                     * path=Configuration.getJavaClassFile(); }
0220:                     */
0221:                    if (Configuration.wasJarSpecified()
0222:                            && Configuration.wasSingleClassSpecified()
0223:                            && Configuration.getDecompileroption()
0224:                                    .equals("jar")) {
0225:                        mesg += "Jdec was Run with options jar\n";
0226:                        path = Configuration.getJarPath();
0227:
0228:                    }
0229:                    if (Configuration.wasJarSpecified()
0230:                            && Configuration.wasSingleClassSpecified()
0231:                            && !Configuration.getDecompileroption().equals(
0232:                                    "jar")) {
0233:
0234:                        path = Configuration.getJavaClassFile();
0235:
0236:                    }
0237:
0238:                    if (Configuration.wasJarSpecified()
0239:                            && Configuration.wasSingleClassSpecified() == false) {
0240:                        mesg += "Jdec was Run with options jar\n";
0241:                        path = Configuration.getJarPath();
0242:
0243:                    }
0244:                    if (!Configuration.wasJarSpecified()
0245:                            && Configuration.wasSingleClassSpecified()) {
0246:
0247:                        path = Configuration.getJavaClassFile();
0248:
0249:                    }
0250:
0251:                    // path=Util.getClassPath();
0252:                    if (path.equalsIgnoreCase("***Not-Initialized***")) {
0253:                        java.lang.String message = "";
0254:                        message = "Check whether the Default entry(***Not-Initialized***) has been changed or not...";
0255:                        AllExceptionHandler handler = new AllExceptionHandler(
0256:                                new InvalidInputException(message));
0257:                        handler.reportException();
0258:                        System.out
0259:                                .println("[ERROR] Please check the input settings to Jdec again");
0260:                        System.out
0261:                                .println("Please check the log output for more details");
0262:                        System.exit(1);
0263:                    }
0264:
0265:                    // path=checkFilePath(path);
0266:                    if (!validInput(path)) {
0267:                        String message = "[ERROR :]\tClass file/Jar File not reachable....\n";
0268:                        message += "Check whether the File Exists \n";
0269:                        AllExceptionHandler handler = new AllExceptionHandler(
0270:                                message);
0271:                        handler.sendMessage();
0272:                        System.out.println("Input Path specified by user :"
0273:                                + path + "\n");
0274:                        System.out
0275:                                .println("[ERROR] Please check the input settings to Jdec again");
0276:                        System.out
0277:                                .println("Please check the log output for more details");
0278:                        System.exit(1);
0279:                    } else {
0280:                        // Register ClassPath in Configuration Class For Retrieveing
0281:                        // Later...
0282:                        Configuration.setClassFilePath(path);
0283:                        String tooloption = Configuration.getDecompileroption();
0284:                        // System.out.println(tooloption+" tooloption");
0285:                        if (tooloption.equals("jar")) {
0286:                            Util
0287:                                    .explodeJar(new File(Configuration
0288:                                            .getJarPath()));
0289:                            decompileJarFromConsole(Configuration.getJarPath(),
0290:                                    Util.getRegisteredClasses());
0291:                        } else if (tooloption.equals("llv")) {
0292:                            showLocalVariables(path);
0293:                        } else if (tooloption.equals("dc")) {
0294:                            couldNotFinish = new ArrayList();
0295:                            addLicence = true;
0296:                            try {
0297:                                decompileClass(path);
0298:                            } catch (Exception exp) {
0299:                                AllExceptionHandler h1 = new AllExceptionHandler(
0300:                                        exp);
0301:                                h1.reportException();
0302:                                System.out
0303:                                        .println("Exception occured while decompiling class");
0304:                                System.out
0305:                                        .println("Please check the log output for more details");
0306:                                System.exit(1);
0307:                            }
0308:
0309:                            currentDepthLevel = 0;
0310:                            setResultFilePath(Configuration
0311:                                    .getOutputFolderPath()
0312:                                    + File.separator
0313:                                    + getClassNameWithExtension());
0314:                            decompileInnerClasses(); // TODO Also Fix For The UI side
0315:                            // also later
0316:                            // Now need to concatenate inner class content here
0317:                            Configuration.setClassFilePath(mainRoot
0318:                                    .getClassPath());
0319:                            java.lang.String importedclassesInInnerclasses = "";
0320:
0321:                            // if(!Configuration.getInlineInnerClassMethodContent().equalsIgnoreCase("true"))
0322:                            // {
0323:                            if (innerClassesDecompied != null
0324:                                    && innerClassesDecompied.size() != 0) {
0325:                                java.lang.String innerClassFileContents = "";
0326:                                for (int s = 0; s < innerClassesDecompied
0327:                                        .size(); s++) {
0328:                                    java.lang.String classfilepath = (java.lang.String) innerClassesDecompied
0329:                                            .get(s);
0330:                                    try {
0331:                                        java.lang.String currentFileContent = "";
0332:                                        java.lang.String cname = getClassName(classfilepath);
0333:                                        if (cname.indexOf(".") != -1) {
0334:                                            cname = cname.substring(0, cname
0335:                                                    .indexOf("."));
0336:                                            cname = cname
0337:                                                    + "."
0338:                                                    + Configuration
0339:                                                            .getFileExtension();
0340:                                            classfilepath = Configuration
0341:                                                    .getOutputFolderPath()
0342:                                                    + File.separator + cname;
0343:                                        } else {
0344:                                            cname = cname
0345:                                                    + "."
0346:                                                    + Configuration
0347:                                                            .getFileExtension();
0348:                                            classfilepath = Configuration
0349:                                                    .getOutputFolderPath()
0350:                                                    + File.separator + cname;
0351:                                        }
0352:                                        File temp = new File(classfilepath);
0353:                                        FileInputStream fis = new FileInputStream(
0354:                                                temp);
0355:                                        BufferedInputStream bis = new BufferedInputStream(
0356:                                                fis);
0357:                                        BufferedReader br = new BufferedReader(
0358:                                                new InputStreamReader(bis));
0359:                                        java.lang.String line = null;
0360:                                        while ((line = br.readLine()) != null) {
0361:                                            currentFileContent += line + "\n";
0362:                                        }
0363:                                        if (currentFileContent.trim().length() != 0) {
0364:                                            // TODO: Remove Imports and store elsewhere
0365:                                            int importend = currentFileContent
0366:                                                    .indexOf("// End of Import");
0367:                                            importedclassesInInnerclasses = "";
0368:                                            if (importend != -1) {
0369:                                                java.lang.String p = currentFileContent
0370:                                                        .substring(0, importend);
0371:                                                currentFileContent = currentFileContent
0372:                                                        .substring(importend
0373:                                                                + "// End of Import"
0374:                                                                        .length());
0375:                                                importedclassesInInnerclasses += p;
0376:                                            }
0377:                                            innerClassFileContents += currentFileContent;
0378:                                            innerClassFileContents += "\n\n//End Of a Inner Class File Content...\n\n";
0379:                                        }
0380:
0381:                                        temp = null;
0382:                                        fis = null;
0383:                                        bis = null;
0384:                                        br = null;
0385:                                        System.gc();
0386:
0387:                                    } catch (IOException ioe) {
0388:
0389:                                    }
0390:                                }
0391:                                if (innerClassFileContents.trim().length() != 0) {
0392:                                    innerClassFileContents = checkForLicenceAndPackageInInnerClassContent(innerClassFileContents);
0393:                                    java.lang.String mainFileContent = "";
0394:                                    java.lang.String cname = getClassName(mainRoot
0395:                                            .getClassPath());
0396:                                    java.lang.String mainfilepath = "";
0397:                                    if (cname.indexOf(".") != -1) {
0398:                                        cname = cname.substring(0, cname
0399:                                                .indexOf("."));
0400:                                        cname = cname
0401:                                                + "."
0402:                                                + Configuration
0403:                                                        .getFileExtension();
0404:                                        mainfilepath = Configuration
0405:                                                .getOutputFolderPath()
0406:                                                + File.separator + cname;
0407:                                    } else {
0408:                                        cname = cname
0409:                                                + "."
0410:                                                + Configuration
0411:                                                        .getFileExtension();
0412:                                        mainfilepath = Configuration
0413:                                                .getOutputFolderPath()
0414:                                                + File.separator + cname;
0415:                                    }
0416:                                    File mainfile = new File(mainfilepath);
0417:                                    FileInputStream fis = new FileInputStream(
0418:                                            mainfile);
0419:                                    BufferedInputStream bis = new BufferedInputStream(
0420:                                            fis);
0421:                                    BufferedReader br = new BufferedReader(
0422:                                            new InputStreamReader(bis));
0423:                                    java.lang.String line = null;
0424:                                    while ((line = br.readLine()) != null) {
0425:                                        mainFileContent += line + "\n";
0426:                                    }
0427:
0428:                                    java.lang.String completeContent = mainFileContent;
0429:                                    completeContent += "\n\n//Beginning of Inner Class Content...\n\n ";
0430:                                    completeContent += innerClassFileContents;
0431:
0432:                                    // Write back to Main File
0433:                                    if (mainfile.exists()) {
0434:                                        mainfile.delete();
0435:                                    }
0436:
0437:                                    mainfile = new File(mainfilepath);
0438:                                    mainfile.createNewFile();
0439:                                    try {
0440:                                        FileOutputStream fos = new FileOutputStream(
0441:                                                mainfile);
0442:                                        BufferedWriter bw = new BufferedWriter(
0443:                                                new OutputStreamWriter(fos));
0444:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
0445:                                                .replaceAll(
0446:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
0447:                                                        "");
0448:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
0449:                                                .replaceAll("\n\n", "\n");
0450:                                        completeContent = completeContent
0451:                                                .replaceAll(
0452:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
0453:                                                        "");
0454:                                        Iterator classNames = getClazzObjects()
0455:                                                .keySet().iterator();
0456:                                        java.lang.String classname = "";
0457:                                        while (classNames.hasNext()) {
0458:                                            classname = (java.lang.String) classNames
0459:                                                    .next();
0460:                                            break;
0461:                                        }
0462:
0463:                                        /*
0464:                                         * if(classname.indexOf(".")!=-1) {
0465:                                         * 
0466:                                         * java.lang.String
0467:                                         * pkg=classname.substring(0,classname.lastIndexOf("."));
0468:                                         * //bw.write("package "+pkg+";\n\n"); }
0469:                                         */
0470:                                        completeContent = completeContent
0471:                                                .replaceAll("this\\$",
0472:                                                        "This\\$");
0473:                                        bw.write(completeContent);
0474:                                        // bw.write("/**** List of All Imported Classes
0475:                                        // ***/");
0476:                                        completeContent = completeContent
0477:                                                .replaceAll("\n\n", "\n");
0478:                                        if (importedclassesInInnerclasses
0479:                                                .endsWith("\n")) {
0480:                                            int n = importedclassesInInnerclasses
0481:                                                    .lastIndexOf("\n");
0482:                                            if (n != -1) {
0483:                                                importedclassesInInnerclasses = importedclassesInInnerclasses
0484:                                                        .substring(0, n);
0485:                                            }
0486:
0487:                                        }
0488:                                        // bw.write(importedclassesInInnerclasses);
0489:                                        completeContent = checkForImportDuplicates(
0490:                                                importedclassesInInnerclasses,
0491:                                                completeContent);
0492:
0493:                                        int present = completeContent
0494:                                                .indexOf(localvariablenote);
0495:
0496:                                        completeContent = completeContent
0497:                                                .replaceAll(localVarNote, "");
0498:
0499:                                        bw.flush();
0500:                                        bw.close();
0501:                                    } catch (IOException ioe) {
0502:
0503:                                    }
0504:
0505:                                }
0506:
0507:                            }
0508:                            // }
0509:                            /*
0510:                             * else { }
0511:                             */
0512:                            // Restore orig classpath when over
0513:                        } else if (tooloption.equals("vcp")) {
0514:
0515:                            constantPool(path);
0516:
0517:                        } else if (tooloption.equals("help")) {
0518:                            showHelp();
0519:                        } else if (tooloption.equals("nocode")) {
0520:                            showSkeletonClass(path);
0521:
0522:                        } else if (tooloption.equals("dis")) {
0523:                            disassemble(path);
0524:                        } else {
0525:                            AllExceptionHandler handler = new AllExceptionHandler(
0526:                                    "Invalid Option passed to jdec...\nPlease set jdec_option as help and execute ....");
0527:                            handler.sendMessage();
0528:                            System.exit(1);
0529:                        }
0530:
0531:                    }
0532:
0533:                }
0534:
0535:                catch (IOException ioe) {
0536:                    AllExceptionHandler handler = new AllExceptionHandler(ioe);
0537:                    handler.reportException();
0538:
0539:                }
0540:
0541:                catch (InvalidInputException IIE) {
0542:                    try {
0543:
0544:                        System.out
0545:                                .println("Invalid Options provided to Jdec....");
0546:                        System.out.println("Jdec will now terminate....\n");
0547:                        System.out
0548:                                .println("NOTE: If no HELP message is visible here , Please check the log files Or \n Change the Log_Mode to console....\n");
0549:                        Util.showUsage();
0550:                    } catch (IOException iousage) {
0551:
0552:                    }
0553:
0554:                } finally {
0555:                    closeLogWriter();
0556:                    long endTime = System.currentTimeMillis();
0557:                    double duration = (double) (endTime - startTime) / 1000;
0558:                    System.out.println("\n\nJDec took " + duration
0559:                            + " seconds to complete...");
0560:                }
0561:
0562:            }
0563:
0564:            private static void closeLogWriter() {
0565:                Writer writer = null;
0566:                try {
0567:                    writer = Writer.getWriter("log");
0568:                    if (writer != null) {
0569:                        java.util.Date d = new java.util.Date();
0570:                        writer
0571:                                .writeLog("\n\nCurrent Run Of Jdec Terminated At Time "
0572:                                        + d.toString());
0573:                        // Let These System.outs be . SO The user will come to know when
0574:                        // the
0575:                        // jdec has terminated and can check the log files and out
0576:                        // put files
0577:                        System.out.println("Decompiler was Run With option "
0578:                                + Configuration.getDecompileroption());
0579:                        if (Configuration.getLogMode().equalsIgnoreCase("file")) {
0580:                            System.out
0581:                                    .println("Please Check The Log Files For Details");
0582:                            // System.out.println("Please Check The Output Files For
0583:                            // Details");
0584:                        } else if (Configuration.getLogMode().equalsIgnoreCase(
0585:                                "console")) {
0586:                            System.out
0587:                                    .println("Please Check The Log Output in the console For Further Details");
0588:                            // System.out.println("Please Check the Decompiler output in
0589:                            // the console ");
0590:                        }
0591:                        if (Configuration.getOutputMode().equalsIgnoreCase(
0592:                                "file")) {
0593:                            System.out
0594:                                    .println("Please Check The Decompiled Output in Output Folder");
0595:                            // System.out.println("Please Check The Output Files For
0596:                            // Details");
0597:                        } else if (Configuration.getOutputMode()
0598:                                .equalsIgnoreCase("console")) {
0599:                            System.out
0600:                                    .println("Please Check The Decompiled  Output in the console ");
0601:                            // System.out.println("Please Check the Decompiler output in
0602:                            // the console ");
0603:                        }
0604:                        System.out
0605:                                .println("Current Run Of Jdec Terminated At Time "
0606:                                        + d.toString());
0607:                        writer.flush();
0608:                    }
0609:                } catch (IOException e) {
0610:                    // Leave Blank. Cannot do anything This is the place where logwriter
0611:                    // is closed
0612:                } finally {
0613:                    if (writer != null) {
0614:                        writer.close("log");
0615:                    }
0616:                }
0617:
0618:            }
0619:
0620:            private static java.lang.String showConstantPool(
0621:                    java.lang.String path) {
0622:                java.lang.String cpooldesc = "";
0623:                try {
0624:                    InputStream readerStream = null;
0625:                    try {
0626:                        readerStream = VerifyClassFile(path);
0627:                    } catch (MalFormedClassException mfe) {
0628:                        AllExceptionHandler handler = new AllExceptionHandler(
0629:                                mfe);
0630:                        handler.reportException();
0631:                        JFrame mainFrame = UILauncher.getMainFrame();
0632:                        if (mainFrame != null) {
0633:                            Manager.getManager().setShowProgressBar(false);
0634:                            java.lang.String msg = "Invalid Class Specified As Input To Jdec..\n";
0635:                            msg += mfe.getMessage() + "\n";
0636:                            JOptionPane.showMessageDialog(UILauncher
0637:                                    .getMainFrame(), msg,
0638:                                    "Run Jdec Decompiler",
0639:                                    JOptionPane.ERROR_MESSAGE);
0640:                            throw new Exception();
0641:                        }
0642:                        throw new Exception();
0643:
0644:                    }
0645:                    cpooldesc = processOnlyConstantPool(readerStream);
0646:
0647:                } catch (Exception mfe) {
0648:                    AllExceptionHandler handler = new AllExceptionHandler(mfe);
0649:                    handler.reportException();
0650:                    JFrame mainFrame = UILauncher.getMainFrame();
0651:                    if (mainFrame != null) {
0652:                        Manager.getManager().setShowProgressBar(false);
0653:                        try {
0654:                            UIManager.setLookAndFeel(UILauncher.getUIutil()
0655:                                    .getCurrentLNF());
0656:                            SwingUtilities.updateComponentTreeUI(UILauncher
0657:                                    .getMainFrame());
0658:                        } catch (Exception e) {
0659:
0660:                        }
0661:                        return null;
0662:                    } else {
0663:                        System.out
0664:                                .println("Jdec encountered an FatalException. Jdec will now exit..");
0665:                        System.exit(1);
0666:                    }
0667:
0668:                }
0669:                return cpooldesc;
0670:            }
0671:
0672:            public static boolean validInput(String path) {
0673:
0674:                File file = new File(path);
0675:                if (file.exists())
0676:                    return true;
0677:                else
0678:                    return false;
0679:
0680:            }
0681:
0682:            public static void showLocalVariables(String path) {
0683:
0684:                try {
0685:                    InputStream readerStream = null;
0686:                    try {
0687:                        readerStream = VerifyClassFile(path);
0688:                    } catch (MalFormedClassException mfe) {
0689:                        AllExceptionHandler handler = new AllExceptionHandler(
0690:                                mfe);
0691:                        handler.reportException();
0692:                        JFrame mainFrame = UILauncher.getMainFrame();
0693:                        if (mainFrame != null) {
0694:                            Manager.getManager().setShowProgressBar(false);
0695:                            java.lang.String msg = "Invalid Class Specified As Input To Jdec..\n";
0696:                            msg += mfe.getMessage() + "\n";
0697:                            JOptionPane.showMessageDialog(UILauncher
0698:                                    .getMainFrame(), msg,
0699:                                    "Run Jdec Decompiler",
0700:                                    JOptionPane.ERROR_MESSAGE);
0701:                            try {
0702:                                UIManager.setLookAndFeel(UILauncher.getUIutil()
0703:                                        .getCurrentLNF());
0704:                                SwingUtilities.updateComponentTreeUI(UILauncher
0705:                                        .getMainFrame());
0706:                            } catch (Exception e) {
0707:
0708:                            }
0709:                            throw new Exception();
0710:                        } else {
0711:                            System.out
0712:                                    .println("Jdec encountered an FatalException. Jdec will now exit..");
0713:                            System.exit(1);
0714:                        }
0715:                    }
0716:                    processClassFile(readerStream);
0717:                    displayLocalVariables();
0718:
0719:                } catch (Exception mfe) {
0720:
0721:                }
0722:
0723:            }
0724:
0725:            public static java.lang.String decompileClass(String path)
0726:                    throws Exception {
0727:                UIUtil.codeReformatted = false;
0728:                allImportedClasses = new ArrayList();
0729:                java.lang.String classDesc = "";
0730:                boolean notinner = false;
0731:                try {
0732:                    InputStream readerStream = VerifyClassFile(path);
0733:                    ClassDescription cd = processClassFile(readerStream);
0734:
0735:                    // Skip Decompiling This Class ???
0736:                    /**
0737:                     * This is applicable for jdecoption : jar This was introduced to
0738:                     * support filters from UI
0739:                     */
0740:
0741:                    if (Configuration.getDecompileroption().equals("jar")
0742:                            || Configuration.getDecompileroption().equals(
0743:                                    "decompileJar")) {
0744:                        Iterator classNames = getClazzObjects().keySet()
0745:                                .iterator(); // TODO:Modify
0746:                        // this
0747:                        // later
0748:                        // No
0749:                        // need
0750:                        // of
0751:                        // iterator
0752:                        // Here
0753:                        java.lang.String cname = (java.lang.String) classNames
0754:                                .next();
0755:                        java.lang.String pkg = "";
0756:                        if (cname != null && cname.indexOf(".") != -1) {
0757:
0758:                            pkg = cname.substring(0, cname.lastIndexOf("."));
0759:                            boolean skip = skipClazzDecompilation(pkg);
0760:                            if (skip)
0761:                                return "";
0762:                        }
0763:                    }
0764:
0765:                    // NOTE by belurs:
0766:                    /*******************************************************************
0767:                     * The Folllowing 3 stmts are used to create InnerClassTracker for
0768:                     * The current Main Class being Decompiled i.e The class file
0769:                     * specified in config.properties File This tracker will be used for
0770:                     * the current class and any inner class contained in this class or
0771:                     * any inner class reachable from this class
0772:                     * 
0773:                     * For Jar File , it refers to the current File being decompiled in
0774:                     * the jar
0775:                     */
0776:                    tracker = new InnerClassTracker(cd);
0777:                    InnerClassTracker.Node node = tracker.createNode(path,
0778:                            getClassName(path));
0779:                    boolean b = cd.isClassCompiledWithMinusG();
0780:                    node.setCompiledWithMinusG(b);
0781:                    if (mainRoot == null) {
0782:                        InnerClassTracker.rootnodes = new ArrayList();
0783:                    }
0784:                    tracker.addRootNode(node);
0785:                    Configuration.setPathForCurrentClassFile(path);
0786:                    if (mainRoot == null) {
0787:
0788:                        mainRoot = node;
0789:                        notinner = true;
0790:                    } else {
0791:                        notinner = false;
0792:                        currentNode = node;
0793:                    }
0794:                    currentRootAdded = node;
0795:                    currentClassMethods = new ArrayList();
0796:                    innerClassStructures = new ArrayList();
0797:                    formCodeStatements(cd);
0798:                    java.lang.String pth = getPackagePathFromRootForThisClass();
0799:
0800:                    File op = new File(Configuration.getBkpoppath()
0801:                            + File.separator + pth);
0802:                    if (op.exists() == false)
0803:                        op.mkdirs();
0804:                    Configuration.setOutputFolderPath(op.getAbsolutePath());
0805:                    classDesc = displayClass(true, "dc", cd.getClassName());
0806:                    classDesc = classDesc.replaceAll("this\\$", "This\\$");
0807:                    classDesc = classDesc.replaceAll("this$", "This$");
0808:                    node.setHasBeenDecompiled(true);
0809:
0810:                } catch (MalFormedClassException mfe) {
0811:                    currentdecompiledtext = "";
0812:                    AllExceptionHandler handler = new AllExceptionHandler(mfe);
0813:                    handler.reportException();
0814:                    JFrame mainFrame = UILauncher.getMainFrame();
0815:                    if (mainFrame != null) {
0816:
0817:                        if (Configuration.getDecompileroption().equals("jar") == false
0818:                                && Configuration.getDecompileroption().equals(
0819:                                        "decompileJar") == false) {
0820:                            Manager.getManager().setShowProgressBar(false);
0821:                            java.lang.String msg = "Unsupported Class Specified As Input To Jdec..\n";
0822:                            msg += mfe.getMessage() + "\n";
0823:                            JOptionPane.showMessageDialog(UILauncher
0824:                                    .getMainFrame(), msg,
0825:                                    "Run Jdec Decompiler",
0826:                                    JOptionPane.ERROR_MESSAGE);
0827:                            try {
0828:                                UIManager.setLookAndFeel(UILauncher.getUIutil()
0829:                                        .getCurrentLNF());
0830:                                SwingUtilities.updateComponentTreeUI(UILauncher
0831:                                        .getMainFrame());
0832:                            } catch (Exception e) {
0833:
0834:                            }
0835:                            throw new RuntimeException(
0836:                                    "Unsupported Class Version found..Current task will now stop");
0837:                        }
0838:                        if (Configuration.getDecompileroption().equals("jar")
0839:                                || Configuration.getDecompileroption().equals(
0840:                                        "decompileJar")) {
0841:                            throw mfe;
0842:                        }
0843:                    } else {
0844:                        System.out
0845:                                .println("Jdec encountered an FatalException. jdec will now exit..");
0846:                        System.exit(1);
0847:                    }
0848:                } catch (Exception exp) {
0849:                    currentdecompiledtext = "";
0850:                    AllExceptionHandler handler = new AllExceptionHandler(exp);
0851:                    handler.reportException();
0852:                    JFrame mainFrame = UILauncher.getMainFrame();
0853:                    if (mainFrame != null) {
0854:
0855:                        if (Configuration.getDecompileroption().equals("jar") == false
0856:                                && Configuration.getDecompileroption().equals(
0857:                                        "decompileJar") == false) {
0858:                            Manager.getManager().setShowProgressBar(false);
0859:                            throw exp;
0860:                        }
0861:                        if (Configuration.getDecompileroption().equals("jar")
0862:                                || Configuration.getDecompileroption().equals(
0863:                                        "decompileJar")) {
0864:                            throw exp;
0865:                        }
0866:
0867:                    } else {
0868:                        System.out
0869:                                .println("Jdec encountered an FatalException. Jdec will now exit..");
0870:                        System.exit(1);
0871:                    }
0872:
0873:                }
0874:
0875:                if (notinner) {
0876:                    ClassStructure mainCS = new ClassStructure();
0877:                    mainClassStructure = mainCS;
0878:                    mainCS.setName(mainRoot.getClassName());
0879:                    mainCS.setMethods(currentClassMethods);
0880:                    boolean add = addClassStructure(mainRoot.getClassName());
0881:                    if (add)
0882:                        allClassStructures.add(mainCS);
0883:                } else {
0884:                    ClassStructure aCS = new ClassStructure();
0885:                    aCS.setName(currentNode.getClassName());
0886:                    aCS.setMethods(currentClassMethods);
0887:                    boolean add = addClassStructure(currentNode.getClassName());
0888:                    if (add)
0889:                        allClassStructures.add(aCS);
0890:                }
0891:
0892:                currentdecompiledtext = classDesc;
0893:                return classDesc;
0894:            }
0895:
0896:            private static void formCodeStatements(ClassDescription cd) {
0897:                Hashtable ht = getClazzObjects();
0898:                Iterator it = ht.keySet().iterator();
0899:                while (it.hasNext()) {
0900:                    String classname = (java.lang.String) it.next();
0901:                    JavaClass clazz = (JavaClass) ht.get(classname);
0902:                    // Disassemble Each Method
0903:                    /**
0904:                     * 
0905:                     * Basically The following 2 loops will just store the disassembled
0906:                     * code in a manner so that API external to reflection API Can acess
0907:                     * that behaviour and show its disassembled code...
0908:                     * 
0909:                     * 
0910:                     */
0911:
0912:                    ArrayList cons = clazz.getConstructors();
0913:                    Iterator consIt = cons.iterator();
0914:                    if (cons.size() > 8)
0915:                        Configuration.setLogLevel("2");
0916:                    while (consIt.hasNext()) {
0917:                        l3 = System.currentTimeMillis();
0918:                        Behaviour b = (Behaviour) consIt.next();
0919:                        boolean skip = skipBehaviour(b);
0920:                        if (!b.isHasBeenDissassembled() && !skip) {
0921:                            b.setHasBeenDissassembled(true);
0922:                            Decompiler decompiler = new Decompiler(b, cd);
0923:                            if (b.getCode() != null) {
0924:
0925:                                if (UIUtil.getUIUtil() != null) {
0926:                                    JDialog pf = UIUtil.getProgressBarFrame();
0927:                                    if (pf != null) {
0928:                                        pf.setTitle("In Progress...");
0929:                                        UIUtil.proframedetails_class
0930:                                                .setText("");
0931:                                        UIUtil.proframedetails.revalidate();
0932:                                        UIUtil.proframedetails.repaint();
0933:                                        UIUtil.proframedetails_pkg
0934:                                                .setText("Package :"
0935:                                                        + clazz
0936:                                                                .getPackageName());
0937:                                        UIUtil.proframedetails_class
0938:                                                .setText("Current Class :"
0939:                                                        + clazz.getSimpleName());
0940:                                        UIUtil.proframedetails_method
0941:                                                .setText("Current Method :"
0942:                                                        + b.getBehaviourName());
0943:                                        UIUtil.proframedetails_pkg
0944:                                                .setFont(new Font("Monospaced",
0945:                                                        Font.BOLD, 12));
0946:                                        UIUtil.proframedetails_pkg
0947:                                                .setForeground(Color.BLUE);
0948:                                        UIUtil.proframedetails_class
0949:                                                .setFont(new Font("Monospaced",
0950:                                                        Font.BOLD, 12));
0951:                                        UIUtil.proframedetails_class
0952:                                                .setForeground(Color.BLUE);
0953:                                        UIUtil.proframedetails_method
0954:                                                .setFont(new Font("Monospaced",
0955:                                                        Font.BOLD, 12));
0956:                                        UIUtil.proframedetails_method
0957:                                                .setForeground(Color.BLUE);
0958:                                        UIUtil.proframedetails.revalidate();
0959:                                        UIUtil.proframedetails.repaint();
0960:
0961:                                        // UIUtil.getProgressBarFrame().repaint();
0962:                                    }
0963:                                }
0964:                                // ADD
0965:                                String bname = b.getBehaviourName();
0966:                                String mname = bname.concat(b
0967:                                        .getUserFriendlyMethodParams());
0968:                                currentClassMethods.add(mname);
0969:                                decompiler.decompileCode();
0970:                            } else {
0971:                                // ADD
0972:                                String bname = b.getBehaviourName();
0973:                                String mname = bname.concat(b
0974:                                        .getUserFriendlyMethodParams());
0975:                                currentClassMethods.add(mname);
0976:                                b.replaceBuffer("");
0977:                            }
0978:                            decompiler = null;
0979:                        }
0980:
0981:                    }
0982:
0983:                    ArrayList met = clazz.getDecalaredMethods();
0984:                    if (met.size() > 5)
0985:                        Configuration.setLogLevel("2");
0986:                    Iterator metIt = met.iterator();
0987:                    while (metIt.hasNext()) {
0988:                        l3 = System.currentTimeMillis();
0989:                        Behaviour b = (Behaviour) metIt.next();
0990:                        boolean skip = skipBehaviour(b);
0991:                        if (!b.isHasBeenDissassembled() && !skip) {
0992:                            b.setHasBeenDissassembled(true);
0993:                            Decompiler decompiler = new Decompiler(b, cd);
0994:                            if (UIUtil.getUIUtil() != null) {
0995:                                JDialog pf = UIUtil.getProgressBarFrame();
0996:                                if (pf != null) {
0997:                                    pf.setTitle("In Progress...");
0998:                                    UIUtil.proframedetails_class.setText("");
0999:                                    UIUtil.proframedetails.revalidate();
1000:                                    UIUtil.proframedetails.repaint();
1001:                                    UIUtil.proframedetails_pkg
1002:                                            .setText("Package :"
1003:                                                    + clazz.getPackageName());
1004:                                    UIUtil.proframedetails_class
1005:                                            .setText("Current Class :"
1006:                                                    + clazz.getSimpleName());
1007:                                    UIUtil.proframedetails_pkg
1008:                                            .setFont(new Font("Monospaced",
1009:                                                    Font.BOLD, 12));
1010:                                    UIUtil.proframedetails_pkg
1011:                                            .setForeground(Color.BLUE);
1012:                                    UIUtil.proframedetails_method
1013:                                            .setText("Current Method :"
1014:                                                    + b.getBehaviourName());
1015:                                    UIUtil.proframedetails_class
1016:                                            .setFont(new Font("Monospaced",
1017:                                                    Font.BOLD, 12));
1018:                                    UIUtil.proframedetails_class
1019:                                            .setForeground(Color.BLUE);
1020:                                    UIUtil.proframedetails_method
1021:                                            .setFont(new Font("Monospaced",
1022:                                                    Font.BOLD, 12));
1023:                                    UIUtil.proframedetails_method
1024:                                            .setForeground(Color.BLUE);
1025:                                    UIUtil.proframedetails.revalidate();
1026:                                    UIUtil.proframedetails.repaint();
1027:
1028:                                }
1029:                            }
1030:                            if (b.getCode() != null) {
1031:                                // ADD
1032:                                String bname = b.getBehaviourName();
1033:                                if (bname.equals("this")) {
1034:                                    bname = "jdecThis/**[ Originally this(method name) ]**/ ";
1035:                                }
1036:                                String mname = bname.concat(b
1037:                                        .getUserFriendlyMethodParams());
1038:                                currentClassMethods.add(mname);
1039:
1040:                                decompiler.decompileCode();
1041:                            } else {
1042:                                String bname = b.getBehaviourName();
1043:                                if (bname.equals("this")) {
1044:                                    bname = "jdecThis/**[ Originally this(method name) ]**/ ";
1045:                                }
1046:                                String mname = bname.concat(b
1047:                                        .getUserFriendlyMethodParams());
1048:                                currentClassMethods.add(mname);
1049:                                b.replaceBuffer("");
1050:                            }
1051:                            decompiler = null;
1052:                        }
1053:                    }
1054:
1055:                    // TODO
1056:                    // Print The Class Along with disassembled code
1057:                    // for each method in that Class.
1058:
1059:                }
1060:
1061:            }
1062:
1063:            public static String checkFilePath(String path) {
1064:
1065:                if (path == null)
1066:                    return null;
1067:                char oldChar = '@';
1068:                char newChar = '@';
1069:                int unixPath = path.indexOf("/");
1070:                int winPath = path.indexOf("\\");
1071:                if (unixPath != -1) {
1072:                    if (unixPath != File.separatorChar) {
1073:                        oldChar = '/';
1074:                        newChar = '\\';
1075:                    }
1076:                } else {
1077:                    if (winPath != -1 && winPath != File.separatorChar) {
1078:                        oldChar = '\\';
1079:                        newChar = '/';
1080:                    }
1081:                }
1082:                if (oldChar != '@' || newChar != '@')
1083:                    path = path.replace(oldChar, newChar);
1084:
1085:                return path;
1086:
1087:            }
1088:
1089:            private static InputStream VerifyClassFile(String path)
1090:                    throws MalFormedClassException {
1091:                Reader reader = Reader.createStreamReader(path);
1092:                InputStream readerStream = reader.getStreamReader();
1093:
1094:                boolean ok = checkMagic(readerStream, path);
1095:                if (ok == true) {
1096:                    ok = checkVersion(readerStream);
1097:                    if (!ok) {
1098:                        throw new MalFormedClassException(
1099:                                "Invalid Version Number for class file "
1100:                                        + getVesion());
1101:                    }
1102:                    magicNumber = Constants.CLASS_MAGIC_NUMBER;
1103:                } else {
1104:                    throw new MalFormedClassException(
1105:                            "Invalid Magic Number For Class File...."
1106:                                    + geterrormagicnumber() + "\n");
1107:                }
1108:
1109:                return readerStream;
1110:
1111:            }
1112:
1113:            public static java.lang.String geterrormagicnumber() {
1114:                return errormagicnumber;
1115:            }
1116:
1117:            private static java.lang.String errormagicnumber = "-1";
1118:
1119:            private static boolean checkMagic(InputStream is, String path) {
1120:                int magic = -1;
1121:                try {
1122:                    boolean validFile = false;
1123:                    DataInputStream dis = null;
1124:
1125:                    if (is instanceof  DataInputStream) {
1126:                        dis = (DataInputStream) is;
1127:
1128:                    } else // Should Ideally Not Happen As we are passing a DIS...
1129:                    {
1130:                        dis = new DataInputStream(new BufferedInputStream(is));
1131:                    }
1132:
1133:                    // Read Magic Number
1134:
1135:                    magic = dis.readInt();
1136:                    // LOG the Magic Number of the Class...
1137:                    Writer logwriter = Writer.getWriter("log");
1138:                    String classname = getClassName(path);
1139:                    logwriter.writeLog("[INFO]Magic Number of the Class \""
1140:                            + classname
1141:                            + "\" Is "
1142:                            + new String(Integer.toHexString(magic))
1143:                                    .toUpperCase());
1144:                    logwriter.writeLog("\n");
1145:                    logwriter.flush();
1146:
1147:                }
1148:
1149:                catch (IOException ioe) {
1150:                    AllExceptionHandler handler = new AllExceptionHandler(ioe);
1151:                    handler.reportException();
1152:                }
1153:                // Check Here
1154:                errormagicnumber = new String(Integer.toHexString(magic))
1155:                        .toUpperCase();
1156:                if (magic == Constants.CLASS_MAGIC_NUMBER) {
1157:                    return true;
1158:                } else
1159:                    return false;
1160:
1161:            }
1162:
1163:            public static float getVesion() {
1164:                return version;
1165:            }
1166:
1167:            private static boolean checkVersion(InputStream is) {
1168:
1169:                int minor_version = -1;
1170:                int major_version = -1;
1171:                float class_file_format_version = -1;
1172:                try {
1173:                    DataInputStream dis = null;
1174:                    if (is instanceof  DataInputStream) {
1175:                        dis = (DataInputStream) is;
1176:                    } else // Should Ideally Not Happen As we are passing a DIS...
1177:                    {
1178:                        dis = new DataInputStream(new BufferedInputStream(is));
1179:                    }
1180:
1181:                    minor_version = dis.readUnsignedShort();
1182:                    major_version = dis.readUnsignedShort();
1183:
1184:                    class_file_format_version = major_version
1185:                            + (minor_version / 100);
1186:                    Writer logwriter = Writer.getWriter("log");
1187:                    logwriter.writeLog("[INFO]class Version is "
1188:                            + class_file_format_version + "\n\n");
1189:                    logwriter.flush();
1190:
1191:                } catch (IOException ioe) {
1192:                    AllExceptionHandler handler = new AllExceptionHandler(ioe);
1193:                    handler.reportException();
1194:
1195:                }
1196:                supportedVersion = true;
1197:                if (class_file_format_version >= 45.0f
1198:                        && class_file_format_version <= 48.0f) {
1199:                    setClassMajorVersionNumber(major_version);
1200:                    setClassMinorVersionNumber(minor_version);
1201:                    return true;
1202:                } else {
1203:                    boolean versionCheck;
1204:                    if (UILauncher.getMainFrame() != null) {
1205:                        versionCheck = UIUtil.getUIUtil()
1206:                                .getSkipClassVersionCheck().equalsIgnoreCase(
1207:                                        "true");
1208:                    } else {
1209:                        versionCheck = Configuration.getSkipClassVersionCheck()
1210:                                .equalsIgnoreCase("true");
1211:                    }
1212:                    if (versionCheck) {
1213:                        setClassMajorVersionNumber(major_version);
1214:                        setClassMinorVersionNumber(minor_version);
1215:                        supportedVersion = false;
1216:                        try {
1217:                            Writer writer = Writer.getWriter("log");
1218:                            writer
1219:                                    .writeLog("Class File Version Number: "
1220:                                            + class_file_format_version
1221:                                            + " is not supported officially\nHowever Jdec will try to decompile the class now.\n");
1222:                            writer
1223:                                    .writeLog("To disable such class file decompilation , please specify false for skip_class_version_check in \t\tconfig.properties");
1224:                        } catch (IOException ex) {
1225:
1226:                        }
1227:                        return true;
1228:                    } else {
1229:                        version = class_file_format_version;
1230:                        return false;
1231:                    }
1232:                }
1233:
1234:            }
1235:
1236:            private static void setClassMajorVersionNumber(int n) {
1237:                majorversion = n;
1238:            }
1239:
1240:            private static void setClassMinorVersionNumber(int n) {
1241:                minorversion = n;
1242:            }
1243:
1244:            private static int majorversion = -1;
1245:
1246:            private static int minorversion = -1;
1247:
1248:            public static int getMajorVersion() {
1249:                return majorversion;
1250:            }
1251:
1252:            public static int getMinorVersion() {
1253:                return minorversion;
1254:            }
1255:
1256:            public static String getClassName(String path) {
1257:                String slash = "";
1258:                if (path.indexOf("\\") != -1) {
1259:                    slash = "\\";
1260:                } else {
1261:                    slash = "/";
1262:                }
1263:                int lastSlash = path.lastIndexOf(slash);
1264:                if (lastSlash != -1) {
1265:                    classDir = path.substring(0, lastSlash);
1266:                }
1267:                return path.substring(lastSlash + 1);
1268:
1269:            }
1270:
1271:            public static String getClassDir() {
1272:                return classDir;
1273:            }
1274:
1275:            private static java.lang.String classDir = "";
1276:
1277:            private static ClassDescription processClassFile(InputStream is) {
1278:
1279:                initializeJvmInstructionMap();
1280:                ClassDescription cd = new ClassDescription();
1281:                try {
1282:                    Writer logr = Writer.getWriter("log");
1283:                    DataInputStream dis = null;
1284:                    if (is instanceof  DataInputStream) {
1285:                        dis = (DataInputStream) is;
1286:                    } else // Should Ideally Not Happen As we are passing a DIS...
1287:                    {
1288:                        dis = new DataInputStream(new BufferedInputStream(is));
1289:                    }
1290:                    JDialog proframe = UIUtil.getProgressBarFrame();
1291:                    if (proframe != null) {
1292:                        proframe.setTitle("Creating Constant Pool ...");
1293:                    }
1294:                    CPool.createConstantPool(dis);
1295:                    logr.writeLog("\nConstant Pool Created ", Configuration
1296:                            .getLogLevel());
1297:
1298:                    if (proframe != null) {
1299:                        proframe.setTitle("Constant Pool Created ");
1300:                    }
1301:
1302:                    CPool cpoolobj = new CPool();
1303:                    cd.setConstantPool(cpoolobj); // Not Needed actually.No use of
1304:                    // setting also since all members
1305:                    // are static : belurs
1306:                    cd.readAccessSpecifiers(dis);
1307:                    logr.writeLog("\nAccess specifiers for class registered ",
1308:                            Configuration.getLogLevel());
1309:                    if (proframe != null) {
1310:                        proframe
1311:                                .setTitle("Access specifiers for class registered ");
1312:                    }
1313:                    cd.readClassAndSuperClassInfo(dis);
1314:                    logr.writeLog(
1315:                            "\nThis class and Super class Names Regsitered",
1316:                            Configuration.getLogLevel());
1317:                    cd.readInterfaceInformation(dis);
1318:                    logr.writeLog("\nInterfaces for this class registered",
1319:                            Configuration.getLogLevel());
1320:                    cd.readFieldInformation(dis);
1321:                    logr.writeLog(
1322:                            "\nField Information for this class registered",
1323:                            Configuration.getLogLevel());
1324:                    if (proframe != null) {
1325:                        proframe
1326:                                .setTitle("Field Information for this class registered ");
1327:                    }
1328:                    cd.readMethodInformation(dis);
1329:                    logr.writeLog(
1330:                            "\nMethod Information for this class registered ",
1331:                            Configuration.getLogLevel());
1332:                    if (proframe != null) {
1333:                        proframe
1334:                                .setTitle("Method Information for this class registered ");
1335:                    }
1336:                    clazzObjects = new Hashtable();
1337:                    logr.writeLog(
1338:                            "\nCreating Reflection Details For This Class... ",
1339:                            Configuration.getLogLevel());
1340:                    cd.populateReflection(clazzObjects);
1341:                    logr
1342:                            .writeLog(
1343:                                    "\nReflection Details For This Class Registered... ",
1344:                                    Configuration.getLogLevel());
1345:                    if (proframe != null) {
1346:                        proframe
1347:                                .setTitle("Reflection Access Details Created... ");
1348:                    }
1349:
1350:                } catch (IOException ioe) {
1351:                    AllExceptionHandler handler = new AllExceptionHandler(ioe);
1352:                    handler.reportException();
1353:                    return null;
1354:                } catch (Throwable t) {
1355:                    t.printStackTrace();
1356:                    AllExceptionHandler handler = new AllExceptionHandler(t);
1357:                    handler.reportException();
1358:                    return null;
1359:                }
1360:                return cd;
1361:            }
1362:
1363:            private static java.lang.String processOnlyConstantPool(
1364:                    InputStream is) {
1365:                try {
1366:                    DataInputStream dis = null;
1367:                    if (is instanceof  DataInputStream) {
1368:                        dis = (DataInputStream) is;
1369:                    } else // Should Ideally Not Happen As we are passing a DIS...
1370:                    {
1371:                        dis = new DataInputStream(new BufferedInputStream(is));
1372:                    }
1373:
1374:                    CPool.createConstantPool(dis);
1375:
1376:                } catch (IOException ioe) {
1377:                    AllExceptionHandler handler = new AllExceptionHandler(ioe);
1378:                    handler.reportException();
1379:                    JFrame mainFrame = UILauncher.getMainFrame();
1380:                    if (mainFrame == null) {
1381:                        System.exit(1);
1382:                    }
1383:                }
1384:                return CPool.returnConstantPoolDesc();
1385:            }
1386:
1387:            /**
1388:             * This method is an exception to the case of writing log statements It does
1389:             * not use the writer objects in this project... It directly used System.out
1390:             * Stream to output help statements... This is so that The user can
1391:             * immediately see the mistake in the console....
1392:             */
1393:
1394:            public static void showHelp() {
1395:                try {
1396:
1397:                    System.out
1398:                            .println("******* Welcome to Jdec Decompiler help option *******");
1399:                    System.out
1400:                            .println("\nThis tool is meant to convert a .class file to a resultant output file");
1401:                    System.out
1402:                            .println("...containing the decompiled java code...");
1403:                    System.out
1404:                            .println("Following are the options Supported For This Release...");
1405:                    System.out
1406:                            .println("1>\tDecompile Class File...option is dc");
1407:                    System.out
1408:                            .println("2>\tDecompile Jar File...option is jar");
1409:                    System.out
1410:                            .println("3>\tDisplay Constant Pool contents...option is vcp");
1411:                    System.out
1412:                            .println("4>\tDisplay Disassembled output...option is dis");
1413:                    System.out
1414:                            .println("5>\tDisplay Skeleton Class...option is nocode");
1415:                    System.out.println("6>\tView Help again...option is help");
1416:                    System.out.println("\n\n");
1417:                    System.out
1418:                            .println("NOTE: It is not necessary to specify any argument while running Jdec");
1419:                    System.out
1420:                            .println("Just Ensure the config.properties File has Values set properly");
1421:                    System.out
1422:                            .println("Also you can update the consolefilter.properties to chnage file filte level settings for jar decompilation");
1423:                    System.out
1424:                            .println("\nHowever the user should remember that by specifying any parameter and value \nfrom Command Prompt Or By specifying arguments to the main class in the .bat file\nthose values  will then override any value in Configuration.properties File");
1425:                    Thread.sleep(5000);
1426:                    System.exit(0);
1427:                } catch (Exception e) {
1428:                    // Do Nothing
1429:                }
1430:
1431:            }
1432:
1433:            public static void showSkeletonClass(String path) {
1434:                try {
1435:                    InputStream readerStream = VerifyClassFile(path);
1436:                    ClassDescription cd = processClassFile(readerStream);
1437:                    displayClass(false, null, cd.getClassName());
1438:
1439:                } catch (MalFormedClassException mfe) {
1440:                    AllExceptionHandler handler = new AllExceptionHandler(mfe);
1441:                    handler.reportException();
1442:                    JFrame mainFrame = UILauncher.getMainFrame();
1443:                    if (mainFrame != null) {
1444:                        Manager.getManager().setShowProgressBar(false);
1445:                        java.lang.String msg = "Invalid Class Specified As Input To Jdec..\n";
1446:                        msg += mfe.getMessage() + "\n";
1447:                        JOptionPane.showMessageDialog(
1448:                                UILauncher.getMainFrame(), msg,
1449:                                "Run Jdec Decompiler",
1450:                                JOptionPane.ERROR_MESSAGE);
1451:                        try {
1452:                            UIManager.setLookAndFeel(UILauncher.getUIutil()
1453:                                    .getCurrentLNF());
1454:                            SwingUtilities.updateComponentTreeUI(UILauncher
1455:                                    .getMainFrame());
1456:                        } catch (Exception e) {
1457:
1458:                        }
1459:                    } else {
1460:                        System.out
1461:                                .println("Jdec encountered an FatalException. Jdec will now exit..");
1462:                        System.exit(1);
1463:                    }
1464:                }
1465:            }
1466:
1467:            /**
1468:             * @param showMethodCode
1469:             *            boolean variable to indicate whether Code has to be displayed
1470:             *            or not for this method... <p/> Usage : true: In Case of
1471:             *            disassemble option or decompile option false: In case of
1472:             *            dis_nocode option
1473:             * @param typeofcodedisplay
1474:             *            Indicates the manner in which code has to be displayed Usage
1475:             *            dis: In case of disassemble option dc : In case of decompile
1476:             *            option null: In case of dis_nocode option <p/> Example Full
1477:             *            usage: displayClass(false,null) for dis_nocode option.
1478:             */
1479:            static java.lang.String classDescdup = "";
1480:
1481:            private static java.lang.String displayClass(
1482:                    boolean showMethodCode, java.lang.String typeofcodedisplay,
1483:                    String classname) {
1484:                StringBuffer temp = new StringBuffer();
1485:                java.lang.String classDescCopy = "";
1486:                java.lang.String importedFiles = "";
1487:                classDescdup = "";
1488:                java.lang.String licenceWarning = getLicenceWarning();
1489:                if (addLicence)
1490:                    temp.append(licenceWarning);
1491:                Iterator classNames = getClazzObjects().keySet().iterator(); // TODO:Modify
1492:                // this
1493:                // later
1494:                // No
1495:                // need
1496:                // of
1497:                // iterator
1498:                // Here
1499:                java.lang.String cname = (java.lang.String) classNames.next();
1500:                java.lang.String pkg = "";
1501:                if (cname != null && cname.indexOf(".") != -1) {
1502:
1503:                    pkg = classname.substring(0, classname.lastIndexOf("."));
1504:                    temp.append("package " + pkg + ";\n \n");
1505:                }
1506:
1507:                if (allImportedClasses != null && allImportedClasses.size() > 0) {
1508:                    importedFiles = showImportedClasses(allImportedClasses,
1509:                            classname);
1510:                    temp.append(importedFiles);
1511:                }
1512:                temp.append("#INTERFACE_IMPORT_PLACEHOLDER");
1513:                temp.append("#ABSTRACT_METHOD_IMPORT_PLACEHOLDER");
1514:                temp.append("\n// End of Import\n\n");
1515:                classNames = getClazzObjects().keySet().iterator();
1516:                while (classNames.hasNext()) {
1517:                    java.lang.String name = (java.lang.String) classNames
1518:                            .next();
1519:
1520:                    JavaClass cl = (JavaClass) getClazzObjects().get(name);
1521:                    String accesstypes = cl.getUserFriendlyAccessSpecifiers();
1522:                    if (accesstypes.indexOf("interface") != -1)
1523:                        cl.setInterface(true);
1524:
1525:                    if (!supportedVersion) {
1526:                        String versionStmt = "\n/***\n\tClass Version > 48.0.\n ";
1527:                        versionStmt += "\tCurrent supported version is upto 48.0. By default jdec tries to decompile such classes.\n";
1528:                        versionStmt += "\tTo turn off support for such classes please set false to Skip_Class_Version_Check in config.properties\n ***/\n";
1529:                        temp.append(versionStmt + "\n");
1530:                    }
1531:                    if (accesstypes != null)
1532:                        temp.append(accesstypes);
1533:                    if (accesstypes.indexOf("interface") == -1)
1534:                        temp.append("class");
1535:                    StringBuffer st = new StringBuffer("");
1536:                    Util.checkForImport(name, st, true);
1537:                    temp.append("  " + st.toString() + "  ");
1538:
1539:                    if (!cl.getSuperclassname().equals(
1540:                            "I am not initialized!!!")
1541:                            && accesstypes.indexOf("interface") == -1) {
1542:                        st = new StringBuffer("");
1543:                        Util.checkForImport(cl.getSuperclassname(), st);
1544:                        if (getClazzRef().getQualifiedSuperClassName().indexOf(
1545:                                "java.lang.Object") != -1) {
1546:                            if (getShowextendsobject())
1547:                                temp.append("extends  " + st.toString());
1548:                        } else
1549:                            temp.append("extends  " + st.toString());
1550:                    }
1551:                    StringBuffer interfaceImports = new StringBuffer("");
1552:                    if (cl.getInterfacesImplemented().size() > 0) {
1553:                        if (accesstypes.indexOf("interface") == -1)
1554:                            temp.append("  implements  ");
1555:                        else
1556:                            temp.append("  extends  ");
1557:                        for (int i = 0; i < cl.getInterfacesImplemented()
1558:                                .size(); i++) {
1559:                            st = new StringBuffer("");
1560:                            String str = cl.getInterfacesImplemented().get(i)
1561:                                    .toString();
1562:                            if (importedFiles.indexOf(str) == -1) {
1563:                                java.lang.String s = Util.checkForImport(str,
1564:                                        st);
1565:                                // if(!allImportedClasses.contains(s))
1566:                                interfaceImports.append("import " + s + ";\n");
1567:                                temp.append(st.toString());
1568:                                if (i == 0
1569:                                        && cl.getInterfacesImplemented().size() > 1)
1570:                                    temp.append(" , ");
1571:                                if (i > 0
1572:                                        && i != cl.getInterfacesImplemented()
1573:                                                .size() - 1)
1574:                                    temp.append(" , ");
1575:                            } else {
1576:                                java.lang.String s = Util.checkForImport(str,
1577:                                        st);
1578:                                temp.append(st.toString());
1579:                                if (i == 0
1580:                                        && cl.getInterfacesImplemented().size() > 1)
1581:                                    temp.append(" , ");
1582:                                if (i > 0
1583:                                        && i != cl.getInterfacesImplemented()
1584:                                                .size() - 1)
1585:                                    temp.append(" , ");
1586:                            }
1587:                        }
1588:                    }
1589:                    java.lang.String contentStr = temp.toString().replaceAll(
1590:                            "#INTERFACE_IMPORT_PLACEHOLDER",
1591:                            interfaceImports.toString());
1592:                    temp = new StringBuffer(contentStr + "\n");
1593:
1594:                    temp.append("\n{\n");
1595:                    // System.out.println(temp.toString());
1596:                    ArrayList allfields = cl.getDecalaredFields();
1597:                    StringBuffer fieldDesc = new StringBuffer();
1598:                    if (allfields != null && allfields.size() > 0)
1599:                        fieldDesc = new StringBuffer(
1600:                                " /***\n **Class Fields\n ***/\n");
1601:                    collectFeildDetails(allfields, fieldDesc);
1602:                    String newLine = "";
1603:                    if (fieldDesc.toString().trim().length() != 0)
1604:                        newLine = "\n";
1605:                    java.lang.String classDesc = temp.toString();
1606:                    if (getShowfieldsfirst())
1607:                        classDesc = classDesc.concat(newLine).concat(
1608:                                fieldDesc.toString());
1609:                    // System.out.println(classDesc.toString());
1610:                    StringBuffer methodDesc = new StringBuffer();
1611:                    ArrayList allMethods = cl.getALLMethods();
1612:                    classDescdup = classDesc;
1613:                    StringBuffer newimports = new StringBuffer("");
1614:                    try {
1615:                        collectMethodDetails(allMethods, methodDesc,
1616:                                showMethodCode, typeofcodedisplay, cl,
1617:                                importedFiles, newimports);
1618:                    } catch (ApplicationException e) {
1619:                        AllExceptionHandler handler = new AllExceptionHandler(e);
1620:                        handler.reportException();
1621:
1622:                    }
1623:                    classDesc = classDesc.toString().concat(
1624:                            methodDesc.toString());
1625:                    classDesc = classDesc.toString().replaceFirst(
1626:                            "#ABSTRACT_METHOD_IMPORT_PLACEHOLDER",
1627:                            newimports.toString());
1628:                    if (!getShowfieldsfirst()) {
1629:                        if (allfields != null && allfields.size() > 0)
1630:                            classDesc = classDesc.toString().concat(
1631:                                    newLine + "\n")
1632:                                    .concat(fieldDesc.toString());
1633:                        else
1634:                            classDesc = classDesc.toString();
1635:                    }
1636:
1637:                    classDesc = classDesc.toString().concat("\n}");
1638:
1639:                    classDescCopy = classDesc;
1640:                    // System.out.println(classDesc.toString());
1641:
1642:                    // Send to output
1643:                    Writer outputwriter = null;
1644:                    try {
1645:
1646:                        outputwriter = Writer.getWriter("output");
1647:                        // Why is some part commented?
1648:                        /*
1649:                         * if(classDesc.indexOf("JdecGenerated")!=-1)// &&
1650:                         * Configuration.getDecompileroption().equals("dc")) {
1651:                         * java.lang.String note="/****\nNOTE: THe decompiled
1652:                         * statmements contain some Temporary Variables. \n(Beginning
1653:                         * with JdecGenerated) Jdec Generates These while" ; note+="
1654:                         * \nprocessing blocks like NEW. However the actual variable in
1655:                         * the code\n then gets assigned to the respective temporary
1656:                         * variable.***\n"; localvariablenote=note;
1657:                         * 
1658:                         * classDesc+="\n\n\n"+note; }
1659:                         */
1660:
1661:                        if (getDummyVarNoteStatus()) {
1662:                            java.lang.String note = "/*****\nNOTE: THe decompiled statmements contain some local variables with $ as part of the name...";
1663:                            note += " \nThis means that those variables are not used in the code at all...That is there is no access to the variable\n";
1664:                            note += " Either by means of getting the variable content or by means of storing them....";
1665:                            note += "\n\n[JUST AS A POINT OF INTEREST TO THE USER, Jdec SETS THE POSITION IN THE CODE \nWHERE THE LOCAL VARIABLE IS FIRST ";
1666:                            note += "ENCOUNTERED AS PART OF THE VARIABLE NAME\n AFTER THE FIRST DASH .]\n****/\n";
1667:                            classDesc += "\n\n\n" + note;
1668:                        }
1669:                        outputwriter.writeOutput(classDesc);
1670:                        outputwriter.flush();
1671:                    } catch (IOException ioe) {
1672:                        AllExceptionHandler handler = new AllExceptionHandler(
1673:                                ioe);
1674:                        handler.reportException();
1675:                    }
1676:
1677:                    finally {
1678:
1679:                        // if(Configuration.getDecompileroption().equals("jar"))
1680:                        // {
1681:                        outputwriter.close("output");
1682:                        // }
1683:
1684:                    }
1685:
1686:                }
1687:                return classDescCopy;
1688:            }
1689:
1690:            public static Hashtable getClazzObjects() {
1691:                return clazzObjects;
1692:            }
1693:
1694:            public static void setClazzObjects(Hashtable clazzObjects) {
1695:                ConsoleLauncher.clazzObjects = clazzObjects;
1696:            }
1697:
1698:            private static void collectFeildDetails(ArrayList allfields,
1699:                    StringBuffer temp) {
1700:                Iterator it = allfields.iterator();
1701:
1702:                while (it.hasNext()) {
1703:                    FieldMember f = (FieldMember) it.next();
1704:                    int br = f.getUnParsedDataType().indexOf("[");
1705:                    boolean addBrackets = false;
1706:                    if (br == -1 && f.getDimension() > 0) {
1707:                        addBrackets = true;
1708:                    }
1709:                    String fieldType = f.getDataType();
1710:                    String brk = "";
1711:                    if (addBrackets) {
1712:                        for (int v = 1; v <= f.getDimension(); v++) {
1713:                            brk += "[]";
1714:                        }
1715:                        fieldType = fieldType + " " + brk;
1716:                    }
1717:
1718:                    StringBuffer bf = new StringBuffer("");
1719:                    Util.checkForImport(fieldType, bf);
1720:                    fieldType = bf.toString();
1721:                    if (fieldType.indexOf("/") != -1) {
1722:                        fieldType = fieldType.replaceAll("/", ".");
1723:                    }
1724:                    java.lang.String fieldContent = ((f
1725:                            .getUserFriendlyAccessSpecifiers().trim().length() == 0) ? ""
1726:                            : Util
1727:                                    .formatFieldsOrMethodHeader(f
1728:                                            .getUserFriendlyAccessSpecifiers(),
1729:                                            "field"))
1730:                            + fieldType + "  " + f.getName();
1731:                    fieldContent = fieldContent.replaceAll("this", "This");
1732:                    //fieldContent = fieldContent.replaceAll("this\\$", "This\\$");
1733:                    //fieldContent = fieldContent.replaceAll("this$", "This$");
1734:                    fieldContent = Util.formatFieldsOrMethodHeader(
1735:                            fieldContent, "field");
1736:                    temp.append(fieldContent);
1737:                    Object value = f.getFieldValue();
1738:                    java.lang.String fieldDesc = "";// (value!=null)?"
1739:                    // ="+value.toString()+";":";";
1740:                    if (value != null) {
1741:                        fieldDesc = "=" + value.toString();
1742:                        if (fieldType != null
1743:                                && fieldType.trim().equals("long")) {
1744:                            fieldDesc += "L" + ";";
1745:                        } else if (fieldType != null
1746:                                && fieldType.trim().equals("float")) {
1747:                            fieldDesc += "f" + ";";
1748:                        } else if (fieldType != null
1749:                                && fieldType.trim().equals("double")) {
1750:                            fieldDesc += "D" + ";";
1751:                        } else {
1752:                            fieldDesc += ";";
1753:                        }
1754:                    } else {
1755:                        fieldDesc = ";";
1756:                    }
1757:                    fieldDesc = Util.formatFieldsOrMethodHeader(fieldDesc,
1758:                            "field");
1759:                    temp.append(fieldDesc);
1760:                    temp.append("\n");
1761:                    // System.out.println(temp.toString());
1762:                }
1763:                temp.append("\n\n");
1764:            }
1765:
1766:            private static Hashtable clazzObjects = new Hashtable();
1767:
1768:            private static void collectMethodDetails(ArrayList allMethods,
1769:                    StringBuffer methodDesc, boolean showCode,
1770:                    java.lang.String typeofdisplay, JavaClass cl,
1771:                    String importfiles, StringBuffer newimports)
1772:                    throws ApplicationException {
1773:
1774:                method_names_signature = new HashMap();
1775:
1776:                method_names_methodref = new HashMap();
1777:                // CASE 1: option is dis_nocode:
1778:                if (showCode == false) {
1779:                    Iterator allMethodsIt = allMethods.iterator();
1780:                    // methodDesc.append("\n\t");
1781:                    while (allMethodsIt.hasNext()) {
1782:
1783:                        Behaviour method = (Behaviour) allMethodsIt.next();
1784:                        StringBuffer t = new StringBuffer("");
1785:                        Util.checkForImport(method.getReturnType(), t);
1786:                        String bname = method.getBehaviourName();
1787:                        boolean this found = false;
1788:                        if (bname.equals("this")) {
1789:                            bname = "jdecThis";
1790:                            this found = true;
1791:                        }
1792:                        java.lang.String methodAccessor = method
1793:                                .getUserFriendlyMethodAccessors()
1794:                                + " " + t.toString() + " " + bname;
1795:                        if (method.getReturnType().trim().length() == 0) {
1796:                            if (method.getUserFriendlyMethodAccessors().trim()
1797:                                    .length() == 0) {
1798:                                methodAccessor = method.getBehaviourName();
1799:                            }
1800:                        }
1801:                        if (method.getReturnType().trim().length() != 0) {
1802:                            if (method.getUserFriendlyMethodAccessors().trim()
1803:                                    .length() == 0) {
1804:                                // methodAccessor=method.getReturnType()+"
1805:                                // "+method.getBehaviourName();
1806:                                java.lang.String rettype = method
1807:                                        .getReturnType();
1808:                                int pos = rettype.lastIndexOf(".");
1809:                                if (pos == -1)
1810:                                    pos = rettype.lastIndexOf("/");
1811:                                if (pos != -1) {
1812:                                    java.lang.String simpleName = rettype
1813:                                            .substring(pos + 1);
1814:                                    addImportClass(rettype.replace('/', '.'));
1815:                                    rettype = simpleName;
1816:
1817:                                }
1818:                                methodAccessor = rettype + " "
1819:                                        + method.getBehaviourName();
1820:                            }
1821:                        }
1822:                        methodAccessor = Util.formatFieldsOrMethodHeader(
1823:                                methodAccessor, "method");
1824:                        methodDesc.append(methodAccessor);
1825:
1826:                        if (method.getBehaviourName().trim().equals("static") == false) {
1827:
1828:                            methodDesc.append(getAllMethodParams(method
1829:                                    .getUserFriendlyMethodParams(), method, cl,
1830:                                    importfiles, newimports));
1831:                            java.lang.String[] exceptionTypesDecalred = method
1832:                                    .getExceptionTypes();
1833:                            for (int count = 0; count < exceptionTypesDecalred.length; count++) {
1834:                                if (count == 0)
1835:                                    methodDesc.append(" \t"
1836:                                            + Util.formatFieldsOrMethodHeader(
1837:                                                    "\n throws ", "method"));
1838:                                methodDesc.append(exceptionTypesDecalred[count]
1839:                                        .replace('/', '.'));
1840:                                if (count != exceptionTypesDecalred.length - 1)
1841:                                    methodDesc.append("  ,");
1842:                            }
1843:                            if (exceptionTypesDecalred.length > 0) {
1844:                                //methodDesc.append("\n");
1845:                            }
1846:                        }
1847:                        java.lang.String accs = method
1848:                                .getUserFriendlyMethodAccessors();
1849:                        if (accs.indexOf("native") >= 0
1850:                                || accs.indexOf("abstract") >= 0) {
1851:                            methodDesc.append(";\n\n");
1852:                        } else {
1853:
1854:                            methodDesc.append(Util.formatFieldsOrMethodHeader(
1855:                                    "\n{\n", "method"));
1856:                            methodDesc.append("\n");
1857:                            methodDesc.append(Util.formatFieldsOrMethodHeader(
1858:                                    "}\n\n", "method"));
1859:
1860:                        }
1861:
1862:                        // System.out.println(methodDesc.toString());
1863:
1864:                    }
1865:                }
1866:                // CASE 2 and 3
1867:                else {
1868:                    // No need to test for showCode = true
1869:                    if (typeofdisplay.equals("dis")) {
1870:
1871:                        Iterator allMethodsIt = allMethods.iterator();
1872:                        // methodDesc.append("\n\t");
1873:                        while (allMethodsIt.hasNext()) {
1874:
1875:                            Behaviour method = (Behaviour) allMethodsIt.next();
1876:                            boolean skip = skipBehaviour(method);
1877:                            if (skip)
1878:                                continue;
1879:                            StringBuffer t = new StringBuffer("");
1880:                            Util.checkForImport(method.getReturnType(), t);
1881:                            java.lang.String methodAccessor = method
1882:                                    .getUserFriendlyMethodAccessors()
1883:                                    + " "
1884:                                    + t.toString()
1885:                                    + " "
1886:                                    + method.getBehaviourName();
1887:                            if (method.getReturnType().trim().length() == 0) {
1888:                                if (method.getUserFriendlyMethodAccessors()
1889:                                        .trim().length() == 0) {
1890:                                    methodAccessor = method.getBehaviourName();
1891:                                }
1892:                            }
1893:                            if (method.getReturnType().trim().length() != 0) {
1894:                                if (method.getUserFriendlyMethodAccessors()
1895:                                        .trim().length() == 0) {
1896:                                    // methodAccessor=method.getReturnType()+"
1897:                                    // "+method.getBehaviourName();
1898:                                    java.lang.String rettype = method
1899:                                            .getReturnType();
1900:                                    int pos = rettype.lastIndexOf(".");
1901:                                    if (pos == -1)
1902:                                        pos = rettype.lastIndexOf("/");
1903:                                    if (pos != -1) {
1904:                                        java.lang.String simpleName = rettype
1905:                                                .substring(pos + 1);
1906:                                        addImportClass(rettype
1907:                                                .replace('/', '.'));
1908:                                        rettype = simpleName;
1909:
1910:                                    }
1911:                                    methodAccessor = rettype + " "
1912:                                            + method.getBehaviourName();
1913:                                }
1914:                            }
1915:                            methodAccessor = Util.formatFieldsOrMethodHeader(
1916:                                    methodAccessor, "method");
1917:                            methodDesc.append(methodAccessor);
1918:                            if (method.getBehaviourName().trim().equals(
1919:                                    "static") == false) {
1920:                                methodDesc.append(getAllMethodParams(method
1921:                                        .getUserFriendlyMethodParams(), method,
1922:                                        cl, importfiles, newimports));
1923:                                java.lang.String[] exceptionTypesDecalred = method
1924:                                        .getExceptionTypes();
1925:                                for (int count = 0; count < exceptionTypesDecalred.length; count++) {
1926:                                    if (count == 0)
1927:                                        methodDesc
1928:                                                .append(" \t"
1929:                                                        + Util
1930:                                                                .formatFieldsOrMethodHeader(
1931:                                                                        "\n throws ",
1932:                                                                        "method"));
1933:                                    methodDesc
1934:                                            .append(exceptionTypesDecalred[count]
1935:                                                    .replace('/', '.'));
1936:                                    if (count != exceptionTypesDecalred.length - 1)
1937:                                        methodDesc.append("  ,");
1938:                                }
1939:                                if (exceptionTypesDecalred.length > 0) {
1940:                                    //methodDesc.append("\n");
1941:                                }
1942:                            }
1943:                            java.lang.String accs = method
1944:                                    .getUserFriendlyMethodAccessors();
1945:                            if (accs.indexOf("native") >= 0
1946:                                    || accs.indexOf("abstract") >= 0) {
1947:                                methodDesc.append(";\n\n");
1948:                            } else {
1949:
1950:                                methodDesc.append(Util
1951:                                        .formatFieldsOrMethodHeader("\n{\n",
1952:                                                "method"));
1953:                                boolean skipCode = didThisMethodFail(method);
1954:                                if (!skipCode) {
1955:                                    // BigInteger bh;
1956:                                    methodDesc.append(method
1957:                                            .getVMInstructions());
1958:                                    methodDesc.append("\n");
1959:                                    methodDesc.append(Util
1960:                                            .formatFieldsOrMethodHeader(
1961:                                                    "}\n\n", "method"));
1962:                                    methodDesc
1963:                                            .append(getAnyExceptionTableDetails(method));
1964:
1965:                                    methodDesc
1966:                                            .append("\n\n-----------------------------------------------");
1967:                                    // methodDesc.append("-----------------------------------------------");
1968:                                    // methodDesc.append("-----------------------------------------------");
1969:                                    methodDesc
1970:                                            .append("-----------------------------------------------\n\n");
1971:                                } else {
1972:                                    java.lang.String message = "\n/***Could Not disassemble This Method.\n";
1973:                                    message += "A Runtime Exception Occured while decompiling This method....\n";
1974:                                    message += "Please Check up the log message for this method and \n";
1975:                                    message += "send The following details to project admin at its home page..\n ";
1976:                                    message += "    1>Log File\n";
1977:                                    message += "     2>Class File\n";
1978:                                    message += "     3>Java Version***/\n";
1979:                                    methodDesc.append(Util
1980:                                            .formatDecompiledStatement(message)
1981:                                            + "\n");
1982:                                    methodDesc.append(Util
1983:                                            .formatFieldsOrMethodHeader(
1984:                                                    "}\n\n", "method"));
1985:                                }
1986:                            }
1987:
1988:                            // System.out.println(methodDesc.toString());
1989:
1990:                        }
1991:
1992:                    } else if (typeofdisplay.equals("dc")) {
1993:
1994:                        Iterator allMethodsIt = allMethods.iterator();
1995:                        // methodDesc.append("\n\t");
1996:                        while (allMethodsIt.hasNext()) {
1997:
1998:                            Behaviour method = (Behaviour) allMethodsIt.next();
1999:                            String completedesc = "";
2000:                            boolean skip = skipBehaviour(method);
2001:                            if (skip)
2002:                                continue;
2003:                            StringBuffer t = new StringBuffer("");
2004:                            Util.checkForImport(method.getReturnType(), t);
2005:                            StringBuffer t2 = new StringBuffer("");
2006:                            Util.checkForImport(method.getBehaviourName(), t2);
2007:                            boolean this found = false;
2008:                            if (t2.toString().equals("this")) {
2009:                                t2 = new StringBuffer("jdecThis");
2010:                                this found = true;
2011:                            }
2012:                            java.lang.String methodAccessor = method
2013:                                    .getUserFriendlyMethodAccessors()
2014:                                    + " " + t.toString() + " " + t2.toString();// method.getBehaviourName();
2015:                            if (method.getReturnType().trim().length() == 0) {
2016:                                if (method.getUserFriendlyMethodAccessors()
2017:                                        .trim().length() == 0) {
2018:                                    String bname = method.getBehaviourName();
2019:                                    if (bname.equals("this")) {
2020:                                        bname = "jdecThis";
2021:                                        this found = true;
2022:                                    }
2023:                                    methodAccessor = bname;
2024:                                }
2025:                            }
2026:                            if (method.getReturnType().trim().length() != 0) {
2027:                                if (method.getUserFriendlyMethodAccessors()
2028:                                        .trim().length() == 0) {
2029:                                    // methodAccessor=method.getReturnType()+"
2030:                                    // "+method.getBehaviourName();
2031:                                    java.lang.String rettype = method
2032:                                            .getReturnType();
2033:                                    int pos = rettype.lastIndexOf(".");
2034:                                    if (pos == -1)
2035:                                        pos = rettype.lastIndexOf("/");
2036:                                    if (pos != -1) {
2037:                                        java.lang.String simpleName = rettype
2038:                                                .substring(pos + 1);
2039:                                        addImportClass(rettype
2040:                                                .replace('/', '.'));
2041:                                        rettype = simpleName;
2042:
2043:                                    }
2044:                                    String bname = method.getBehaviourName();
2045:                                    if (bname.equals("this")) {
2046:                                        bname = "jdecThis";
2047:                                        this found = true;
2048:                                    }
2049:                                    methodAccessor = rettype + " " + bname;
2050:                                }
2051:                            }
2052:                            methodAccessor = Util.formatFieldsOrMethodHeader(
2053:                                    methodAccessor, "method");
2054:
2055:                            // ClassStructure
2056:                            // cst=InnerClassTracker.getClassStructure(cl.getClassName()+".class",allClassStructures);
2057:
2058:                            String identifierComment = "";
2059:                            // "//"+
2060:                            // " DO NOT REMOVE COMMENT\n";
2061:
2062:                            identifierComment += "//  CLASS: "
2063:                                    + cl.getClassName() + ":" + "\n";
2064:                            methodDesc.append(identifierComment);
2065:                            completedesc += identifierComment;
2066:                            completedesc += methodAccessor;
2067:                            if (completedesc.endsWith("jdecThis")) {
2068:                                completedesc += "/**[ Originally this(method name) ]**/ ";
2069:                            }
2070:                            if (this found) {
2071:                                methodAccessor = methodAccessor
2072:                                        + "/**[ Originally this(method name) ]**/ ";
2073:                            }
2074:                            methodDesc.append(methodAccessor);
2075:                            if (method.getBehaviourName().trim().equals(
2076:                                    "static") == true) {
2077:                                methodDesc
2078:                                        .append("      //[Static Initializer]");
2079:                            }
2080:                            if (method.getBehaviourName().trim().equals(
2081:                                    "static") == false) {
2082:                                String mp = getAllMethodParams(method
2083:                                        .getUserFriendlyMethodParams(), method,
2084:                                        cl, importfiles, newimports);
2085:                                methodDesc.append(mp);
2086:                                completedesc += mp;
2087:                                java.lang.String[] exceptionTypesDecalred = method
2088:                                        .getExceptionTypes();
2089:                                for (int count = 0; count < exceptionTypesDecalred.length; count++) {
2090:                                    if (count == 0)
2091:                                        methodDesc
2092:                                                .append(" \t"
2093:                                                        + Util
2094:                                                                .formatFieldsOrMethodHeader(
2095:                                                                        "\n throws ",
2096:                                                                        "method"));
2097:                                    methodDesc
2098:                                            .append(exceptionTypesDecalred[count]
2099:                                                    .replace('/', '.'));
2100:                                    if (count != exceptionTypesDecalred.length - 1)
2101:                                        methodDesc.append("  ,");
2102:                                }
2103:                                if (exceptionTypesDecalred.length > 0) {
2104:                                    //methodDesc.append("\n");
2105:                                }
2106:                            }
2107:                            java.lang.String accs = method
2108:                                    .getUserFriendlyMethodAccessors();
2109:                            // Map names with complete Signature
2110:                            // [Static Initializer]
2111:                            String bname = method.getBehaviourName();
2112:                            if (bname.equals("this")) {
2113:                                bname = "jdecThis/**[ Originally this(method name) ]**/ ";
2114:                            }
2115:
2116:                            String mn = bname.concat(method
2117:                                    .getUserFriendlyMethodParams());
2118:
2119:                            if (method.getBehaviourName().equals("static")) {
2120:                                completedesc += "      //[Static Initializer]";
2121:                            }
2122:                            if (method.getBehaviourName().equals("this")) {
2123:
2124:                                bname = "jdecThis/**[ Originally this(method name) ]**/ ";
2125:                            }
2126:                            if (completedesc.length() > 0) {
2127:                                completedesc = completedesc.substring(0,
2128:                                        completedesc.length() - 1);
2129:                            }
2130:                            method_names_signature.put(mn, completedesc);
2131:                            method_names_methodref.put(mn, method);
2132:                            if (accs.indexOf("native") >= 0
2133:                                    || accs.indexOf("abstract") >= 0) {
2134:                                methodDesc.append(";\n\n");
2135:                            } else {
2136:
2137:                                methodDesc.append(Util
2138:                                        .formatFieldsOrMethodHeader("\n{\n",
2139:                                                "method"));
2140:                                boolean skipCode = didThisMethodFail(method);
2141:                                if (!skipCode) {
2142:                                    // BigInteger bh;
2143:                                    methodDesc.append(method
2144:                                            .getCodeStatements());
2145:                                    methodDesc.append("\n");
2146:                                    methodDesc.append(Util
2147:                                            .formatFieldsOrMethodHeader(
2148:                                                    "}\n\n", "method"));
2149:                                } else {
2150:                                    java.lang.String message = "\n/***Could Not Decompile This Method.\n";
2151:                                    message += "A Runtime Exception Occured while decompiling This method....\n";
2152:                                    message += "Please Check up the log message for this method and \n";
2153:                                    message += "send The following details to project admin at its home page..\n ";
2154:                                    message += "    1>Log File\n";
2155:                                    message += "     2>Class File\n";
2156:                                    message += "     3>Java Version***/\n";
2157:                                    methodDesc.append(Util
2158:                                            .formatDecompiledStatement(message)
2159:                                            + "\n");
2160:                                    methodDesc.append(Util
2161:                                            .formatFieldsOrMethodHeader(
2162:                                                    "}\n\n", "method"));
2163:                                }
2164:                            }
2165:
2166:                            // System.out.println(methodDesc.toString());
2167:
2168:                        }
2169:                        String key = cl.getClassName();
2170:                        if (cl.getClassName().indexOf(".") != -1) {
2171:                            int l = cl.getClassName().lastIndexOf(".");
2172:                            key = key.substring(l + 1);
2173:                        }
2174:                        classMethodMap.put(key + ".class",
2175:                                method_names_signature);
2176:                        classMethodRefMap.put(cl.getClassName() + ".class",
2177:                                method_names_methodref);
2178:                        // methodDesc=format(methodDesc);
2179:                    } else // NOTE:
2180:                    // Should Never Happen. At least at the time of writing this method
2181:                    // when the options are restricted to 3: dis_nocode,dc,dis.
2182:                    // Need to have alook in case of adding More options
2183:                    {
2184:                        java.lang.String errMessage = "Unknown option encountered while adding method description to the Class Content";
2185:                        errMessage += "Application ERROR: UNKNOWN INPUT TO CollectMethodDetails method of Class ConsoleLauncher.";
2186:                        throw new ApplicationException(errMessage);
2187:                    }
2188:
2189:                } // End of outer Else
2190:
2191:            }// End of Method
2192:
2193:            // Have to check whether this code will work even for inner class
2194:            // and its methods.... ?
2195:
2196:            public static void disassemble(java.lang.String path) {
2197:
2198:                try {
2199:                    InputStream readerStream = VerifyClassFile(path);
2200:                    ClassDescription cd = processClassFile(readerStream);
2201:                    Hashtable ht = getClazzObjects();
2202:                    Iterator it = ht.keySet().iterator();
2203:                    while (it.hasNext()) {
2204:                        String classname = (java.lang.String) it.next();
2205:                        JavaClass clazz = (JavaClass) ht.get(classname);
2206:                        // Disassemble Each Method
2207:                        /**
2208:                         * 
2209:                         * Basically The following 2 loops will just store the
2210:                         * disassembled code in a manner so that API external to
2211:                         * reflection API Can acess that behaviour and show its
2212:                         * disassembled code...
2213:                         * 
2214:                         * 
2215:                         */
2216:
2217:                        ArrayList cons = clazz.getConstructors();
2218:                        Iterator consIt = cons.iterator();
2219:                        while (consIt.hasNext()) {
2220:                            Behaviour b = (Behaviour) consIt.next();
2221:                            if (!b.isHasBeenDissassembled()) {
2222:                                if (UIUtil.getUIUtil() != null) {
2223:                                    JDialog pf = UIUtil.getProgressBarFrame();
2224:                                    if (pf != null) {
2225:                                        pf.setTitle("In Progress...");
2226:                                        UIUtil.proframedetails_class
2227:                                                .setText("");
2228:                                        UIUtil.proframedetails_pkg
2229:                                                .setText("Package :"
2230:                                                        + clazz
2231:                                                                .getPackageName());
2232:                                        UIUtil.proframedetails_class
2233:                                                .setText("Current Class :"
2234:                                                        + clazz.getSimpleName());
2235:                                        UIUtil.proframedetails_pkg
2236:                                                .setFont(new Font("Monospaced",
2237:                                                        Font.BOLD, 12));
2238:                                        UIUtil.proframedetails_pkg
2239:                                                .setForeground(Color.BLUE);
2240:                                        UIUtil.proframedetails_method
2241:                                                .setText("Method :"
2242:                                                        + b.getBehaviourName());
2243:                                        UIUtil.proframedetails_class
2244:                                                .setFont(new Font("Monospaced",
2245:                                                        Font.BOLD, 12));
2246:                                        UIUtil.proframedetails_class
2247:                                                .setForeground(Color.BLUE);
2248:                                        UIUtil.proframedetails_method
2249:                                                .setFont(new Font("Monospaced",
2250:                                                        Font.BOLD, 12));
2251:                                        UIUtil.proframedetails_method
2252:                                                .setForeground(Color.BLUE);
2253:                                        UIUtil.proframedetails.revalidate();
2254:                                        UIUtil.proframedetails.repaint();
2255:
2256:                                    }
2257:                                }
2258:                                b.setHasBeenDissassembled(true);
2259:                                Disassembler dis = new Disassembler(b, cd);
2260:                                if (b.getCode() != null) {
2261:                                    dis.disassembleCode();
2262:                                } else {
2263:                                    b.replaceBuffer("");
2264:                                }
2265:                                dis = null;
2266:                            }
2267:
2268:                        }
2269:
2270:                        ArrayList met = clazz.getDecalaredMethods();
2271:                        Iterator metIt = met.iterator();
2272:                        while (metIt.hasNext()) {
2273:                            Behaviour b = (Behaviour) metIt.next();
2274:                            boolean skip = skipBehaviour(b);
2275:                            if (!b.isHasBeenDissassembled() && !skip) {
2276:                                if (UIUtil.getUIUtil() != null) {
2277:                                    JDialog pf = UIUtil.getProgressBarFrame();
2278:                                    if (pf != null) {
2279:                                        pf.setTitle("In Progress...");
2280:                                        UIUtil.proframedetails_class
2281:                                                .setText("");
2282:                                        UIUtil.proframedetails_pkg
2283:                                                .setText("Package :"
2284:                                                        + clazz
2285:                                                                .getPackageName());
2286:                                        UIUtil.proframedetails_class
2287:                                                .setText("Current Class :"
2288:                                                        + clazz.getSimpleName());
2289:                                        UIUtil.proframedetails_pkg
2290:                                                .setFont(new Font("Monospaced",
2291:                                                        Font.BOLD, 12));
2292:                                        UIUtil.proframedetails_pkg
2293:                                                .setForeground(Color.BLUE);
2294:                                        UIUtil.proframedetails_method
2295:                                                .setText("Method :"
2296:                                                        + b.getBehaviourName());
2297:                                        UIUtil.proframedetails_class
2298:                                                .setFont(new Font("Monospaced",
2299:                                                        Font.BOLD, 12));
2300:                                        UIUtil.proframedetails_class
2301:                                                .setForeground(Color.BLUE);
2302:                                        UIUtil.proframedetails_method
2303:                                                .setFont(new Font("Monospaced",
2304:                                                        Font.BOLD, 12));
2305:                                        UIUtil.proframedetails_method
2306:                                                .setForeground(Color.BLUE);
2307:                                        UIUtil.proframedetails.revalidate();
2308:                                        UIUtil.proframedetails.repaint();
2309:
2310:                                    }
2311:                                }
2312:                                b.setHasBeenDissassembled(true);
2313:                                Disassembler dis = new Disassembler(b, cd);
2314:                                if (b.getCode() != null) {
2315:                                    dis.disassembleCode();
2316:                                } else {
2317:                                    b.replaceBuffer("");
2318:                                }
2319:
2320:                                dis = null;
2321:                            }
2322:                        }
2323:
2324:                        // TODO
2325:                        // Print The Class Along with disassembled code
2326:                        // for each method in that Class.
2327:
2328:                        displayClass(true, "dis", clazz.getClassName());
2329:
2330:                    }
2331:                } catch (MalFormedClassException mfe) {
2332:                    AllExceptionHandler handler = new AllExceptionHandler(mfe);
2333:                    handler.reportException();
2334:                    JFrame mainFrame = UILauncher.getMainFrame();
2335:                    if (mainFrame != null) {
2336:                        Manager.getManager().setShowProgressBar(false);
2337:                        java.lang.String msg = "Invalid Class Specified As Input To Jdec..\n";
2338:                        msg += mfe.getMessage() + "\n";
2339:                        JOptionPane.showMessageDialog(
2340:                                UILauncher.getMainFrame(), msg,
2341:                                "Run Jdec Decompiler",
2342:                                JOptionPane.ERROR_MESSAGE);
2343:                        try {
2344:                            UIManager.setLookAndFeel(UILauncher.getUIutil()
2345:                                    .getCurrentLNF());
2346:                            SwingUtilities.updateComponentTreeUI(UILauncher
2347:                                    .getMainFrame());
2348:                        } catch (Exception e) {
2349:
2350:                        }
2351:                    } else {
2352:                        System.out
2353:                                .println("Jdec encountered an FatalException. Jdec will now exit..");
2354:                        System.exit(1);
2355:                    }
2356:                }
2357:
2358:            }
2359:
2360:            private static void displayLocalVariables() {
2361:
2362:                LocalVariableTable obj = LocalVariableTable.getInstance();
2363:                Hashtable ht = obj.getAllLocalVaraibles();
2364:                Iterator it = ht.keySet().iterator();
2365:                StringBuffer localVars = new StringBuffer();
2366:                while (it.hasNext()) {
2367:                    java.lang.String mDesc = (java.lang.String) it.next();
2368:                    // localVars.append("*********************************\n");
2369:                    localVars.append("Local Variables For Method " + mDesc
2370:                            + "\n");
2371:                    localVars.append("*********************************\n\n\n");
2372:                    // localVars.append("Local Variables for "+mDesc);
2373:                    LocalVariableStructure structure = (LocalVariableStructure) ht
2374:                            .get(mDesc);
2375:                    ArrayList al = structure.getMethodLocalVaribales();
2376:                    // localVars.append("VERIFYING METHOD DESCRIPTOR");
2377:                    // localVars.append("Local Variables for
2378:                    // "+structure.getMethodDescriptor());
2379:                    Iterator allfields = al.iterator();
2380:
2381:                    localVars.append("[DataType\tLocal Variable Name]\n");
2382:                    localVars.append("--------------------------------\n");
2383:                    while (allfields.hasNext()) {
2384:                        LocalVariable local = (LocalVariable) allfields.next();
2385:                        localVars.append(local.toString());
2386:                        localVars.append("\n");
2387:
2388:                    }
2389:                    localVars.append("\n\n");
2390:                }
2391:                Writer writer = null;
2392:                // Print output
2393:                try {
2394:                    writer = Writer.getWriter("output");
2395:                    writer.writeOutput(localVars.toString());
2396:                    writer.flush();
2397:
2398:                } catch (IOException ioe) {
2399:                    AllExceptionHandler handler = new AllExceptionHandler(ioe);
2400:                    handler.reportException();
2401:                } finally {
2402:                    if (writer != null) {
2403:                        writer.flush(); // Can be Avoided as flush call was made earlier
2404:                        // .put it just in case Some Data is still left
2405:                        writer.close("output");
2406:                    }
2407:                }
2408:
2409:            }
2410:
2411:            private static String getAllMethodParams(String params,
2412:                    Behaviour method, JavaClass cl, String importfiles,
2413:                    StringBuffer newimports) {
2414:
2415:                // newimports=new StringBuffer("");
2416:                // if(cl.isInterface())return params;
2417:
2418:                if (params.equals("( )") == false) {
2419:
2420:                    String allParams = "";
2421:                    StringTokenizer tokenizer = new StringTokenizer(params, ",");
2422:                    int localVarindex = 1;
2423:
2424:                    String[] methodAccessors = method.getMethodAccessors();
2425:
2426:                    if (contains(methodAccessors, "static")) {
2427:                        localVarindex = 0;
2428:                    }
2429:
2430:                    LocalVariableStructure structure = method
2431:                            .getLocalVariables();
2432:                    ArrayList variables = null;
2433:                    if (structure != null)
2434:                        variables = structure.getMethodLocalVaribales();
2435:
2436:                    allParams = "(";
2437:                    int count = 0;
2438:                    // && count<method.getMethodParams().length
2439:                    int start = 0;
2440:                    if (method.getUserFriendlyMethodAccessors().indexOf(
2441:                            "static") == -1)
2442:                        start = 1;
2443:                    int total = method.getNumberofparamters();
2444:                    int current = 0;
2445:                    if (variables != null) {
2446:                        LocalVariable sortedVars[] = (LocalVariable[]) variables
2447:                                .toArray(new LocalVariable[variables.size()]);
2448:                        Arrays.sort(sortedVars);
2449:                        for (int s = 0; s < sortedVars.length; s++) {
2450:                            LocalVariable lv = (LocalVariable) sortedVars[s];
2451:                            String dt = lv.getDataType();
2452:                            if (dt.indexOf(".") == -1 && dt.indexOf("/") != -1) {
2453:                                dt = dt.replaceAll("/", ".");
2454:                            }
2455:                            String name = lv.getVarName();
2456:                            if (name.equalsIgnoreCase("this"))
2457:                                continue;
2458:                            int index = lv.getIndexPos();
2459:
2460:                            if (isCurrentClassCompiledWithDebugInfo()) {
2461:                                int blkstart = lv.getBlockStart();
2462:                                int blkend = lv.getBlockEnd();
2463:                                // if(index==localVarindex)
2464:                                if (blkstart == 0
2465:                                        && blkend == method.getCode().length) {
2466:
2467:                                    allParams += dt + " " + name;
2468:                                    if (count < (method.getMethodParams().length - 1)) {
2469:                                        allParams += ",";
2470:                                    }
2471:                                    // localVarindex++;
2472:                                    count++;
2473:                                }
2474:                            } else // -g:none
2475:                            {
2476:                                if (index == start && current < total) {
2477:                                    current++;
2478:                                    allParams += dt + " " + name;
2479:                                    if (current < (total))
2480:                                        allParams += ",";
2481:                                    if (dt.trim().equals("long")
2482:                                            || dt.trim().equals("double"))
2483:                                        start++;
2484:                                    start++;
2485:
2486:                                }
2487:
2488:                            }
2489:                        }
2490:                    } else {
2491:                        int pos = 0;
2492:                        allParams = "";
2493:                        StringBuffer paramImports = new StringBuffer("");
2494:                        while (tokenizer.hasMoreTokens()) {
2495:                            String token = (String) tokenizer.nextToken();
2496:                            int br = token.indexOf(")");
2497:                            if (br != -1) {
2498:                                token = token.substring(0, br);
2499:                            }
2500:                            if (token.startsWith("(")) {
2501:                                br = token.indexOf("(");
2502:                                token = token.substring(br + 1);
2503:                            }
2504:                            StringBuffer sb = new StringBuffer("");
2505:                            token = Util.checkForImport(token, sb);
2506:                            token = token.trim();
2507:                            if (importfiles.indexOf(token) == -1
2508:                                    && paramImports.toString().indexOf(token) == -1
2509:                                    && newimports.indexOf(token) == -1)
2510:                                paramImports.append("import " + token + ";\n");
2511:                            allParams += sb.toString() + " " + "param_" + pos++;
2512:
2513:                            if (tokenizer.hasMoreTokens())
2514:                                allParams += " , ";
2515:                        }
2516:                        newimports.append(paramImports.toString());
2517:
2518:                    }
2519:
2520:                    if (!allParams.trim().startsWith("("))
2521:                        allParams = "(" + allParams;
2522:                    return allParams + ")";
2523:                } else {
2524:                    return "( )";
2525:                }
2526:            }
2527:
2528:            private static boolean contains(String[] array, String element) {
2529:                boolean flag = false;
2530:
2531:                for (int x = 0; x < array.length; x++) {
2532:                    if (element.equals(array[x])) {
2533:                        flag = true;
2534:                        break;
2535:                    }
2536:                }
2537:
2538:                return flag;
2539:            }
2540:
2541:            public static ArrayList getAllImportedClasses() {
2542:                return allImportedClasses;
2543:            }
2544:
2545:            private static ArrayList allImportedClasses = new ArrayList();
2546:
2547:            public static void addImportClass(java.lang.String className) {
2548:                allImportedClasses.add(className);
2549:            }
2550:
2551:            private static String showImportedClasses(
2552:                    ArrayList allImportedClasses, String name) {
2553:                // String temp="";
2554:                String formattedtemp = "";
2555:                allImportedClasses = Util.removeDuplicates(allImportedClasses);
2556:                if (allImportedClasses.size() > 0) {
2557:                    formattedtemp += "/**** List of All Imported Classes ***/\n\n";
2558:
2559:                }
2560:                for (int s = 0; s < allImportedClasses.size(); s++) {
2561:                    String fullname = (java.lang.String) allImportedClasses
2562:                            .get(s);
2563:                    if (fullname != null)
2564:                        fullname = fullname.trim();
2565:
2566:                    if (name != null)
2567:                        name = name.trim();
2568:                    if (fullname.equalsIgnoreCase(name))
2569:                        continue;
2570:                    // temp=Util.formatDecompiledStatement("import "+fullname);
2571:                    String t = fullname;
2572:                    if (t != null) {
2573:                        int br = t.indexOf("[]");
2574:                        if (br == -1)
2575:                            br = t.indexOf("[");
2576:                        if (br != -1)
2577:                            t = t.substring(0, br);
2578:                        t = t.trim();
2579:                        fullname = t;
2580:                    }
2581:                    if (fullname.trim().equals("byte")
2582:                            || fullname.trim().equals("short")
2583:                            || fullname.trim().equals("char")
2584:                            || fullname.trim().equals("int")
2585:                            || fullname.trim().equals("long")
2586:                            || fullname.trim().equals("float")
2587:                            || fullname.trim().equals("double"))
2588:                        continue;
2589:                    if (fullname.indexOf(".") == -1)
2590:                        continue;
2591:                    boolean addImport = addimportstmt(fullname);
2592:                    if (fullname.indexOf("$") == -1 && addImport)
2593:                        formattedtemp += "import " + fullname + ";\n";
2594:                    else if (fullname.indexOf("$") != -1 && addImport) {
2595:                        fullname = fullname.replaceAll("\\$", ".");
2596:                        //fullname = fullname.substring(0, fullname.indexOf("$"));
2597:                        formattedtemp += "import " + fullname + ";\n";
2598:
2599:                    }
2600:                    // formattedtemp+=temp;
2601:                    // formattedtemp+=";\n";
2602:                }
2603:
2604:                return formattedtemp;
2605:            }
2606:
2607:            // TODO : Take Filters into account
2608:            public static void decompileJar(java.lang.String jarPath) {
2609:                try {
2610:                    if (UILauncher.getMainFrame() == null) {
2611:                        InnerClassTracker.reinitializeStaticMembers();
2612:                        allClassStructures = new ArrayList();
2613:                        currentIsInner = false;
2614:                        classMethodMap = new HashMap();
2615:                        classMethodRefMap = new HashMap();
2616:                    }
2617:                    JarFile jf = new JarFile(jarPath);
2618:                    Enumeration alljarentries = jf.entries();
2619:                    ArrayList jarfiles = new ArrayList();
2620:                    while (alljarentries.hasMoreElements()) {
2621:                        ZipEntry ze = (ZipEntry) alljarentries.nextElement();
2622:                        String name = ze.getName();
2623:                        if (name.endsWith(".class")) {
2624:                            InputStream is = jf.getInputStream(ze);
2625:                            FileOutputStream fos = null;
2626:                            String JarDir = Configuration.getTempDir();
2627:                            File f = new File(JarDir);
2628:                            if (f.exists() == false) {
2629:                                Writer w = Writer.getWriter("log");
2630:                                w.writeLog("Temp Dir Does Not Exist...");
2631:                                w
2632:                                        .writeLog("Jdec will not create The Directory "
2633:                                                + JarDir);
2634:                                w.flush();
2635:                                f.mkdirs();
2636:                            }
2637:                            int slash = name.lastIndexOf("/");
2638:                            File tempFile = null;
2639:                            if (slash != -1) {
2640:                                tempFile = new File(JarDir
2641:                                        + name.substring(slash));
2642:                                tempFile.delete();
2643:                                fos = new FileOutputStream(tempFile);
2644:                            } else {
2645:                                tempFile = new File(JarDir + File.separator
2646:                                        + name);
2647:                                tempFile.delete();
2648:                                fos = new FileOutputStream(tempFile);
2649:                            }
2650:                            int i = is.read();
2651:                            while (i != -1) {
2652:                                fos.write(i);
2653:                                i = is.read();
2654:                            }
2655:                            fos.flush();
2656:                            fos.close();
2657:                            is.close();
2658:                            fos = null;
2659:                            is = null;
2660:                            jarfiles.add(tempFile);
2661:                            // System.out.println("Added to jar list "+tempFile);
2662:                        }
2663:                    }
2664:
2665:                    if (jarfiles.size() > 0) {
2666:                        String classContent = "";
2667:                        java.lang.String orgpath = Configuration.getBkpoppath();
2668:                        for (int start = 0; start < jarfiles.size(); start++) {
2669:                            mainRoot = null;
2670:                            File currentFile = (File) jarfiles.get(start);
2671:                            System.out.println("Decompiling class ..."
2672:                                    + currentFile.getAbsolutePath());
2673:                            Configuration.setClassFilePath(currentFile
2674:                                    .getAbsolutePath());
2675:                            couldNotFinish = new ArrayList();
2676:                            addLicence = true;
2677:                            try {
2678:                                classContent += decompileClass(currentFile
2679:                                        .getAbsolutePath());
2680:                                if (UILauncher.getMainFrame() == null) {
2681:                                    InnerClassTracker
2682:                                            .reinitializeStaticMembers();
2683:                                    allClassStructures = new ArrayList();
2684:                                }
2685:                            } catch (RuntimeException rxe) {
2686:                                Writer w = Writer.getWriter("log");
2687:                                AllExceptionHandler handler = new AllExceptionHandler(
2688:                                        rxe);
2689:                                handler.reportException();
2690:                                reInitializeConstantPoolEntries();
2691:                                continue;
2692:                            }
2693:
2694:                            catch (Exception exp) {
2695:                                AllExceptionHandler hl = new AllExceptionHandler(
2696:                                        exp, "Could Not decompile Class "
2697:                                                + currentFile.getAbsolutePath());
2698:                                hl.reportException();
2699:                                reInitializeConstantPoolEntries();
2700:                                continue;
2701:                            }
2702:
2703:                            currentDepthLevel = 0;
2704:                            decompileInnerClasses(); // TODO
2705:                            if (mainRoot != null)
2706:                                Configuration.setClassFilePath(mainRoot
2707:                                        .getClassPath());
2708:                            java.lang.String importedclassesInInnerclasses = "";
2709:
2710:                            if (innerClassesDecompied != null
2711:                                    && innerClassesDecompied.size() != 0) {
2712:                                java.lang.String innerClassFileContents = "";
2713:                                for (int s = 0; s < innerClassesDecompied
2714:                                        .size(); s++) {
2715:                                    java.lang.String classfilepath = (java.lang.String) innerClassesDecompied
2716:                                            .get(s);
2717:                                    try {
2718:                                        java.lang.String currentFileContent = "";
2719:                                        java.lang.String cname = getClassName(classfilepath);
2720:                                        if (cname.indexOf(".") != -1) {
2721:                                            cname = cname.substring(0, cname
2722:                                                    .indexOf("."));
2723:                                            cname = cname
2724:                                                    + "."
2725:                                                    + Configuration
2726:                                                            .getFileExtension();
2727:                                            classfilepath = Configuration
2728:                                                    .getOutputFolderPath()
2729:                                                    + File.separator + cname;
2730:                                        } else {
2731:                                            cname = cname
2732:                                                    + "."
2733:                                                    + Configuration
2734:                                                            .getFileExtension();
2735:                                            classfilepath = Configuration
2736:                                                    .getOutputFolderPath()
2737:                                                    + File.separator + cname;
2738:                                        }
2739:                                        File temp = new File(classfilepath);
2740:                                        FileInputStream fis = new FileInputStream(
2741:                                                temp);
2742:                                        BufferedInputStream bis = new BufferedInputStream(
2743:                                                fis);
2744:                                        BufferedReader br = new BufferedReader(
2745:                                                new InputStreamReader(bis));
2746:                                        java.lang.String line = null;
2747:                                        while ((line = br.readLine()) != null) {
2748:                                            currentFileContent += line + "\n";
2749:                                        }
2750:                                        if (currentFileContent.trim().length() != 0) {
2751:
2752:                                            int importend = currentFileContent
2753:                                                    .indexOf("// End of Import");
2754:                                            importedclassesInInnerclasses = "";
2755:                                            if (importend != -1) {
2756:                                                java.lang.String p = currentFileContent
2757:                                                        .substring(0, importend);
2758:                                                currentFileContent = currentFileContent
2759:                                                        .substring(importend
2760:                                                                + "// End of Import"
2761:                                                                        .length());
2762:                                                importedclassesInInnerclasses += p;
2763:                                            }
2764:                                            innerClassFileContents += currentFileContent;
2765:                                            innerClassFileContents += "\n\n//End Of a Inner Class File Content...\n\n";
2766:                                        }
2767:
2768:                                        temp = null;
2769:                                        fis = null;
2770:                                        bis = null;
2771:                                        br = null;
2772:                                        System.gc();
2773:
2774:                                    } catch (IOException ioe) {
2775:
2776:                                    }
2777:                                }
2778:                                if (innerClassFileContents.trim().length() != 0) {
2779:                                    innerClassFileContents = checkForLicenceAndPackageInInnerClassContent(innerClassFileContents);
2780:                                    java.lang.String mainFileContent = "";
2781:                                    java.lang.String cname = getClassName(mainRoot
2782:                                            .getClassPath());
2783:                                    java.lang.String mainfilepath = "";
2784:                                    if (cname.indexOf(".") != -1) {
2785:                                        cname = cname.substring(0, cname
2786:                                                .indexOf("."));
2787:                                        cname = cname
2788:                                                + "."
2789:                                                + Configuration
2790:                                                        .getFileExtension();
2791:                                        mainfilepath = Configuration
2792:                                                .getOutputFolderPath()
2793:                                                + File.separator + cname;
2794:                                    } else {
2795:                                        cname = cname
2796:                                                + "."
2797:                                                + Configuration
2798:                                                        .getFileExtension();
2799:                                        mainfilepath = Configuration
2800:                                                .getOutputFolderPath()
2801:                                                + File.separator + cname;
2802:                                    }
2803:                                    File mainfile = new File(mainfilepath);
2804:                                    FileInputStream fis = new FileInputStream(
2805:                                            mainfile);
2806:                                    BufferedInputStream bis = new BufferedInputStream(
2807:                                            fis);
2808:                                    BufferedReader br = new BufferedReader(
2809:                                            new InputStreamReader(bis));
2810:                                    java.lang.String line = null;
2811:                                    while ((line = br.readLine()) != null) {
2812:                                        mainFileContent += line + "\n";
2813:                                    }
2814:
2815:                                    java.lang.String completeContent = mainFileContent;
2816:                                    completeContent += "\n\n//Beginning of Inner Class Content...\n\n ";
2817:                                    completeContent += innerClassFileContents;
2818:
2819:                                    // Write back to Main File
2820:                                    if (mainfile.exists()) {
2821:                                        mainfile.delete();
2822:                                    }
2823:
2824:                                    mainfile = new File(mainfilepath);
2825:                                    mainfile.createNewFile();
2826:                                    try {
2827:                                        FileOutputStream fos = new FileOutputStream(
2828:                                                mainfile);
2829:                                        BufferedWriter bw = new BufferedWriter(
2830:                                                new OutputStreamWriter(fos));
2831:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
2832:                                                .replaceAll(
2833:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
2834:                                                        "");
2835:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
2836:                                                .replaceAll("\n\n", "\n");
2837:                                        completeContent = completeContent
2838:                                                .replaceAll(
2839:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
2840:                                                        "");
2841:                                        Iterator classNames = getClazzObjects()
2842:                                                .keySet().iterator();
2843:                                        java.lang.String classname = "";
2844:                                        while (classNames.hasNext()) {
2845:                                            classname = (java.lang.String) classNames
2846:                                                    .next();
2847:                                            break;
2848:                                        }
2849:
2850:                                        bw.write(completeContent);
2851:                                        // bw.write("/**** List of All Imported Classes
2852:                                        // ***/");
2853:                                        completeContent = completeContent
2854:                                                .replaceAll("\n\n", "\n");
2855:                                        if (importedclassesInInnerclasses
2856:                                                .endsWith("\n")) {
2857:                                            int n = importedclassesInInnerclasses
2858:                                                    .lastIndexOf("\n");
2859:                                            if (n != -1) {
2860:                                                importedclassesInInnerclasses = importedclassesInInnerclasses
2861:                                                        .substring(0, n);
2862:                                            }
2863:
2864:                                        }
2865:                                        // bw.write(importedclassesInInnerclasses);
2866:                                        completeContent = checkForImportDuplicates(
2867:                                                importedclassesInInnerclasses,
2868:                                                completeContent);
2869:
2870:                                        int present = completeContent
2871:                                                .indexOf(localvariablenote);
2872:
2873:                                        completeContent = completeContent
2874:                                                .replaceAll(localVarNote, "");
2875:
2876:                                        bw.flush();
2877:                                        bw.close();
2878:                                    } catch (IOException ioe) {
2879:
2880:                                    }
2881:
2882:                                }
2883:
2884:                            }
2885:
2886:                            // Restore orig classpath when over
2887:                            System.out.println("Decompiled class ..."
2888:                                    + currentFile.getAbsolutePath() + "\n");
2889:                            reInitializeConstantPoolEntries();
2890:                        }
2891:                        Manager.getManager().setShowProgressBar(false);
2892:                        // Repaint the Jar Tab again....
2893:                        java.lang.String jarDir = Configuration.getBkpoppath();
2894:                        File temp = new File(jarDir);
2895:                        if (temp.exists()) {
2896:                            JdecTree jarExploded = new JdecTree(jarDir);
2897:                            UIObserver observer = UILauncher.getObserver();
2898:                            if (observer != null) // Actually no need to check
2899:                            {
2900:                                observer.resetTabsPane(true);
2901:                                Manager manager = Manager.getManager();
2902:                                ArrayList list = manager
2903:                                        .getCurrentSplitPaneComponents();
2904:                                JTabbedPane tabPane = null;
2905:                                for (int s = 0; s < list.size(); s++) {
2906:                                    Object o = list.get(s);
2907:                                    if (o instanceof  JTabbedPane) {
2908:                                        tabPane = (JTabbedPane) o;
2909:                                        break;
2910:                                    }
2911:                                }
2912:                                if (tabPane != null) {
2913:                                    int jarTabIndex = tabPane.indexOfTab("Jar");
2914:                                    if (jarTabIndex >= 0) {
2915:                                        tabPane.remove(jarTabIndex);
2916:                                        tabPane.addTab("Jar", jarExploded);
2917:                                        tabPane
2918:                                                .setSelectedComponent(jarExploded);
2919:                                    }
2920:                                }
2921:
2922:                            }
2923:
2924:                            JFrame mainFrame = UILauncher.getMainFrame();
2925:                            // mainFrame.repaint();
2926:
2927:                            // Ensure Look and Feel does not change
2928:                            try {
2929:                                UIManager.setLookAndFeel(UILauncher.getUIutil()
2930:                                        .getCurrentLNF());
2931:                                SwingUtilities.updateComponentTreeUI(UILauncher
2932:                                        .getMainFrame());
2933:                            } catch (Exception looknfeel) {
2934:                                // Handle todo
2935:                            }
2936:                            if (mainFrame != null)
2937:                                mainFrame.repaint();
2938:
2939:                            File jd = new File(Configuration.getBkpoppath()
2940:                                    + File.separator + "JARDECOMPILED");
2941:                            if (jd.exists()) {
2942:                                jd.delete();
2943:                            }
2944:                            if (jd.exists()) {
2945:                                jd.deleteOnExit();
2946:                            }
2947:
2948:                        }
2949:                        // /
2950:
2951:                    }
2952:
2953:                } catch (FileNotFoundException fne) {
2954:                    AllExceptionHandler handler = new AllExceptionHandler(fne);
2955:                    handler.reportException();
2956:                } catch (IOException io) {
2957:                    AllExceptionHandler handler = new AllExceptionHandler(io);
2958:                    handler.reportException();
2959:                }
2960:
2961:            }
2962:
2963:            public static void decompileJarFromUI(java.lang.String jarPath,
2964:                    ArrayList classes) {
2965:                try {
2966:                    if (UILauncher.getMainFrame() == null) {
2967:                        InnerClassTracker.reinitializeStaticMembers();
2968:                        allClassStructures = new ArrayList();
2969:                        currentIsInner = false;
2970:                        classMethodMap = new HashMap();
2971:                        classMethodRefMap = new HashMap();
2972:                    }
2973:                    ArrayList jarfiles = classes;
2974:                    if (jarfiles.size() > 0) {
2975:                        String classContent = "";
2976:                        java.lang.String orgpath = Configuration.getBkpoppath();
2977:                        for (int start = 0; start < jarfiles.size(); start++) {
2978:                            mainRoot = null;
2979:                            File currentFile = (File) jarfiles.get(start);
2980:                            System.out.println("Decompiling class ..."
2981:                                    + currentFile.getAbsolutePath());
2982:                            Configuration.setClassFilePath(currentFile
2983:                                    .getAbsolutePath());
2984:                            couldNotFinish = new ArrayList();
2985:                            addLicence = true;
2986:                            try {
2987:                                classContent += decompileClass(currentFile
2988:                                        .getAbsolutePath());
2989:                                if (UILauncher.getMainFrame() == null) {
2990:                                    InnerClassTracker
2991:                                            .reinitializeStaticMembers();
2992:                                    allClassStructures = new ArrayList();
2993:                                }
2994:                            } catch (RuntimeException rxe) {
2995:                                Writer w = Writer.getWriter("log");
2996:                                rxe.printStackTrace(w);
2997:                                reInitializeConstantPoolEntries();
2998:                                continue;
2999:                                //throw new RuntimeException(rxe.getMessage());//needs to be commented out...
3000:                            }
3001:
3002:                            catch (Exception exp) {
3003:                                AllExceptionHandler hl = new AllExceptionHandler(
3004:                                        exp, "Could Not decompile Class "
3005:                                                + currentFile.getAbsolutePath());
3006:                                hl.reportException();
3007:                                reInitializeConstantPoolEntries();
3008:                                continue;
3009:                            }
3010:
3011:                            currentDepthLevel = 0;
3012:                            decompileInnerClasses(); // TODO
3013:                            if (mainRoot != null)
3014:                                Configuration.setClassFilePath(mainRoot
3015:                                        .getClassPath());
3016:                            java.lang.String importedclassesInInnerclasses = "";
3017:
3018:                            if (innerClassesDecompied != null
3019:                                    && innerClassesDecompied.size() != 0) {
3020:                                java.lang.String innerClassFileContents = "";
3021:                                for (int s = 0; s < innerClassesDecompied
3022:                                        .size(); s++) {
3023:                                    java.lang.String classfilepath = (java.lang.String) innerClassesDecompied
3024:                                            .get(s);
3025:                                    try {
3026:                                        java.lang.String currentFileContent = "";
3027:                                        java.lang.String cname = getClassName(classfilepath);
3028:                                        if (cname.indexOf(".") != -1) {
3029:                                            cname = cname.substring(0, cname
3030:                                                    .indexOf("."));
3031:                                            cname = cname
3032:                                                    + "."
3033:                                                    + Configuration
3034:                                                            .getFileExtension();
3035:                                            classfilepath = Configuration
3036:                                                    .getOutputFolderPath()
3037:                                                    + File.separator + cname;
3038:                                        } else {
3039:                                            cname = cname
3040:                                                    + "."
3041:                                                    + Configuration
3042:                                                            .getFileExtension();
3043:                                            classfilepath = Configuration
3044:                                                    .getOutputFolderPath()
3045:                                                    + File.separator + cname;
3046:                                        }
3047:                                        File temp = new File(classfilepath);
3048:                                        FileInputStream fis = new FileInputStream(
3049:                                                temp);
3050:                                        BufferedInputStream bis = new BufferedInputStream(
3051:                                                fis);
3052:                                        BufferedReader br = new BufferedReader(
3053:                                                new InputStreamReader(bis));
3054:                                        java.lang.String line = null;
3055:                                        while ((line = br.readLine()) != null) {
3056:                                            currentFileContent += line + "\n";
3057:                                        }
3058:                                        if (currentFileContent.trim().length() != 0) {
3059:
3060:                                            int importend = currentFileContent
3061:                                                    .indexOf("// End of Import");
3062:                                            importedclassesInInnerclasses = "";
3063:                                            if (importend != -1) {
3064:                                                java.lang.String p = currentFileContent
3065:                                                        .substring(0, importend);
3066:                                                currentFileContent = currentFileContent
3067:                                                        .substring(importend
3068:                                                                + "// End of Import"
3069:                                                                        .length());
3070:                                                importedclassesInInnerclasses += p;
3071:                                            }
3072:                                            innerClassFileContents += currentFileContent;
3073:                                            innerClassFileContents += "\n\n//End Of a Inner Class File Content...\n\n";
3074:                                        }
3075:
3076:                                        temp = null;
3077:                                        fis = null;
3078:                                        bis = null;
3079:                                        br = null;
3080:                                        System.gc();
3081:
3082:                                    } catch (IOException ioe) {
3083:
3084:                                    }
3085:                                }
3086:                                if (innerClassFileContents.trim().length() != 0) {
3087:                                    innerClassFileContents = checkForLicenceAndPackageInInnerClassContent(innerClassFileContents);
3088:                                    java.lang.String mainFileContent = "";
3089:                                    java.lang.String cname = getClassName(mainRoot
3090:                                            .getClassPath());
3091:                                    java.lang.String mainfilepath = "";
3092:                                    if (cname.indexOf(".") != -1) {
3093:                                        cname = cname.substring(0, cname
3094:                                                .indexOf("."));
3095:                                        cname = cname
3096:                                                + "."
3097:                                                + Configuration
3098:                                                        .getFileExtension();
3099:                                        mainfilepath = Configuration
3100:                                                .getOutputFolderPath()
3101:                                                + File.separator + cname;
3102:                                    } else {
3103:                                        cname = cname
3104:                                                + "."
3105:                                                + Configuration
3106:                                                        .getFileExtension();
3107:                                        mainfilepath = Configuration
3108:                                                .getOutputFolderPath()
3109:                                                + File.separator + cname;
3110:                                    }
3111:                                    File mainfile = new File(mainfilepath);
3112:                                    FileInputStream fis = new FileInputStream(
3113:                                            mainfile);
3114:                                    BufferedInputStream bis = new BufferedInputStream(
3115:                                            fis);
3116:                                    BufferedReader br = new BufferedReader(
3117:                                            new InputStreamReader(bis));
3118:                                    java.lang.String line = null;
3119:                                    while ((line = br.readLine()) != null) {
3120:                                        mainFileContent += line + "\n";
3121:                                    }
3122:
3123:                                    java.lang.String completeContent = mainFileContent;
3124:                                    completeContent += "\n\n//Beginning of Inner Class Content...\n\n ";
3125:                                    completeContent += innerClassFileContents;
3126:
3127:                                    // Write back to Main File
3128:                                    if (mainfile.exists()) {
3129:                                        mainfile.delete();
3130:                                    }
3131:
3132:                                    mainfile = new File(mainfilepath);
3133:                                    mainfile.createNewFile();
3134:                                    try {
3135:                                        FileOutputStream fos = new FileOutputStream(
3136:                                                mainfile);
3137:                                        BufferedWriter bw = new BufferedWriter(
3138:                                                new OutputStreamWriter(fos));
3139:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
3140:                                                .replaceAll(
3141:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
3142:                                                        "");
3143:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
3144:                                                .replaceAll("\n\n", "\n");
3145:                                        completeContent = completeContent
3146:                                                .replaceAll(
3147:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
3148:                                                        "");
3149:                                        Iterator classNames = getClazzObjects()
3150:                                                .keySet().iterator();
3151:                                        java.lang.String classname = "";
3152:                                        while (classNames.hasNext()) {
3153:                                            classname = (java.lang.String) classNames
3154:                                                    .next();
3155:                                            break;
3156:                                        }
3157:
3158:                                        bw.write(completeContent);
3159:                                        // bw.write("/**** List of All Imported Classes
3160:                                        // ***/");
3161:                                        completeContent = completeContent
3162:                                                .replaceAll("\n\n", "\n");
3163:                                        if (importedclassesInInnerclasses
3164:                                                .endsWith("\n")) {
3165:                                            int n = importedclassesInInnerclasses
3166:                                                    .lastIndexOf("\n");
3167:                                            if (n != -1) {
3168:                                                importedclassesInInnerclasses = importedclassesInInnerclasses
3169:                                                        .substring(0, n);
3170:                                            }
3171:
3172:                                        }
3173:                                        // bw.write(importedclassesInInnerclasses);
3174:                                        completeContent = checkForImportDuplicates(
3175:                                                importedclassesInInnerclasses,
3176:                                                completeContent);
3177:
3178:                                        int present = completeContent
3179:                                                .indexOf(localvariablenote);
3180:
3181:                                        completeContent = completeContent
3182:                                                .replaceAll(localVarNote, "");
3183:
3184:                                        bw.flush();
3185:                                        bw.close();
3186:                                    } catch (IOException ioe) {
3187:
3188:                                    }
3189:
3190:                                }
3191:
3192:                            }
3193:
3194:                            // Restore orig classpath when over
3195:                            System.out.println("Decompiled class ..."
3196:                                    + currentFile.getAbsolutePath() + "\n");
3197:                            reInitializeConstantPoolEntries();
3198:                        }
3199:                        Manager.getManager().setShowProgressBar(false);
3200:                        // Repaint the Jar Tab again....
3201:                        java.lang.String jarDir = Configuration.getBkpoppath();
3202:                        File temp = new File(jarDir);
3203:                        if (temp.exists()) {
3204:                            JdecTree jarExploded = new JdecTree(jarDir);
3205:                            UIObserver observer = UILauncher.getObserver();
3206:                            if (observer != null) // Actually no need to check
3207:                            {
3208:                                observer.resetTabsPane(true);
3209:                                Manager manager = Manager.getManager();
3210:                                ArrayList list = manager
3211:                                        .getCurrentSplitPaneComponents();
3212:                                JTabbedPane tabPane = null;
3213:                                for (int s = 0; s < list.size(); s++) {
3214:                                    Object o = list.get(s);
3215:                                    if (o instanceof  JTabbedPane) {
3216:                                        tabPane = (JTabbedPane) o;
3217:                                        break;
3218:                                    }
3219:                                }
3220:                                if (tabPane != null) {
3221:                                    int jarTabIndex = tabPane.indexOfTab("Jar");
3222:                                    if (jarTabIndex >= 0) {
3223:                                        tabPane.remove(jarTabIndex);
3224:                                        tabPane.addTab("Jar", jarExploded);
3225:                                        tabPane
3226:                                                .setSelectedComponent(jarExploded);
3227:                                    }
3228:                                }
3229:
3230:                            }
3231:
3232:                            JFrame mainFrame = UILauncher.getMainFrame();
3233:                            // mainFrame.repaint();
3234:
3235:                            // Ensure Look and Feel does not change
3236:                            try {
3237:                                UIManager.setLookAndFeel(UILauncher.getUIutil()
3238:                                        .getCurrentLNF());
3239:                                SwingUtilities.updateComponentTreeUI(UILauncher
3240:                                        .getMainFrame());
3241:                            } catch (Exception looknfeel) {
3242:                                // Handle todo
3243:                            }
3244:                            if (mainFrame != null)
3245:                                mainFrame.repaint();
3246:
3247:                            File jd = new File(Configuration.getBkpoppath()
3248:                                    + File.separator + "JARDECOMPILED");
3249:                            if (jd.exists()) {
3250:                                jd.delete();
3251:                            }
3252:                            if (jd.exists()) {
3253:                                jd.deleteOnExit();
3254:                            }
3255:
3256:                        }
3257:                        // /
3258:
3259:                    }
3260:
3261:                } catch (FileNotFoundException fne) {
3262:                    AllExceptionHandler handler = new AllExceptionHandler(fne);
3263:                    handler.reportException();
3264:                } catch (IOException io) {
3265:                    AllExceptionHandler handler = new AllExceptionHandler(io);
3266:                    handler.reportException();
3267:                }
3268:
3269:            }
3270:
3271:            private static void initializeJvmInstructionMap() {
3272:                JvmUtil jvmutil = new JvmUtil();
3273:                jvmutil.populateMap();
3274:            }
3275:
3276:            public static void setInstrMap(HashMap map) {
3277:                InstructionMap = map;
3278:            }
3279:
3280:            public static void constantPool(java.lang.String path)
3281:                    throws IOException {
3282:                String desc = showConstantPool(path);
3283:                if (desc != null) {
3284:                    if (desc.trim().length() > 0) {
3285:                        String interpret = "";
3286:                        interpret += "# Entry:   Signifies The Constant Pool Entry.\n#[NOTE ] Constant Pool always begins at Position 1\n";
3287:                        interpret += "# TagType: Signifies the Type of Entry ";
3288:                        interpret += "# Read As Follows:\n";
3289:                        interpret += "# TAG_MREF Stands For  Method Ref Type\n";
3290:                        interpret += "# TAG_CLASS Stands For Class Type\n";
3291:                        interpret += "# TAG_STR Stands For String Type\n";
3292:                        interpret += "# TAG_FREF Stands For  Field Ref Type\n";
3293:                        interpret += "# TAG_IMREF Stands For Interface Method Ref Type\n";
3294:                        interpret += "# TAG_UTF8 Stands For Interface UTF8 Type\n";
3295:                        interpret += "# TAG_NTYPE Stands For NameAndType Structure\n";
3296:                        interpret += "# TAG_INT Stands For Integer Type\n";
3297:                        interpret += "# TAG_FLOAT Stands For Float Type\n";
3298:                        interpret += "# TAG_DBL Stands For Double Type\n";
3299:                        interpret += "# TAG_LONG Stands For Long Type\n\n";
3300:                        java.lang.String header = "Entry    \t     TagType\t    PoolIndex\t    PoolIndex\t   UTF8value\n\n";
3301:                        desc = header.concat(desc);
3302:                        desc = interpret.concat(desc);
3303:                    }
3304:
3305:                    File f = new File(Configuration.getOutputFolderPath()
3306:                            + File.separator
3307:                            + getSimpleName(getClassName(Configuration
3308:                                    .getJavaClassFile())) + "."
3309:                            + Configuration.getFileExtension());
3310:                    if (f.exists())
3311:                        f.delete();
3312:                    Writer writer = Writer.getWriter("output");
3313:                    writer.writeOutput(desc);
3314:                    writer.flush();
3315:                    writer.close("output");
3316:                } else {
3317:                    UIUtil uiutil = UILauncher.getUIutil();
3318:                    if (uiutil != null) {
3319:                        uiutil.setcpdescription(null);
3320:                    }
3321:                }
3322:            }
3323:
3324:            private static HashMap InstructionMap;
3325:
3326:            public static HashMap getInstructionMap() {
3327:                return InstructionMap;
3328:            }
3329:
3330:            public static void reInitializeConstantPoolEntries() {
3331:                CPool.setAllClassInfos(new ArrayList());
3332:                CPool.setAllDoubles(new ArrayList());
3333:                CPool.setAllFieldRefs(new ArrayList());
3334:                CPool.setAllFloats(new ArrayList());
3335:                CPool.setAllIntegers(new ArrayList());
3336:                CPool.setAllInterfaceMethodRefs(new ArrayList());
3337:                CPool.setAllLongs(new ArrayList());
3338:                CPool.setAllMethodRefs(new ArrayList());
3339:                CPool.setAllNameAndTypes(new ArrayList());
3340:                CPool.setAllStrings(new ArrayList());
3341:                CPool.setAllUtf8(new ArrayList());
3342:
3343:            }
3344:
3345:            private static int poolcount = -1;
3346:
3347:            public static int getPoolCount() {
3348:                return poolcount;
3349:            }
3350:
3351:            public static void setPoolCount(int n) {
3352:                poolcount = n;
3353:            }
3354:
3355:            public static int getMagicNumber() {
3356:                return magicNumber;
3357:            }
3358:
3359:            public static JavaClass getClazzRef() {
3360:                return clazzRef;
3361:            }
3362:
3363:            public static void setClazzRef(JavaClass clazzRef) {
3364:                ConsoleLauncher.clazzRef = clazzRef;
3365:            }
3366:
3367:            public static java.lang.String getResultFileName() {
3368:                return resultFileName;
3369:            }
3370:
3371:            public static void setFileDecompiled(boolean status) {
3372:                filedecompiled = status;
3373:            }
3374:
3375:            private static boolean filedecompiled = false;
3376:
3377:            public static void setCurrentSourceFile(File f) {
3378:                currentSourceFile = f;
3379:            }
3380:
3381:            private static File currentSourceFile = null; // The File for which
3382:
3383:            // ConsoleLauncher was
3384:            // invoked
3385:
3386:            public static File getCurrentSourceFile() {
3387:                return currentSourceFile;
3388:            }
3389:
3390:            public static void setCurrentJarSourceFile(File f) {
3391:                currentJarSourceFile = f;
3392:            }
3393:
3394:            private static File currentJarSourceFile = null; // The File for which
3395:
3396:            // ConsoleLauncher was
3397:            // invoked
3398:
3399:            public static File getCurrentJarSourceFile() {
3400:                return currentJarSourceFile;
3401:            }
3402:
3403:            public static boolean isFiledecompiled() {
3404:                return filedecompiled;
3405:            }
3406:
3407:            public static void setMethodLookUp(Hashtable ht) {
3408:                msignref = new Hashtable();
3409:                createmsignref(msignref, ht);
3410:                ConsoleLauncher.ht = ht;
3411:            }
3412:
3413:            private static void createmsignref(Hashtable msignref, Hashtable ht) {
3414:                Iterator i = ht.values().iterator();
3415:                while (i.hasNext()) {
3416:                    Behaviour b = (Behaviour) i.next();
3417:                    String sign = "";
3418:                    b.getUserFriendlyMethodAccessors();
3419:                    if (b.isMethodConstructor()) {
3420:                        sign = b.getBehaviourName()
3421:                                + b.getUserFriendlyMethodParams();
3422:                    } else {
3423:
3424:                        // sign+=" "+b.getReturnType();
3425:                        sign = b.getBehaviourName()
3426:                                + b.getUserFriendlyMethodParams();
3427:
3428:                    }
3429:                    msignref.put("\t\t" + sign, b);
3430:                }
3431:
3432:            }
3433:
3434:            private static Hashtable ht = null;
3435:
3436:            private static Hashtable msignref = null;
3437:
3438:            public static Hashtable getMethodLookup() {
3439:                return ht;
3440:            }
3441:
3442:            public static Hashtable getMethodSignMethodLookup() {
3443:                return msignref;
3444:            }
3445:
3446:            /**
3447:             * Important : Do not use this variable anywhere EXCEPT for refresh purpose
3448:             */
3449:            private static java.lang.String currentDecompiledFile = null;
3450:
3451:            public static java.lang.String getCurrentDecompiledFile() {
3452:                return currentDecompiledFile;
3453:            }
3454:
3455:            public static void setCurrentDecompiledFile(java.lang.String s) {
3456:                currentDecompiledFile = s;
3457:            }
3458:
3459:            public static boolean isCurrentClassCompiledWithDebugInfo() {
3460:                return currentClassCompiledWithDebugInfo;
3461:            }
3462:
3463:            public static void setCurrentClassCompiledWithDebugInfo(boolean b) {
3464:                currentClassCompiledWithDebugInfo = b;
3465:            }
3466:
3467:            private static boolean currentClassCompiledWithDebugInfo = false;
3468:
3469:            private static boolean addNoteWRTDummyVar = false;
3470:
3471:            public static void dummyVariablesCreated(boolean b) {
3472:                addNoteWRTDummyVar = b;
3473:            }
3474:
3475:            public static boolean getDummyVarNoteStatus() {
3476:                return addNoteWRTDummyVar;
3477:            }
3478:
3479:            public static Behaviour getCurrentMethodBeingExecuted() {
3480:                return currentMethodBeingExecuted;
3481:            }
3482:
3483:            public static void setCurrentMethodBeingExecuted(Behaviour cur) {
3484:                currentMethodBeingExecuted = cur;
3485:            }
3486:
3487:            private static Behaviour currentMethodBeingExecuted = null;
3488:
3489:            public static InnerClassTracker getTracker() {
3490:                return tracker;
3491:            }
3492:
3493:            private static InnerClassTracker tracker = null;
3494:
3495:            private static ArrayList innerClassesDecompied = null;
3496:
3497:            private static void decompileInnerClasses() {
3498:                // ArrayList decompiledclasses=new ArrayList();
3499:                // Now decompile Inner classes here // TODO:
3500:                if (mainRoot == null)
3501:                    return;
3502:                addLicence = false;
3503:                currentIsInner = true;
3504:                boolean decompileInnerClass = (mainRoot.getChildren().size() > 0);
3505:                if (decompileInnerClass && Configuration.getInnerdepth() > 0) {
3506:                    innerClassesDecompied = new ArrayList();
3507:                    reInitializeConstantPoolEntries();
3508:                    InnerClassTracker.Node rootUnderConsideration = mainRoot;
3509:                    while (rootUnderConsideration != null) {
3510:                        InnerClassTracker.Node firstchild = tracker
3511:                                .getParentsFirstNode(rootUnderConsideration);
3512:                        if (firstchild != null) {
3513:                            java.lang.String classpath = firstchild
3514:                                    .getClassPath();
3515:                            // Backup current Main Class File // mainRoot should reflect
3516:                            // this
3517:                            // NOTE: mainRoot should onlu be set once per main Class
3518:                            Configuration.setClassFilePath(classpath); // This call
3519:                            // needs to be
3520:                            // called again
3521:                            // after every
3522:                            // inner class
3523:                            // decompilation
3524:                            // is over to
3525:                            // mainRoot
3526:                            couldNotFinish = new ArrayList();
3527:                            File f = new File(classpath);
3528:                            boolean exists = f.exists();
3529:                            boolean alreadyDec = shouldInnerClassBeDecompiled(classpath);
3530:                            /*
3531:                             * if(alreadyDec) { innerClassesDecompied.add(classpath); }
3532:                             */
3533:                            if (exists) {// && !alreadyDec) {
3534:                                try {
3535:                                    decompileClass(classpath);
3536:                                    innerClassesDecompied.add(classpath);
3537:                                    ClassStructure innerCS = new ClassStructure();
3538:                                    innerCS.setName(getClassName(classpath));
3539:                                    innerCS.setMethods(currentClassMethods);
3540:                                    ClassStructure parent = getClassStructure(rootUnderConsideration
3541:                                            .getClassName());
3542:                                    boolean add = addClassStructure(getClassName(classpath));
3543:                                    if (add)
3544:                                        allClassStructures.add(innerCS);
3545:                                    if (parent != null) {
3546:                                        parent.addInnerClass(innerCS);
3547:                                        innerCS.setParent(parent);
3548:                                    }
3549:
3550:                                } catch (Exception exp) {
3551:                                    AllExceptionHandler h1 = new AllExceptionHandler(
3552:                                            exp);
3553:                                    h1.reportException();
3554:                                }
3555:                            }
3556:                            reInitializeConstantPoolEntries();
3557:
3558:                            // Done with First child of Main Node
3559:                            // Now iterate through a loop and decompile each of its
3560:                            // siblings
3561:                            InnerClassTracker.Node sibling = firstchild
3562:                                    .getNextSibling(rootUnderConsideration);
3563:                            Node tempNode = null;
3564:                            while (sibling != null) {
3565:                                classpath = sibling.getClassPath();
3566:                                Configuration.setClassFilePath(classpath);
3567:                                couldNotFinish = new ArrayList(); // TODO: Add this
3568:                                // later to UI side
3569:                                // also.
3570:                                f = new File(classpath);
3571:                                exists = f.exists();
3572:
3573:                                if (exists) {
3574:                                    try {
3575:                                        decompileClass(classpath);
3576:                                        innerClassesDecompied.add(classpath);
3577:                                        ClassStructure innerCS = new ClassStructure();
3578:                                        innerCS
3579:                                                .setName(getClassName(classpath));
3580:                                        innerCS.setMethods(currentClassMethods);
3581:                                        ClassStructure parent = getClassStructure(rootUnderConsideration
3582:                                                .getClassName());
3583:                                        boolean add = addClassStructure(getClassName(classpath));
3584:                                        if (add)
3585:                                            allClassStructures.add(innerCS);
3586:                                        if (parent != null) {
3587:                                            parent.addInnerClass(innerCS);
3588:                                            innerCS.setParent(parent);
3589:                                        }
3590:                                    } catch (Exception exp) {
3591:                                        AllExceptionHandler h1 = new AllExceptionHandler(
3592:                                                exp);
3593:                                        h1.reportException();
3594:                                    }
3595:                                }
3596:                                reInitializeConstantPoolEntries();
3597:                                tempNode = sibling;
3598:                                sibling = sibling
3599:                                        .getNextSibling(rootUnderConsideration);
3600:
3601:                            }
3602:                            /***********************************************************
3603:                             * * Sibling is null what does it mean ??? 1 Level is
3604:                             * over...So if the user has specified .So need to check
3605:                             * with user set level over here either to exit from the
3606:                             * current main ... Class File or to continue.
3607:                             **********************************************************/
3608:                            if (tempNode != null) {
3609:                                Node anyOther = InnerClassTracker
3610:                                        .getNextSiblingForParentWithChildren(tempNode
3611:                                                .getParent());
3612:                                if (anyOther == null)
3613:                                    currentDepthLevel++; // Increment Inner class
3614:                                // Level depth
3615:                            } else
3616:                                currentDepthLevel++;
3617:
3618:                            // Sould the decomoile stop decompiling inner clases ...?
3619:                            if (currentDepthLevel == Configuration
3620:                                    .getInnerdepth()) {
3621:                                break;
3622:                            } else {
3623:
3624:                                InnerClassTracker.Node newroot = tracker
3625:                                        .getCurrentRoot();
3626:                                rootUnderConsideration = newroot;
3627:
3628:                            }
3629:
3630:                        } else
3631:                            break;
3632:
3633:                    }
3634:
3635:                } else {
3636:                    innerClassesDecompied = new ArrayList();
3637:                }
3638:
3639:                // end of inner class decompilation
3640:
3641:            }
3642:
3643:            public static InnerClassTracker.Node getCurrentRootAdded() {
3644:                return currentRootAdded;
3645:            }
3646:
3647:            private static InnerClassTracker.Node currentRootAdded = null;
3648:
3649:            private static java.lang.String checkForImportDuplicates(
3650:                    java.lang.String importedclassesInInnerclasses,
3651:                    java.lang.String completeContent) {
3652:                java.lang.String temp = completeContent;
3653:                int end = temp.indexOf("// End of Import");
3654:                java.lang.String importsinmainclass = "";
3655:                java.lang.String temp2 = completeContent.substring(end
3656:                        + "// End of Import".length());
3657:                if (end != -1) {
3658:                    importsinmainclass = temp.substring(0, end);
3659:                    java.lang.String validImports = removeDuplicateImports(
3660:                            importedclassesInInnerclasses, importsinmainclass);
3661:                    if (validImports.length() > 0) {
3662:                        validImports += "\n\n// End of Import\n\n";
3663:                    }
3664:                    return validImports + temp2;
3665:                }
3666:                return temp;
3667:            }
3668:
3669:            private static java.lang.String removeDuplicateImports(
3670:                    java.lang.String importedclassesInInnerclasses,
3671:                    java.lang.String importsinmainclass) {
3672:                java.lang.String valid = "\n";
3673:                StringTokenizer st = new StringTokenizer(
3674:                        importedclassesInInnerclasses, "\n");
3675:                ArrayList importedClasses = new ArrayList();
3676:                while (st.hasMoreTokens()) {
3677:                    java.lang.String token = (java.lang.String) st.nextToken();
3678:                    importedClasses.add(token);
3679:                }
3680:                st = new StringTokenizer(importsinmainclass, "\n");
3681:                while (st.hasMoreTokens()) {
3682:                    java.lang.String token = (java.lang.String) st.nextToken();
3683:                    importedClasses.add(token);
3684:                }
3685:                importedClasses = Util.removeDuplicates(importedClasses);
3686:                for (int i = 0; i < importedClasses.size(); i++) {
3687:                    valid += (java.lang.String) importedClasses.get(i) + "\n";
3688:                }
3689:                return valid;
3690:
3691:            }
3692:
3693:            private static java.lang.String localVarNote = "";
3694:
3695:            private static java.lang.String localvariablenote = "";
3696:
3697:            static {
3698:                localVarNote = "/\\*\\*\\*\\*\nNOTE: THe decompiled statmements contain some Temporary Variables. \n(Beginning with JdecGenerated) Jdec Generates These while";
3699:                localVarNote += "\nprocessing blocks like NEW. However the actual variable in the code\n then gets assigned to the respective  temporary variable.\\*\\*\\*\\*/\n";
3700:            }
3701:
3702:            private static ArrayList couldNotDecompileMethods() {
3703:                return couldNotFinish;
3704:            }
3705:
3706:            public static void addCouldNotFinish(Behaviour couldNotFinish) {
3707:                if (couldNotFinish != null)
3708:                    ConsoleLauncher.couldNotFinish.add(couldNotFinish);
3709:            }
3710:
3711:            private static ArrayList couldNotFinish;
3712:
3713:            private static boolean didThisMethodFail(Behaviour method) {
3714:                if (couldNotFinish != null) {
3715:                    for (int i = 0; i < couldNotFinish.size(); i++) {
3716:
3717:                        Behaviour cur = (Behaviour) couldNotFinish.get(i);
3718:                        if (cur == method)
3719:                            return true;
3720:                    }
3721:                    return false;
3722:
3723:                } else
3724:                    return false;
3725:
3726:            }
3727:
3728:            public static void reInitializeConstantPoolDesc() {
3729:                CPool.resetCpoolDesc();
3730:            }
3731:
3732:            public static java.lang.String getLicenceWarning() {
3733:                java.lang.String mesg = "//  Decompiled by jdec\n"
3734:                        + "//  DECOMPILER HOME PAGE: jdec.sourceforge.net\n"
3735:                        + "//  Main HOSTING SITE: sourceforge.net\n"
3736:                        + "//  Copyright (C)2006,2007,2008 Swaroop Belur.\n"
3737:                        + "//  jdec comes with ABSOLUTELY NO WARRANTY;\n"
3738:                        + "//  This is free software, and you are welcome to redistribute\n"
3739:                        + "//  it under certain conditions;\n"
3740:                        + "//  See the File 'COPYING' For more details.\n\n";
3741:                return mesg;
3742:
3743:            }
3744:
3745:            private static java.lang.String getAnyExceptionTableDetails(
3746:                    Behaviour method) {
3747:                method.createExceptionTableInStringifiedForm();
3748:                java.lang.String synchDesc = method.getSynchTableDetails();
3749:                java.lang.String det = Configuration
3750:                        .getDetailedExceptionTableInfo();
3751:                java.lang.String excep = "";
3752:
3753:                if (det.equalsIgnoreCase("true")) {
3754:                    excep = method.getDetailedExceptionTableDetails();
3755:                }
3756:                if (det.equalsIgnoreCase("false")) {
3757:                    excep = method.getShortExceptionTableDetails();
3758:                }
3759:                if (synchDesc.length() > 0) {
3760:                    java.lang.String desc = synchDesc;
3761:                    if (excep.length() > 0) {
3762:                        desc += "\n\n";
3763:                        desc += excep;
3764:                    }
3765:                    return desc;
3766:                } else {
3767:                    java.lang.String desc = "";
3768:                    if (excep.length() > 0) {
3769:                        desc += excep;
3770:                    }
3771:                    return desc;
3772:
3773:                }
3774:
3775:            }
3776:
3777:            private static java.lang.String getSimpleName(java.lang.String name) {
3778:                if (name == null || name.length() == 0)
3779:                    return name;
3780:                int index = name.indexOf(".");
3781:                java.lang.String simplename = "";
3782:                if (index != -1)
3783:                    simplename = name.substring(0, index);
3784:                else
3785:                    simplename = name;
3786:
3787:                return simplename;
3788:
3789:            }
3790:
3791:            private static java.lang.String getPackagePathFromRootForThisClass() {
3792:
3793:                Iterator classNames = getClazzObjects().keySet().iterator();
3794:                java.lang.String classname = "";
3795:                while (classNames.hasNext()) {
3796:                    classname = (java.lang.String) classNames.next();
3797:                    break;
3798:                }
3799:                StringTokenizer token = new StringTokenizer(classname, ".");
3800:                ArrayList list = new ArrayList();
3801:                while (token.hasMoreTokens()) {
3802:                    java.lang.String cur = token.nextToken();
3803:                    list.add(cur);
3804:                }
3805:                java.lang.String path = "";
3806:                for (int z = 0; z < list.size() - 1; z++) {
3807:                    java.lang.String cur = (java.lang.String) list.get(z);
3808:                    if (z < list.size() - 2)
3809:                        path = path + cur + File.separator;
3810:                    else
3811:                        path = path + cur;
3812:                }
3813:                return path;
3814:
3815:            }
3816:
3817:            private static void verifyConfigProperties() {
3818:                try {
3819:                    // HashMap mp;
3820:                    java.lang.String s = "***REPLACE_ME***";
3821:                    java.lang.String msg = "Please Set The Properties To Valid Values In config.properties File Before Running jdec.\n";
3822:                    msg += "You Can also pass parameters to the Main class(ConsoleLauncher) instead of setting in config.properties File...\n";
3823:
3824:                    if (Configuration.getOutputMode() != null
3825:                            && Configuration.getOutputMode().equals("file")) {
3826:                        java.lang.String outputpath = Configuration
3827:                                .getOutputFolderPath();
3828:                        if (outputpath == null || outputpath.trim().equals(s)) {
3829:                            throw new InvalidInputException(
3830:                                    msg
3831:                                            + "(INVALID PARAMETER IS Output_Folder_Path)");
3832:                        }
3833:                    }
3834:                    if (Configuration.getLogMode() != null
3835:                            && Configuration.getLogMode().equals("file")) {
3836:                        java.lang.String logpath = Configuration
3837:                                .getLogFilePath();
3838:                        if (logpath == null || logpath.trim().equals(s)) {
3839:                            throw new InvalidInputException(msg
3840:                                    + "(INVALID PARAMETER IS Log_File_Path)");
3841:                        }
3842:                    }
3843:                    if (Configuration.getDecompileroption() != null
3844:                            && Configuration.getDecompileroption()
3845:                                    .equals("jar") == false) {
3846:                        java.lang.String file = Configuration
3847:                                .getJavaClassFile();
3848:                        if (file == null || file.trim().equals(s)) {
3849:                            throw new InvalidInputException(msg
3850:                                    + "(INVALID PARAMETER IS JAVA_CLASS_FILE)");
3851:                        }
3852:                    }
3853:                    if (Configuration.getDecompileroption() != null
3854:                            && Configuration.getDecompileroption()
3855:                                    .equals("jar") == true) {
3856:                        java.lang.String file = Configuration.getJarPath();
3857:                        if (file == null || file.trim().equals(s)) {
3858:                            throw new InvalidInputException(msg
3859:                                    + "(INVALID PARAMETER IS JAR_FILE_PATH)");
3860:                        }
3861:                    }
3862:
3863:                    if (Configuration.getDecompileroption() != null
3864:                            && Configuration.getDecompileroption()
3865:                                    .equals("jar") == true) {
3866:                        java.lang.String file = Configuration.getTempDir();
3867:                        if (file == null || file.trim().equals(s)) {
3868:                            throw new InvalidInputException(msg
3869:                                    + "(INVALID PARAMETER IS Temp_Dir)");
3870:                        }
3871:                    }
3872:
3873:                    File f = new File(Configuration.getOutputFolderPath());
3874:                    if (f.exists() == false) {
3875:                        throw new InvalidInputException(
3876:                                "Output Folder Path Does Not Exist...Please Create This Path For Jdec to proceed.\n");
3877:                    }
3878:                    if (Configuration.getDecompileroption() != null
3879:                            && Configuration.getDecompileroption()
3880:                                    .equals("jar")) {
3881:                        f = new File(Configuration.getTempDir());
3882:                        if (f.exists() == false) {
3883:                            throw new InvalidInputException(
3884:                                    "Temp Dir Path Does Not Exist...Please Create This Path For Jdec to proceed.\n");
3885:                        }
3886:                    }
3887:
3888:                } catch (InvalidInputException ie) {
3889:                    AllExceptionHandler handler = new AllExceptionHandler(
3890:                            "\n\n" + "[ERROR :]" + ie.getMessage());
3891:                    handler.sendMessage();
3892:                    System.out
3893:                            .println("[ERROR] Please check the input settings to Jdec again");
3894:                    System.out
3895:                            .println("Please check the log output for more details");
3896:                    System.exit(1);
3897:                }
3898:
3899:            }
3900:
3901:            private static boolean addLicence = true;
3902:
3903:            public static void decompileClassFromUI(java.lang.String path) {
3904:                try {
3905:
3906:                    mainRoot = null;
3907:                    couldNotFinish = new ArrayList();
3908:                    addLicence = true;
3909:                    tabChange.add(0, getCurrentSourceFile());
3910:                    classMethodMap = new HashMap();
3911:                    classMethodRefMap = new HashMap();
3912:                    InnerClassTracker.reinitializeStaticMembers();
3913:                    allClassStructures = new ArrayList();
3914:                    decompileClass(path);
3915:                    currentDepthLevel = 0;
3916:                    setResultFilePath(Configuration.getOutputFolderPath()
3917:                            + File.separator + getClassNameWithExtension());
3918:                    decompileInnerClasses(); // TODO Also Fix For The UI side also
3919:                    // later
3920:                    // Now need to concatenate inner class content here
3921:                    Configuration.setClassFilePath(mainRoot.getClassPath());
3922:                    java.lang.String importedclassesInInnerclasses = "";
3923:
3924:                    // if(!Configuration.getInlineInnerClassMethodContent().equalsIgnoreCase("true"))
3925:                    // {
3926:                    if (innerClassesDecompied != null
3927:                            && innerClassesDecompied.size() != 0) {
3928:                        java.lang.String innerClassFileContents = "";
3929:                        for (int s = 0; s < innerClassesDecompied.size(); s++) {
3930:                            java.lang.String classfilepath = (java.lang.String) innerClassesDecompied
3931:                                    .get(s);
3932:                            try {
3933:                                java.lang.String currentFileContent = "";
3934:                                java.lang.String cname = getClassName(classfilepath);
3935:                                if (cname.indexOf(".") != -1) {
3936:                                    cname = cname.substring(0, cname
3937:                                            .indexOf("."));
3938:                                    cname = cname + "."
3939:                                            + Configuration.getFileExtension();
3940:                                    classfilepath = Configuration
3941:                                            .getOutputFolderPath()
3942:                                            + File.separator + cname;
3943:                                } else {
3944:                                    cname = cname + "."
3945:                                            + Configuration.getFileExtension();
3946:                                    classfilepath = Configuration
3947:                                            .getOutputFolderPath()
3948:                                            + File.separator + cname;
3949:                                }
3950:                                File temp = new File(classfilepath);
3951:                                FileInputStream fis = new FileInputStream(temp);
3952:                                BufferedInputStream bis = new BufferedInputStream(
3953:                                        fis);
3954:                                BufferedReader br = new BufferedReader(
3955:                                        new InputStreamReader(bis));
3956:                                java.lang.String line = null;
3957:                                while ((line = br.readLine()) != null) {
3958:                                    currentFileContent += line + "\n";
3959:                                }
3960:                                if (currentFileContent.trim().length() != 0) {
3961:                                    // TODO: Remove Imports and store elsewhere
3962:                                    int importend = currentFileContent
3963:                                            .indexOf("// End of Import");
3964:                                    importedclassesInInnerclasses = "";
3965:                                    if (importend != -1) {
3966:                                        java.lang.String p = currentFileContent
3967:                                                .substring(0, importend);
3968:                                        currentFileContent = currentFileContent
3969:                                                .substring(importend
3970:                                                        + "// End of Import"
3971:                                                                .length());
3972:                                        importedclassesInInnerclasses += p;
3973:                                    }
3974:                                    innerClassFileContents += currentFileContent;
3975:                                    innerClassFileContents += "\n\n//End Of a Inner Class File Content...\n\n";
3976:                                }
3977:
3978:                                temp = null;
3979:                                fis = null;
3980:                                bis = null;
3981:                                br = null;
3982:                                System.gc();
3983:
3984:                            } catch (IOException ioe) {
3985:
3986:                            }
3987:                        }
3988:                        if (innerClassFileContents.trim().length() != 0) {
3989:                            innerClassFileContents = checkForLicenceAndPackageInInnerClassContent(innerClassFileContents);
3990:                            java.lang.String mainFileContent = "";
3991:                            java.lang.String cname = getClassName(mainRoot
3992:                                    .getClassPath());
3993:                            java.lang.String mainfilepath = "";
3994:                            if (cname.indexOf(".") != -1) {
3995:                                cname = cname.substring(0, cname.indexOf("."));
3996:                                cname = cname + "."
3997:                                        + Configuration.getFileExtension();
3998:                                mainfilepath = Configuration
3999:                                        .getOutputFolderPath()
4000:                                        + File.separator + cname;
4001:                            } else {
4002:                                cname = cname + "."
4003:                                        + Configuration.getFileExtension();
4004:                                mainfilepath = Configuration
4005:                                        .getOutputFolderPath()
4006:                                        + File.separator + cname;
4007:                            }
4008:                            File mainfile = new File(mainfilepath);
4009:                            FileInputStream fis = new FileInputStream(mainfile);
4010:                            BufferedInputStream bis = new BufferedInputStream(
4011:                                    fis);
4012:                            BufferedReader br = new BufferedReader(
4013:                                    new InputStreamReader(bis));
4014:                            java.lang.String line = null;
4015:                            while ((line = br.readLine()) != null) {
4016:                                mainFileContent += line + "\n";
4017:                            }
4018:
4019:                            java.lang.String completeContent = mainFileContent;
4020:                            completeContent += "\n\n//Beginning of Inner Class Content...\n\n ";
4021:                            completeContent += innerClassFileContents;
4022:
4023:                            // Write back to Main File
4024:                            if (mainfile.exists()) {
4025:                                mainfile.delete();
4026:                            }
4027:
4028:                            mainfile = new File(mainfilepath);
4029:                            mainfile.createNewFile();
4030:                            try {
4031:                                FileOutputStream fos = new FileOutputStream(
4032:                                        mainfile);
4033:                                BufferedWriter bw = new BufferedWriter(
4034:                                        new OutputStreamWriter(fos));
4035:                                importedclassesInInnerclasses = importedclassesInInnerclasses
4036:                                        .replaceAll(
4037:                                                "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
4038:                                                "");
4039:                                importedclassesInInnerclasses = importedclassesInInnerclasses
4040:                                        .replaceAll("\n\n", "\n");
4041:                                completeContent = completeContent
4042:                                        .replaceAll(
4043:                                                "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
4044:                                                "");
4045:                                Iterator classNames = getClazzObjects()
4046:                                        .keySet().iterator();
4047:                                java.lang.String classname = "";
4048:                                while (classNames.hasNext()) {
4049:                                    classname = (java.lang.String) classNames
4050:                                            .next();
4051:                                    break;
4052:                                }
4053:
4054:                                /*
4055:                                 * if(classname.indexOf(".")!=-1) {
4056:                                 * 
4057:                                 * java.lang.String
4058:                                 * pkg=classname.substring(0,classname.lastIndexOf("."));
4059:                                 * //bw.write("package "+pkg+";\n\n"); }
4060:                                 */
4061:                                completeContent = completeContent.replaceAll(
4062:                                        "this\\$", "This\\$");
4063:                                bw.write(completeContent);
4064:                                // bw.write("/**** List of All Imported Classes ***/");
4065:                                completeContent = completeContent.replaceAll(
4066:                                        "\n\n", "\n");
4067:                                if (importedclassesInInnerclasses
4068:                                        .endsWith("\n")) {
4069:                                    int n = importedclassesInInnerclasses
4070:                                            .lastIndexOf("\n");
4071:                                    if (n != -1) {
4072:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
4073:                                                .substring(0, n);
4074:                                    }
4075:
4076:                                }
4077:                                // bw.write(importedclassesInInnerclasses);
4078:                                completeContent = checkForImportDuplicates(
4079:                                        importedclassesInInnerclasses,
4080:                                        completeContent);
4081:
4082:                                int present = completeContent
4083:                                        .indexOf(localvariablenote);
4084:
4085:                                completeContent = completeContent.replaceAll(
4086:                                        localVarNote, "");
4087:
4088:                                bw.flush();
4089:                                bw.close();
4090:                            } catch (IOException ioe) {
4091:
4092:                            }
4093:
4094:                        }
4095:
4096:                    }
4097:
4098:                    tabChange.add(0, getCurrentSourceFile());
4099:
4100:                } catch (Exception exp) {
4101:                    AllExceptionHandler handler = new AllExceptionHandler(exp);
4102:                    handler.reportException();
4103:                }
4104:                testPrintClassStructure();
4105:            }
4106:
4107:            private static java.lang.String getClassNameWithExtension() {
4108:                String classpath = Configuration.getClassPath();
4109:                String className = "";
4110:                int dot = classpath.lastIndexOf(".");
4111:                int start = dot - 1;
4112:                if (dot != -1) {
4113:                    boolean ok = false;
4114:                    while (start >= 0) {
4115:                        char ch = classpath.charAt(start);
4116:                        if (ch == '\\' || ch == '/') {
4117:                            ok = true;
4118:                            break;
4119:                        }
4120:                        start--;
4121:
4122:                    }
4123:                    if (ok) {
4124:
4125:                        className = classpath.substring(start + 1);
4126:                        dot = className.lastIndexOf(".");
4127:                        if (dot != -1)
4128:                            className = className.substring(0, dot).concat(
4129:                                    "." + Configuration.getFileExtension());
4130:                    }
4131:
4132:                }
4133:                return className;
4134:            }
4135:
4136:            private static java.lang.String checkForLicenceAndPackageInInnerClassContent(
4137:                    java.lang.String innerClassFileContents) {
4138:                java.lang.String temp = innerClassFileContents;
4139:                // java.lang.String licence=getLicenceWarning();
4140:                // temp=temp.replaceAll(licence,"");
4141:                int i = temp.indexOf("package");
4142:                while (i != -1) {
4143:                    int semi = temp.indexOf(";", i);
4144:                    if (semi != -1) {
4145:                        java.lang.String str = temp.substring(i, semi + 1);
4146:                        temp = temp.replaceAll(str, "");
4147:                    } else {
4148:                        break;
4149:                    }
4150:                    i = temp.indexOf("package");
4151:
4152:                }
4153:                return temp;
4154:            }
4155:
4156:            public static ArrayList getTabChangeList() {
4157:                return tabChange;
4158:            }
4159:
4160:            private static boolean shouldInnerClassBeDecompiled(
4161:                    java.lang.String cp) {
4162:
4163:                for (int z = 0; z < innerClassesDecompied.size(); z++) {
4164:                    if (((java.lang.String) innerClassesDecompied.get(z))
4165:                            .equals(cp)) {
4166:                        return true;
4167:                    }
4168:                }
4169:                return false;
4170:
4171:            }
4172:
4173:            public static void showGeneralInformation(String path) {
4174:
4175:                try {
4176:                    InputStream readerStream = VerifyClassFile(path);
4177:                    processClassFile(readerStream);
4178:                } catch (MalFormedClassException mfe) {
4179:                    AllExceptionHandler handler = new AllExceptionHandler(mfe);
4180:                    handler.reportException();
4181:                    JFrame mainFrame = UILauncher.getMainFrame();
4182:                    if (mainFrame != null) {
4183:                        Manager.getManager().setShowProgressBar(false);
4184:                        java.lang.String msg = "Invalid Class Specified As Input To Jdec..\n";
4185:                        msg += mfe.getMessage() + "\n";
4186:                        JOptionPane.showMessageDialog(
4187:                                UILauncher.getMainFrame(), msg,
4188:                                "Run Jdec Decompiler",
4189:                                JOptionPane.ERROR_MESSAGE);
4190:
4191:                    }
4192:
4193:                } catch (Exception e) {
4194:                    AllExceptionHandler handler = new AllExceptionHandler(e);
4195:                    handler.reportException();
4196:
4197:                }
4198:
4199:            }
4200:
4201:            public static boolean isDontpvtmethods() {
4202:                return dontpvtmethods;
4203:            }
4204:
4205:            public static void setDontpvtmethods(boolean dontpvtmethods) {
4206:                ConsoleLauncher.dontpvtmethods = dontpvtmethods;
4207:            }
4208:
4209:            public static boolean isDontstaticinit() {
4210:                return dontstaticinit;
4211:            }
4212:
4213:            public static void setDontstaticinit(boolean dontstaticinit) {
4214:                ConsoleLauncher.dontstaticinit = dontstaticinit;
4215:            }
4216:
4217:            public static boolean isDontsynth() {
4218:                return dontsynth;
4219:            }
4220:
4221:            public static void setDontsynth(boolean dontsynth) {
4222:                ConsoleLauncher.dontsynth = dontsynth;
4223:            }
4224:
4225:            public static boolean isDontshowemptyconst() {
4226:                return dontshowemptyconst;
4227:            }
4228:
4229:            public static void setDontshowemptyconst(boolean dontshowemptyconst) {
4230:                ConsoleLauncher.dontshowemptyconst = dontshowemptyconst;
4231:            }
4232:
4233:            public static boolean isDontshownative() {
4234:                return dontshownative;
4235:            }
4236:
4237:            public static void setDontshownative(boolean dontshownative) {
4238:                ConsoleLauncher.dontshownative = dontshownative;
4239:            }
4240:
4241:            public static boolean isDontshowabs() {
4242:                return dontshowabs;
4243:            }
4244:
4245:            public static void setDontshowabs(boolean dontshowabs) {
4246:                ConsoleLauncher.dontshowabs = dontshowabs;
4247:            }
4248:
4249:            public static boolean isShowconstfirst() {
4250:                return showconstfirst;
4251:            }
4252:
4253:            public static void setShowconstfirst(boolean showconstfirst) {
4254:                ConsoleLauncher.showconstfirst = showconstfirst;
4255:            }
4256:
4257:            public static void setShowfieldsfirst(boolean b) {
4258:                showfieldsfirst = b;
4259:            }
4260:
4261:            public static void setShowObjectSuperClass(boolean b) {
4262:                showextendsobject = b;
4263:            }
4264:
4265:            public static ArrayList getInclList() {
4266:                return inclList;
4267:            }
4268:
4269:            public static ArrayList getExclList() {
4270:                return exclList;
4271:            }
4272:
4273:            public static void setInclListInJar(ArrayList inclList) {
4274:                ConsoleLauncher.inclList = inclList;
4275:            }
4276:
4277:            public static void setExclImpList(ArrayList list) {
4278:                exclList = list;
4279:            }
4280:
4281:            private static boolean skipBehaviour(Behaviour b) {
4282:                boolean bl = false;
4283:                if (dontpvtmethods) {
4284:                    java.lang.String accs = b.getUserFriendlyMethodAccessors();
4285:                    if (accs.indexOf("private") != -1) {
4286:                        return true;
4287:                    }
4288:                }
4289:                if (dontstaticinit) {
4290:                    if (b.getBehaviourName().equals("static")) {
4291:                        return true;
4292:                    }
4293:                }
4294:                if (dontsynth) {
4295:                    if (b.getBehaviourName().indexOf("$") != -1) {
4296:                        return true;
4297:                    }
4298:                }
4299:                if (dontshowabs) {
4300:                    java.lang.String accs = b.getUserFriendlyMethodAccessors();
4301:                    if (accs.indexOf("abstract") != -1) {
4302:                        return true;
4303:                    }
4304:                }
4305:                if (dontshownative) {
4306:                    java.lang.String accs = b.getUserFriendlyMethodAccessors();
4307:                    if (accs.indexOf("native") != -1) {
4308:                        return true;
4309:                    }
4310:                }
4311:                if (dontshowemptyconst) {
4312:                    if (b instanceof  ConstructorMember) {
4313:                        byte[] c = b.getCode();
4314:                        if (c == null || c.length == 5) {
4315:                            return true;
4316:                        }
4317:
4318:                    }
4319:                }
4320:
4321:                return bl;
4322:            }
4323:
4324:            private static boolean skipClazzDecompilation(java.lang.String pkg) {
4325:                if (inclList == null || inclList.size() == 0) {
4326:                    return false;
4327:                }
4328:                for (int z = 0; z < inclList.size(); z++) {
4329:                    java.lang.String cpkg = (java.lang.String) inclList.get(z);
4330:                    if (cpkg.equals(pkg))
4331:                        return false;
4332:                }
4333:                return true;
4334:
4335:            }
4336:
4337:            private static boolean addimportstmt(java.lang.String fullname) {
4338:
4339:                if (exclList == null || exclList.size() == 0)
4340:                    return true;
4341:                for (int z = 0; z < exclList.size(); z++) {
4342:                    String s1 = (String) exclList.get(z);
4343:                    int lastDot = fullname.lastIndexOf(".");
4344:                    if (lastDot != -1) {
4345:                        String str = fullname.substring(0, lastDot);
4346:                        if (fullname != null && str.equals(s1) == true) {
4347:                            return false;
4348:                        }
4349:                    }
4350:
4351:                }
4352:
4353:                return true;
4354:            }
4355:
4356:            public static void currentClassMethods(ArrayList mlist) {
4357:                currentClassMethods = mlist;
4358:            }
4359:
4360:            public static ArrayList getcurrentClassMethods() {
4361:                return currentClassMethods;
4362:
4363:            }
4364:
4365:            /*
4366:             * public static void processClassInJar(File jar,String clx) { try { String
4367:             * path=getFilePathForClassEntryInJar(jar,clx); if(path!=null)
4368:             * decompileClass(path); } catch(Throwable e) { AllExceptionHandler h=new
4369:             * AllExceptionHandler(e); h.reportException(); fatalErrorOccured=true;
4370:             * Manager.getManager().setShowProgressBar(false); } }
4371:             */
4372:
4373:            // folder can be null
4374:            // if not null a new folder with specified name is created if does not exist
4375:            public static String getFilePathForClassEntryInJar(File jar,
4376:                    String clx, String folder) {
4377:                try {
4378:
4379:                    if (jar.exists() == false) {
4380:                        JOptionPane.showMessageDialog(
4381:                                UILauncher.getMainFrame(),
4382:                                "Jar File does not exist");
4383:                        Manager.getManager().setShowProgressBar(false);
4384:                        throw new Throwable();
4385:                    }
4386:                    JarFile jf = new JarFile(jar);
4387:                    JarEntry je = jf.getJarEntry(clx);
4388:                    if (je == null) {
4389:                        JOptionPane.showMessageDialog(
4390:                                UILauncher.getMainFrame(),
4391:                                "Class does not exist within jar");
4392:                        Manager.getManager().setShowProgressBar(false);
4393:                        throw new Throwable();
4394:                    }
4395:                    String name = je.getName();
4396:                    String outputf = Configuration.getOutputFolderPath();
4397:                    if (outputf == null || outputf.trim().length() == 0) {
4398:                        JOptionPane.showMessageDialog(
4399:                                UILauncher.getMainFrame(),
4400:                                "Please set output folder path");
4401:                        Manager.getManager().setShowProgressBar(false);
4402:                        throw new Throwable();
4403:                    }
4404:
4405:                    InputStream is = jf.getInputStream(je);
4406:                    FileOutputStream fos = null;
4407:                    String JarDir = Configuration.getTempDir();
4408:                    File f = new File(JarDir);
4409:                    if (f.exists() == false) {
4410:                        f = new File(System.getProperty("user.dir"));
4411:                        JarDir = System.getProperty("user.dir");
4412:                    }
4413:                    if (folder != null) {
4414:                        if (JarDir.endsWith(File.separator) == false)
4415:                            JarDir = JarDir + File.separator + folder;
4416:                        else
4417:                            JarDir = JarDir + folder;
4418:                    }
4419:
4420:                    if (new File(JarDir).exists() == false) {
4421:                        new File(JarDir).mkdirs();
4422:                    }
4423:                    int slash = name.lastIndexOf("/");
4424:                    File tempFile = null;
4425:                    if (slash != -1) {
4426:                        tempFile = new File(JarDir + name.substring(slash));
4427:                        tempFile.delete();
4428:                        fos = new FileOutputStream(tempFile);
4429:                    } else {
4430:                        tempFile = new File(JarDir + File.separator + name);
4431:                        tempFile.delete();
4432:                        fos = new FileOutputStream(tempFile);
4433:                    }
4434:                    int i = is.read();
4435:                    while (i != -1) {
4436:                        fos.write(i);
4437:                        i = is.read();
4438:                    }
4439:                    fos.flush();
4440:                    fos.close();
4441:                    is.close();
4442:                    fos = null;
4443:                    is = null;
4444:
4445:                    int i2 = name.lastIndexOf("/");
4446:                    if (i2 != -1) {
4447:                        name = name.substring(i2 + 1);
4448:                    }
4449:                    String path = JarDir + File.separator + name;
4450:                    Writer w = Writer.getWriter("log");
4451:                    w.writeLog("For Task Class in Jar Task");
4452:                    w.writeLog("Writing class bytes to File " + path);
4453:                    w.flush();
4454:                    return JarDir + File.separator + name;
4455:                } catch (Throwable e) {
4456:                    AllExceptionHandler h = new AllExceptionHandler(e);
4457:                    h.reportException();
4458:                    fatalErrorOccured = true;
4459:                    Manager.getManager().setShowProgressBar(false);
4460:                    return null;
4461:                }
4462:
4463:            }
4464:
4465:            public static HashMap getMethod_names_methodref() {
4466:                return method_names_methodref;
4467:            }
4468:
4469:            public static boolean getShowextendsobject() {
4470:                return showextendsobject;
4471:            }
4472:
4473:            public static boolean getShowfieldsfirst() {
4474:                return showfieldsfirst;
4475:            }
4476:
4477:            public static ClassStructure getClassStructure(String string) {
4478:                for (int x = 0; x < allClassStructures.size(); x++) {
4479:                    ClassStructure cur = (ClassStructure) allClassStructures
4480:                            .get(x);
4481:                    if (cur.getName().equals(string)) {
4482:                        return cur;
4483:                    }
4484:                }
4485:                return null;
4486:            }
4487:
4488:            /*
4489:             * public static ClassStructure getClassStructureForMethodName(String
4490:             * string) { for(int x=0;x<allClassStructures.size();x++){ ClassStructure
4491:             * cur=(ClassStructure)allClassStructures.get(x); ArrayList
4492:             * methods=cur.getMethods(); for(int z=0;z<methods.size();z++){ String
4493:             * m=(String)methods.get(z); if(m.equals(string)){ } } } }
4494:             */
4495:            private static void testPrintClassStructure() {
4496:
4497:                for (int x = 0; x < allClassStructures.size(); x++) {
4498:                    ClassStructure cs = (ClassStructure) allClassStructures
4499:                            .get(x);
4500:                    String s = "s";
4501:                }
4502:
4503:            }
4504:
4505:            private static boolean addClassStructure(String name) {
4506:                for (int x = 0; x < allClassStructures.size(); x++) {
4507:                    ClassStructure cs = (ClassStructure) allClassStructures
4508:                            .get(x);
4509:                    if (cs.getName().equals(name)) {
4510:                        return false;
4511:                    }
4512:                }
4513:                return true;
4514:            }
4515:
4516:            public static void decompileJarFromConsole(
4517:                    java.lang.String jarPath, ArrayList classes) {
4518:                try {
4519:                    if (UILauncher.getMainFrame() == null) {
4520:                        InnerClassTracker.reinitializeStaticMembers();
4521:                        allClassStructures = new ArrayList();
4522:                        currentIsInner = false;
4523:                        classMethodMap = new HashMap();
4524:                        classMethodRefMap = new HashMap();
4525:                    }
4526:                    ArrayList jarfiles = classes;
4527:                    if (jarfiles.size() > 0) {
4528:                        //String classContent = "";
4529:                        java.lang.String orgpath = Configuration.getBkpoppath();
4530:                        for (int start = 0; start < jarfiles.size(); start++) {
4531:                            mainRoot = null;
4532:                            File currentFile = (File) jarfiles.get(start);
4533:                            System.out.println("Decompiling class ..."
4534:                                    + currentFile.getAbsolutePath());
4535:                            Configuration.setClassFilePath(currentFile
4536:                                    .getAbsolutePath());
4537:                            couldNotFinish = new ArrayList();
4538:                            addLicence = true;
4539:                            try {
4540:                                decompileClass(currentFile.getAbsolutePath());
4541:                                if (UILauncher.getMainFrame() == null) {
4542:                                    InnerClassTracker
4543:                                            .reinitializeStaticMembers();
4544:                                    allClassStructures = new ArrayList();
4545:                                }
4546:                            } catch (RuntimeException rxe) {
4547:                                Writer w = Writer.getWriter("log");
4548:                                rxe.printStackTrace(w);
4549:                                reInitializeConstantPoolEntries();
4550:                                continue;
4551:                            }
4552:
4553:                            catch (Exception exp) {
4554:                                AllExceptionHandler hl = new AllExceptionHandler(
4555:                                        exp, "Could Not decompile Class "
4556:                                                + currentFile.getAbsolutePath());
4557:                                hl.reportException();
4558:                                reInitializeConstantPoolEntries();
4559:                                continue;
4560:                            }
4561:
4562:                            currentDepthLevel = 0;
4563:                            decompileInnerClasses(); // TODO
4564:                            if (mainRoot != null)
4565:                                Configuration.setClassFilePath(mainRoot
4566:                                        .getClassPath());
4567:                            java.lang.String importedclassesInInnerclasses = "";
4568:
4569:                            if (innerClassesDecompied != null
4570:                                    && innerClassesDecompied.size() != 0) {
4571:                                java.lang.String innerClassFileContents = "";
4572:                                for (int s = 0; s < innerClassesDecompied
4573:                                        .size(); s++) {
4574:                                    java.lang.String classfilepath = (java.lang.String) innerClassesDecompied
4575:                                            .get(s);
4576:                                    File temp;
4577:                                    FileInputStream fis;
4578:                                    BufferedInputStream bis;
4579:                                    BufferedReader br;
4580:                                    try {
4581:                                        java.lang.String currentFileContent = "";
4582:                                        java.lang.String cname = getClassName(classfilepath);
4583:                                        if (cname.indexOf(".") != -1) {
4584:                                            cname = cname.substring(0, cname
4585:                                                    .indexOf("."));
4586:                                            cname = cname
4587:                                                    + "."
4588:                                                    + Configuration
4589:                                                            .getFileExtension();
4590:                                            classfilepath = Configuration
4591:                                                    .getOutputFolderPath()
4592:                                                    + File.separator + cname;
4593:                                        } else {
4594:                                            cname = cname
4595:                                                    + "."
4596:                                                    + Configuration
4597:                                                            .getFileExtension();
4598:                                            classfilepath = Configuration
4599:                                                    .getOutputFolderPath()
4600:                                                    + File.separator + cname;
4601:                                        }
4602:                                        temp = new File(classfilepath);
4603:                                        fis = new FileInputStream(temp);
4604:                                        bis = new BufferedInputStream(fis);
4605:                                        br = new BufferedReader(
4606:                                                new InputStreamReader(bis));
4607:                                        java.lang.String line = null;
4608:                                        while ((line = br.readLine()) != null) {
4609:                                            currentFileContent += line + "\n";
4610:                                        }
4611:                                        if (currentFileContent.trim().length() != 0) {
4612:
4613:                                            int importend = currentFileContent
4614:                                                    .indexOf("// End of Import");
4615:                                            importedclassesInInnerclasses = "";
4616:                                            if (importend != -1) {
4617:                                                java.lang.String p = currentFileContent
4618:                                                        .substring(0, importend);
4619:                                                currentFileContent = currentFileContent
4620:                                                        .substring(importend
4621:                                                                + "// End of Import"
4622:                                                                        .length());
4623:                                                importedclassesInInnerclasses += p;
4624:                                            }
4625:                                            innerClassFileContents += currentFileContent;
4626:                                            innerClassFileContents += "\n\n//End Of a Inner Class File Content...\n\n";
4627:                                        }
4628:
4629:                                    } catch (IOException ioe) {
4630:
4631:                                    } finally {
4632:                                        temp = null;
4633:                                        fis = null;
4634:                                        bis = null;
4635:                                        br = null;
4636:                                        System.gc();
4637:                                    }
4638:                                }
4639:                                if (innerClassFileContents.trim().length() != 0) {
4640:                                    innerClassFileContents = checkForLicenceAndPackageInInnerClassContent(innerClassFileContents);
4641:                                    java.lang.String mainFileContent = "";
4642:                                    java.lang.String cname = getClassName(mainRoot
4643:                                            .getClassPath());
4644:                                    java.lang.String mainfilepath = "";
4645:                                    if (cname.indexOf(".") != -1) {
4646:                                        cname = cname.substring(0, cname
4647:                                                .indexOf("."));
4648:                                        cname = cname
4649:                                                + "."
4650:                                                + Configuration
4651:                                                        .getFileExtension();
4652:                                        mainfilepath = Configuration
4653:                                                .getOutputFolderPath()
4654:                                                + File.separator + cname;
4655:                                    } else {
4656:                                        cname = cname
4657:                                                + "."
4658:                                                + Configuration
4659:                                                        .getFileExtension();
4660:                                        mainfilepath = Configuration
4661:                                                .getOutputFolderPath()
4662:                                                + File.separator + cname;
4663:                                    }
4664:                                    File mainfile = new File(mainfilepath);
4665:                                    FileInputStream fis = new FileInputStream(
4666:                                            mainfile);
4667:                                    BufferedInputStream bis = new BufferedInputStream(
4668:                                            fis);
4669:                                    BufferedReader br = new BufferedReader(
4670:                                            new InputStreamReader(bis));
4671:                                    java.lang.String line = null;
4672:                                    while ((line = br.readLine()) != null) {
4673:                                        mainFileContent += line + "\n";
4674:                                    }
4675:
4676:                                    java.lang.String completeContent = mainFileContent;
4677:                                    completeContent += "\n\n//Beginning of Inner Class Content...\n\n ";
4678:                                    completeContent += innerClassFileContents;
4679:
4680:                                    // Write back to Main File
4681:                                    if (mainfile.exists()) {
4682:                                        mainfile.delete();
4683:                                    }
4684:
4685:                                    mainfile = new File(mainfilepath);
4686:                                    mainfile.createNewFile();
4687:                                    try {
4688:                                        FileOutputStream fos = new FileOutputStream(
4689:                                                mainfile);
4690:                                        BufferedWriter bw = new BufferedWriter(
4691:                                                new OutputStreamWriter(fos));
4692:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
4693:                                                .replaceAll(
4694:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
4695:                                                        "");
4696:                                        importedclassesInInnerclasses = importedclassesInInnerclasses
4697:                                                .replaceAll("\n\n", "\n");
4698:                                        completeContent = completeContent
4699:                                                .replaceAll(
4700:                                                        "/\\*\\*\\*\\* List of All Imported Classes \\*\\*\\*/",
4701:                                                        "");
4702:                                        Iterator classNames = getClazzObjects()
4703:                                                .keySet().iterator();
4704:                                        java.lang.String classname = "";
4705:                                        while (classNames.hasNext()) {
4706:                                            classname = (java.lang.String) classNames
4707:                                                    .next();
4708:                                            break;
4709:                                        }
4710:
4711:                                        bw.write(completeContent);
4712:                                        // bw.write("/**** List of All Imported Classes
4713:                                        // ***/");
4714:                                        completeContent = completeContent
4715:                                                .replaceAll("\n\n", "\n");
4716:                                        if (importedclassesInInnerclasses
4717:                                                .endsWith("\n")) {
4718:                                            int n = importedclassesInInnerclasses
4719:                                                    .lastIndexOf("\n");
4720:                                            if (n != -1) {
4721:                                                importedclassesInInnerclasses = importedclassesInInnerclasses
4722:                                                        .substring(0, n);
4723:                                            }
4724:
4725:                                        }
4726:                                        // bw.write(importedclassesInInnerclasses);
4727:                                        completeContent = checkForImportDuplicates(
4728:                                                importedclassesInInnerclasses,
4729:                                                completeContent);
4730:
4731:                                        int present = completeContent
4732:                                                .indexOf(localvariablenote);
4733:
4734:                                        completeContent = completeContent
4735:                                                .replaceAll(localVarNote, "");
4736:
4737:                                        bw.flush();
4738:                                        bw.close();
4739:                                    } catch (IOException ioe) {
4740:
4741:                                    }
4742:
4743:                                }
4744:
4745:                            }
4746:
4747:                            // Restore orig classpath when over
4748:                            System.out.println("Decompiled class ..."
4749:                                    + currentFile.getAbsolutePath() + "\n");
4750:                            reInitializeConstantPoolEntries();
4751:                        }
4752:
4753:                        // Repaint the Jar Tab again....
4754:                        java.lang.String jarDir = Configuration.getBkpoppath();
4755:                        File temp = new File(jarDir);
4756:                        if (temp.exists()) {
4757:                            File jd = new File(Configuration.getBkpoppath()
4758:                                    + File.separator + "JARDECOMPILED");
4759:                            if (jd.exists()) {
4760:                                jd.delete();
4761:                            }
4762:                            if (jd.exists()) {
4763:                                jd.deleteOnExit();
4764:                            }
4765:
4766:                        }
4767:                        // /
4768:
4769:                    }
4770:
4771:                } catch (FileNotFoundException fne) {
4772:                    AllExceptionHandler handler = new AllExceptionHandler(fne);
4773:                    handler.reportException();
4774:                } catch (IOException io) {
4775:                    AllExceptionHandler handler = new AllExceptionHandler(io);
4776:                    handler.reportException();
4777:                }
4778:
4779:            }
4780:
4781:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.