|
|
@ -43,14 +43,20 @@ public class PackageIdentifier extends Identifier { |
|
|
|
this.bundle = bundle; |
|
|
|
this.bundle = bundle; |
|
|
|
this.parent = parent; |
|
|
|
this.parent = parent; |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
this.loadOnDemand = loadOnDemand; |
|
|
|
|
|
|
|
this.loadedClasses = new Hashtable(); |
|
|
|
this.loadedClasses = new Hashtable(); |
|
|
|
if (loadOnDemand && !Obfuscator.shouldStrip) { |
|
|
|
if (loadOnDemand) |
|
|
|
|
|
|
|
setLoadOnDemand(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setLoadOnDemand() { |
|
|
|
|
|
|
|
if (loadOnDemand) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
loadOnDemand = true; |
|
|
|
|
|
|
|
if (!Obfuscator.shouldStrip) { |
|
|
|
// Load all classes and packages now, so they don't get stripped
|
|
|
|
// Load all classes and packages now, so they don't get stripped
|
|
|
|
Vector v = new Vector(); |
|
|
|
Vector v = new Vector(); |
|
|
|
Enumeration enum = |
|
|
|
Enumeration enum = |
|
|
|
ClassInfo.getClassesAndPackages(parent.getFullName() |
|
|
|
ClassInfo.getClassesAndPackages(getFullName()); |
|
|
|
+getName()); |
|
|
|
|
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
//insert sorted and remove double elements;
|
|
|
|
//insert sorted and remove double elements;
|
|
|
|
String subclazz = (String)enum.nextElement(); |
|
|
|
String subclazz = (String)enum.nextElement(); |
|
|
@ -70,7 +76,10 @@ public class PackageIdentifier extends Identifier { |
|
|
|
enum = v.elements(); |
|
|
|
enum = v.elements(); |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
String subclazz = (String) enum.nextElement(); |
|
|
|
String subclazz = (String) enum.nextElement(); |
|
|
|
String fullname = getFullName() + subclazz; |
|
|
|
String fullname = getFullName(); |
|
|
|
|
|
|
|
fullname = (fullname.length() > 0) |
|
|
|
|
|
|
|
? fullname + "."+ subclazz |
|
|
|
|
|
|
|
: subclazz; |
|
|
|
if (ClassInfo.isPackage(fullname)) { |
|
|
|
if (ClassInfo.isPackage(fullname)) { |
|
|
|
Identifier ident = new PackageIdentifier |
|
|
|
Identifier ident = new PackageIdentifier |
|
|
|
(bundle, this, subclazz, true); |
|
|
|
(bundle, this, subclazz, true); |
|
|
@ -111,12 +120,15 @@ public class PackageIdentifier extends Identifier { |
|
|
|
if (index == -1) { |
|
|
|
if (index == -1) { |
|
|
|
Identifier ident = (Identifier) loadedClasses.get(name); |
|
|
|
Identifier ident = (Identifier) loadedClasses.get(name); |
|
|
|
if (ident == null) { |
|
|
|
if (ident == null) { |
|
|
|
String fullname = getFullName() + name; |
|
|
|
String fullname = getFullName(); |
|
|
|
|
|
|
|
fullname = (fullname.length() > 0) |
|
|
|
|
|
|
|
? fullname + "."+ name |
|
|
|
|
|
|
|
: name; |
|
|
|
if (ClassInfo.isPackage(fullname)) { |
|
|
|
if (ClassInfo.isPackage(fullname)) { |
|
|
|
ident = new PackageIdentifier(bundle, this, name, true); |
|
|
|
ident = new PackageIdentifier(bundle, this, name, true); |
|
|
|
loadedClasses.put(name, ident); |
|
|
|
loadedClasses.put(name, ident); |
|
|
|
} else if (!ClassInfo.exists(fullname)) { |
|
|
|
} else if (!ClassInfo.exists(fullname)) { |
|
|
|
System.err.println("Warning: Can't find class "+fullname); |
|
|
|
Obfuscator.err.println("Warning: Can't find class "+fullname); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ident = new ClassIdentifier(bundle, this, name, |
|
|
|
ident = new ClassIdentifier(bundle, this, name, |
|
|
|
ClassInfo.forName(fullname)); |
|
|
|
ClassInfo.forName(fullname)); |
|
|
@ -144,20 +156,91 @@ public class PackageIdentifier extends Identifier { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Identifier loadClasses(String packageOrClass) { |
|
|
|
public void loadMatchingClasses(WildCard wildcard) { |
|
|
|
int index = packageOrClass.indexOf('.'); |
|
|
|
String component = wildcard.getNextComponent(getFullName()); |
|
|
|
if (index == -1) { |
|
|
|
if (component != null) { |
|
|
|
return loadClass(packageOrClass); |
|
|
|
Identifier ident = (Identifier) loadedClasses.get(component); |
|
|
|
|
|
|
|
if (ident == null) { |
|
|
|
|
|
|
|
String fullname = getFullName(); |
|
|
|
|
|
|
|
fullname = (fullname.length() > 0) |
|
|
|
|
|
|
|
? fullname + "."+ name |
|
|
|
|
|
|
|
: name; |
|
|
|
|
|
|
|
if (ClassInfo.isPackage(fullname)) { |
|
|
|
|
|
|
|
ident = new PackageIdentifier(bundle, this, |
|
|
|
|
|
|
|
component, loadOnDemand); |
|
|
|
|
|
|
|
loadedClasses.put(component, ident); |
|
|
|
|
|
|
|
} else if (!ClassInfo.exists(fullname)) { |
|
|
|
|
|
|
|
Obfuscator.err.println("Warning: Can't find class "+fullname); |
|
|
|
|
|
|
|
} else if (wildcard.matches(fullname)) { |
|
|
|
|
|
|
|
if (Obfuscator.verboseLevel > 1) |
|
|
|
|
|
|
|
Obfuscator.err.println("loading Class " +fullname); |
|
|
|
|
|
|
|
ident = new ClassIdentifier(bundle, this, name, |
|
|
|
|
|
|
|
ClassInfo.forName(fullname)); |
|
|
|
|
|
|
|
loadedClasses.put(name, ident); |
|
|
|
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
|
|
|
if (bundle.preserveRule != -1) |
|
|
|
|
|
|
|
ident.applyPreserveRule(bundle.preserveRule); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (ident instanceof PackageIdentifier) { |
|
|
|
|
|
|
|
if (wildcard.matches(ident.getFullName())) { |
|
|
|
|
|
|
|
if (Obfuscator.verboseLevel > 0) |
|
|
|
|
|
|
|
Obfuscator.err.println("loading Package " +ident.getFullName()); |
|
|
|
|
|
|
|
((PackageIdentifier) ident).setLoadOnDemand(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wildcard.startsWith(ident.getFullName()+".")) |
|
|
|
|
|
|
|
((PackageIdentifier) ident).loadMatchingClasses(wildcard); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
String subpack = packageOrClass.substring(0, index); |
|
|
|
String fullname = getFullName(); |
|
|
|
PackageIdentifier pack = (PackageIdentifier) |
|
|
|
if (fullname.length() > 0) |
|
|
|
loadedClasses.get(subpack); |
|
|
|
fullname += "."; |
|
|
|
if (pack == null) { |
|
|
|
/* Load all matching classes and packages */ |
|
|
|
pack = new PackageIdentifier(bundle, this, |
|
|
|
Enumeration enum = |
|
|
|
subpack, loadOnDemand); |
|
|
|
ClassInfo.getClassesAndPackages(getFullName()); |
|
|
|
loadedClasses.put(subpack, pack); |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
|
|
|
|
String subclazz = (String)enum.nextElement(); |
|
|
|
|
|
|
|
if (loadedClasses.contains(subclazz)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
String subFull = fullname + subclazz; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wildcard.matches(subFull)) { |
|
|
|
|
|
|
|
if (ClassInfo.isPackage(subFull)) { |
|
|
|
|
|
|
|
if (Obfuscator.verboseLevel > 0) |
|
|
|
|
|
|
|
Obfuscator.err.println("loading Package " +subFull); |
|
|
|
|
|
|
|
Identifier ident = new PackageIdentifier |
|
|
|
|
|
|
|
(bundle, this, subclazz, true); |
|
|
|
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (Obfuscator.verboseLevel > 1) |
|
|
|
|
|
|
|
Obfuscator.err.println("loading Class " +subFull); |
|
|
|
|
|
|
|
ClassIdentifier ident = new ClassIdentifier |
|
|
|
|
|
|
|
(bundle, this, |
|
|
|
|
|
|
|
subclazz, ClassInfo.forName(subFull)); |
|
|
|
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
|
|
|
if (bundle.preserveRule != -1) |
|
|
|
|
|
|
|
ident.applyPreserveRule(bundle.preserveRule); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (ClassInfo.isPackage(subFull) |
|
|
|
|
|
|
|
&& wildcard.startsWith(subFull + ".")) { |
|
|
|
|
|
|
|
Identifier ident = new PackageIdentifier |
|
|
|
|
|
|
|
(bundle, this, subclazz, loadOnDemand); |
|
|
|
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
enum = loadedClasses.elements(); |
|
|
|
|
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
|
|
|
|
Identifier ident = (Identifier) enum.nextElement(); |
|
|
|
|
|
|
|
if (ident instanceof PackageIdentifier) { |
|
|
|
|
|
|
|
if (wildcard.matches(ident.getFullName())) |
|
|
|
|
|
|
|
((PackageIdentifier) ident).setLoadOnDemand(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wildcard.startsWith(ident.getFullName()+".")) |
|
|
|
|
|
|
|
((PackageIdentifier) ident).loadMatchingClasses(wildcard); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return pack.loadClasses(packageOrClass.substring(index+1)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -196,45 +279,94 @@ public class PackageIdentifier extends Identifier { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void preserveIdentifier(String fqn) { |
|
|
|
public void preserveMatchingIdentifier(WildCard wildcard) { |
|
|
|
int index = fqn.indexOf('.'); |
|
|
|
String component = wildcard.getNextComponent(getFullName()); |
|
|
|
String component = index == -1 ? fqn : fqn.substring(0, index); |
|
|
|
if (component != null) { |
|
|
|
Identifier ident = getIdentifier(component); |
|
|
|
Identifier ident = (Identifier) loadedClasses.get(component); |
|
|
|
if (ident == null) |
|
|
|
if (ident == null && loadOnDemand) { |
|
|
|
return; |
|
|
|
String fullname = getFullName(); |
|
|
|
ident.setReachable(); |
|
|
|
fullname = (fullname.length() > 0) |
|
|
|
ident.setPreserved(); |
|
|
|
? fullname + "."+ component |
|
|
|
if (index == -1) |
|
|
|
: component; |
|
|
|
return; |
|
|
|
if (ClassInfo.isPackage(fullname)) { |
|
|
|
|
|
|
|
ident = new PackageIdentifier(bundle, this, |
|
|
|
if (ident instanceof PackageIdentifier) |
|
|
|
component, loadOnDemand); |
|
|
|
((PackageIdentifier) ident).preserveIdentifier |
|
|
|
loadedClasses.put(component, ident); |
|
|
|
(fqn.substring(index+1)); |
|
|
|
} else if (!ClassInfo.exists(fullname)) { |
|
|
|
else { |
|
|
|
Obfuscator.err.println("Warning: Can't find class "+fullname); |
|
|
|
String method = fqn.substring(index+1); |
|
|
|
} else { |
|
|
|
index = method.indexOf('.'); |
|
|
|
ident = new ClassIdentifier(bundle, this, name, |
|
|
|
if (index == -1) { |
|
|
|
ClassInfo.forName(fullname)); |
|
|
|
((ClassIdentifier) ident).reachableIdentifier |
|
|
|
loadedClasses.put(name, ident); |
|
|
|
(method, null, false); |
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
((ClassIdentifier) ident).preserveIdentifier |
|
|
|
if (bundle.preserveRule != -1) |
|
|
|
(method, null); |
|
|
|
ident.applyPreserveRule(bundle.preserveRule); |
|
|
|
} else { |
|
|
|
} |
|
|
|
((ClassIdentifier) ident).reachableIdentifier |
|
|
|
} |
|
|
|
(method.substring(0, index), method.substring(index+1), |
|
|
|
if (wildcard.startsWith(ident.getFullName()+".")) { |
|
|
|
false); |
|
|
|
if (ident instanceof PackageIdentifier) |
|
|
|
((ClassIdentifier) ident).preserveIdentifier |
|
|
|
((PackageIdentifier) ident) |
|
|
|
(method.substring(0, index), method.substring(index+1)); |
|
|
|
.preserveMatchingIdentifier(wildcard); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
((ClassIdentifier) ident) |
|
|
|
|
|
|
|
.preserveMatchingIdentifier(wildcard); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
String fullname = getFullName(); |
|
|
|
|
|
|
|
if (fullname.length() > 0) |
|
|
|
|
|
|
|
fullname += "."; |
|
|
|
|
|
|
|
if (loadOnDemand) { |
|
|
|
|
|
|
|
/* Load all matching classes and packages */ |
|
|
|
|
|
|
|
Enumeration enum = |
|
|
|
|
|
|
|
ClassInfo.getClassesAndPackages(getFullName()); |
|
|
|
|
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
|
|
|
|
String subclazz = (String)enum.nextElement(); |
|
|
|
|
|
|
|
if (loadedClasses.contains(subclazz)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
String subFull = fullname + subclazz; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wildcard.startsWith(subFull + ".")) { |
|
|
|
|
|
|
|
if (ClassInfo.isPackage(subFull)) { |
|
|
|
|
|
|
|
Identifier ident = new PackageIdentifier |
|
|
|
|
|
|
|
(bundle, this, subclazz, true); |
|
|
|
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ClassIdentifier ident = new ClassIdentifier |
|
|
|
|
|
|
|
(bundle, this, |
|
|
|
|
|
|
|
subclazz, ClassInfo.forName(subFull)); |
|
|
|
|
|
|
|
loadedClasses.put(subclazz, ident); |
|
|
|
|
|
|
|
((ClassIdentifier) ident).initClass(); |
|
|
|
|
|
|
|
if (bundle.preserveRule != -1) |
|
|
|
|
|
|
|
ident.applyPreserveRule(bundle.preserveRule); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Enumeration enum = loadedClasses.elements(); |
|
|
|
|
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
|
|
|
|
Identifier ident = (Identifier) enum.nextElement(); |
|
|
|
|
|
|
|
if (wildcard.startsWith(ident.getFullName()+".")) { |
|
|
|
|
|
|
|
if (ident instanceof PackageIdentifier) |
|
|
|
|
|
|
|
((PackageIdentifier) ident) |
|
|
|
|
|
|
|
.preserveMatchingIdentifier(wildcard); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
((ClassIdentifier) ident) |
|
|
|
|
|
|
|
.preserveMatchingIdentifier(wildcard); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the full qualified name, including trailing dot. |
|
|
|
* @return the full qualified name. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getFullName() { |
|
|
|
public String getFullName() { |
|
|
|
if (parent != null) |
|
|
|
if (parent != null) { |
|
|
|
return parent.getFullName() + getName() + "."; |
|
|
|
if (parent.getFullName().length() > 0) |
|
|
|
else |
|
|
|
return parent.getFullName() + "." + getName(); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return getName(); |
|
|
|
|
|
|
|
} else |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|