getChilds abstract method added

renaming reworked (uses Renamer now)
applyPreserveRule implemented


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@983 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 09e72e0daa
commit af2e3db3e2
  1. 81
      jode/jode/obfuscator/Identifier.java

@ -19,9 +19,14 @@
package jode.obfuscator; package jode.obfuscator;
import jode.GlobalOptions; import jode.GlobalOptions;
import jode.Obfuscator;
import java.io.*; import java.io.*;
import java.util.Hashtable; ///#ifdef JDK12
///import java.util.Map;
///import java.util.Iterator;
///#else
import jode.util.Map;
import jode.util.Iterator;
///#endif
public abstract class Identifier { public abstract class Identifier {
/** /**
@ -120,10 +125,15 @@ public abstract class Identifier {
return left == null; return left == null;
} }
public final boolean wasAliased() {
return getRepresentative().wasAliased;
}
public final void setAlias(String name) { public final void setAlias(String name) {
if (name != null) { if (name != null) {
getRepresentative().wasAliased = true; Identifier rep = getRepresentative();
getRepresentative().alias = name; rep.wasAliased = true;
rep.alias = name;
} }
} }
@ -159,56 +169,26 @@ public abstract class Identifier {
} }
static int serialnr = 0; static int serialnr = 0;
public void buildTable(int renameRule) {
public void buildTable(Renamer renameRule) {
if (isPreserved()) { if (isPreserved()) {
if (GlobalOptions.verboseLevel > 4) if (GlobalOptions.verboseLevel > 4)
GlobalOptions.err.println(toString() + " is preserved"); GlobalOptions.err.println(toString() + " is preserved");
} else if (renameRule != Obfuscator.RENAME_NONE) { } else {
Identifier rep = getRepresentative(); Identifier rep = getRepresentative();
if (rep.wasAliased) if (rep.wasAliased)
return; return;
rep.wasAliased = true; rep.wasAliased = true;
if (renameRule == Obfuscator.RENAME_UNIQUE) // set alias to empty string, so it won't conflict!
rep.setAlias("xxx" + serialnr++); alias = "";
else { String newAlias = null;
StringBuffer newAlias = new StringBuffer();
next_alias: next_alias:
for (;;) { for (;;) {
okay: newAlias = renameRule.generateName(this, newAlias);
do {
for (int pos = 0; pos < newAlias.length(); pos++) {
char c = newAlias.charAt(pos);
if (renameRule == Obfuscator.RENAME_WEAK) {
if (c == '9') {
newAlias.setCharAt(pos, 'A');
break okay;
} else if (c == 'Z') {
newAlias.setCharAt(pos, 'a');
break okay;
} else if (c != 'z') {
newAlias.setCharAt(pos, (char)(c+1));
break okay;
}
newAlias.setCharAt(pos, pos == 0 ? 'A': '0');
} else {
while (c++ < 126) {
if (Character.isJavaIdentifierPart(c)) {
newAlias.setCharAt(pos, c);
break okay;
}
}
newAlias.setCharAt(pos, '0');
}
}
newAlias.append(renameRule == Obfuscator.RENAME_WEAK
&& newAlias.length() == 0 ? "A": "0");
} while (false);
Identifier ptr = rep; Identifier ptr = rep;
while (ptr != null) { while (ptr != null) {
if (ptr.conflicting(newAlias.toString(), if (ptr.conflicting(newAlias))
renameRule
== Obfuscator.RENAME_STRONG))
continue next_alias; continue next_alias;
ptr = ptr.right; ptr = ptr.right;
} }
@ -217,13 +197,12 @@ public abstract class Identifier {
} }
} }
} }
}
public void writeTable(Hashtable table) { public void writeTable(Map table) {
table.put(getFullAlias(), getName()); table.put(getFullAlias(), getName());
} }
public void readTable(Hashtable table) { public void readTable(Map table) {
Identifier rep = getRepresentative(); Identifier rep = getRepresentative();
if (!rep.wasAliased) { if (!rep.wasAliased) {
String newAlias = (String) table.get(getFullName()); String newAlias = (String) table.get(getFullName());
@ -234,13 +213,21 @@ public abstract class Identifier {
} }
} }
public abstract void applyPreserveRule(int preserveRule); public void applyPreserveRule(IdentifierMatcher preserveRule) {
if (preserveRule.matches(this)) {
setReachable();
setPreserved();
}
for (Iterator i = getChilds(); i.hasNext(); )
((Identifier)i.next()).applyPreserveRule(preserveRule);
}
public abstract Iterator getChilds();
public abstract Identifier getParent(); public abstract Identifier getParent();
public abstract String getName(); public abstract String getName();
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, boolean strong); public abstract boolean conflicting(String newAlias);
/** /**
* This is called by ClassBundle when it a class is added with * This is called by ClassBundle when it a class is added with

Loading…
Cancel
Save