correct inner/outer class handling

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@827 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 9894638f6c
commit 873fcef956
  1. 250
      jode/jode/obfuscator/ClassIdentifier.java

@ -184,7 +184,7 @@ public class ClassIdentifier extends Identifier {
} }
ClassInfo[] ifaces = superclass.getInterfaces(); ClassInfo[] ifaces = superclass.getInterfaces();
for (int i=0; i < ifaces.length; i++) for (int i=0; i < ifaces.length; i++)
initSuperClasses(ifaces[i]); analyzeSuperClasses(ifaces[i]);
superclass = superclass.getSuperclass(); superclass = superclass.getSuperclass();
} }
} }
@ -194,20 +194,9 @@ public class ClassIdentifier extends Identifier {
GlobalOptions.err.println("Reachable: "+this); GlobalOptions.err.println("Reachable: "+this);
ClassInfo[] ifaces = info.getInterfaces(); ClassInfo[] ifaces = info.getInterfaces();
ifaceNames = new String[ifaces.length]; for (int i=0; i < ifaces.length; i++)
for (int i=0; i < ifaces.length; i++) {
ifaceNames[i] = ifaces[i].getName();
ClassIdentifier ifaceident
= bundle.getClassIdentifier(ifaceNames[i]);
analyzeSuperClasses(ifaces[i]); analyzeSuperClasses(ifaces[i]);
} analyzeSuperClasses(info.getSuperclass());
if (info.getSuperclass() != null) {
superName = info.getSuperclass().getName();
ClassIdentifier superident
= bundle.getClassIdentifier(superName);
analyzeSuperClasses(info.getSuperclass());
}
} }
public void initSuperClasses(ClassInfo superclass) { public void initSuperClasses(ClassInfo superclass) {
@ -301,6 +290,7 @@ public class ClassIdentifier extends Identifier {
identifiers[fieldCount + i].setPreserved(); identifiers[fieldCount + i].setPreserved();
} }
// preserve / chain inherited methods and fields.
ClassInfo[] ifaces = info.getInterfaces(); ClassInfo[] ifaces = info.getInterfaces();
ifaceNames = new String[ifaces.length]; ifaceNames = new String[ifaces.length];
for (int i=0; i < ifaces.length; i++) { for (int i=0; i < ifaces.length; i++) {
@ -404,148 +394,142 @@ public class ClassIdentifier extends Identifier {
} }
public void transformInnerClasses() { public void transformInnerClasses() {
InnerClassInfo[] innerClasses = info.getInnerClasses();
InnerClassInfo[] outerClasses = info.getOuterClasses(); InnerClassInfo[] outerClasses = info.getOuterClasses();
InnerClassInfo[] extraClasses = info.getExtraClasses(); if (outerClasses != null) {
if (innerClasses == null && outerClasses == null int newOuterCount = outerClasses.length;
&& extraClasses == null) if (Obfuscator.shouldStrip) {
return;
int newInnerCount, newOuterCount, newExtraCount;
if (Obfuscator.shouldStrip) {
newInnerCount = newOuterCount = newExtraCount = 0;
if (outerClasses != null) {
for (int i=0; i < outerClasses.length; i++) { for (int i=0; i < outerClasses.length; i++) {
if (outerClasses[i].outer != null) { if (outerClasses[i].outer != null) {
ClassIdentifier outerIdent ClassIdentifier outerIdent
= bundle.getClassIdentifier(outerClasses[i].outer); = bundle.getClassIdentifier(outerClasses[i].outer);
if (outerIdent == null || outerIdent.isReachable()) if (outerIdent != null && !outerIdent.isReachable())
newOuterCount++; newOuterCount--;
} else }
newOuterCount++;
} }
} }
if (innerClasses != null) { if (newOuterCount == 0) {
info.setOuterClasses(null);
} else {
InnerClassInfo[] newOuters = new InnerClassInfo[newOuterCount];
int pos = 0;
String lastClass = getFullAlias();
for (int i=0; i<outerClasses.length; i++) {
ClassIdentifier outerIdent = outerClasses[i].outer != null
? bundle.getClassIdentifier(outerClasses[i].outer)
: null;
if (outerIdent != null && !outerIdent.isReachable())
continue;
String inner = lastClass;
String outer = outerIdent == null
? outerClasses[i].outer
: outerIdent.getFullAlias();
String name = outerClasses[i].name == null ? null
: ((outer != null && inner.startsWith(outer+"$"))
? inner.substring(outer.length()+1)
: inner.substring(inner.lastIndexOf('.')+1));
newOuters[pos++] = new InnerClassInfo
(inner, outer, name, outerClasses[i].modifiers);
lastClass = outer;
}
info.setOuterClasses(newOuters);
}
}
InnerClassInfo[] innerClasses = info.getInnerClasses();
if (innerClasses != null) {
int newInnerCount = innerClasses.length;
if (Obfuscator.shouldStrip) {
for (int i=0; i < innerClasses.length; i++) { for (int i=0; i < innerClasses.length; i++) {
ClassIdentifier innerIdent ClassIdentifier innerIdent
= bundle.getClassIdentifier(innerClasses[i].inner); = bundle.getClassIdentifier(innerClasses[i].inner);
if (innerIdent == null || innerIdent.isReachable()) if (innerIdent != null && !innerIdent.isReachable())
newInnerCount++; newInnerCount--;
}
}
if (newInnerCount == 0) {
info.setInnerClasses(null);
} else {
InnerClassInfo[] newInners = new InnerClassInfo[newInnerCount];
int pos = 0;
for (int i=0; i<innerClasses.length; i++) {
ClassIdentifier innerIdent
= bundle.getClassIdentifier(innerClasses[i].inner);
if (innerIdent != null
&& Obfuscator.shouldStrip && !innerIdent.isReachable())
continue;
String inner = innerIdent == null
? innerClasses[i].inner
: innerIdent.getFullAlias();
String outer = getFullAlias();
String name = innerClasses[i].name == null ? null
: ((outer != null && inner.startsWith(outer+"$"))
? inner.substring(outer.length()+1)
: inner.substring(inner.lastIndexOf('.')+1));
newInners[pos++] = new InnerClassInfo
(inner, outer, name, innerClasses[i].modifiers);
} }
info.setInnerClasses(newInners);
} }
if (extraClasses != null) { }
InnerClassInfo[] extraClasses = info.getExtraClasses();
if (extraClasses != null) {
int newExtraCount = extraClasses.length;
if (Obfuscator.shouldStrip) {
for (int i=0; i < extraClasses.length; i++) { for (int i=0; i < extraClasses.length; i++) {
ClassIdentifier outerIdent = extraClasses[i].outer != null ClassIdentifier outerIdent = extraClasses[i].outer != null
? bundle.getClassIdentifier(extraClasses[i].outer) ? bundle.getClassIdentifier(extraClasses[i].outer)
: null; : null;
ClassIdentifier innerIdent ClassIdentifier innerIdent
= bundle.getClassIdentifier(extraClasses[i].inner); = bundle.getClassIdentifier(extraClasses[i].inner);
if ((outerIdent == null || outerIdent.isReachable()) if ((outerIdent != null && !outerIdent.isReachable())
&& (innerIdent == null || innerIdent.isReachable())) || (innerIdent != null && !innerIdent.isReachable()))
newExtraCount++; newExtraCount--;
}
}
} else {
newInnerCount = innerClasses != null ? innerClasses.length : 0;
newOuterCount = outerClasses != null ? outerClasses.length : 0;
newExtraCount = extraClasses != null ? extraClasses.length : 0;
}
InnerClassInfo[] newInners = newInnerCount > 0
? new InnerClassInfo[newInnerCount] : null;
InnerClassInfo[] newOuters = newOuterCount > 0
? new InnerClassInfo[newOuterCount] : null;
InnerClassInfo[] newExtras = newExtraCount > 0
? new InnerClassInfo[newExtraCount] : null;
if (newInners != null) {
int pos = 0;
for (int i=0; i<innerClasses.length; i++) {
ClassIdentifier innerIdent
= bundle.getClassIdentifier(innerClasses[i].inner);
if (innerIdent != null && !innerIdent.isReachable())
continue;
String inner, outer, name;
if (innerIdent == null) {
inner = innerClasses[i].inner;
} else {
inner = innerIdent.getFullAlias();
} }
outer = getFullAlias();
if (innerClasses[i].name == null)
/* This is an anonymous class */
name = null;
else if (outer != null && inner.startsWith(outer+"$"))
name = inner.substring(outer.length()+1);
else
name = inner;
newInners[pos++] = new InnerClassInfo
(inner, outer, name, innerClasses[i].modifiers);
} }
}
if (newOuters != null) { if (newExtraCount == 0) {
int pos = 0; info.setExtraClasses(null);
String lastClass = getFullAlias(); } else {
for (int i=0; i<outerClasses.length; i++) { InnerClassInfo[] newExtras = newExtraCount > 0
ClassIdentifier outerIdent = outerClasses[i].outer != null ? new InnerClassInfo[newExtraCount] : null;
? bundle.getClassIdentifier(outerClasses[i].outer)
: null; int pos = 0;
for (int i=0; i<extraClasses.length; i++) {
if (outerIdent != null && !outerIdent.isReachable()) ClassIdentifier outerIdent = extraClasses[i].outer != null
continue; ? bundle.getClassIdentifier(extraClasses[i].outer)
: null;
String inner = lastClass; ClassIdentifier innerIdent
String outer = outerIdent == null = bundle.getClassIdentifier(extraClasses[i].inner);
? outerClasses[i].outer : outerIdent.getFullAlias();
String name; if (innerIdent != null && !innerIdent.isReachable())
lastClass = outer; continue;
if (outerClasses[i].name == null) if (outerIdent != null && !outerIdent.isReachable())
/* This is an anonymous class */ continue;
name = null;
else if (outer != null && inner.startsWith(outer+"$")) String inner = innerIdent == null
name = inner.substring(outer.length()+1); ? extraClasses[i].inner
else : innerIdent.getFullAlias();
name = inner.substring(inner.lastIndexOf('.')+1); String outer = outerIdent == null
newOuters[pos++] = new InnerClassInfo ? extraClasses[i].outer
(inner, outer, name, outerClasses[i].modifiers); : outerIdent.getFullAlias();
}
} String name = extraClasses[i].name == null ? null
if (newExtras != null) { : ((outer != null && inner.startsWith(outer+"$"))
int pos = 0; ? inner.substring(outer.length()+1)
for (int i=0; i<extraClasses.length; i++) { : inner.substring(inner.lastIndexOf('.')+1));
ClassIdentifier outerIdent = extraClasses[i].outer != null
? bundle.getClassIdentifier(extraClasses[i].outer) newExtras[pos++] = new InnerClassInfo
: null; (inner, outer, name, extraClasses[i].modifiers);
ClassIdentifier innerIdent }
= bundle.getClassIdentifier(extraClasses[i].inner); info.setExtraClasses(newExtras);
if (innerIdent != null && !innerIdent.isReachable())
continue;
if (outerIdent != null && !outerIdent.isReachable())
continue;
String inner = innerIdent == null
? extraClasses[i].inner : innerIdent.getFullAlias();
String outer = outerIdent == null
? extraClasses[i].outer : outerIdent.getFullAlias();
String name;
if (extraClasses[i].name == null)
/* This is an anonymous class */
name = null;
else if (outer != null && inner.startsWith(outer+"$"))
name = inner.substring(outer.length()+1);
else
name = inner;
newExtras[pos++] = new InnerClassInfo
(inner, outer, name, extraClasses[i].modifiers);
} }
} }
info.setInnerClasses(newInners);
info.setOuterClasses(newOuters);
info.setExtraClasses(newExtras);
} }
public void doTransformations() { public void doTransformations() {

Loading…
Cancel
Save