*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@169 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 4984990fbe
commit 0c77d2f8e9
  1. 99
      jode/JodeAppletOneZero.java
  2. 41
      jode/jode-applet.html
  3. 103
      jode/jode/JodeWindow.java
  4. 2
      jode/jode/bytecode/SearchPath.java
  5. 6
      jode/jode/decompiler/ImportHandler.java
  6. 2
      jode/maketar

@ -5,12 +5,11 @@ import java.io.*;
public class JodeAppletOneZero extends Applet implements Runnable {
TextField classpathField;
TextField classField;
TextArea sourcecodeArea;
TextArea errorArea;
Thread decompileThread;
TextField classpathField, classField;
TextArea sourcecodeArea, errorArea;
Checkbox verboseCheck, prettyCheck;
Button startButton, saveButton;
String lastClassName;
public JodeAppletOneZero() {
buildComponents(this);
@ -25,23 +24,37 @@ public class JodeAppletOneZero extends Applet implements Runnable {
setClass(cls);
}
private void buildComponents(Container frame) {
private void buildComponents(Container window) {
classpathField = new TextField(50);
classField = new TextField(50);
sourcecodeArea = new TextArea(20, 80);
errorArea = new TextArea(3, 80);
verboseCheck = new Checkbox("verbose");
prettyCheck = new Checkbox("pretty");
startButton = new Button("start");
saveButton = new Button("save");
saveButton.disable();
sourcecodeArea.setEditable(false);
errorArea.setEditable(false);
GridBagLayout gbl = new GridBagLayout();
frame.setLayout(gbl);
window.setLayout(gbl);
GridBagConstraints labelConstr = new GridBagConstraints();
GridBagConstraints textConstr = new GridBagConstraints();
GridBagConstraints areaConstr = new GridBagConstraints();
GridBagConstraints checkConstr = new GridBagConstraints();
GridBagConstraints buttonConstr = new GridBagConstraints();
labelConstr.fill = GridBagConstraints.NONE;
textConstr.fill = GridBagConstraints.HORIZONTAL;
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.weightx = 1.0;
areaConstr.gridwidth = GridBagConstraints.REMAINDER;
@ -50,20 +63,34 @@ public class JodeAppletOneZero extends Applet implements Runnable {
Label label = new Label("class path: ");
gbl.setConstraints(label, labelConstr);
frame.add(label);
window.add(label);
gbl.setConstraints(classpathField, textConstr);
frame.add(classpathField);
window.add(classpathField);
label = new Label("class name: ");
gbl.setConstraints(label, labelConstr);
frame.add(label);
window.add(label);
gbl.setConstraints(classField, textConstr);
frame.add(classField);
window.add(classField);
gbl.setConstraints(verboseCheck, checkConstr);
window.add(verboseCheck);
gbl.setConstraints(prettyCheck, checkConstr);
window.add(prettyCheck);
labelConstr.weightx = 1.0;
label = new Label();
gbl.setConstraints(label, labelConstr);
window.add(label);
gbl.setConstraints(startButton, buttonConstr);
window.add(startButton);
buttonConstr.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints(saveButton, buttonConstr);
window.add(saveButton);
gbl.setConstraints(sourcecodeArea, areaConstr);
frame.add(sourcecodeArea);
window.add(sourcecodeArea);
areaConstr.gridheight = GridBagConstraints.REMAINDER;
areaConstr.weighty = 0.0;
gbl.setConstraints(errorArea, areaConstr);
frame.add(errorArea);
window.add(errorArea);
Decompiler.err = new PrintStream(new AreaOutputStream(errorArea));
}
@ -76,14 +103,32 @@ public class JodeAppletOneZero extends Applet implements Runnable {
}
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");
if (e.target == startButton) {
startButton.disable();
Thread decompileThread = new Thread(this);
sourcecodeArea.setText("Please wait, while decompiling...\n");
decompileThread.start();
} else if (e.target == saveButton) {
FileDialog fd = new FileDialog(new 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 true;
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);
}
}
return true;
}
@ -105,7 +150,12 @@ public class JodeAppletOneZero extends Applet implements Runnable {
}
public void run() {
Decompiler.isVerbose = verboseCheck.getState();
Decompiler.prettyLocals = prettyCheck.getState();
errorArea.setText("");
saveButton.disable();
lastClassName = classField.getText();
String cp = classpathField.getText();
cp = cp.replace(':', jode.bytecode.SearchPath.protocolSeparator);
cp = cp.replace(',', File.pathSeparatorChar);
@ -115,14 +165,13 @@ public class JodeAppletOneZero extends Applet implements Runnable {
TabbedPrintWriter writer = new TabbedPrintWriter(out, " ");
env.doClass(classField.getText(), writer);
sourcecodeArea.setText(out.toString());
saveButton.enable();
} 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;
}
startButton.enable();
}
}
}

@ -3,20 +3,45 @@
<title>Jode Test Applet</title>
</head>
<body>
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.<br>
<a href="index.html">Home</a> <a href="jode.html">Up</a>
<h1>Test Applet</h1>
Press the start button to decompile this applet. You may change the
class name to point to an class file of your choice. But
note that most browsers doesn't allow loading files from a different
server.<br>
Save doesn't work in Netscape because the FileDialog is missing
there. But access to local files is most probably forbidden
anyway. <br>
You may give multiple entries in the class path field separated by a
comma. The components may also be local zip or jar files, but that is
probably forbidden by the browser. <br>
You can download <a href="jode/jode-applet.html">HTML-file</a> and
this <a href="jode_cls.zip">archive, if you want to test it yourself.
You should use the appletviewer in this case.
BTW: If you just want to read the source, you may <a
href="jode/">browse it online</a><br>
<applet code="jode/JodeAppletOneZero.class" codebase="./" width=640 height=400>
<param name=classpath
value="http://nirwana/~jochen/">
value="http://www.informatik.uni-oldenburg.de/~jochen/">
<param name=class value="jode.JodeAppletOneZero">
</applet>
You may run this locally; you need at least a java 1.1 compatible
virtual machine and the <a href="jode_cls.zip">decompiler classes</a>.
The entry class is <code>jode.JodeWindow</code>, so you may start it
under SUN JDK with (the exact commands depend on your operating
system, java virtual machine, shell etc):
<pre>
set CLASSPATH=jode_cls.zip
java jode.JodeWindow
</pre>
<a href="jode.html">Back to the Decompiler Page</a>
</body>
</html>

