(Package)?Identifier: Handle unified packages.

small bug fixes
Makefile optimized


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1220 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 25 years ago
parent 7fc1ab0b1e
commit 6ea8124cad
  1. 44
      jode/jode/obfuscator/Identifier.java.in
  2. 4
      jode/jode/obfuscator/Makefile.am
  3. 74
      jode/jode/obfuscator/PackageIdentifier.java.in

@ -175,24 +175,24 @@ public abstract class Identifier {
GlobalOptions.err.println(toString() + " is preserved"); GlobalOptions.err.println(toString() + " is preserved");
} else { } else {
Identifier rep = getRepresentative(); Identifier rep = getRepresentative();
if (rep.wasAliased) if (!rep.wasAliased) {
return; rep.wasAliased = true;
rep.wasAliased = true;
// set alias to empty string, so it won't conflict! // set alias to empty string, so it won't conflict!
rep.alias = ""; rep.alias = "";
Iterator aliases = renameRule.generateNames(this); Iterator aliases = renameRule.generateNames(this);
next_alias: next_alias:
for (;;) { for (;;) {
String newAlias = (String) aliases.next(); String newAlias = (String) aliases.next();
Identifier ptr = rep; Identifier ptr = rep;
while (ptr != null) { while (ptr != null) {
if (ptr.conflicting(newAlias)) if (ptr.conflicting(newAlias))
continue next_alias; continue next_alias;
ptr = ptr.right; ptr = ptr.right;
}
setAlias(newAlias.toString());
break;
} }
setAlias(newAlias.toString());
break;
} }
} }
for (Iterator i = getChilds(); i.hasNext(); ) for (Iterator i = getChilds(); i.hasNext(); )
@ -204,7 +204,17 @@ public abstract class Identifier {
&& (Main.stripping & Main.STRIP_UNREACH) != 0) && (Main.stripping & Main.STRIP_UNREACH) != 0)
return; return;
table.put(getFullAlias(), getName()); if (getAlias().length() != 0) {
String name = getName();
Identifier outer = getParent();
while (outer != null && outer.getAlias().length() == 0) {
if (outer.getName().length() > 0)
name = outer.getName() + "." + name;
outer = outer.getParent();
}
table.put(getFullAlias(), name);
}
for (Iterator i = getChilds(); i.hasNext(); ) for (Iterator i = getChilds(); i.hasNext(); )
((Identifier)i.next()).writeTable(table); ((Identifier)i.next()).writeTable(table);
} }

@ -10,7 +10,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 = \
ClassBundle.java \ ClassBundle.java \
@ -37,7 +37,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) $^

