|
|
@ -7,49 +7,75 @@ import java.io.*; |
|
|
|
public class JodeWindow |
|
|
|
public class JodeWindow |
|
|
|
implements ActionListener, Runnable |
|
|
|
implements ActionListener, Runnable |
|
|
|
{ |
|
|
|
{ |
|
|
|
TextField classpathField; |
|
|
|
TextField classpathField, classField; |
|
|
|
TextField classField; |
|
|
|
TextArea sourcecodeArea, errorArea; |
|
|
|
TextArea sourcecodeArea; |
|
|
|
Checkbox verboseCheck, prettyCheck; |
|
|
|
TextArea errorArea; |
|
|
|
Button startButton, saveButton; |
|
|
|
|
|
|
|
String lastClassName; |
|
|
|
|
|
|
|
Frame frame; |
|
|
|
|
|
|
|
|
|
|
|
Thread decompileThread; |
|
|
|
Thread decompileThread; |
|
|
|
|
|
|
|
|
|
|
|
public JodeWindow(Container frame) { |
|
|
|
public JodeWindow(Container window) { |
|
|
|
buildComponents(frame); |
|
|
|
buildComponents(window); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void buildComponents(Container frame) { |
|
|
|
private void buildComponents(Container window) { |
|
|
|
|
|
|
|
if (window instanceof Frame) |
|
|
|
|
|
|
|
frame = (Frame) window; |
|
|
|
classpathField = new TextField(50); |
|
|
|
classpathField = new TextField(50); |
|
|
|
classField = new TextField(50); |
|
|
|
classField = new TextField(50); |
|
|
|
sourcecodeArea = new TextArea(20, 80); |
|
|
|
sourcecodeArea = new TextArea(20, 80); |
|
|
|
errorArea = new TextArea(3, 80); |
|
|
|
errorArea = new TextArea(3, 80); |
|
|
|
|
|
|
|
verboseCheck = new Checkbox("verbose", false); |
|
|
|
|
|
|
|
prettyCheck = new Checkbox("pretty", false); |
|
|
|
|
|
|
|
startButton = new Button("start"); |
|
|
|
|
|
|
|
saveButton = new Button("save"); |
|
|
|
|
|
|
|
saveButton.setEnabled(false); |
|
|
|
|
|
|
|
|
|
|
|
sourcecodeArea.setEditable(false); |
|
|
|
sourcecodeArea.setEditable(false); |
|
|
|
errorArea.setEditable(false); |
|
|
|
errorArea.setEditable(false); |
|
|
|
|
|
|
|
|
|
|
|
frame.setLayout(new GridBagLayout()); |
|
|
|
window.setLayout(new GridBagLayout()); |
|
|
|
GridBagConstraints labelConstr = new GridBagConstraints(); |
|
|
|
GridBagConstraints labelConstr = new GridBagConstraints(); |
|
|
|
GridBagConstraints textConstr = new GridBagConstraints(); |
|
|
|
GridBagConstraints textConstr = new GridBagConstraints(); |
|
|
|
GridBagConstraints areaConstr = new GridBagConstraints(); |
|
|
|
GridBagConstraints areaConstr = new GridBagConstraints(); |
|
|
|
|
|
|
|
GridBagConstraints checkConstr = new GridBagConstraints(); |
|
|
|
|
|
|
|
GridBagConstraints buttonConstr = new GridBagConstraints(); |
|
|
|
labelConstr.fill = GridBagConstraints.NONE; |
|
|
|
labelConstr.fill = GridBagConstraints.NONE; |
|
|
|
textConstr.fill = GridBagConstraints.HORIZONTAL; |
|
|
|
textConstr.fill = GridBagConstraints.HORIZONTAL; |
|
|
|
areaConstr.fill = GridBagConstraints.BOTH; |
|
|
|
areaConstr.fill = GridBagConstraints.BOTH; |
|
|
|
|
|
|
|
checkConstr.fill = GridBagConstraints.NONE; |
|
|
|
|
|
|
|
buttonConstr.fill = GridBagConstraints.NONE; |
|
|
|
|
|
|
|
labelConstr.anchor = GridBagConstraints.EAST; |
|
|
|
|
|
|
|
textConstr.anchor = GridBagConstraints.CENTER; |
|
|
|
|
|
|
|
checkConstr.anchor = GridBagConstraints.WEST; |
|
|
|
|
|
|
|
buttonConstr.anchor = GridBagConstraints.CENTER; |
|
|
|
|
|
|
|
labelConstr.anchor = GridBagConstraints.EAST; |
|
|
|
textConstr.gridwidth = GridBagConstraints.REMAINDER; |
|
|
|
textConstr.gridwidth = GridBagConstraints.REMAINDER; |
|
|
|
textConstr.weightx = 1.0; |
|
|
|
textConstr.weightx = 1.0; |
|
|
|
areaConstr.gridwidth = GridBagConstraints.REMAINDER; |
|
|
|
areaConstr.gridwidth = GridBagConstraints.REMAINDER; |
|
|
|
areaConstr.weightx = 1.0; |
|
|
|
areaConstr.weightx = 1.0; |
|
|
|
areaConstr.weighty = 1.0; |
|
|
|
areaConstr.weighty = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
frame.add(new Label("class path: "), labelConstr); |
|
|
|
window.add(new Label("class path: "), labelConstr); |
|
|
|
frame.add(classpathField, textConstr); |
|
|
|
window.add(classpathField, textConstr); |
|
|
|
frame.add(new Label("class name: "), labelConstr); |
|
|
|
window.add(new Label("class name: "), labelConstr); |
|
|
|
frame.add(classField, textConstr); |
|
|
|
window.add(classField, textConstr); |
|
|
|
frame.add(sourcecodeArea, areaConstr); |
|
|
|
window.add(verboseCheck, checkConstr); |
|
|
|
|
|
|
|
window.add(prettyCheck, checkConstr); |
|
|
|
|
|
|
|
labelConstr.weightx = 1.0; |
|
|
|
|
|
|
|
window.add(new Label(), labelConstr); |
|
|
|
|
|
|
|
window.add(startButton, buttonConstr); |
|
|
|
|
|
|
|
buttonConstr.gridwidth = GridBagConstraints.REMAINDER; |
|
|
|
|
|
|
|
window.add(saveButton, buttonConstr); |
|
|
|
|
|
|
|
window.add(sourcecodeArea, areaConstr); |
|
|
|
areaConstr.gridheight = GridBagConstraints.REMAINDER; |
|
|
|
areaConstr.gridheight = GridBagConstraints.REMAINDER; |
|
|
|
areaConstr.weighty = 0.0; |
|
|
|
areaConstr.weighty = 0.0; |
|
|
|
frame.add(errorArea, areaConstr); |
|
|
|
window.add(errorArea, areaConstr); |
|
|
|
|
|
|
|
|
|
|
|
classField.addActionListener(this); |
|
|
|
startButton.addActionListener(this); |
|
|
|
|
|
|
|
saveButton.addActionListener(this); |
|
|
|
|
|
|
|
|
|
|
|
String cp = System.getProperty("java.class.path"); |
|
|
|
String cp = System.getProperty("java.class.path"); |
|
|
|
if (cp != null) |
|
|
|
if (cp != null) |
|
|
@ -61,19 +87,42 @@ public class JodeWindow |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setClasspath(String cp) { |
|
|
|
public void setClasspath(String cp) { |
|
|
|
classpathField.setText(cp); |
|
|
|
classpathField.setText(cp.replace(File.pathSeparatorChar, ',')); |
|
|
|
} |
|
|
|
} |
|
|
|
public void setClass(String cls) { |
|
|
|
public void setClass(String cls) { |
|
|
|
classField.setText(cls); |
|
|
|
classField.setText(cls); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized void actionPerformed(ActionEvent e) { |
|
|
|
public synchronized void actionPerformed(ActionEvent e) { |
|
|
|
if (decompileThread == null) { |
|
|
|
if (e.getSource() == startButton) { |
|
|
|
|
|
|
|
startButton.setEnabled(false); |
|
|
|
decompileThread = new Thread(this); |
|
|
|
decompileThread = new Thread(this); |
|
|
|
sourcecodeArea.setText("Please wait, while decompiling...\n"); |
|
|
|
sourcecodeArea.setText("Please wait, while decompiling...\n"); |
|
|
|
decompileThread.start(); |
|
|
|
decompileThread.start(); |
|
|
|
} else |
|
|
|
} else if (e.getSource() == saveButton) { |
|
|
|
sourcecodeArea.append("Be a little bit more patient, please.\n"); |
|
|
|
if (frame == null) |
|
|
|
|
|
|
|
frame = new Frame(); //XXX
|
|
|
|
|
|
|
|
FileDialog fd = new FileDialog(frame, |
|
|
|
|
|
|
|
"Save decompiled code", |
|
|
|
|
|
|
|
FileDialog.SAVE); |
|
|
|
|
|
|
|
fd.setFile(lastClassName.substring |
|
|
|
|
|
|
|
(lastClassName.lastIndexOf('.')+1).concat(".java")); |
|
|
|
|
|
|
|
fd.show(); |
|
|
|
|
|
|
|
String fileName = fd.getFile(); |
|
|
|
|
|
|
|
if (fileName == null) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
File f = new File(new File(fd.getDirectory()), fileName); |
|
|
|
|
|
|
|
FileWriter out = new FileWriter(f); |
|
|
|
|
|
|
|
out.write(sourcecodeArea.getText()); |
|
|
|
|
|
|
|
out.close(); |
|
|
|
|
|
|
|
} catch (IOException ex) { |
|
|
|
|
|
|
|
errorArea.setText(""); |
|
|
|
|
|
|
|
Decompiler.err.println("Couldn't write to file " |
|
|
|
|
|
|
|
+ fileName + ": "); |
|
|
|
|
|
|
|
ex.printStackTrace(Decompiler.err); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class AreaOutputStream extends OutputStream { |
|
|
|
public class AreaOutputStream extends OutputStream { |
|
|
@ -93,13 +142,22 @@ public class JodeWindow |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
JodeEnvironment env = new JodeEnvironment(classpathField.getText()); |
|
|
|
Decompiler.isVerbose = verboseCheck.getState(); |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
Decompiler.prettyLocals = prettyCheck.getState(); |
|
|
|
errorArea.setText(""); |
|
|
|
errorArea.setText(""); |
|
|
|
|
|
|
|
saveButton.setEnabled(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastClassName = classField.getText(); |
|
|
|
|
|
|
|
String cp = classpathField.getText(); |
|
|
|
|
|
|
|
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, " "); |
|
|
|
TabbedPrintWriter writer = new TabbedPrintWriter(out, " "); |
|
|
|
env.doClass(classField.getText(), writer); |
|
|
|
env.doClass(lastClassName, writer); |
|
|
|
sourcecodeArea.setText(out.toString()); |
|
|
|
sourcecodeArea.setText(out.toString()); |
|
|
|
|
|
|
|
saveButton.setEnabled(true); |
|
|
|
} catch (Throwable t) { |
|
|
|
} catch (Throwable t) { |
|
|
|
sourcecodeArea.setText("Didn't succeed.\n" |
|
|
|
sourcecodeArea.setText("Didn't succeed.\n" |
|
|
|
+"Check the below area for more info."); |
|
|
|
+"Check the below area for more info."); |
|
|
@ -107,6 +165,7 @@ public class JodeWindow |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
decompileThread = null; |
|
|
|
decompileThread = null; |
|
|
|
|
|
|
|
startButton.setEnabled(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|