From 10db6a2447fcd518e0c3d69cbcb7c731e19aab29 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 17 Jan 1999 18:17:20 +0000 Subject: [PATCH] Initial revision git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@164 379699f6-c40d-0410-875b-85095c16579e --- jode/JodeAppletOneZero.java | 128 ++++++++++++++++++++++++++++++++++++ jode/jode-applet.html | 22 +++++++ jode/jode/JodeWindow.java | 125 +++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 jode/JodeAppletOneZero.java create mode 100644 jode/jode-applet.html create mode 100644 jode/jode/JodeWindow.java diff --git a/jode/JodeAppletOneZero.java b/jode/JodeAppletOneZero.java new file mode 100644 index 0000000..73f37cb --- /dev/null +++ b/jode/JodeAppletOneZero.java @@ -0,0 +1,128 @@ +package jode; +import java.applet.*; +import java.awt.*; +import java.io.*; + +public class JodeAppletOneZero extends Applet implements Runnable { + + TextField classpathField; + TextField classField; + TextArea sourcecodeArea; + TextArea errorArea; + + Thread decompileThread; + + public JodeAppletOneZero() { + buildComponents(this); + } + + public void init() { + String cp = getParameter("classpath"); + if (cp != null) + setClasspath(cp); + String cls = getParameter("class"); + if (cls != null) + setClass(cls); + } + + private void buildComponents(Container frame) { + classpathField = new TextField(50); + classField = new TextField(50); + sourcecodeArea = new TextArea(20, 80); + errorArea = new TextArea(3, 80); + + sourcecodeArea.setEditable(false); + errorArea.setEditable(false); + + GridBagLayout gbl = new GridBagLayout(); + frame.setLayout(gbl); + GridBagConstraints labelConstr = new GridBagConstraints(); + GridBagConstraints textConstr = new GridBagConstraints(); + GridBagConstraints areaConstr = new GridBagConstraints(); + labelConstr.fill = GridBagConstraints.NONE; + textConstr.fill = GridBagConstraints.HORIZONTAL; + areaConstr.fill = GridBagConstraints.BOTH; + textConstr.gridwidth = GridBagConstraints.REMAINDER; + textConstr.weightx = 1.0; + areaConstr.gridwidth = GridBagConstraints.REMAINDER; + areaConstr.weightx = 1.0; + areaConstr.weighty = 1.0; + + Label label = new Label("class path: "); + gbl.setConstraints(label, labelConstr); + frame.add(label); + gbl.setConstraints(classpathField, textConstr); + frame.add(classpathField); + label = new Label("class name: "); + gbl.setConstraints(label, labelConstr); + frame.add(label); + gbl.setConstraints(classField, textConstr); + frame.add(classField); + gbl.setConstraints(sourcecodeArea, areaConstr); + frame.add(sourcecodeArea); + areaConstr.gridheight = GridBagConstraints.REMAINDER; + areaConstr.weighty = 0.0; + gbl.setConstraints(errorArea, areaConstr); + frame.add(errorArea); + + Decompiler.err = new PrintStream(new AreaOutputStream(errorArea)); + } + + public void setClasspath(String cp) { + classpathField.setText(cp); + } + public void setClass(String cls) { + classField.setText(cls); + } + + public boolean action(Event e, Object arg) { + if (e.target == classField) { + if (decompileThread == null) { + decompileThread = new Thread(this); + sourcecodeArea.setText("Please wait, while decompiling...\n"); + decompileThread.start(); + } else + sourcecodeArea + .appendText("Be a little bit more patient, please.\n"); + } + return true; + } + + public class AreaOutputStream extends OutputStream { + private TextArea area; + + public AreaOutputStream(TextArea a) { + area = a; + } + + public void write(int b) throws IOException { + area.appendText(String.valueOf((byte)b)); + } + + public void write(byte[] b, int off, int len) throws IOException { + area.appendText(new String(b, off, len)); + } + } + + public void run() { + errorArea.setText(""); + 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 { + TabbedPrintWriter writer = new TabbedPrintWriter(out, " "); + env.doClass(classField.getText(), writer); + sourcecodeArea.setText(out.toString()); + } catch (Throwable t) { + sourcecodeArea.setText("Didn't succeed.\n" + +"Check the below area for more info."); + t.printStackTrace(Decompiler.err); + } finally { + synchronized(this) { + decompileThread = null; + } + } + } +} diff --git a/jode/jode-applet.html b/jode/jode-applet.html new file mode 100644 index 0000000..6ad1dd0 --- /dev/null +++ b/jode/jode-applet.html @@ -0,0 +1,22 @@ + + +Jode Test Applet + + + +Press enter in the class name field to decompile this applet. You may +change the class path and name to point to an class file of your +choice. But note that most browsers doesn't allow loading files from +a different server.
+ +You can download HTML-file and +this archive, if you want to test it yourself. +You should use the appletviewer in this case. + + + + + + + \ No newline at end of file diff --git a/jode/jode/JodeWindow.java b/jode/jode/JodeWindow.java new file mode 100644 index 0000000..21f697a --- /dev/null +++ b/jode/jode/JodeWindow.java @@ -0,0 +1,125 @@ +package jode; +import java.applet.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; + +public class JodeWindow + implements ActionListener, Runnable +{ + TextField classpathField; + TextField classField; + TextArea sourcecodeArea; + TextArea errorArea; + + Thread decompileThread; + + public JodeWindow(Container frame) { + buildComponents(frame); + } + + private void buildComponents(Container frame) { + classpathField = new TextField(50); + classField = new TextField(50); + sourcecodeArea = new TextArea(20, 80); + errorArea = new TextArea(3, 80); + + sourcecodeArea.setEditable(false); + errorArea.setEditable(false); + + frame.setLayout(new GridBagLayout()); + GridBagConstraints labelConstr = new GridBagConstraints(); + GridBagConstraints textConstr = new GridBagConstraints(); + GridBagConstraints areaConstr = new GridBagConstraints(); + labelConstr.fill = GridBagConstraints.NONE; + textConstr.fill = GridBagConstraints.HORIZONTAL; + areaConstr.fill = GridBagConstraints.BOTH; + textConstr.gridwidth = GridBagConstraints.REMAINDER; + textConstr.weightx = 1.0; + areaConstr.gridwidth = GridBagConstraints.REMAINDER; + areaConstr.weightx = 1.0; + areaConstr.weighty = 1.0; + + frame.add(new Label("class path: "), labelConstr); + frame.add(classpathField, textConstr); + frame.add(new Label("class name: "), labelConstr); + frame.add(classField, textConstr); + frame.add(sourcecodeArea, areaConstr); + areaConstr.gridheight = GridBagConstraints.REMAINDER; + areaConstr.weighty = 0.0; + frame.add(errorArea, areaConstr); + + classField.addActionListener(this); + + String cp = System.getProperty("java.class.path"); + if (cp != null) + classpathField.setText(cp); + String cls = "jode.JodeWindow"; + classField.setText(cls); + + Decompiler.err = new PrintStream(new AreaOutputStream(errorArea)); + } + + public void setClasspath(String cp) { + classpathField.setText(cp); + } + public void setClass(String cls) { + classField.setText(cls); + } + + public synchronized void actionPerformed(ActionEvent e) { + if (decompileThread == null) { + decompileThread = new Thread(this); + sourcecodeArea.setText("Please wait, while decompiling...\n"); + decompileThread.start(); + } else + sourcecodeArea.append("Be a little bit more patient, please.\n"); + } + + public class AreaOutputStream extends OutputStream { + private TextArea area; + + public AreaOutputStream(TextArea a) { + area = a; + } + + public void write(int b) throws IOException { + area.append(String.valueOf((byte)b)); + } + + public void write(byte[] b, int off, int len) throws IOException { + area.append(new String(b, off, len)); + } + } + + public void run() { + JodeEnvironment env = new JodeEnvironment(classpathField.getText()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + errorArea.setText(""); + try { + TabbedPrintWriter writer = new TabbedPrintWriter(out, " "); + env.doClass(classField.getText(), writer); + sourcecodeArea.setText(out.toString()); + } catch (Throwable t) { + sourcecodeArea.setText("Didn't succeed.\n" + +"Check the below area for more info."); + t.printStackTrace(); + } finally { + synchronized(this) { + decompileThread = null; + } + } + } + + public static void main(String argv[]) { + Frame frame = new Frame(Decompiler.copyright); + new JodeWindow(frame); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + frame.pack(); + frame.show(); + } +}