@Override protected void setUp() throws Exception { super.setUp(); typeSerializable = ObjectTypeFactory.getInstance("java.io.Serializable"); typeClonable = ObjectTypeFactory.getInstance("java.lang.Cloneable"); typeObject = ObjectTypeFactory.getInstance("java.lang.Object"); typeInteger = ObjectTypeFactory.getInstance("java.lang.Integer"); typeString = ObjectTypeFactory.getInstance("java.lang.String"); typeComparable = ObjectTypeFactory.getInstance("java.lang.Comparable"); typeList = ObjectTypeFactory.getInstance("java.util.List"); typeCollection = ObjectTypeFactory.getInstance("java.util.Collection"); typeHashSet = ObjectTypeFactory.getInstance("java.util.HashSet"); typeArrayClonable = new ArrayType(typeClonable, 1); typeArrayComparable = new ArrayType(typeComparable, 1); typeArrayObject = new ArrayType(typeObject, 1); typeArrayInteger = new ArrayType(typeInteger, 1); typeArrayString = new ArrayType(typeString, 1); typeArrayArrayObject = new ArrayType(typeObject, 2); typeArrayArraySerializable = new ArrayType(typeSerializable, 2); typeArrayArrayString = new ArrayType(typeString, 2); typeArrayInt = new ArrayType(Type.INT, 1); typeArrayArrayInt = new ArrayType(Type.INT, 2); typeArrayArrayArrayInt = new ArrayType(Type.INT, 3); typeArrayChar = new ArrayType(Type.CHAR, 1); typeArrayArrayChar = new ArrayType(Type.CHAR, 2); typeArrayArrayArrayChar = new ArrayType(Type.CHAR, 3); typeDynamicString = new FindRefComparison.DynamicStringType(); typeStaticString = new FindRefComparison.StaticStringType(); typeParameterString = new FindRefComparison.ParameterStringType(); }
@Override public void visitANEWARRAY(ANEWARRAY obj) { consumeStack(obj); Type elementType = obj.getType(getCPG()); pushValue(new ArrayType(elementType, 1)); // We now have an exact type for this value. setTopOfStackIsExact(); }
return null; return new ArrayType(componentType, index);
new ArrayType(typeBasicType, typeAsArrayType.getDimensions() - possibleSupertypeAsArrayType.getDimensions()), (ObjectType) possibleSupertypeBasicType);
/** * @return element type of array, i.e., for int[][][] the element type is int[][] */ public Type getElementType() { if (dimensions == 1) { return basic_type; } return new ArrayType(basic_type, dimensions - 1); }
/** * @return element type of array, i.e., for int[][][] the element type is int[][] */ public Type getElementType() { if(dimensions == 1) return basic_type; else return new ArrayType(basic_type, dimensions - 1); }
/** * @return type of constructed array */ public final Type getType() { return new ArrayType(BasicType.getType(type), 1); }
/** * @return type of constructed array */ public final Type getType() { return new ArrayType(BasicType.getType(type), 1); }
private MethodGen createMethodGen(final String methodname, final InstructionList il, final ConstantPoolGen cp) { return new MethodGen(Const.ACC_STATIC | Const.ACC_PUBLIC, // access // flags Type.VOID, // return type new Type[] { new ArrayType(Type.STRING, 1) }, // argument // types new String[] { "argv" }, // arg names methodname, "HelloWorld", // method, class il, cp); }
/** * Method getBCELType. * Maps the java datatype and the BCEL datatype * * @param clazz the class * @return Type the type */ protected Type getBCELType(Class clazz) { if (clazz.isPrimitive()) { return getBCELPrimitiveType(clazz.getName()); } else if (!clazz.isArray()) { return new ObjectType(clazz.getName()); } else { String className = clazz.getName(); int index = className.lastIndexOf('['); int arrayDepth = className.indexOf('[') - className.lastIndexOf('[') + 1; if (className.charAt(index + 1) == 'L') { return new ArrayType(new ObjectType(clazz.getComponentType().getName()), arrayDepth); } return new ArrayType(getBCELPrimitiveType(className.substring(arrayDepth)), arrayDepth); } }
static Type translate(Class clazz) { if (clazz.isPrimitive()) { if (clazz == Integer.TYPE) { return Type.INT; } else if (clazz == Boolean.TYPE) { return Type.BOOLEAN; } else if (clazz == Short.TYPE) { return Type.SHORT; } else if (clazz == Byte.TYPE) { return Type.BYTE; } else if (clazz == Long.TYPE) { return Type.LONG; } else if (clazz == Double.TYPE) { return Type.DOUBLE; } else if (clazz == Float.TYPE) { return Type.FLOAT; } else if (clazz == Character.TYPE) { return Type.CHAR; } else if (clazz == Void.TYPE) { return Type.VOID; } else { throw new InternalError(); } } else if (clazz.isArray()) { return new ArrayType(translate(clazz.getComponentType()), 1); } else { return new ObjectType(clazz.getName()); } }
/** * Convert signature to a Type object. * @param signature signature string such as Ljava/lang/String; * @return type object */ public static final Type getType(String signature) throws StringIndexOutOfBoundsException { byte type = Utility.typeOfSignature(signature); if(type <= Constants.T_VOID) { consumed_chars = 1; return BasicType.getType(type); } else if(type == Constants.T_ARRAY) { int dim=0; do { // Count dimensions dim++; } while(signature.charAt(dim) == '['); // Recurse, but just once, if the signature is ok Type t = getType(signature.substring(dim)); consumed_chars += dim; // update counter return new ArrayType(t, dim); } else { // type == T_REFERENCE int index = signature.indexOf(';'); // Look for closing `;' if(index < 0) throw new ClassFormatException("Invalid signature: " + signature); consumed_chars = index + 1; // "Lblabla;" `L' and `;' are removed return new ObjectType(signature.substring(1, index).replace('/', '.')); } }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ @Override public void visitANEWARRAY(final ANEWARRAY o) { stack().pop(); //count stack().push( new ArrayType(o.getType(cpg), 1) ); } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitANEWARRAY(ANEWARRAY o){ stack().pop(); //count stack().push( new ArrayType(o.getType(cpg), 1) ); } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
@Override public void visitANEWARRAY(ANEWARRAY obj) { consumeStack(obj); Type elementType = obj.getType(getCPG()); pushValue(new ArrayType(elementType, 1)); // We now have an exact type for this value. setTopOfStackIsExact(); }
/** Create new array of given size and type. * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction */ public Instruction createNewArray(Type t, short dim) { if(dim == 1) { if(t instanceof ObjectType) return new ANEWARRAY(cp.addClass((ObjectType)t)); else if(t instanceof ArrayType) return new ANEWARRAY(cp.addArrayClass((ArrayType)t)); else return new NEWARRAY(((BasicType)t).getType()); } else { ArrayType at; if(t instanceof ArrayType) at = (ArrayType)t; else at = new ArrayType(t, dim); return new MULTIANEWARRAY(cp.addArrayClass(at), dim); } }
/** Create new array of given size and type. * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction */ public Instruction createNewArray( final Type t, final short dim ) { if (dim == 1) { if (t instanceof ObjectType) { return new ANEWARRAY(cp.addClass((ObjectType) t)); } else if (t instanceof ArrayType) { return new ANEWARRAY(cp.addArrayClass((ArrayType) t)); } else { return new NEWARRAY(t.getType()); } } ArrayType at; if (t instanceof ArrayType) { at = (ArrayType) t; } else { at = new ArrayType(t, dim); } return new MULTIANEWARRAY(cp.addArrayClass(at), dim); }