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
* 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
: value.equals(other.value)) {
if (value != VOLATILE) {
// other.addConstantListener(this);
other.addConstantListener(this);
this.addConstantListener(other);
}
return;
@ -280,7 +280,9 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
ConstValue[] locals,
TodoQueue notifyQueue) {
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;
}
@ -446,6 +448,7 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
for (int i=0; i < locals.length; i++) {
if (locals[i] != null) {
if (other.locals[i] == null) {
locals[i].constantChanged();
locals[i] = null;
enqueue();
} else {
@ -514,6 +517,21 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
((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) {
Reference ref = instr.getReference();
Identifier ident = Main.getClassBundle().getIdentifier(ref);
@ -538,7 +556,9 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
(clName.substring(1, clName.length()-1)
.replace('/','.'));
}
if (instr.getOpcode() >= opc_invokevirtual) {
if (instr.getOpcode() == opc_invokeinterface) {
clazz = canonizeIfaceRef(clazz, ref);
} else if (instr.getOpcode() >= opc_invokevirtual) {
while (clazz != null
&& clazz.findMethod(ref.getName(),
ref.getType()) == null)

@ -8,7 +8,7 @@ JAVADEP = $(top_builddir)/javaDependencies.pl -subdir=$(subdir)\
CLASSPATH = @CLASSPATH@
CLASSLIB = @CLASSLIB@
SUBSTCP = @SUBSTCP@
BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB)
FULL_CLASSPATH := $(shell $(SUBSTCP) $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB))
MY_JAVA_FILES = \
ConstantAnalyzer.java \
@ -31,7 +31,7 @@ EXTRA_DIST = $(MY_JAVA_FILES)
@QUOTE@-include Makefile.dep
%.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)
$(JAVADEP) $^

@ -23,12 +23,13 @@ import jode.obfuscator.Identifier;
import jode.obfuscator.ClassIdentifier;
import jode.obfuscator.FieldIdentifier;
import jode.obfuscator.MethodIdentifier;
import jode.obfuscator.OptionHandler;
import java.lang.reflect.Modifier;
import @COLLECTIONS@.Collection;
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 PROTECTED = Modifier.PROTECTED;
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
* 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 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() {
charsets = new String[idents.length][parts.length];
for (int i=0; i< idents.length; i++)
@ -87,16 +99,14 @@ public class StrongRenamer implements Renamer, OptionHandler {
int identType;
if (ident instanceof PackageIdentifier)
identType = 0;
else if (ident instanceof PackageIdentifier)
identType = 1;
else if (ident instanceof ClassIdentifier)
identType = 2;
identType = 1;
else if (ident instanceof FieldIdentifier)
identType = 3;
identType = 2;
else if (ident instanceof MethodIdentifier)
identType = 4;
identType = 3;
else if (ident instanceof LocalIdentifier)
identType = 5;
identType = 4;
else
throw new IllegalArgumentException(ident.getClass().getName());
final String[] theCharset = charsets[identType];
@ -114,29 +124,38 @@ public class StrongRenamer implements Renamer, OptionHandler {
headIndex = 0;
return new String(name);
}
if (++headIndex < theCharset[0].length()) {
name[0] = theCharset[0].charAt(headIndex);
return new String(name);
}
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);
next_name:
while (true) {
if (++headIndex < theCharset[0].length()) {
name[0] = theCharset[0].charAt(headIndex);
return new String(name);
}
name[pos] = charset.charAt(0);
}
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);
}
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;
return new String(name);
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() {

Loading…
Cancel
Save