ConstantAnalyzer: Fixed a bug (but it is much slower now).

ModifierMatcher: implement OptionHandler.
StrongRenamer: handle charsetClass, etc. correctly
StrongRenamer: don't rename to java keywords
Makefile optimized


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1221 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 25 years ago
parent 6ea8124cad
commit 2bc051bee9
  1. 28
      jode/jode/obfuscator/modules/ConstantAnalyzer.java.in
  2. 4
      jode/jode/obfuscator/modules/Makefile.am
  3. 3
      jode/jode/obfuscator/modules/ModifierMatcher.java.in
  4. 73
      jode/jode/obfuscator/modules/StrongRenamer.java.in

@ -1,4 +1,4 @@
/* ConstantAnalyzer Copyright (C) 1999 Jochen Hoenicke. /* ConstantAnalyzer Copyright (C) 1999, 2000 Jochen Hoenicke.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -227,7 +227,7 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
if (value == null ? other.value == null if (value == null ? other.value == null
: value.equals(other.value)) { : value.equals(other.value)) {
if (value != VOLATILE) { if (value != VOLATILE) {
// other.addConstantListener(this); other.addConstantListener(this);
this.addConstantListener(other); this.addConstantListener(other);
} }
return; return;
@ -280,7 +280,9 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
ConstValue[] locals, ConstValue[] locals,
TodoQueue notifyQueue) { TodoQueue notifyQueue) {
this.stack = stack; this.stack = stack;
this.locals = locals; this.locals = new ConstValue[locals.length];
for (int i=0; i< locals.length; i++)
this.locals[i] = copy(locals[i]);
this.notifyQueue = notifyQueue; this.notifyQueue = notifyQueue;
} }
@ -446,6 +448,7 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
for (int i=0; i < locals.length; i++) { for (int i=0; i < locals.length; i++) {
if (locals[i] != null) { if (locals[i] != null) {
if (other.locals[i] == null) { if (other.locals[i] == null) {
locals[i].constantChanged();
locals[i] = null; locals[i] = null;
enqueue(); enqueue();
} else { } else {
@ -514,6 +517,21 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
((StackLocalInfo)instr.getTmpInfo()).merge(info); ((StackLocalInfo)instr.getTmpInfo()).merge(info);
} }
private ClassInfo canonizeIfaceRef(ClassInfo clazz, Reference ref) {
while (clazz != null) {
if (clazz.findMethod(ref.getName(), ref.getType()) != null)
return clazz;
ClassInfo[] ifaces = clazz.getInterfaces();
for (int i = 0; i < ifaces.length; i++) {
ClassInfo realClass = canonizeIfaceRef(ifaces[i], ref);
if (realClass != null)
return realClass;
}
clazz = clazz.getSuperclass();
}
return null;
}
public Identifier canonizeReference(Instruction instr) { public Identifier canonizeReference(Instruction instr) {
Reference ref = instr.getReference(); Reference ref = instr.getReference();
Identifier ident = Main.getClassBundle().getIdentifier(ref); Identifier ident = Main.getClassBundle().getIdentifier(ref);
@ -538,7 +556,9 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
(clName.substring(1, clName.length()-1) (clName.substring(1, clName.length()-1)
.replace('/','.')); .replace('/','.'));
} }
if (instr.getOpcode() >= opc_invokevirtual) { if (instr.getOpcode() == opc_invokeinterface) {
clazz = canonizeIfaceRef(clazz, ref);
} else if (instr.getOpcode() >= opc_invokevirtual) {
while (clazz != null while (clazz != null
&& clazz.findMethod(ref.getName(), && clazz.findMethod(ref.getName(),
ref.getType()) == null) ref.getType()) == null)

@ -8,7 +8,7 @@ JAVADEP = $(top_builddir)/javaDependencies.pl -subdir=$(subdir)\
CLASSPATH = @CLASSPATH@ CLASSPATH = @CLASSPATH@
CLASSLIB = @CLASSLIB@ CLASSLIB = @CLASSLIB@
SUBSTCP = @SUBSTCP@ SUBSTCP = @SUBSTCP@
BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) FULL_CLASSPATH := $(shell $(SUBSTCP) $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB))
MY_JAVA_FILES = \ MY_JAVA_FILES = \
ConstantAnalyzer.java \ ConstantAnalyzer.java \
@ -31,7 +31,7 @@ EXTRA_DIST = $(MY_JAVA_FILES)
@QUOTE@-include Makefile.dep @QUOTE@-include Makefile.dep
%.class: %.java %.class: %.java
$(JAVAC) -classpath `$(SUBSTCP) $(BUILD_CLASSPATH):$(CLASSLIB)` -d $(top_builddir) $< $(JAVAC) -classpath $(FULL_CLASSPATH) -d $(top_builddir) $<
Makefile.dep: $(MY_JAVA_FILES:.java=.class) Makefile.dep: $(MY_JAVA_FILES:.java=.class)
$(JAVADEP) $^ $(JAVADEP) $^

@ -23,12 +23,13 @@ import jode.obfuscator.Identifier;
import jode.obfuscator.ClassIdentifier; import jode.obfuscator.ClassIdentifier;
import jode.obfuscator.FieldIdentifier; import jode.obfuscator.FieldIdentifier;
import jode.obfuscator.MethodIdentifier; import jode.obfuscator.MethodIdentifier;
import jode.obfuscator.OptionHandler;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import @COLLECTIONS@.Collection; import @COLLECTIONS@.Collection;
import @COLLECTIONS@.Iterator; import @COLLECTIONS@.Iterator;
public class ModifierMatcher implements IdentifierMatcher, Cloneable { public class ModifierMatcher implements IdentifierMatcher, OptionHandler, Cloneable {
static final int PUBLIC = Modifier.PUBLIC; static final int PUBLIC = Modifier.PUBLIC;
static final int PROTECTED = Modifier.PROTECTED; static final int PROTECTED = Modifier.PROTECTED;
static final int PRIVATE = Modifier.PRIVATE; static final int PRIVATE = Modifier.PRIVATE;

@ -1,4 +1,4 @@
/* StrongRenamer Copyright (C) 1999 Jochen Hoenicke. /* StrongRenamer Copyright (C) 1999, 2000 Jochen Hoenicke.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -32,6 +32,18 @@ public class StrongRenamer implements Renamer, OptionHandler {
}; };
String charsets[][]; String charsets[][];
String javaKeywords[] = {
"abstract", "default", "if", "private", "throw", "boolean",
"do", "implements", "protected", "throws", "break", "double",
"import", "public", "transient", "byte", "else", "instanceof",
"return", "try", "case", "extends", "int", "short", "void",
"catch", "final", "interface", "static", "volatile", "char",
"finally", "long", "super", "while", "class", "float",
"native", "switch", "const", "for", "new", "synchronized",
"continue", "goto", "package", "this", "strictfp", "null",
"true", "false"
};
public StrongRenamer() { public StrongRenamer() {
charsets = new String[idents.length][parts.length]; charsets = new String[idents.length][parts.length];
for (int i=0; i< idents.length; i++) for (int i=0; i< idents.length; i++)
@ -87,16 +99,14 @@ public class StrongRenamer implements Renamer, OptionHandler {
int identType; int identType;
if (ident instanceof PackageIdentifier) if (ident instanceof PackageIdentifier)
identType = 0; identType = 0;
else if (ident instanceof PackageIdentifier)
identType = 1;
else if (ident instanceof ClassIdentifier) else if (ident instanceof ClassIdentifier)
identType = 2; identType = 1;
else if (ident instanceof FieldIdentifier) else if (ident instanceof FieldIdentifier)
identType = 3; identType = 2;
else if (ident instanceof MethodIdentifier) else if (ident instanceof MethodIdentifier)
identType = 4; identType = 3;
else if (ident instanceof LocalIdentifier) else if (ident instanceof LocalIdentifier)
identType = 5; identType = 4;
else else
throw new IllegalArgumentException(ident.getClass().getName()); throw new IllegalArgumentException(ident.getClass().getName());
final String[] theCharset = charsets[identType]; final String[] theCharset = charsets[identType];
@ -114,29 +124,38 @@ public class StrongRenamer implements Renamer, OptionHandler {
headIndex = 0; headIndex = 0;
return new String(name); return new String(name);
} }
if (++headIndex < theCharset[0].length()) { next_name:
name[0] = theCharset[0].charAt(headIndex); while (true) {
return new String(name); if (++headIndex < theCharset[0].length()) {
} name[0] = theCharset[0].charAt(headIndex);
headIndex = 0;
name[0] = theCharset[0].charAt(0);
String charset = theCharset[1];
for (int pos = 1; pos < name.length; pos++) {
int index = charset.indexOf(name[pos]) + 1;
if (index < charset.length()) {
name[pos] = charset.charAt(index);
return new String(name); return new String(name);
} }
name[pos] = charset.charAt(0); headIndex = 0;
} name[0] = theCharset[0].charAt(0);
name = new char[name.length+1]; String charset = theCharset[1];
name[0] = theCharset[0].charAt(0); for (int pos = 1; pos < name.length; pos++) {
char firstCont = theCharset[1].charAt(0); int index = charset.indexOf(name[pos]) + 1;
for (int i=1; i <name.length; i++) if (index < charset.length()) {
name[i] = firstCont; name[pos] = charset.charAt(index);
return new String(name); return new String(name);
}
name[pos] = charset.charAt(0);
}
name = new char[name.length+1];
name[0] = theCharset[0].charAt(0);
char firstCont = theCharset[1].charAt(0);
for (int i=1; i <name.length; i++)
name[i] = firstCont;
String next = new String(name);
for (int i = 0; i < javaKeywords.length; i++) {
if (next.equals(javaKeywords[i]))
continue next_name;
}
return next;
}
} }
public void remove() { public void remove() {

Loading…
Cancel
Save