oops, previous code did not even compile

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1118 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 25 years ago
parent d9f8ffd373
commit fd99e8bf69
  1. 59
      jode/jode/obfuscator/ConstantAnalyzer.java.in
  2. 43
      jode/jode/obfuscator/ConstantRuntimeEnvironment.java.in

@ -21,8 +21,6 @@ package jode.obfuscator;
import jode.AssertError; import jode.AssertError;
import jode.GlobalOptions; import jode.GlobalOptions;
import jode.type.MethodType;
import jode.type.Type;
import jode.bytecode.*; import jode.bytecode.*;
import jode.jvm.InterpreterException; import jode.jvm.InterpreterException;
@ -236,15 +234,16 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
boolean isStatic, String methodTypeSig, boolean isStatic, String methodTypeSig,
Collection notifyQueue) { Collection notifyQueue) {
MethodType mt = Type.tMethod(methodTypeSig); String[] paramTypes
= TypeSignature.getParameterTypes(methodTypeSig);
locals = new ConstValue[numLocals]; locals = new ConstValue[numLocals];
stack = new ConstValue[0]; stack = new ConstValue[0];
this.notifyQueue = notifyQueue; this.notifyQueue = notifyQueue;
int slot = 0; int slot = 0;
if (!isStatic) if (!isStatic)
locals[slot++] = new ConstValue(1); locals[slot++] = new ConstValue(1);
for (int i=0; i< mt.getParameterTypes().length; i++) { for (int i=0; i< paramTypes.length; i++) {
int stackSize = mt.getParameterTypes()[i].stackSize(); int stackSize = TypeSignature.getTypeSize(paramTypes[i]);
locals[slot] = unknownValue[stackSize-1]; locals[slot] = unknownValue[stackSize-1];
slot += stackSize; slot += stackSize;
} }
@ -1150,12 +1149,12 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
FieldIdentifier fi = (FieldIdentifier) canonizeReference(instr); FieldIdentifier fi = (FieldIdentifier) canonizeReference(instr);
int size = (opcode == opc_putstatic) ? 0 : 1; int size = (opcode == opc_putstatic) ? 0 : 1;
Reference ref = instr.getReference(); Reference ref = instr.getReference();
size += TypeSignature.getTypeSize(ref.getType());
if (fi != null && !fi.isNotConstant()) { if (fi != null && !fi.isNotConstant()) {
fi.setNotConstant(); fi.setNotConstant();
fieldNotConstant(fi); fieldNotConstant(fi);
} }
Type type = Type.tType(ref.getType()); mergeInfo(instr.getNextByAddr(), info.pop(size));
mergeInfo(instr.getNextByAddr(), info.pop(size + type.stackSize()));
break; break;
} }
case opc_getstatic: case opc_getstatic:
@ -1163,15 +1162,33 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
int size = (opcode == opc_getstatic) ? 0 : 1; int size = (opcode == opc_getstatic) ? 0 : 1;
FieldIdentifier fi = (FieldIdentifier) canonizeReference(instr); FieldIdentifier fi = (FieldIdentifier) canonizeReference(instr);
Reference ref = instr.getReference(); Reference ref = instr.getReference();
Type type = Type.tType(ref.getType()); int typesize = TypeSignature.getTypeSize(ref.getType());
if (fi != null) { if (fi != null) {
if (fi.isNotConstant()) { if (fi.isNotConstant()) {
fi.setReachable(); fi.setReachable();
result = unknownValue[type.stackSize()-1]; result = unknownValue[typesize - 1];
} else { } else {
Object obj = fi.getConstant(); Object obj = fi.getConstant();
if (obj == null) if (obj == null) {
obj = type.getDefaultValue(); switch (ref.getType().charAt(0)) {
case 'Z':
case 'B':
case 'S':
case 'C':
case 'I':
obj = new Integer(0);
break;
case 'J':
obj = new Long(0);
break;
case 'F':
obj = new Float(0);
break;
case 'D':
obj = new Double(0);
break;
}
}
ConstantInfo shortInfo = new ConstantInfo(); ConstantInfo shortInfo = new ConstantInfo();
constInfos.put(instr, shortInfo); constInfos.put(instr, shortInfo);
shortInfo.flags |= CONSTANT; shortInfo.flags |= CONSTANT;
@ -1181,7 +1198,7 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
fi.addFieldListener(fieldListener); fi.addFieldListener(fieldListener);
} }
} else } else
result = unknownValue[type.stackSize()-1]; result = unknownValue[typesize - 1];
mergeInfo(instr.getNextByAddr(), info.poppush(size, result)); mergeInfo(instr.getNextByAddr(), info.poppush(size, result));
break; break;
} }
@ -1204,7 +1221,7 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
size += TypeSignature.getTypeSize(paramTypes[i]); size += TypeSignature.getTypeSize(paramTypes[i]);
Object value = (argValues[i] = info.getStack(size)).value; Object value = (argValues[i] = info.getStack(size)).value;
if (value != ConstValue.VOLATILE) if (value != ConstValue.VOLATILE)
arg[i] = value; args[i] = value;
else else
constant = false; constant = false;
} }
@ -1251,7 +1268,8 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
if (!constant) { if (!constant) {
handleReference(ref, opcode == opc_invokevirtual handleReference(ref, opcode == opc_invokevirtual
|| opcode == opc_invokeinterface); || opcode == opc_invokeinterface);
returnVal = unknownValue[mt.getReturnType().stackSize()-1]; int retsize = TypeSignature.getTypeSize(retType);
returnVal = unknownValue[retsize - 1];
} else { } else {
ConstantInfo shortInfo = new ConstantInfo(); ConstantInfo shortInfo = new ConstantInfo();
constInfos.put(instr, shortInfo); constInfos.put(instr, shortInfo);
@ -1432,8 +1450,8 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
break; break;
case opc_putstatic: case opc_putstatic:
case opc_putfield: case opc_putfield:
if (Type.tType(instr.getReference().getType()) if (TypeSignature
.stackSize() == 2) { .getTypeSize(instr.getReference().getType()) == 2) {
iter.set(new Instruction(opc_pop2)); iter.set(new Instruction(opc_pop2));
if (instr.getOpcode() == opc_putfield) if (instr.getOpcode() == opc_putfield)
iter.add(new Instruction(opc_pop)); iter.add(new Instruction(opc_pop));
@ -1446,13 +1464,13 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
case opc_invokeinterface: case opc_invokeinterface:
case opc_invokevirtual: { case opc_invokevirtual: {
Reference ref = instr.getReference(); Reference ref = instr.getReference();
MethodType mt = (MethodType) Type.tType(ref.getType()); String[] pt = TypeSignature.getParameterTypes(ref.getType());
Type[] pt = mt.getParameterTypes();
int arg = 0; int arg = 0;
if (instr.getOpcode() != opc_invokestatic) if (instr.getOpcode() != opc_invokestatic)
iter.set(new Instruction(opc_pop)); iter.set(new Instruction(opc_pop));
else if (pt.length > 0) { else if (pt.length > 0) {
iter.set(new Instruction(pt[0].stackSize() + opc_pop - 1)); iter.set(new Instruction(TypeSignature.getTypeSize(pt[0])
+ opc_pop - 1));
arg++; arg++;
} else { } else {
if (replacement == null) if (replacement == null)
@ -1463,7 +1481,8 @@ public class ConstantAnalyzer implements Opcodes, CodeAnalyzer {
} }
for (int i=arg; i < pt.length; i++) for (int i=arg; i < pt.length; i++)
iter.add(new Instruction(pt[i].stackSize() + opc_pop - 1)); iter.add(new Instruction(TypeSignature.getTypeSize(pt[i])
+ opc_pop - 1));
} }
} }
if (replacement != null) if (replacement != null)

@ -26,41 +26,28 @@ import jode.bytecode.BytecodeInfo;
import jode.type.*; import jode.type.*;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.*; import @COLLECTIONS@.Set;
import @COLLECTIONS@.HashSet;
public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment { public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment {
/** /**
* The references that may be used in constant methods. * The references that may be used in constant methods.
*/ */
///#ifdef JDK12 static Set whiteList = new HashSet();
/// static Set whiteList = new HashSet();
///
/// static void addWhite(Reference ref) {
/// /* note that this gets inlined */
/// whiteList.add(ref);
/// }
///
/// public static boolean isWhite(Reference ref) {
/// return whiteList.contains(ref);
/// }
///#else
static Hashtable whiteList = new Hashtable();
static void addWhite(Reference ref) { static void addWhite(Reference ref) {
/* note that this gets inlined */ whiteList.add(ref);
whiteList.put(ref, ref);
} }
public static boolean isWhite(Reference ref) { public static boolean isWhite(Reference ref) {
return whiteList.containsKey(ref); return whiteList.contains(ref);
} }
public static boolean isWhiteType(String retTypeSig) { public static boolean isWhite(String retTypeSig) {
return retTypeSig.length() != 1; return retTypeSig.length() == 1 // primitive type
&& !whiteList.contains(retTypeSig); || whiteList.contains(retTypeSig);
} }
///#endif
static { static {
addWhite(Reference.getReference addWhite(Reference.getReference
@ -219,6 +206,11 @@ public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment {
("Ljava/lang/Math;", "E", "D")); ("Ljava/lang/Math;", "E", "D"));
addWhite(Reference.getReference addWhite(Reference.getReference
("Ljava/lang/Math;", "PI", "D")); ("Ljava/lang/Math;", "PI", "D"));
whiteList.add("Ljava/lang/String;");
// whiteList.add("Ljava/lang/Class;");
// whiteList.add("Ljava/lang/reflect/Method;");
// whiteList.add("Ljava/lang/reflect/Field;");
} }
private Interpreter interpreter; private Interpreter interpreter;
@ -298,13 +290,4 @@ public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment {
} }
throw new InterpreterException("Creating object array."); throw new InterpreterException("Creating object array.");
} }
public void enterMonitor(Object obj)
throws InterpreterException {
throw new InterpreterException("monitorenter not implemented");
}
public void exitMonitor(Object obj)
throws InterpreterException {
throw new InterpreterException("monitorenter not implemented");
}
} }
Loading…
Cancel
Save