|
|
@ -19,8 +19,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package jode.swingui; |
|
|
|
package jode.swingui; |
|
|
|
import jode.Decompiler; |
|
|
|
import jode.Decompiler; |
|
|
|
import jode.JodeEnvironment; |
|
|
|
import jode.decompiler.*; |
|
|
|
import jode.decompiler.TabbedPrintWriter; |
|
|
|
import jode.bytecode.ClassInfo; |
|
|
|
///#ifdef JDK12
|
|
|
|
///#ifdef JDK12
|
|
|
|
///import javax.swing.*;
|
|
|
|
///import javax.swing.*;
|
|
|
|
///import javax.swing.event.*;
|
|
|
|
///import javax.swing.event.*;
|
|
|
@ -39,12 +39,26 @@ public class MainWindow |
|
|
|
JTree classTree; |
|
|
|
JTree classTree; |
|
|
|
PackagesTreeModel classModel; |
|
|
|
PackagesTreeModel classModel; |
|
|
|
JTextArea sourcecodeArea, errorArea; |
|
|
|
JTextArea sourcecodeArea, errorArea; |
|
|
|
String classpath, lastClassName; |
|
|
|
|
|
|
|
Thread decompileThread; |
|
|
|
Thread decompileThread; |
|
|
|
|
|
|
|
String currentClassPath, lastClassName; |
|
|
|
|
|
|
|
|
|
|
|
public MainWindow(Container contentPane) { |
|
|
|
public MainWindow() { |
|
|
|
Font monospaced = new Font("monospaced", Font.PLAIN, 12); |
|
|
|
setClasspath(System.getProperty("java.class.path")); |
|
|
|
|
|
|
|
JFrame frame = new JFrame(Decompiler.copyright); |
|
|
|
|
|
|
|
fillContentPane(frame.getContentPane()); |
|
|
|
|
|
|
|
addMenu(frame); |
|
|
|
|
|
|
|
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
|
|
|
|
|
|
frame.addWindowListener(new WindowAdapter() { |
|
|
|
|
|
|
|
public void windowClosing(WindowEvent e) { |
|
|
|
|
|
|
|
System.exit(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
frame.pack(); |
|
|
|
|
|
|
|
frame.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void fillContentPane(Container contentPane) { |
|
|
|
|
|
|
|
Font monospaced = new Font("monospaced", Font.PLAIN, 12); |
|
|
|
classModel = new PackagesTreeModel(); |
|
|
|
classModel = new PackagesTreeModel(); |
|
|
|
classTree = new JTree(classModel); |
|
|
|
classTree = new JTree(classModel); |
|
|
|
classTree.setRootVisible(false); |
|
|
|
classTree.setRootVisible(false); |
|
|
@ -72,10 +86,6 @@ public class MainWindow |
|
|
|
Decompiler.err = new PrintStream(new AreaOutputStream(errorArea)); |
|
|
|
Decompiler.err = new PrintStream(new AreaOutputStream(errorArea)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setClasspath(String classpath) { |
|
|
|
|
|
|
|
this.classpath = classpath; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized void valueChanged(TreeSelectionEvent e) { |
|
|
|
public synchronized void valueChanged(TreeSelectionEvent e) { |
|
|
|
if (decompileThread != null) |
|
|
|
if (decompileThread != null) |
|
|
|
return; |
|
|
|
return; |
|
|
@ -146,15 +156,22 @@ public class MainWindow |
|
|
|
errorArea.setText(""); |
|
|
|
errorArea.setText(""); |
|
|
|
// saveButton.setEnabled(false);
|
|
|
|
// saveButton.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
String cp = classpath; |
|
|
|
ImportHandler imports = new ImportHandler(); |
|
|
|
cp = cp.replace(':', jode.bytecode.SearchPath.protocolSeparator); |
|
|
|
|
|
|
|
cp = cp.replace(',', File.pathSeparatorChar); |
|
|
|
|
|
|
|
JodeEnvironment env = new JodeEnvironment(cp); |
|
|
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
TabbedPrintWriter writer = new TabbedPrintWriter(out); |
|
|
|
ClassInfo clazz = ClassInfo.forName(lastClassName); |
|
|
|
env.doClass(lastClassName, writer); |
|
|
|
|
|
|
|
sourcecodeArea.setText(out.toString()); |
|
|
|
imports.init(lastClassName); |
|
|
|
|
|
|
|
ClassAnalyzer clazzAna = new ClassAnalyzer(null, clazz, imports); |
|
|
|
|
|
|
|
clazzAna.analyze(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sourcecodeArea.setText(""); |
|
|
|
|
|
|
|
TabbedPrintWriter writer = |
|
|
|
|
|
|
|
new TabbedPrintWriter(new AreaOutputStream(sourcecodeArea) |
|
|
|
|
|
|
|
, imports); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imports.dumpHeader(writer); |
|
|
|
|
|
|
|
clazzAna.dumpSource(writer); |
|
|
|
|
|
|
|
|
|
|
|
// saveButton.setEnabled(true);
|
|
|
|
// saveButton.setEnabled(true);
|
|
|
|
} catch (Throwable t) { |
|
|
|
} catch (Throwable t) { |
|
|
|
sourcecodeArea.setText("Didn't succeed.\n" |
|
|
|
sourcecodeArea.setText("Didn't succeed.\n" |
|
|
@ -168,23 +185,59 @@ public class MainWindow |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] params) { |
|
|
|
public void addMenu(JFrame frame) { |
|
|
|
JFrame frame = new JFrame(Decompiler.copyright); |
|
|
|
JMenuBar bar = new JMenuBar(); |
|
|
|
String cp = System.getProperty("java.class.path"); |
|
|
|
JMenu menu; |
|
|
|
if (cp != null) |
|
|
|
JMenuItem item; |
|
|
|
jode.bytecode.ClassInfo.setClassPath(cp); |
|
|
|
menu = new JMenu("File"); |
|
|
|
|
|
|
|
item = new JMenuItem("Garbage collect"); |
|
|
|
MainWindow win = new MainWindow(frame.getContentPane()); |
|
|
|
item.addActionListener(new ActionListener() { |
|
|
|
if (cp != null) |
|
|
|
public void actionPerformed(ActionEvent ev) { |
|
|
|
win.setClasspath(cp.replace(File.pathSeparatorChar, ',')); |
|
|
|
System.gc(); |
|
|
|
|
|
|
|
System.runFinalization(); |
|
|
|
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
|
|
} |
|
|
|
frame.addWindowListener(new WindowAdapter() { |
|
|
|
}); |
|
|
|
public void windowClosing(WindowEvent e) { |
|
|
|
menu.add(item); |
|
|
|
|
|
|
|
item = new JMenuItem("Exit"); |
|
|
|
|
|
|
|
item.addActionListener(new ActionListener() { |
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent ev) { |
|
|
|
System.exit(0); |
|
|
|
System.exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
frame.pack(); |
|
|
|
menu.add(item); |
|
|
|
frame.show(); |
|
|
|
bar.add(menu); |
|
|
|
|
|
|
|
menu = new JMenu("Options"); |
|
|
|
|
|
|
|
item = new JMenuItem("Set classpath..."); |
|
|
|
|
|
|
|
item.addActionListener(new ActionListener() { |
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent ev) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String newClassPath = (String) JOptionPane.showInputDialog |
|
|
|
|
|
|
|
(null, "New classpath:", null, |
|
|
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE, null, |
|
|
|
|
|
|
|
null, currentClassPath); |
|
|
|
|
|
|
|
if (newClassPath != null |
|
|
|
|
|
|
|
&& !newClassPath.equals(currentClassPath)) |
|
|
|
|
|
|
|
setClasspath(newClassPath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
menu.add(item); |
|
|
|
|
|
|
|
bar.add(menu); |
|
|
|
|
|
|
|
frame.setJMenuBar(bar); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setClasspath(String classpath) { |
|
|
|
|
|
|
|
if (classpath == null || classpath.length() == 0) |
|
|
|
|
|
|
|
classpath = "."; |
|
|
|
|
|
|
|
currentClassPath = classpath; |
|
|
|
|
|
|
|
ClassInfo.setClassPath(classpath); |
|
|
|
|
|
|
|
if (classModel != null) { |
|
|
|
|
|
|
|
classTree.clearSelection(); |
|
|
|
|
|
|
|
classModel.rebuild(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] params) { |
|
|
|
|
|
|
|
MainWindow win = new MainWindow(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|