public ClassReference14Processor() { InvocationExprent invfor = new InvocationExprent(); invfor.setName("forName"); invfor.setClassname("java/lang/Class"); invfor.setStringDescriptor("(Ljava/lang/String;)Ljava/lang/Class;"); invfor.setDescriptor(MethodDescriptor.parseDescriptor("(Ljava/lang/String;)Ljava/lang/Class;")); invfor.setStatic(true); invfor.setLstParameters( Arrays.asList(new Exprent[] {new VarExprent(0, VarType.VARTYPE_STRING, null)})); bodyexprent = new ExitExprent(ExitExprent.EXIT_RETURN, invfor, VarType.VARTYPE_CLASS, null); InvocationExprent constr = new InvocationExprent(); constr.setName("<init>"); constr.setClassname("java/lang/NoClassDefFoundError"); constr.setStringDescriptor("()V"); constr.setFunctype(InvocationExprent.TYP_INIT); constr.setDescriptor(MethodDescriptor.parseDescriptor("()V")); NewExprent newexpr = new NewExprent( new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/NoClassDefFoundError"), new ArrayList<Exprent>(), null); newexpr.setConstructor(constr); InvocationExprent invcause = new InvocationExprent(); invcause.setName("initCause"); invcause.setClassname("java/lang/NoClassDefFoundError"); invcause.setStringDescriptor("(Ljava/lang/Throwable;)Ljava/lang/Throwable;"); invcause.setDescriptor( MethodDescriptor.parseDescriptor("(Ljava/lang/Throwable;)Ljava/lang/Throwable;")); invcause.setInstance(newexpr); invcause.setLstParameters( Arrays.asList( new Exprent[] { new VarExprent( 2, new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/ClassNotFoundException"), null) })); handlerexprent = new ExitExprent(ExitExprent.EXIT_THROW, invcause, null, null); }
public static Exprent parseAnnotationElement(DataInputStream data, ConstantPool pool) throws IOException { int tag = data.readUnsignedByte(); switch (tag) { case 'e': // enum constant String className = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); String constName = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); FieldDescriptor descr = FieldDescriptor.parseDescriptor(className); return new FieldExprent(constName, descr.type.value, true, null, descr, null); case 'c': // class String descriptor = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); VarType type = FieldDescriptor.parseDescriptor(descriptor).type; String value; switch (type.type) { case CodeConstants.TYPE_OBJECT: value = type.value; break; case CodeConstants.TYPE_BYTE: value = byte.class.getName(); break; case CodeConstants.TYPE_CHAR: value = char.class.getName(); break; case CodeConstants.TYPE_DOUBLE: value = double.class.getName(); break; case CodeConstants.TYPE_FLOAT: value = float.class.getName(); break; case CodeConstants.TYPE_INT: value = int.class.getName(); break; case CodeConstants.TYPE_LONG: value = long.class.getName(); break; case CodeConstants.TYPE_SHORT: value = short.class.getName(); break; case CodeConstants.TYPE_BOOLEAN: value = boolean.class.getName(); break; case CodeConstants.TYPE_VOID: value = void.class.getName(); break; default: throw new RuntimeException("invalid class type: " + type.type); } return new ConstExprent(VarType.VARTYPE_CLASS, value, null); case '[': // array List<Exprent> elements = Collections.emptyList(); int len = data.readUnsignedShort(); if (len > 0) { elements = new ArrayList<Exprent>(len); for (int i = 0; i < len; i++) { elements.add(parseAnnotationElement(data, pool)); } } VarType newType; if (elements.isEmpty()) { newType = new VarType(CodeConstants.TYPE_OBJECT, 1, "java/lang/Object"); } else { VarType elementType = elements.get(0).getExprType(); newType = new VarType(elementType.type, 1, elementType.value); } NewExprent newExpr = new NewExprent(newType, Collections.emptyList(), null); newExpr.setDirectArrayInit(true); newExpr.setLstArrayElements(elements); return newExpr; case '@': // annotation return parseAnnotation(data, pool); default: PrimitiveConstant cn = pool.getPrimitiveConstant(data.readUnsignedShort()); switch (tag) { case 'B': return new ConstExprent(VarType.VARTYPE_BYTE, cn.value, null); case 'C': return new ConstExprent(VarType.VARTYPE_CHAR, cn.value, null); case 'D': return new ConstExprent(VarType.VARTYPE_DOUBLE, cn.value, null); case 'F': return new ConstExprent(VarType.VARTYPE_FLOAT, cn.value, null); case 'I': return new ConstExprent(VarType.VARTYPE_INT, cn.value, null); case 'J': return new ConstExprent(VarType.VARTYPE_LONG, cn.value, null); case 'S': return new ConstExprent(VarType.VARTYPE_SHORT, cn.value, null); case 'Z': return new ConstExprent(VarType.VARTYPE_BOOLEAN, cn.value, null); case 's': return new ConstExprent(VarType.VARTYPE_STRING, cn.value, null); default: throw new RuntimeException("invalid element type!"); } } }