use getIdentifier(ref)

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@583 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 43ea388125
commit 2f20c95fde
  1. 112
      jode/jode/obfuscator/ConstantAnalyzer.java

@ -98,10 +98,15 @@ class ConstantAnalyzerValue implements ConstantListener {
* @return true, if the value changed. * @return true, if the value changed.
*/ */
public void merge(ConstantAnalyzerValue other) { public void merge(ConstantAnalyzerValue other) {
if (value == other.value) if (this == other
|| (value == VOLATILE && other.value == VOLATILE))
return; return;
if (value != null && value.equals(other.value))
if (value == other.value
|| (value != null && value.equals(other.value))) {
other.addConstantListener(this);
return; return;
}
if (value != VOLATILE) if (value != VOLATILE)
fireChanged(); fireChanged();
@ -110,7 +115,6 @@ class ConstantAnalyzerValue implements ConstantListener {
} }
} }
/** /**
* Analyze the code, assuming every field that is not yet written to * Analyze the code, assuming every field that is not yet written to
* is constant. This may imply that some code is dead code. * is constant. This may imply that some code is dead code.
@ -230,8 +234,9 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
if (!instrStack.contains(instr)) if (!instrStack.contains(instr))
instrStack.push(instr); instrStack.push(instr);
locals[i] = null; locals[i] = null;
} else } else {
locals[i].merge(other.locals[i]); locals[i].merge(other.locals[i]);
}
} }
} }
if (stack.length != other.stack.length) if (stack.length != other.stack.length)
@ -280,24 +285,23 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
} }
public void handleReference(Reference ref, boolean isVirtual) { public void handleReference(Reference ref, boolean isVirtual) {
m.clazz.bundle.reachableIdentifier String clName = ref.getClazz();
(ref.getClazz()+"."+ref.getName()+"."+ref.getType(), isVirtual); /* Don't have to reach array methods */
if (clName.charAt(0) != '[') {
clName = clName.substring(1, clName.length()-1).replace('/', '.');
m.clazz.bundle.reachableIdentifier
(clName+"."+ref.getName()+"."+ref.getType(), isVirtual);
}
} }
public void handleClass(String clName) { public void handleClass(String clName) {
if (clName.charAt(0) == '[') { int i = 0;
int i; while (i < clName.length() && clName.charAt(i) == '[')
for (i=0; i< clName.length(); i++) i++;
if (clName.charAt(i) != '[') if (i < clName.length() && clName.charAt(i) == 'L') {
break; clName = clName.substring(i+1, clName.length()-1);
if (i >= clName.length() || clName.charAt(i) != 'L') m.clazz.bundle.reachableIdentifier(clName, false);
return;
int index = clName.indexOf(';', i);
if (index != clName.length()-1)
return;
clName = clName.substring(i+1, index);
} }
m.clazz.bundle.reachableIdentifier(clName, false);
} }
public void handleOpcode(Instruction instr) { public void handleOpcode(Instruction instr) {
@ -926,15 +930,11 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
case opc_putfield: { case opc_putfield: {
int size = (opcode == opc_putstatic) ? 0 : 1; int size = (opcode == opc_putstatic) ? 0 : 1;
Reference ref = (Reference) instr.objData; Reference ref = (Reference) instr.objData;
ClassIdentifier ci = (ClassIdentifier) FieldIdentifier fi = (FieldIdentifier)
m.clazz.bundle.getIdentifier(ref.getClazz()); m.clazz.bundle.getIdentifier(ref);
if (ci != null) { if (fi != null && !fi.isNotConstant()) {
FieldIdentifier fi = (FieldIdentifier)
ci.getIdentifier(ref.getName(), ref.getType());
if (!fi.isNotConstant()) {
fi.setNotConstant(); fi.setNotConstant();
fieldNotConstant(fi); fieldNotConstant(fi);
}
} }
Type type = Type.tType(ref.getType()); Type type = Type.tType(ref.getType());
mergeInfo(instr.nextByAddr, info.pop(size + type.stackSize())); mergeInfo(instr.nextByAddr, info.pop(size + type.stackSize()));
@ -945,12 +945,13 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
int size = (opcode == opc_getstatic) ? 0 : 1; int size = (opcode == opc_getstatic) ? 0 : 1;
Reference ref = (Reference) instr.objData; Reference ref = (Reference) instr.objData;
Type type = Type.tType(ref.getType()); Type type = Type.tType(ref.getType());
ClassIdentifier ci = (ClassIdentifier) FieldIdentifier fi = (FieldIdentifier)
m.clazz.bundle.getIdentifier(ref.getClazz()); m.clazz.bundle.getIdentifier(ref);
if (ci != null) { if (fi != null) {
FieldIdentifier fi = (FieldIdentifier) if (fi.isNotConstant()) {
ci.getIdentifier(ref.getName(), ref.getType()); fi.setReachable();
if (!fi.isNotConstant()) { result = unknownValue[type.stackSize()-1];
} else {
Object obj = fi.getConstant(); Object obj = fi.getConstant();
if (obj == null) if (obj == null)
obj = type.getDefaultValue(); obj = type.getDefaultValue();
@ -959,9 +960,6 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
result = new ConstantAnalyzerValue(obj); result = new ConstantAnalyzerValue(obj);
result.addConstantListener(shortInfo); result.addConstantListener(shortInfo);
fi.addFieldListener(m); fi.addFieldListener(m);
} else {
fi.setReachable();
result = unknownValue[type.stackSize()-1];
} }
} else } else
result = unknownValue[type.stackSize()-1]; result = unknownValue[type.stackSize()-1];
@ -1012,17 +1010,18 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
(ref, opcode != opc_invokespecial, cls, args); (ref, opcode != opc_invokespecial, cls, args);
} catch (InterpreterException ex) { } catch (InterpreterException ex) {
constant = false; constant = false;
Obfuscator.err.println("Can't interpret "+ref+": " if (jode.Obfuscator.verboseLevel > 3)
+ ex.getMessage()); Obfuscator.err.println("Can't interpret "+ref+": "
+ ex.getMessage());
/* result is not constant */ /* result is not constant */
} catch (InvocationTargetException ex) { } catch (InvocationTargetException ex) {
constant = false; constant = false;
Obfuscator.err.println("Method "+ref+" throwed exception: " if (jode.Obfuscator.verboseLevel > 3)
+ ex.getTargetException().getMessage()); Obfuscator.err.println("Method "+ref
+" throwed exception: "
+ ex.getTargetException()
.getMessage());
/* method always throws exception ? */ /* method always throws exception ? */
} catch (Exception ex) {
Obfuscator.err.println("Unexpected exception in method: "+ref+" while analyzing "+m);
ex.printStackTrace(Obfuscator.err);
} }
} }
ConstantAnalyzerValue returnVal; ConstantAnalyzerValue returnVal;
@ -1050,15 +1049,6 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
mergeInfo(instr.nextByAddr, info.poppush(0, unknownValue[0])); mergeInfo(instr.nextByAddr, info.poppush(0, unknownValue[0]));
break; break;
} }
case opc_newarray: {
mergeInfo(instr.nextByAddr, info.poppush(1, unknownValue[0]));
break;
}
case opc_anewarray: {
handleClass((String) instr.objData);
mergeInfo(instr.nextByAddr, info.poppush(1, unknownValue[0]));
break;
}
case opc_arraylength: { case opc_arraylength: {
ConstantAnalyzerValue array = info.getStack(1); ConstantAnalyzerValue array = info.getStack(1);
if (array.value != ConstantAnalyzerValue.VOLATILE if (array.value != ConstantAnalyzerValue.VOLATILE
@ -1249,9 +1239,10 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
instr.localSlot = -1; instr.localSlot = -1;
instr.length = 2; instr.length = 2;
instr.objData = info.constant; instr.objData = info.constant;
// Obfuscator.err.println(m+": Replacing " if (Obfuscator.verboseLevel > 2)
// +opcodeString[instr.opcode] Obfuscator.err.println
// +" with constant "+info.constant); (m + ": Replacing " + instr
+ " with constant " + info.constant);
} }
instr.tmpInfo = null; instr.tmpInfo = null;
} else if ((info.flags & CONSTANTFLOW) != 0) { } else if ((info.flags & CONSTANTFLOW) != 0) {
@ -1312,15 +1303,12 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
case opc_putstatic: case opc_putstatic:
case opc_putfield: { case opc_putfield: {
Reference ref = (Reference) instr.objData; Reference ref = (Reference) instr.objData;
ClassIdentifier ci = (ClassIdentifier) FieldIdentifier fi = (FieldIdentifier)
m.clazz.bundle.getIdentifier(ref.getClazz()); m.clazz.bundle.getIdentifier(ref);
if (ci != null) { if (fi != null
FieldIdentifier fi = (FieldIdentifier) && jode.Obfuscator.shouldStrip && !fi.isReachable()) {
ci.getIdentifier(ref.getName(), ref.getType()); insertPop(instr);
if (jode.Obfuscator.shouldStrip && !fi.isReachable()) { instr.removeInstruction();
insertPop(instr);
instr.removeInstruction();
}
} }
break; break;
} }

Loading…
Cancel
Save