@ -34,6 +34,9 @@ import @COLLECTIONS@.HashMap;
import @COLLECTIONS@.Iterator; import @COLLECTIONS@.Iterator;
import @COLLECTIONS@.List; import @COLLECTIONS@.List;
import @COLLECTIONS@.ArrayList; import @COLLECTIONS@.ArrayList;
import @COLLECTIONS@.Random;
import @COLLECTIONS@.Arrays;
import @COLLECTIONS@.Collections;
public class PackageIdentifier extends Identifier { public class PackageIdentifier extends Identifier {
ClassBundle bundle; ClassBundle bundle;
@ -43,6 +46,8 @@ public class PackageIdentifier extends Identifier {
boolean loadOnDemand; boolean loadOnDemand;
Map loadedClasses; Map loadedClasses;
List swappedClasses;
Random rand = new Random();
public PackageIdentifier(ClassBundle bundle, public PackageIdentifier(ClassBundle bundle,
PackageIdentifier parent, PackageIdentifier parent,
@ -84,6 +89,7 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier ident = new PackageIdentifier PackageIdentifier ident = new PackageIdentifier
(bundle, this, subFull, subclazz); (bundle, this, subFull, subclazz);
loadedClasses.put(subclazz, ident); loadedClasses.put(subclazz, ident);
swappedClasses = null;
ident.setLoadOnDemand(); ident.setLoadOnDemand();
} else { } else {
ClassIdentifier ident = new ClassIdentifier ClassIdentifier ident = new ClassIdentifier
@ -93,6 +99,7 @@ public class PackageIdentifier extends Identifier {
GlobalOptions.err.println("preloading Class " GlobalOptions.err.println("preloading Class "
+ subFull); + subFull);
loadedClasses.put(subclazz, ident); loadedClasses.put(subclazz, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident); bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass(); ((ClassIdentifier) ident).initClass();
} }
@ -132,6 +139,7 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier pack PackageIdentifier pack
= new PackageIdentifier(bundle, this, subFull, name); = new PackageIdentifier(bundle, this, subFull, name);
loadedClasses.put(name, pack); loadedClasses.put(name, pack);
swappedClasses = null;
pack.setLoadOnDemand(); pack.setLoadOnDemand();
ident = pack; ident = pack;
} else if (!ClassInfo.exists(subFull)) { } else if (!ClassInfo.exists(subFull)) {
@ -142,6 +150,7 @@ public class PackageIdentifier extends Identifier {
ident = new ClassIdentifier(this, subFull, name, ident = new ClassIdentifier(this, subFull, name,
ClassInfo.forName(subFull)); ClassInfo.forName(subFull));
loadedClasses.put(name, ident); loadedClasses.put(name, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident); bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass(); ((ClassIdentifier) ident).initClass();
} }
@ -159,6 +168,7 @@ public class PackageIdentifier extends Identifier {
pack = new PackageIdentifier(bundle, this, pack = new PackageIdentifier(bundle, this,
subFull, subpack); subFull, subpack);
loadedClasses.put(subpack, pack); loadedClasses.put(subpack, pack);
swappedClasses = null;
if (loadOnDemand) if (loadOnDemand)
pack.setLoadOnDemand(); pack.setLoadOnDemand();
} }
@ -184,6 +194,7 @@ public class PackageIdentifier extends Identifier {
ident = new PackageIdentifier(bundle, this, ident = new PackageIdentifier(bundle, this,
subFull, component); subFull, component);
loadedClasses.put(component, ident); loadedClasses.put(component, ident);
swappedClasses = null;
if (loadOnDemand) if (loadOnDemand)
((PackageIdentifier) ident).setLoadOnDemand(); ((PackageIdentifier) ident).setLoadOnDemand();
} else if (ClassInfo.exists(subFull)) { } else if (ClassInfo.exists(subFull)) {
@ -193,6 +204,7 @@ public class PackageIdentifier extends Identifier {
ClassInfo.forName(subFull)); ClassInfo.forName(subFull));
if (loadOnDemand || matcher.matches(ident)) { if (loadOnDemand || matcher.matches(ident)) {
loadedClasses.put(component, ident); loadedClasses.put(component, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident); bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass(); ((ClassIdentifier) ident).initClass();
} }
@ -232,6 +244,7 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier ident = new PackageIdentifier PackageIdentifier ident = new PackageIdentifier
(bundle, this, subFull, subclazz); (bundle, this, subFull, subclazz);
loadedClasses.put(subclazz, ident); loadedClasses.put(subclazz, ident);
swappedClasses = null;
if (loadOnDemand || matcher.matches(ident)) if (loadOnDemand || matcher.matches(ident))
ident.setLoadOnDemand(); ident.setLoadOnDemand();
} else { } else {
@ -244,6 +257,7 @@ public class PackageIdentifier extends Identifier {
GlobalOptions.err.println("loading Class " GlobalOptions.err.println("loading Class "
+ subFull); + subFull);
loadedClasses.put(subclazz, ident); loadedClasses.put(subclazz, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident); bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass(); ((ClassIdentifier) ident).initClass();
} }
@ -284,10 +298,14 @@ public class PackageIdentifier extends Identifier {
*/ */
public String getFullAlias() { public String getFullAlias() {
if (parent != null) { if (parent != null) {
if (parent.getFullAlias().length() > 0) String parentAlias = parent.getFullAlias();
return parent.getFullAlias() + "." + getAlias(); String alias = getAlias();
else if (alias.length() == 0)
return getAlias(); return parentAlias;
else if (parentAlias.length() == 0)
return alias;
else
return parentAlias + "." + alias;
} }
return ""; return "";
} }
@ -313,7 +331,7 @@ public class PackageIdentifier extends Identifier {
} }
public void doTransformations() { public void doTransformations() {
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { for (Iterator i = getChilds(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next(); Identifier ident = (Identifier) i.next();
if (ident instanceof ClassIdentifier) { if (ident instanceof ClassIdentifier) {
((ClassIdentifier) ident).doTransformations(); ((ClassIdentifier) ident).doTransformations();
@ -333,17 +351,6 @@ public class PackageIdentifier extends Identifier {
} }
} }
public void writeTable(Map table) {
if (parent != null)
table.put(getFullAlias(), getName());
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next();
if ((Main.stripping & Main.STRIP_UNREACH) == 0
|| ident.isReachable())
ident.writeTable(table);
}
}
public Identifier getParent() { public Identifier getParent() {
return parent; return parent;
} }
@ -357,11 +364,19 @@ public class PackageIdentifier extends Identifier {
} }
public Iterator getChilds() { public Iterator getChilds() {
return loadedClasses.values().iterator(); /* Since loadedClasses is somewhat sorted by the hashcode
* of the _original_ names, swap it here to prevent to guess
* even parts of the names.
*/
if (swappedClasses == null) {
swappedClasses = Arrays.asList(loadedClasses.values().toArray());
Collections.shuffle(swappedClasses, rand);
}
return swappedClasses.iterator();
} }
public void storeClasses(ZipOutputStream zip) { public void storeClasses(ZipOutputStream zip) {
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { for (Iterator i = getChilds(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next(); Identifier ident = (Identifier) i.next();
if ((Main.stripping & Main.STRIP_UNREACH) != 0 if ((Main.stripping & Main.STRIP_UNREACH) != 0
&& !ident.isReachable()) { && !ident.isReachable()) {
@ -399,7 +414,7 @@ public class PackageIdentifier extends Identifier {
GlobalOptions.err.println("Could not create directory " GlobalOptions.err.println("Could not create directory "
+newDest.getPath()+", check permissions."); +newDest.getPath()+", check permissions.");
} }
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { for (Iterator i = getChilds(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next(); Identifier ident = (Identifier) i.next();
if ((Main.stripping & Main.STRIP_UNREACH) != 0 if ((Main.stripping & Main.STRIP_UNREACH) != 0
&& !ident.isReachable()) { && !ident.isReachable()) {
@ -442,12 +457,23 @@ public class PackageIdentifier extends Identifier {
public boolean contains(String newAlias, Identifier except) { public boolean contains(String newAlias, Identifier except) {
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) { for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) {
Identifier ident = (Identifier)i.next(); Identifier ident = (Identifier)i.next();
if (((Main.stripping & Main.STRIP_UNREACH) == 0 if (ident != except) {
|| ident.isReachable()) if (((Main.stripping & Main.STRIP_UNREACH) == 0
&& ident != except || ident.isReachable())
&& ident.getAlias().equals(newAlias)) && ident.getAlias().equalsIgnoreCase(newAlias))
return true; return true;
if (ident instanceof PackageIdentifier
&& ident.getAlias().length() == 0
&& (((PackageIdentifier) ident)
.contains(newAlias, this)))
return true;
}
} }
if (getAlias().length() == 0
&& parent != null
&& parent != except
&& parent.contains(newAlias, this))
return true;
return false; return false;
} }

Loading…
Cancel
Save