@ -7,49 +7,75 @@ import java.io.*;
public class JodeWindow
implements ActionListener, Runnable
{
TextField classpathField;
TextField classField;
TextArea sourcecodeArea;
TextArea errorArea;
TextField classpathField, classField;
TextArea sourcecodeArea, errorArea;
Checkbox verboseCheck, prettyCheck;
Button startButton, saveButton;
String lastClassName;
Frame frame;
Thread decompileThread;
public JodeWindow(Container frame) {
buildComponents(frame);
public JodeWindow(Container window) {
buildComponents(window);
}
private void buildComponents(Container frame) {
private void buildComponents(Container window) {
if (window instanceof Frame)
frame = (Frame) window;
classpathField = new TextField(50);
classField = new TextField(50);
sourcecodeArea = new TextArea(20, 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);
errorArea.setEditable(false);
frame.setLayout(new GridBagLayout());
window.setLayout(new GridBagLayout());
GridBagConstraints labelConstr = new GridBagConstraints();
GridBagConstraints textConstr = new GridBagConstraints();
GridBagConstraints areaConstr = new GridBagConstraints();
GridBagConstraints checkConstr = new GridBagConstraints();
GridBagConstraints buttonConstr = new GridBagConstraints();
labelConstr.fill = GridBagConstraints.NONE;
textConstr.fill = GridBagConstraints.HORIZONTAL;
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.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);
window.add(new Label("class path: "), labelConstr);
window.add(classpathField, textConstr);
window.add(new Label("class name: "), labelConstr);
window.add(classField, textConstr);
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.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");
if (cp != null)
@ -61,19 +87,42 @@ public class JodeWindow
}
public void setClasspath(String cp) {
classpathField.setText(cp);
classpathField.setText(cp.replace(File.pathSeparatorChar, ','));
}
public void setClass(String cls) {
classField.setText(cls);
}
public synchronized void actionPerformed(ActionEvent e) {
if (decompileThread == null) {
if (e.getSource() == startButton) {
startButton.setEnabled(false);
decompileThread = new Thread(this);
sourcecodeArea.setText("Please wait, while decompiling...\n");
decompileThread.start();
} else
sourcecodeArea.append("Be a little bit more patient, please.\n");
} else if (e.getSource() == saveButton) {
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 {
@ -93,13 +142,22 @@ public class JodeWindow
}
public void run() {
JodeEnvironment env = new JodeEnvironment(classpathField.getText());
ByteArrayOutputStream out = new ByteArrayOutputStream();
Decompiler.isVerbose = verboseCheck.getState();
Decompiler.prettyLocals = prettyCheck.getState();
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 {
TabbedPrintWriter writer = new TabbedPrintWriter(out, " ");
env.doClass(classField.getText(), writer);
env.doClass(lastClassName, writer);
sourcecodeArea.setText(out.toString());
saveButton.setEnabled(true);
} catch (Throwable t) {
sourcecodeArea.setText("Didn't succeed.\n"
+"Check the below area for more info.");
@ -107,6 +165,7 @@ public class JodeWindow
} finally {
synchronized(this) {
decompileThread = null;
startButton.setEnabled(true);
}
}
}

@ -140,11 +140,13 @@ public class SearchPath {
try {
URL url = new URL(bases[i], filename);
URLConnection conn = url.openConnection();
conn.setAllowUserInteraction(true);
return conn.getInputStream();
} catch (SecurityException ex) {
Decompiler.err.println("Warning: SecurityException"
+" while accessing "
+bases[i]+filename);
ex.printStackTrace(Decompiler.err);
/* ignore and take next element */
} catch (FileNotFoundException ex) {
/* ignore and take next element */

@ -34,9 +34,6 @@ public class JodeEnvironment {
public JodeEnvironment(String path) {
ClassInfo.setClassPath(path);
Type.setEnvironment(this);
imports = new Hashtable();
/* java.lang is always imported */
imports.put("java.lang.*", new Integer(Integer.MAX_VALUE));
}
/**
@ -162,6 +159,9 @@ public class JodeEnvironment {
throws IOException
{
ClassInfo clazz;
imports = new Hashtable();
/* java.lang is always imported */
imports.put("java.lang.*", new Integer(Integer.MAX_VALUE));
try {
clazz = ClassInfo.forName(className);
} catch (IllegalArgumentException ex) {

@ -5,6 +5,8 @@ echo co -u COPYING *.java */*.java >> co.all
echo javac -d \$HOME/java -g Decompiler.java >> co.all
echo javac -d \$HOME/java -g Obfuscator.java >> co.all
echo javac -d \$HOME/java -g JodeApplet.java >> co.all
echo javac -d \$HOME/java -g JodeWindow.java >> co.all
echo javac -d \$HOME/java -g JodeAppletOneZero.java >> co.all
cd ..
tar -cvzf jode.tar.gz jode/co.all jode/RCS jode/*/RCS

Loading…
Cancel
Save