new_decompiler_package

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@255 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 2ddfc783b7
commit ab5f3eb09f
  1. 1
      jode/JodeAppletOneZero.java
  2. 1
      jode/jode/Decompiler.java
  3. 1
      jode/jode/JodeWindow.java
  4. 2
      jode/jode/bytecode/AttributeInfo.java
  5. 2
      jode/jode/decompiler/Analyzer.java
  6. 67
      jode/jode/decompiler/ClassAnalyzer.java
  7. 4
      jode/jode/decompiler/CodeAnalyzer.java
  8. 7
      jode/jode/decompiler/FieldAnalyzer.java
  9. 2
      jode/jode/decompiler/ImportHandler.java
  10. 4
      jode/jode/decompiler/LocalInfo.java
  11. 4
      jode/jode/decompiler/LocalVariableRangeList.java
  12. 6
      jode/jode/decompiler/LocalVariableTable.java
  13. 11
      jode/jode/decompiler/MethodAnalyzer.java
  14. 9
      jode/jode/decompiler/Opcodes.java
  15. 3
      jode/jode/decompiler/TabbedPrintWriter.java
  16. 2
      jode/jode/expr/CheckNullOperator.java
  17. 2
      jode/jode/expr/ClassFieldOperator.java
  18. 2
      jode/jode/expr/ConstantArrayOperator.java
  19. 2
      jode/jode/expr/GetFieldOperator.java
  20. 2
      jode/jode/expr/IIncOperator.java
  21. 2
      jode/jode/expr/InvokeOperator.java
  22. 2
      jode/jode/expr/LocalLoadOperator.java
  23. 2
      jode/jode/expr/LocalStoreOperator.java
  24. 2
      jode/jode/expr/LocalVarOperator.java
  25. 8
      jode/jode/expr/PutFieldOperator.java
  26. 2
      jode/jode/flow/BreakBlock.java
  27. 2
      jode/jode/flow/BreakableBlock.java
  28. 4
      jode/jode/flow/CaseBlock.java
  29. 6
      jode/jode/flow/CatchBlock.java
  30. 2
      jode/jode/flow/ConditionalBlock.java
  31. 2
      jode/jode/flow/ContinueBlock.java
  32. 2
      jode/jode/flow/CreateCheckNull.java
  33. 2
      jode/jode/flow/DescriptionBlock.java
  34. 2
      jode/jode/flow/EmptyBlock.java
  35. 2
      jode/jode/flow/FinallyBlock.java
  36. 5
      jode/jode/flow/FlowBlock.java
  37. 2
      jode/jode/flow/IfThenElseBlock.java
  38. 4
      jode/jode/flow/InstructionBlock.java
  39. 2
      jode/jode/flow/JsrBlock.java
  40. 2
      jode/jode/flow/Jump.java
  41. 4
      jode/jode/flow/LoopBlock.java
  42. 4
      jode/jode/flow/RetBlock.java
  43. 2
      jode/jode/flow/ReturnBlock.java
  44. 2
      jode/jode/flow/SequentialBlock.java
  45. 2
      jode/jode/flow/SpecialBlock.java
  46. 12
      jode/jode/flow/StructuredBlock.java
  47. 2
      jode/jode/flow/SwitchBlock.java
  48. 4
      jode/jode/flow/SynchronizedBlock.java
  49. 2
      jode/jode/flow/ThrowBlock.java
  50. 8
      jode/jode/flow/TransformConstructors.java
  51. 2
      jode/jode/flow/TransformExceptionHandlers.java
  52. 2
      jode/jode/flow/TryBlock.java
  53. 2
      jode/jode/flow/VariableSet.java
  54. 4
      jode/jode/obfuscator/ClassBundle.java
  55. 44
      jode/jode/obfuscator/ClassIdentifier.java
  56. 9
      jode/jode/obfuscator/FieldIdentifier.java
  57. 6
      jode/jode/obfuscator/Identifier.java
  58. 8
      jode/jode/obfuscator/Main.java
  59. 13
      jode/jode/obfuscator/MethodIdentifier.java
  60. 35
      jode/jode/obfuscator/PackageIdentifier.java

