001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
015: * more details.
016: *
017: * You should have received a copy of the GNU General Public License along
018: * with this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.retrace;
022:
023: import proguard.obfuscate.MappingReader;
024:
025: import java.io.*;
026:
027: /**
028: * Tool for de-obfuscating stack traces of applications that were obfuscated
029: * with ProGuard.
030: *
031: * @author Eric Lafortune
032: */
033: public class ReTrace {
034: private static final String VERBOSE_OPTION = "-verbose";
035:
036: // The class settings.
037: private final boolean verbose;
038: private final File mappingFile;
039: private final File stackTraceFile;
040:
041: /**
042: * Creates a new ReTrace object to process stack traces on the standard
043: * input, based on the given mapping file name.
044: * @param verbose specifies whether the de-obfuscated stack trace
045: * should be verbose.
046: * @param mappingFile the mapping file that was written out by ProGuard.
047: */
048: public ReTrace(boolean verbose, File mappingFile) {
049: this (verbose, mappingFile, null);
050: }
051:
052: /**
053: * Creates a new ReTrace object to process a stack trace from the given file,
054: * based on the given mapping file name.
055: * @param verbose specifies whether the de-obfuscated stack trace
056: * should be verbose.
057: * @param mappingFile the mapping file that was written out by ProGuard.
058: * @param stackTraceFile the optional name of the file that contains the
059: * stack trace.
060: */
061: public ReTrace(boolean verbose, File mappingFile,
062: File stackTraceFile) {
063: this .verbose = verbose;
064: this .mappingFile = mappingFile;
065: this .stackTraceFile = stackTraceFile;
066: }
067:
068: /**
069: * Performs the subsequent ReTrace operations.
070: */
071: public void execute() throws IOException {
072: StackTrace stackTrace = new StackTrace(verbose);
073: MappingReader reader = new MappingReader(mappingFile);
074:
075: // Read the obfuscated stack trace.
076: stackTrace.read(stackTraceFile);
077:
078: // Resolve the obfuscated stack trace by means of the mapping file.
079: reader.pump(stackTrace);
080:
081: // Print out the resolved stack trace.
082: stackTrace.print();
083: }
084:
085: /**
086: * The main program for ReTrace.
087: */
088: public static void main(String[] args) {
089: if (args.length < 1) {
090: System.err
091: .println("Usage: java proguard.ReTrace [-verbose] <mapping_file> [<stacktrace_file>]");
092: System.exit(-1);
093: }
094:
095: int argumentIndex = 0;
096:
097: boolean verbose = false;
098: if (args[argumentIndex].equals(VERBOSE_OPTION)) {
099: verbose = true;
100: argumentIndex++;
101:
102: if (args.length < 2) {
103: System.err
104: .println("Usage: java proguard.ReTrace [-verbose] <mapping_file> [<stacktrace_file>]");
105: System.exit(-1);
106: }
107: }
108:
109: File mappingFile = new File(args[argumentIndex++]);
110: File stackTraceFile = argumentIndex < args.length ? new File(
111: args[argumentIndex]) : null;
112:
113: ReTrace reTrace = new ReTrace(verbose, mappingFile,
114: stackTraceFile);
115:
116: try {
117: // Execute ReTrace with its given settings.
118: reTrace.execute();
119: } catch (IOException ex) {
120: if (verbose) {
121: // Print a verbose stack trace.
122: ex.printStackTrace();
123: } else {
124: // Print just the stack trace message.
125: System.err.println("Error: " + ex.getMessage());
126: }
127:
128: System.exit(1);
129: }
130:
131: System.exit(0);
132: }
133: }
|