protected final Class resolveClass(int i) throws IOException, ClassNotFoundException { int oldPos = pos; try { Class c = (Class) cpool[i]; if (c == null) { pos = cpoolIndex[i]; String name = resolveUtf8(readShort()); cpool[i] = c = Class.forName(classDescriptorToName(name)); } return c; } finally { pos = oldPos; } }
/** * read a code attribute * @throws IOException */ public void readCode() throws IOException { readShort(); // max stack readShort(); // max locals skipFully(readInt()); // code skipFully(8 * readShort()); // exception table // read the code attributes (recursive). This is where // we will find the LocalVariableTable attribute. readAttributes(); }
protected final void readCpool() throws IOException { int count = readShort(); // cpool count cpoolIndex = new int[count]; cpool = new Object[count]; for (int i = 1; i < count; i++) { int c = read(); cpoolIndex[i] = super.pos; switch (c) // constant pool tag case CONSTANT_NameAndType: readShort(); // class index or (12) name index case CONSTANT_String: readShort(); // string index or class index break; case CONSTANT_Double: readInt(); // hi-value readInt(); // value break; int len = readShort(); skipFully(len); break;
int count = readShort(); for (int i = 0; i < count; i++) { int nameIndex = readShort(); // name index int attrLen = readInt(); int curPos = pos; String attrName = resolveUtf8(nameIndex); } catch (IllegalAccessException e) { pos = curPos; skipFully(attrLen); } catch (InvocationTargetException e) { try { } catch (Throwable ex) { pos = curPos; skipFully(attrLen); skipFully(attrLen);
if (m == null) { pos = cpoolIndex[index]; Class owner = resolveClass(readShort()); NameAndType nt = resolveNameAndType(readShort()); String signature = nt.name + nt.type; if (nt.name.equals("<init>")) { Constructor[] ctors = owner.getConstructors(); for (int i = 0; i < ctors.length; i++) { String sig = getSignature(ctors[i], ctors[i].getParameterTypes()); if (sig.equals(signature)) { cpool[index] = m = ctors[i]; Method[] methods = owner.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { String sig = getSignature(methods[i], methods[i].getParameterTypes()); if (sig.equals(signature)) { cpool[index] = m = methods[i];
protected final Field resolveField(int i) throws IOException, ClassNotFoundException, NoSuchFieldException { int oldPos = pos; try { Field f = (Field) cpool[i]; if (f == null) { pos = cpoolIndex[i]; Class owner = resolveClass(readShort()); NameAndType nt = resolveNameAndType(readShort()); cpool[i] = f = owner.getDeclaredField(nt.name); } return f; } finally { pos = oldPos; } }
protected final NameAndType resolveNameAndType(int i) throws IOException { int oldPos = pos; try { NameAndType nt = (NameAndType) cpool[i]; if (nt == null) { pos = cpoolIndex[i]; String name = resolveUtf8(readShort()); String type = resolveUtf8(readShort()); cpool[i] = nt = new NameAndType(name, type); } return nt; } finally { pos = oldPos; } }
protected static String getSignature(Member method, Class[] paramTypes) { // compute the method descriptor StringBuffer b = new StringBuffer((method instanceof Method) ? method.getName() : "<init>"); b.append('('); for (int i = 0; i < paramTypes.length; i++) { addDescriptor(b, paramTypes[i]); } b.append(')'); if (method instanceof Method) { addDescriptor(b, ((Method) method).getReturnType()); } else if (method instanceof Constructor) { addDescriptor(b, void.class); } return b.toString(); }
private static void addDescriptor(StringBuffer b, Class c) { if (c.isPrimitive()) { if (c == void.class) b.append('V'); else if (c == int.class) b.append('I'); else if (c == boolean.class) b.append('Z'); else if (c == byte.class) b.append('B'); else if (c == short.class) b.append('S'); else if (c == long.class) b.append('J'); else if (c == char.class) b.append('C'); else if (c == float.class) b.append('F'); else if (c == double.class) b.append('D'); } else if (c.isArray()) { b.append('['); addDescriptor(b, c.getComponentType()); } else { b.append('L').append(c.getName().replace('.', '/')).append(';'); } }