01: package tide.exttools.proguard;
02:
03: import tide.project.ProjectSettings;
04: import java.util.*;
05: import snow.utils.StreamGobbler;
06: import tide.editor.MainEditorFrame;
07: import java.io.*;
08:
09: /** Reconstruct obfuscated traces using an obfuscation map.
10: */
11: public final class Retracer {
12: public static void retrace(File mapPath, String obfuscatedTrace)
13: throws Exception {
14: if (!mapPath.exists())
15: throw new Exception("ProGuard map file not found at "
16: + mapPath.getAbsolutePath());
17: ProjectSettings actualProject = MainEditorFrame.instance
18: .getActualProject();
19:
20: File csJar = new File(actualProject.getProperty(
21: "ProGuard_path",
22: ProGuardSettingsDialog.defaultPGLocation));
23: if (!csJar.exists())
24: throw new Exception("ProGuard jar not found at "
25: + csJar.getAbsolutePath());
26:
27: File retraceJar = new File(csJar.getParentFile(), "retrace.jar");
28: if (!retraceJar.exists())
29: throw new Exception("ProGuard Retrace jar not found at "
30: + retraceJar.getAbsolutePath());
31:
32: File javaExePath = actualProject.getJava_TOOL();
33:
34: List<String> execCommand = new ArrayList<String>();
35: execCommand.add(javaExePath.getAbsolutePath());
36: execCommand.add("-jar");
37: execCommand.add(retraceJar.getAbsolutePath());
38: // TODO: opts...
39: execCommand.add(mapPath.getAbsolutePath());
40:
41: MainEditorFrame.instance.outputPanels.executionOutputPanel
42: .setCaretEnd();
43: MainEditorFrame.instance.outputPanels.executionOutputPanel.doc
44: .appendLine("\nProguard retraced stack:\n");
45: MainEditorFrame.instance.outputPanels.selectOutputTab(true);
46:
47: ProcessBuilder pb = new ProcessBuilder(execCommand);
48: Process proc = pb.start();
49:
50: StreamGobbler sg = new StreamGobbler(
51: proc.getInputStream(),
52: MainEditorFrame.instance.outputPanels.executionOutputPanel.doc
53: .createWriterForThisDocument(false), "");
54: sg.start();
55:
56: // errors
57: StreamGobbler sge = new StreamGobbler(
58: proc.getErrorStream(),
59: MainEditorFrame.instance.outputPanels.executionOutputPanel.doc
60: .createWriterForThisDocument(true), "ProGuard");
61: sge.start();
62:
63: // write the trace
64: proc.getOutputStream().write(obfuscatedTrace.getBytes());
65: proc.getOutputStream().write(-1); // EOF
66: proc.getOutputStream().flush();
67: proc.getOutputStream().close();
68:
69: // wait until proc completed...
70: proc.waitFor();
71: sg.join();
72: sge.join();
73: }
74:
75: }
|