@ -2,6 +2,7 @@ package jode;
import java.applet.*; import java.applet.*;
import java.awt.*; import java.awt.*;
import java.io.*; import java.io.*;
import jode.decompiler.TabbedPrintWriter;
public class JodeAppletOneZero extends Applet implements Runnable { public class JodeAppletOneZero extends Applet implements Runnable {

@ -19,6 +19,7 @@
package jode; package jode;
import java.io.*; import java.io.*;
import jode.decompiler.TabbedPrintWriter;
public class Decompiler { public class Decompiler {
public final static String version = "0.99"; public final static String version = "0.99";

@ -3,6 +3,7 @@ import java.applet.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
import jode.decompiler.TabbedPrintWriter;
public class JodeWindow public class JodeWindow
implements ActionListener, Runnable implements ActionListener, Runnable

@ -17,7 +17,7 @@
* $Id$ * $Id$
*/ */
package jode.bytecode; package jode.bytecode;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import java.io.*; import java.io.*;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;

@ -17,7 +17,7 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
public interface Analyzer { public interface Analyzer {
public void analyze(); public void analyze();

@ -17,20 +17,22 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import jode.*;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;
import jode.bytecode.FieldInfo; import jode.bytecode.FieldInfo;
import jode.bytecode.MethodInfo; import jode.bytecode.MethodInfo;
import jode.bytecode.ConstantPool; import jode.bytecode.ConstantPool;
import jode.bytecode.ClassFormatException; import jode.bytecode.ClassFormatException;
import jode.decompiler.Expression; import jode.expr.Expression;
import jode.flow.TransformConstructors; import jode.flow.TransformConstructors;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
public class ClassAnalyzer implements Analyzer { public class ClassAnalyzer implements Analyzer {
JodeEnvironment env; JodeEnvironment env;
Analyzer[] analyzers; FieldAnalyzer[] fields;
MethodAnalyzer[] methods;
MethodAnalyzer staticConstructor; MethodAnalyzer staticConstructor;
MethodAnalyzer[] constructors; MethodAnalyzer[] constructors;
@ -46,14 +48,14 @@ public class ClassAnalyzer implements Analyzer {
this.env = env; this.env = env;
} }
public boolean setFieldInitializer(String fieldName, Expression expr) { public boolean setFieldInitializer(String fieldName, Type fieldType,
for (int i=0; i< analyzers.length; i++) { Expression expr) {
if (analyzers[i] instanceof FieldAnalyzer) { for (int i=0; i< fields.length; i++) {
FieldAnalyzer field = (FieldAnalyzer) analyzers[i]; if (fields[i].getName().equals(fieldName)
if (field.getName().equals(fieldName)) && fields[i].getType().isOfType(fieldType))
return field.setInitializer(expr); return fields[i].setInitializer(expr);
}
} }
System.err.println("Can't find field "+fieldType+" "+fieldName+".");
return false; return false;
} }
@ -65,37 +67,42 @@ public class ClassAnalyzer implements Analyzer {
int numFields = 0; int numFields = 0;
int i = 0; int i = 0;
FieldInfo[] fields = clazz.getFields(); FieldInfo[] finfos = clazz.getFields();
MethodInfo[] methods = clazz.getMethods(); MethodInfo[] minfos = clazz.getMethods();
if (fields == null) { if (finfos == null) {
/* This means that the class could not be loaded. /* This means that the class could not be loaded.
* give up. * give up.
*/ */
return; return;
} }
analyzers = new Analyzer[fields.length + fields = new FieldAnalyzer[finfos.length];
methods.length]; methods = new MethodAnalyzer[minfos.length];
for (int j=0; j < fields.length; j++) { for (int j=0; j < finfos.length; j++) {
analyzers[i] = new FieldAnalyzer(this, fields[j], env); fields[j] = new FieldAnalyzer(this, finfos[j], env);
analyzers[i++].analyze(); fields[j].analyze();
} }
staticConstructor = null; staticConstructor = null;
java.util.Vector constrVector = new java.util.Vector(); java.util.Vector constrVector = new java.util.Vector();
for (int j=0; j < methods.length; j++) { for (int j=0; j < methods.length; j++) {
MethodAnalyzer analyzer = methods[j] = new MethodAnalyzer(this, minfos[j], env);
new MethodAnalyzer(this, methods[j], env);
analyzers[i++] = analyzer;
if (analyzer.isConstructor()) { if (methods[j].isConstructor()) {
if (analyzer.isStatic()) if (methods[j].isStatic())
staticConstructor = analyzer; staticConstructor = methods[j];
else else
constrVector.addElement(analyzer); constrVector.addElement(methods[j]);
} }
analyzer.analyze(); // First analyze only synthetic methods.
if (methods[j].isSynthetic())
methods[j].analyze();
} }
for (int j=0; j < methods.length; j++) {
// Now analyze the remaining methods
if (!methods[j].isSynthetic())
methods[j].analyze();
}
constructors = new MethodAnalyzer[constrVector.size()]; constructors = new MethodAnalyzer[constrVector.size()];
if (constructors.length > 0) { if (constructors.length > 0) {
constrVector.copyInto(constructors); constrVector.copyInto(constructors);
@ -115,7 +122,7 @@ public class ClassAnalyzer implements Analyzer {
public void dumpSource(TabbedPrintWriter writer) throws java.io.IOException public void dumpSource(TabbedPrintWriter writer) throws java.io.IOException
{ {
if (analyzers == null) { if (fields == null) {
/* This means that the class could not be loaded. /* This means that the class could not be loaded.
* give up. * give up.
*/ */
@ -148,8 +155,10 @@ public class ClassAnalyzer implements Analyzer {
writer.openBrace(); writer.openBrace();
writer.tab(); writer.tab();
for (int i=0; i< analyzers.length; i++) for (int i=0; i< fields.length; i++)
analyzers[i].dumpSource(writer); fields[i].dumpSource(writer);
for (int i=0; i< methods.length; i++)
methods[i].dumpSource(writer);
writer.untab(); writer.untab();
writer.closeBrace(); writer.closeBrace();
} }

@ -17,12 +17,12 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import jode.*;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;
import jode.bytecode.ConstantPool; import jode.bytecode.ConstantPool;
import jode.bytecode.AttributeInfo; import jode.bytecode.AttributeInfo;
import jode.bytecode.CodeInfo; import jode.bytecode.CodeInfo;
import jode.expr.Opcodes;
import jode.flow.FlowBlock; import jode.flow.FlowBlock;
import jode.flow.TransformExceptionHandlers; import jode.flow.TransformExceptionHandlers;

@ -17,8 +17,9 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import jode.*;
import jode.bytecode.FieldInfo; import jode.bytecode.FieldInfo;
import jode.bytecode.AttributeInfo; import jode.bytecode.AttributeInfo;
import jode.bytecode.ClassFormatException; import jode.bytecode.ClassFormatException;
@ -69,6 +70,10 @@ public class FieldAnalyzer implements Analyzer {
return fieldName; return fieldName;
} }
public Type getType() {
return type;
}
public boolean setInitializer(Expression expr) { public boolean setInitializer(Expression expr) {
expr.makeInitializer(); expr.makeInitializer();
if (constant != null) if (constant != null)

@ -19,6 +19,8 @@
package jode; package jode;
import java.util.*; import java.util.*;
import jode.decompiler.TabbedPrintWriter;
import jode.decompiler.ClassAnalyzer;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;
import java.io.IOException; import java.io.IOException;

@ -17,9 +17,11 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;
import jode.Decompiler;
import jode.Type;
import jode.expr.LocalVarOperator; import jode.expr.LocalVarOperator;
/** /**

@ -17,7 +17,9 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import jode.Decompiler;
import jode.Type;
public class LocalVariableRangeList { public class LocalVariableRangeList {

@ -17,10 +17,12 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import java.io.*;
import jode.Decompiler;
import jode.Type;
import jode.bytecode.AttributeInfo; import jode.bytecode.AttributeInfo;
import jode.bytecode.ConstantPool; import jode.bytecode.ConstantPool;
import java.io.*;
public class LocalVariableTable { public class LocalVariableTable {
LocalVariableRangeList[] locals; LocalVariableRangeList[] locals;

@ -17,10 +17,11 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import jode.bytecode.MethodInfo; import jode.bytecode.MethodInfo;
import jode.bytecode.AttributeInfo; import jode.bytecode.AttributeInfo;
import jode.bytecode.CodeInfo; import jode.bytecode.CodeInfo;
import jode.*;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.io.*; import java.io.*;
@ -30,6 +31,7 @@ public class MethodAnalyzer implements Analyzer {
CodeAnalyzer code = null; CodeAnalyzer code = null;
ClassAnalyzer classAnalyzer; ClassAnalyzer classAnalyzer;
boolean isConstructor; boolean isConstructor;
boolean isSynthetic;
int modifiers; int modifiers;
String methodName; String methodName;
MethodType methodType; MethodType methodType;
@ -44,6 +46,7 @@ public class MethodAnalyzer implements Analyzer {
this.methodName = minfo.getName(); this.methodName = minfo.getName();
this.isConstructor = this.isConstructor =
methodName.equals("<init>") || methodName.equals("<clinit>"); methodName.equals("<init>") || methodName.equals("<clinit>");
this.isSynthetic = (minfo.findAttribute("Synthetic") != null);
AttributeInfo codeattr = minfo.findAttribute("Code"); AttributeInfo codeattr = minfo.findAttribute("Code");
if (codeattr != null) { if (codeattr != null) {
@ -91,6 +94,10 @@ public class MethodAnalyzer implements Analyzer {
return methodType.isStatic(); return methodType.isStatic();
} }
public boolean isSynthetic() {
return isSynthetic;
}
public int getParamCount() { public int getParamCount() {
int count = isStatic() ? 0 : 1; int count = isStatic() ? 0 : 1;
Type[] paramTypes = methodType.getParameterTypes(); Type[] paramTypes = methodType.getParameterTypes();
@ -130,7 +137,7 @@ public class MethodAnalyzer implements Analyzer {
if (!isConstructor) if (!isConstructor)
methodType.getReturnType().useType(); methodType.getReturnType().useType();
if (!Decompiler.immediateOutput) { if (!Decompiler.immediateOutput || isSynthetic) {
if (Decompiler.isVerbose) if (Decompiler.isVerbose)
Decompiler.err.print(methodName+": "); Decompiler.err.print(methodName+": ");
code.analyze(); code.analyze();

@ -17,11 +17,10 @@
* $Id$ * $Id$
*/ */
package jode.expr; package jode.decompiler;
import jode.CodeAnalyzer;
import jode.LocalInfo;
import jode.Type; import jode.Type;
import jode.MethodType; import jode.MethodType;
import jode.expr.*;
import jode.flow.*; import jode.flow.*;
import jode.bytecode.*; import jode.bytecode.*;
import java.io.*; import java.io.*;
@ -56,8 +55,8 @@ public abstract class Opcodes implements jode.bytecode.Opcodes {
}; };
private static StructuredBlock createNormal(CodeAnalyzer ca, private static StructuredBlock createNormal(CodeAnalyzer ca,
int addr, int length, int addr, int length,
Expression instr) Expression instr)
{ {
return new InstructionBlock(instr, new Jump(addr+length)); return new InstructionBlock(instr, new Jump(addr+length));
} }

@ -17,8 +17,9 @@
* $Id$ * $Id$
*/ */
package jode; package jode.decompiler;
import java.io.*; import java.io.*;
import jode.Decompiler;
public class TabbedPrintWriter { public class TabbedPrintWriter {
boolean atbol; boolean atbol;

@ -19,7 +19,7 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
/** /**
* This is a pseudo operator, which represents the check against null * This is a pseudo operator, which represents the check against null

@ -19,7 +19,7 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
public class ClassFieldOperator extends NoArgOperator { public class ClassFieldOperator extends NoArgOperator {
Type classType; Type classType;

@ -17,7 +17,7 @@
* $Id$ * $Id$
*/ */
package jode.decompiler; package jode.expr;
import jode.Type; import jode.Type;
import jode.ArrayType; import jode.ArrayType;

@ -19,7 +19,7 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
public class GetFieldOperator extends Operator { public class GetFieldOperator extends Operator {
boolean staticFlag; boolean staticFlag;

@ -19,7 +19,7 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
public class IIncOperator extends NoArgOperator public class IIncOperator extends NoArgOperator
implements LocalVarOperator, CombineableOperator { implements LocalVarOperator, CombineableOperator {

@ -18,7 +18,7 @@
*/ */
package jode.expr; package jode.expr;
import jode.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
import jode.MethodType; import jode.MethodType;
import jode.Type; import jode.Type;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;

@ -20,7 +20,7 @@
package jode.expr; package jode.expr;
import jode.Decompiler; import jode.Decompiler;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
public class LocalLoadOperator extends ConstOperator public class LocalLoadOperator extends ConstOperator
implements LocalVarOperator { implements LocalVarOperator {

@ -19,7 +19,7 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
public class LocalStoreOperator extends StoreInstruction public class LocalStoreOperator extends StoreInstruction
implements LocalVarOperator { implements LocalVarOperator {

@ -19,7 +19,7 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
public interface LocalVarOperator { public interface LocalVarOperator {
public boolean isRead(); public boolean isRead();

@ -19,12 +19,13 @@
package jode.expr; package jode.expr;
import jode.Type; import jode.Type;
import jode.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
public class PutFieldOperator extends StoreInstruction { public class PutFieldOperator extends StoreInstruction {
CodeAnalyzer codeAnalyzer; CodeAnalyzer codeAnalyzer;
boolean staticFlag; boolean staticFlag;
String fieldName; String fieldName;
Type fieldType;
Type classType; Type classType;
public PutFieldOperator(CodeAnalyzer codeAnalyzer, boolean staticFlag, public PutFieldOperator(CodeAnalyzer codeAnalyzer, boolean staticFlag,
@ -33,6 +34,7 @@ public class PutFieldOperator extends StoreInstruction {
this.codeAnalyzer = codeAnalyzer; this.codeAnalyzer = codeAnalyzer;
this.staticFlag = staticFlag; this.staticFlag = staticFlag;
this.fieldName = fieldName; this.fieldName = fieldName;
this.fieldType = type;
this.classType = classType; this.classType = classType;
if (staticFlag) if (staticFlag)
classType.useType(); classType.useType();
@ -46,6 +48,10 @@ public class PutFieldOperator extends StoreInstruction {
return fieldName; return fieldName;
} }
public Type getFieldType() {
return fieldType;
}
public boolean matches(Operator loadop) { public boolean matches(Operator loadop) {
return loadop instanceof GetFieldOperator return loadop instanceof GetFieldOperator
&& ((GetFieldOperator)loadop).classType.equals(classType) && ((GetFieldOperator)loadop).classType.equals(classType)

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* *

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* This is a structured block, that supports break. * This is a structured block, that supports break.

@ -105,7 +105,7 @@ public class CaseBlock extends StructuredBlock {
public void makeDeclaration(VariableSet done) { public void makeDeclaration(VariableSet done) {
java.util.Enumeration enum = allUsed.elements(); java.util.Enumeration enum = allUsed.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
jode.LocalInfo li = (jode.LocalInfo) enum.nextElement(); jode.decompiler.LocalInfo li = (jode.decompiler.LocalInfo) enum.nextElement();
if (!done.contains(li)) { if (!done.contains(li)) {
wantBraces = true; wantBraces = true;
break; break;
@ -123,7 +123,7 @@ public class CaseBlock extends StructuredBlock {
: new StructuredBlock[0]; : new StructuredBlock[0];
} }
public void dumpInstruction(jode.TabbedPrintWriter writer) public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
if (isDefault) { if (isDefault) {

@ -18,7 +18,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
/** /**
* *
@ -91,7 +91,7 @@ public class CatchBlock extends StructuredBlock {
* @param writer The tabbed print writer, where we print to. * @param writer The tabbed print writer, where we print to.
* @param local The local that should be declared. * @param local The local that should be declared.
*/ */
public void dumpDeclaration(jode.TabbedPrintWriter writer, LocalInfo local) public void dumpDeclaration(jode.decompiler.TabbedPrintWriter writer, LocalInfo local)
throws java.io.IOException throws java.io.IOException
{ {
if (local != exceptionLocal) { if (local != exceptionLocal) {
@ -102,7 +102,7 @@ public class CatchBlock extends StructuredBlock {
} }
} }
public void dumpInstruction(jode.TabbedPrintWriter writer) public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException { throws java.io.IOException {
writer.closeBraceContinue(); writer.closeBraceContinue();
writer.print("catch ("+exceptionType.toString() + " " writer.print("catch ("+exceptionType.toString() + " "

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.expr.Expression; import jode.expr.Expression;
import jode.expr.LocalVarOperator; import jode.expr.LocalVarOperator;

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* *

@ -20,7 +20,7 @@
package jode.flow; package jode.flow;
import jode.expr.*; import jode.expr.*;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
public class CreateCheckNull { public class CreateCheckNull {

@ -18,7 +18,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* This is a block which contains a comment/description of what went * This is a block which contains a comment/description of what went

@ -18,7 +18,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* This is the structured block for an empty block. * This is the structured block for an empty block.

@ -44,7 +44,7 @@ public class FinallyBlock extends CatchBlock {
return null; return null;
} }
public void dumpInstruction(jode.TabbedPrintWriter writer) public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException { throws java.io.IOException {
writer.closeBraceContinue(); writer.closeBraceContinue();
writer.print("finally"); writer.print("finally");

@ -19,7 +19,10 @@
package jode.flow; package jode.flow;
import java.util.*; import java.util.*;
import jode.*; import jode.Decompiler;
import jode.AssertError;
import jode.decompiler.TabbedPrintWriter;
import jode.decompiler.CodeAnalyzer;
import jode.expr.Expression; import jode.expr.Expression;
import jode.expr.CombineableOperator; import jode.expr.CombineableOperator;

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.expr.Expression; import jode.expr.Expression;
/** /**

@ -16,8 +16,8 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
import jode.expr.ComplexExpression; import jode.expr.ComplexExpression;
import jode.expr.Expression; import jode.expr.Expression;
import jode.expr.LocalStoreOperator; import jode.expr.LocalStoreOperator;

@ -63,7 +63,7 @@ public class JsrBlock extends StructuredBlock {
return new StructuredBlock[] { innerBlock }; return new StructuredBlock[] { innerBlock };
} }
public void dumpInstruction(jode.TabbedPrintWriter writer) public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
writer.println("JSR"); writer.println("JSR");

@ -85,7 +85,7 @@ public class Jump {
* dumpInstruction afterwards. * dumpInstruction afterwards.
* @param writer The tabbed print writer, where we print to. * @param writer The tabbed print writer, where we print to.
*/ */
public void dumpSource(jode.TabbedPrintWriter writer) public void dumpSource(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
if (jode.Decompiler.debugInOut) { if (jode.Decompiler.debugInOut) {

@ -18,9 +18,9 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
import jode.expr.Expression; import jode.expr.Expression;
import jode.expr.ConstOperator; import jode.expr.ConstOperator;
import jode.expr.LocalStoreOperator; import jode.expr.LocalStoreOperator;

@ -17,7 +17,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
/** /**
* This block represents a ret instruction. A ret instruction is * This block represents a ret instruction. A ret instruction is
@ -46,7 +46,7 @@ public class RetBlock extends StructuredBlock {
gen.addElement(local); gen.addElement(local);
} }
public void dumpInstruction(jode.TabbedPrintWriter writer) public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
writer.println("RET "+local); writer.println("RET "+local);

@ -18,7 +18,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.expr.Expression; import jode.expr.Expression;
/** /**

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* A sequential block combines exactly two structured blocks to a new * A sequential block combines exactly two structured blocks to a new

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.Decompiler; import jode.Decompiler;
import jode.expr.*; import jode.expr.*;

@ -18,9 +18,9 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter;
import jode.AssertError; import jode.AssertError;
import jode.LocalInfo; import jode.decompiler.TabbedPrintWriter;
import jode.decompiler.LocalInfo;
/** /**
* A structured block is the building block of the source programm. * A structured block is the building block of the source programm.
@ -473,7 +473,7 @@ public abstract class StructuredBlock {
* dumpInstruction afterwards. * dumpInstruction afterwards.
* @param writer The tabbed print writer, where we print to. * @param writer The tabbed print writer, where we print to.
*/ */
public void dumpSource(jode.TabbedPrintWriter writer) public void dumpSource(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
if (declare != null) { if (declare != null) {
@ -499,7 +499,7 @@ public abstract class StructuredBlock {
* @param writer The tabbed print writer, where we print to. * @param writer The tabbed print writer, where we print to.
* @param local The local that should be declared. * @param local The local that should be declared.
*/ */
public void dumpDeclaration(jode.TabbedPrintWriter writer, LocalInfo local) public void dumpDeclaration(jode.decompiler.TabbedPrintWriter writer, LocalInfo local)
throws java.io.IOException throws java.io.IOException
{ {
writer.println(local.getType().toString() + " " writer.println(local.getType().toString() + " "
@ -516,8 +516,8 @@ public abstract class StructuredBlock {
public String toString() { public String toString() {
try { try {
java.io.StringWriter strw = new java.io.StringWriter(); java.io.StringWriter strw = new java.io.StringWriter();
jode.TabbedPrintWriter writer = jode.decompiler.TabbedPrintWriter writer =
new jode.TabbedPrintWriter(strw); new jode.decompiler.TabbedPrintWriter(strw);
writer.println(super.toString()); writer.println(super.toString());
writer.tab(); writer.tab();
dumpSource(writer); dumpSource(writer);

@ -18,7 +18,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.expr.Expression; import jode.expr.Expression;
/** /**

@ -17,8 +17,8 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.expr.Expression; import jode.expr.Expression;
/** /**

@ -18,7 +18,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
import jode.expr.Expression; import jode.expr.Expression;
/** /**

@ -17,7 +17,8 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.ClassAnalyzer; import jode.decompiler.ClassAnalyzer;
import jode.decompiler.MethodAnalyzer;
import jode.expr.*; import jode.expr.*;
/** /**
@ -28,7 +29,7 @@ public class TransformConstructors {
public static void transform(ClassAnalyzer clazzAnalyzer, public static void transform(ClassAnalyzer clazzAnalyzer,
boolean isStatic, boolean isStatic,
jode.MethodAnalyzer[] cons) { MethodAnalyzer[] cons) {
if (cons.length == 0) if (cons.length == 0)
return; return;
@ -132,7 +133,8 @@ public class TransformConstructors {
} }
if (!clazzAnalyzer.setFieldInitializer(pfo.getFieldName(), expr)) { if (!clazzAnalyzer.setFieldInitializer(pfo.getFieldName(),
pfo.getFieldType(), expr)) {
// Decompiler.err.println("setField failed"); // Decompiler.err.println("setField failed");
break big_loop; break big_loop;
} }

@ -20,7 +20,7 @@ package jode.flow;
import jode.AssertError; import jode.AssertError;
import jode.Decompiler; import jode.Decompiler;
import jode.Type; import jode.Type;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
import jode.expr.*; import jode.expr.*;
import java.util.Enumeration; import java.util.Enumeration;

@ -17,7 +17,7 @@
*/ */
package jode.flow; package jode.flow;
import jode.TabbedPrintWriter; import jode.decompiler.TabbedPrintWriter;
/** /**
* A TryBlock is created for each exception in the * A TryBlock is created for each exception in the

@ -16,7 +16,7 @@
* $Id$ * $Id$
*/ */
package jode.flow; package jode.flow;
import jode.LocalInfo; import jode.decompiler.LocalInfo;
/** /**
* This class represents a set of Variables, which are mainly used in * This class represents a set of Variables, which are mainly used in

@ -67,10 +67,6 @@ public class ClassBundle {
} }
} }
public void strip() {
basePackage.strip();
}
public void buildTable(int renameRule) { public void buildTable(int renameRule) {
basePackage.buildTable(renameRule); basePackage.buildTable(renameRule);
} }

@ -216,21 +216,10 @@ public class ClassIdentifier extends Identifier {
preserveIdentifier("<init>", null); preserveIdentifier("<init>", null);
} }
public void strip() {
willStrip = true;
if (Obfuscator.isDebugging) {
for (int i=0; i < identifiers.length; i++) {
if (!identifiers[i].isReachable())
Obfuscator.err.println(identifiers[i].toString()
+ " is stripped");
}
}
}
public void buildTable(int renameRule) { public void buildTable(int renameRule) {
super.buildTable(renameRule); super.buildTable(renameRule);
for (int i=0; i < identifiers.length; i++) for (int i=0; i < identifiers.length; i++)
if (!willStrip || identifiers[i].isReachable()) if (!Obfuscator.shouldStrip || identifiers[i].isReachable())
identifiers[i].buildTable(renameRule); identifiers[i].buildTable(renameRule);
} }
@ -238,7 +227,7 @@ public class ClassIdentifier extends Identifier {
if (getName() != getAlias()) if (getName() != getAlias())
out.println("" + getFullAlias() + " = " + getName()); out.println("" + getFullAlias() + " = " + getName());
for (int i=0; i < identifiers.length; i++) for (int i=0; i < identifiers.length; i++)
if (!willStrip || identifiers[i].isReachable()) if (!Obfuscator.shouldStrip || identifiers[i].isReachable())
identifiers[i].writeTable(out); identifiers[i].writeTable(out);
} }
@ -295,7 +284,7 @@ public class ClassIdentifier extends Identifier {
GrowableConstantPool gcp = new GrowableConstantPool(); GrowableConstantPool gcp = new GrowableConstantPool();
for (int i=fieldCount; i < identifiers.length; i++) for (int i=fieldCount; i < identifiers.length; i++)
if (!willStrip || identifiers[i].isReachable()) if (!Obfuscator.shouldStrip || identifiers[i].isReachable())
((MethodIdentifier)identifiers[i]).reserveSmallConstants(gcp); ((MethodIdentifier)identifiers[i]).reserveSmallConstants(gcp);
int[] hierarchyInts; int[] hierarchyInts;
@ -316,13 +305,13 @@ public class ClassIdentifier extends Identifier {
int methods = 0; int methods = 0;
for (int i=0; i<fieldCount; i++) { for (int i=0; i<fieldCount; i++) {
if (!willStrip || identifiers[i].isReachable()) { if (!Obfuscator.shouldStrip || identifiers[i].isReachable()) {
((FieldIdentifier)identifiers[i]).fillConstantPool(gcp); ((FieldIdentifier)identifiers[i]).fillConstantPool(gcp);
fields++; fields++;
} }
} }
for (int i=fieldCount; i < identifiers.length; i++) { for (int i=fieldCount; i < identifiers.length; i++) {
if (!willStrip || identifiers[i].isReachable()) { if (!Obfuscator.shouldStrip || identifiers[i].isReachable()) {
((MethodIdentifier)identifiers[i]).fillConstantPool(gcp); ((MethodIdentifier)identifiers[i]).fillConstantPool(gcp);
methods++; methods++;
} }
@ -341,13 +330,22 @@ public class ClassIdentifier extends Identifier {
out.writeShort(hierarchyInts[i]); out.writeShort(hierarchyInts[i]);
out.writeShort(fields); out.writeShort(fields);
for (int i=0; i<fieldCount; i++) for (int i=0; i<fieldCount; i++) {
if (!willStrip || identifiers[i].isReachable()) if (!Obfuscator.shouldStrip || identifiers[i].isReachable())
((FieldIdentifier)identifiers[i]).write(out); ((FieldIdentifier)identifiers[i]).write(out);
else if (Obfuscator.isDebugging)
Obfuscator.err.println(identifiers[i].toString()
+ " is stripped");
}
out.writeShort(methods); out.writeShort(methods);
for (int i=fieldCount; i < identifiers.length; i++) for (int i=fieldCount; i < identifiers.length; i++) {
if (!willStrip || identifiers[i].isReachable()) if (!Obfuscator.shouldStrip || identifiers[i].isReachable())
((MethodIdentifier)identifiers[i]).write(out); ((MethodIdentifier)identifiers[i]).write(out);
else if (Obfuscator.isDebugging)
Obfuscator.err.println(identifiers[i].toString()
+ " is stripped");
}
out.writeShort(0); // no attributes; out.writeShort(0); // no attributes;
} }
@ -439,7 +437,7 @@ public class ClassIdentifier extends Identifier {
public boolean containFieldAlias(String fieldName, String typeSig) { public boolean containFieldAlias(String fieldName, String typeSig) {
for (int i=0; i < fieldCount; i++) { for (int i=0; i < fieldCount; i++) {
if ((!willStrip || identifiers[i].isReachable()) if ((!Obfuscator.shouldStrip || identifiers[i].isReachable())
&& identifiers[i].getAlias().equals(fieldName) && identifiers[i].getAlias().equals(fieldName)
&& identifiers[i].getType().startsWith(typeSig)) && identifiers[i].getType().startsWith(typeSig))
return true; return true;
@ -501,7 +499,7 @@ public class ClassIdentifier extends Identifier {
public Object getMethod(String methodName, String paramType) { public Object getMethod(String methodName, String paramType) {
for (int i=fieldCount; i< identifiers.length; i++) { for (int i=fieldCount; i< identifiers.length; i++) {
if ((!willStrip || identifiers[i].isReachable()) if ((!Obfuscator.shouldStrip || identifiers[i].isReachable())
&& identifiers[i].getAlias().equals(methodName) && identifiers[i].getAlias().equals(methodName)
&& identifiers[i].getType().startsWith(paramType)) && identifiers[i].getType().startsWith(paramType))
return identifiers[i]; return identifiers[i];
@ -539,7 +537,7 @@ public class ClassIdentifier extends Identifier {
return null; return null;
} }
public boolean conflicting(String newAlias) { public boolean conflicting(String newAlias, boolean strong) {
return pack.contains(newAlias); return pack.contains(newAlias);
} }
} }

@ -65,9 +65,12 @@ public class FieldIdentifier extends Identifier{
return "MethodIdentifier "+getFullName()+"."+getType(); return "MethodIdentifier "+getFullName()+"."+getType();
} }
public boolean conflicting(String newAlias) { public boolean conflicting(String newAlias, boolean strong) {
return clazz.containFieldAlias(newAlias, "") if (strong) {
|| (clazz.getMethod(newAlias, "") != null); return clazz.containFieldAlias(newAlias, getType());
} else {
return clazz.containFieldAlias(newAlias, "");
}
} }
int nameIndex; int nameIndex;

@ -194,7 +194,9 @@ public abstract class Identifier {
} while (false); } while (false);
Identifier ptr = this; Identifier ptr = this;
while (ptr != null) { while (ptr != null) {
if (ptr.conflicting(newAlias.toString())) if (ptr.conflicting(newAlias.toString(),
renameRule
== Obfuscator.RENAME_STRONG))
continue next_alias; continue next_alias;
ptr = ptr.right; ptr = ptr.right;
} }
@ -215,5 +217,5 @@ public abstract class Identifier {
public abstract String getType(); public abstract String getType();
public abstract String getFullName(); public abstract String getFullName();
public abstract String getFullAlias(); public abstract String getFullAlias();
public abstract boolean conflicting(String newAlias); public abstract boolean conflicting(String newAlias, boolean strong);
} }

@ -27,6 +27,8 @@ public class Obfuscator {
public static boolean isVerbose = false; public static boolean isVerbose = false;
public static boolean isDebugging = false; public static boolean isDebugging = false;
public static boolean shouldStrip = true;
public static PrintStream err = System.err; public static PrintStream err = System.err;
public static final int PRESERVE_NONE = 0; public static final int PRESERVE_NONE = 0;
public static final int PRESERVE_PUBLIC = Modifier.PUBLIC; public static final int PRESERVE_PUBLIC = Modifier.PUBLIC;
@ -83,7 +85,6 @@ public class Obfuscator {
Vector preservedIdents = new Vector(); Vector preservedIdents = new Vector();
boolean strip = true;
int preserveRule = PRESERVE_NONE; int preserveRule = PRESERVE_NONE;
int rename = RENAME_WEAK; int rename = RENAME_WEAK;
String table = null; String table = null;
@ -95,7 +96,7 @@ public class Obfuscator {
else if (params[i].equals("-debug")) else if (params[i].equals("-debug"))
isDebugging = true; isDebugging = true;
else if (params[i].equals("-nostrip")) else if (params[i].equals("-nostrip"))
strip = false; shouldStrip = false;
else if (params[i].equals("-sourcepath")) else if (params[i].equals("-sourcepath"))
sourcePath = params[++i]; sourcePath = params[++i];
@ -157,9 +158,6 @@ public class Obfuscator {
bundle.setPreserved(preserveRule, preservedIdents); bundle.setPreserved(preserveRule, preservedIdents);
err.println("Renaming methods"); err.println("Renaming methods");
if (strip)
bundle.strip();
if (rename != RENAME_TABLE) if (rename != RENAME_TABLE)
bundle.buildTable(rename); bundle.buildTable(rename);
else else

@ -258,11 +258,14 @@ public class MethodIdentifier extends Identifier implements Opcodes {
return info.getType().getTypeSignature(); return info.getType().getTypeSignature();
} }
public boolean conflicting(String newAlias) { public boolean conflicting(String newAlias, boolean strong) {
String type = getType(); if (strong) {
String paramType = type.substring(0, type.indexOf(')')+1); return clazz.getMethod(newAlias, getType()) != null;
return clazz.getMethod(newAlias, paramType) != null } else {
|| clazz.containFieldAlias(newAlias, ""); String type = getType();
String paramType = type.substring(0, type.indexOf(')')+1);
return clazz.getMethod(newAlias, paramType) != null;
}
} }
public String toString() { public String toString() {

@ -31,7 +31,6 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier parent; PackageIdentifier parent;
String name; String name;
boolean willStrip = false;
boolean loadOnDemand; boolean loadOnDemand;
Hashtable loadedClasses; Hashtable loadedClasses;
@ -211,25 +210,6 @@ public class PackageIdentifier extends Identifier {
return className; return className;
} }
public void strip() {
willStrip = true;
Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement();
if (ident.isReachable()) {
if (ident instanceof ClassIdentifier) {
((ClassIdentifier) ident).strip();
} else
((PackageIdentifier) ident).strip();
} else {
if (Obfuscator.isDebugging)
Obfuscator.err.println("Class/Package "
+ ident.getFullName()
+ " is not reachable");
}
}
}
public void buildTable(int renameRule) { public void buildTable(int renameRule) {
super.buildTable(renameRule); super.buildTable(renameRule);
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
@ -249,7 +229,7 @@ public class PackageIdentifier extends Identifier {
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement(); Identifier ident = (Identifier) enum.nextElement();
if (!willStrip || ident.isReachable()) if (!Obfuscator.shouldStrip || ident.isReachable())
ident.writeTable(out); ident.writeTable(out);
} }
} }
@ -276,8 +256,13 @@ public class PackageIdentifier extends Identifier {
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Identifier ident = (Identifier) enum.nextElement(); Identifier ident = (Identifier) enum.nextElement();
if (willStrip && !ident.isReachable()) if (Obfuscator.shouldStrip && !ident.isReachable()) {
if (Obfuscator.isDebugging)
Obfuscator.err.println("Class/Package "
+ ident.getFullName()
+ " is not reachable");
continue; continue;
}
if (ident instanceof PackageIdentifier) if (ident instanceof PackageIdentifier)
((PackageIdentifier) ident) ((PackageIdentifier) ident)
.storeClasses(newDest); .storeClasses(newDest);
@ -309,13 +294,15 @@ public class PackageIdentifier extends Identifier {
public boolean contains(String newAlias) { public boolean contains(String newAlias) {
Enumeration enum = loadedClasses.elements(); Enumeration enum = loadedClasses.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
if (((Identifier)enum.nextElement()).getAlias().equals(newAlias)) Identifier ident = (Identifier)enum.nextElement();
if ((!Obfuscator.shouldStrip || ident.isReachable())
&& ident.getAlias().equals(newAlias))
return true; return true;
} }
return false; return false;
} }
public boolean conflicting(String newAlias) { public boolean conflicting(String newAlias, boolean strong) {
return parent.contains(newAlias); return parent.contains(newAlias);
} }
} }

Loading…
Cancel
Save