(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. 16
      jode/jode/obfuscator/Identifier.java.in
  2. 4
      jode/jode/obfuscator/Makefile.am
  3. 66
      jode/jode/obfuscator/PackageIdentifier.java.in

@ -175,8 +175,7 @@ public abstract class Identifier {
GlobalOptions.err.println(toString() + " is preserved");
} else {
Identifier rep = getRepresentative();
if (rep.wasAliased)
return;
if (!rep.wasAliased) {
rep.wasAliased = true;
// set alias to empty string, so it won't conflict!
@ -195,6 +194,7 @@ public abstract class Identifier {
break;
}
}
}
for (Iterator i = getChilds(); i.hasNext(); )
((Identifier)i.next()).buildTable(renameRule);
}
@ -204,7 +204,17 @@ public abstract class Identifier {
&& (Main.stripping & Main.STRIP_UNREACH) != 0)
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(); )
((Identifier)i.next()).writeTable(table);
}

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

@ -34,6 +34,9 @@ import @COLLECTIONS@.HashMap;
import @COLLECTIONS@.Iterator;
import @COLLECTIONS@.List;
import @COLLECTIONS@.ArrayList;
import @COLLECTIONS@.Random;
import @COLLECTIONS@.Arrays;
import @COLLECTIONS@.Collections;
public class PackageIdentifier extends Identifier {
ClassBundle bundle;
@ -43,6 +46,8 @@ public class PackageIdentifier extends Identifier {
boolean loadOnDemand;
Map loadedClasses;
List swappedClasses;
Random rand = new Random();
public PackageIdentifier(ClassBundle bundle,
PackageIdentifier parent,
@ -84,6 +89,7 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier ident = new PackageIdentifier
(bundle, this, subFull, subclazz);
loadedClasses.put(subclazz, ident);
swappedClasses = null;
ident.setLoadOnDemand();
} else {
ClassIdentifier ident = new ClassIdentifier
@ -93,6 +99,7 @@ public class PackageIdentifier extends Identifier {
GlobalOptions.err.println("preloading Class "
+ subFull);
loadedClasses.put(subclazz, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass();
}
@ -132,6 +139,7 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier pack
= new PackageIdentifier(bundle, this, subFull, name);
loadedClasses.put(name, pack);
swappedClasses = null;
pack.setLoadOnDemand();
ident = pack;
} else if (!ClassInfo.exists(subFull)) {
@ -142,6 +150,7 @@ public class PackageIdentifier extends Identifier {
ident = new ClassIdentifier(this, subFull, name,
ClassInfo.forName(subFull));
loadedClasses.put(name, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass();
}
@ -159,6 +168,7 @@ public class PackageIdentifier extends Identifier {
pack = new PackageIdentifier(bundle, this,
subFull, subpack);
loadedClasses.put(subpack, pack);
swappedClasses = null;
if (loadOnDemand)
pack.setLoadOnDemand();
}
@ -184,6 +194,7 @@ public class PackageIdentifier extends Identifier {
ident = new PackageIdentifier(bundle, this,
subFull, component);
loadedClasses.put(component, ident);
swappedClasses = null;
if (loadOnDemand)
((PackageIdentifier) ident).setLoadOnDemand();
} else if (ClassInfo.exists(subFull)) {
@ -193,6 +204,7 @@ public class PackageIdentifier extends Identifier {
ClassInfo.forName(subFull));
if (loadOnDemand || matcher.matches(ident)) {
loadedClasses.put(component, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass();
}
@ -232,6 +244,7 @@ public class PackageIdentifier extends Identifier {
PackageIdentifier ident = new PackageIdentifier
(bundle, this, subFull, subclazz);
loadedClasses.put(subclazz, ident);
swappedClasses = null;
if (loadOnDemand || matcher.matches(ident))
ident.setLoadOnDemand();
} else {
@ -244,6 +257,7 @@ public class PackageIdentifier extends Identifier {
GlobalOptions.err.println("loading Class "
+ subFull);
loadedClasses.put(subclazz, ident);
swappedClasses = null;
bundle.addClassIdentifier(ident);
((ClassIdentifier) ident).initClass();
}
@ -284,10 +298,14 @@ public class PackageIdentifier extends Identifier {
*/
public String getFullAlias() {
if (parent != null) {
if (parent.getFullAlias().length() > 0)
return parent.getFullAlias() + "." + getAlias();
String parentAlias = parent.getFullAlias();
String alias = getAlias();
if (alias.length() == 0)
return parentAlias;
else if (parentAlias.length() == 0)
return alias;
else
return getAlias();
return parentAlias + "." + alias;
}
return "";
}
@ -313,7 +331,7 @@ public class PackageIdentifier extends Identifier {
}
public void doTransformations() {
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) {
for (Iterator i = getChilds(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next();
if (ident instanceof ClassIdentifier) {
((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() {
return parent;
}
@ -357,11 +364,19 @@ public class PackageIdentifier extends Identifier {
}
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) {
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) {
for (Iterator i = getChilds(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next();
if ((Main.stripping & Main.STRIP_UNREACH) != 0
&& !ident.isReachable()) {
@ -399,7 +414,7 @@ public class PackageIdentifier extends Identifier {
GlobalOptions.err.println("Could not create directory "
+newDest.getPath()+", check permissions.");
}
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) {
for (Iterator i = getChilds(); i.hasNext(); ) {
Identifier ident = (Identifier) i.next();
if ((Main.stripping & Main.STRIP_UNREACH) != 0
&& !ident.isReachable()) {
@ -442,12 +457,23 @@ public class PackageIdentifier extends Identifier {
public boolean contains(String newAlias, Identifier except) {
for (Iterator i = loadedClasses.values().iterator(); i.hasNext(); ) {
Identifier ident = (Identifier)i.next();
if (ident != except) {
if (((Main.stripping & Main.STRIP_UNREACH) == 0
|| ident.isReachable())
&& ident != except
&& ident.getAlias().equals(newAlias))
&& ident.getAlias().equalsIgnoreCase(newAlias))
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;
}

Loading…
Cancel
Save