KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > retrace > ReTrace


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.retrace;
22
23 import java.io.*;
24
25 import proguard.obfuscate.MappingReader;
26
27
28 /**
29  * Tool for de-obfuscating stack traces of applications that were obfuscated
30  * with ProGuard.
31  *
32  * @author Eric Lafortune
33  */

34 public class ReTrace
35 {
36     private static final String JavaDoc VERBOSE_OPTION = "-verbose";
37
38
39     // The class settings.
40
private boolean verbose;
41     private File mappingFile;
42     private File stackTraceFile;
43
44
45     /**
46      * Creates a new ReTrace object to process stack traces on the standard
47      * input, based on the given mapping file name.
48      * @param verbose specifies whether the de-obfuscated stack trace
49      * should be verbose.
50      * @param mappingFile the mapping file that was written out by ProGuard.
51      */

52     public ReTrace(boolean verbose,
53                    File mappingFile)
54     {
55         this(verbose, mappingFile, null);
56     }
57
58
59     /**
60      * Creates a new ReTrace object to process a stack trace from the given file,
61      * based on the given mapping file name.
62      * @param verbose specifies whether the de-obfuscated stack trace
63      * should be verbose.
64      * @param mappingFile the mapping file that was written out by ProGuard.
65      * @param stackTraceFile the optional name of the file that contains the
66      * stack trace.
67      */

68     public ReTrace(boolean verbose,
69                    File mappingFile,
70                    File stackTraceFile)
71     {
72         this.verbose = verbose;
73         this.mappingFile = mappingFile;
74         this.stackTraceFile = stackTraceFile;
75     }
76
77
78     /**
79      * Performs the subsequent ReTrace operations.
80      */

81     public void execute() throws IOException
82     {
83         StackTrace stackTrace = new StackTrace(verbose);
84         MappingReader reader = new MappingReader(mappingFile);
85
86         // Read the obfuscated stack trace.
87
stackTrace.read(stackTraceFile);
88
89         // Resolve the obfuscated stack trace by means of the mapping file.
90
reader.pump(stackTrace);
91
92         // Print out the resolved stack trace.
93
stackTrace.print();
94     }
95
96
97     /**
98      * The main program for ReTrace.
99      */

100     public static void main(String JavaDoc[] args)
101     {
102         if (args.length < 1)
103         {
104             System.err.println("Usage: java proguard.ReTrace [-verbose] <mapping_file> [<stacktrace_file>]");
105             System.exit(-1);
106         }
107
108         int argumentIndex = 0;
109
110         boolean verbose = false;
111         if (args[argumentIndex].equals(VERBOSE_OPTION))
112         {
113             verbose = true;
114             argumentIndex++;
115
116             if (args.length < 2)
117             {
118                 System.err.println("Usage: java proguard.ReTrace [-verbose] <mapping_file> [<stacktrace_file>]");
119                 System.exit(-1);
120             }
121         }
122
123         File mappingFile = new File(args[argumentIndex++]);
124         File stackTraceFile = argumentIndex < args.length ?
125             new File(args[argumentIndex++]) :
126             null;
127
128         ReTrace reTrace = new ReTrace(verbose, mappingFile, stackTraceFile);
129
130         try
131         {
132             // Execute ReTrace with its given settings.
133
reTrace.execute();
134         }
135         catch (IOException ex)
136         {
137             if (verbose)
138             {
139                 // Print a verbose stack trace.
140
ex.printStackTrace();
141             }
142             else
143             {
144                 // Print just the stack trace message.
145
System.err.println("Error: "+ex.getMessage());
146             }
147
148             System.exit(1);
149         }
150
151         System.exit(0);
152     }
153 }
154
Popular Tags