private void addDependencies(ConstantPool pool) { for (Constant constant : pool.getEntries()) { if (constant instanceof CstType) { checkDescriptor(((CstType) constant).getClassType()); } else if (constant instanceof CstFieldRef) { checkDescriptor(((CstFieldRef) constant).getType()); } else if (constant instanceof CstMethodRef) { Prototype proto = ((CstMethodRef) constant).getPrototype(); checkDescriptor(proto.getReturnType()); StdTypeList args = proto.getParameterTypes(); for (int i = 0; i < args.size(); i++) { checkDescriptor(args.get(i)); } } } }
/** * Helper for {@link #parseValue}, which parses a constant reference * and returns the referred-to constant value. * * @return {@code non-null;} the parsed value */ private Constant parseConstant() throws IOException { int constValueIndex = input.readUnsignedShort(); Constant value = (Constant) pool.get(constValueIndex); if (observer != null) { String human = (value instanceof CstString) ? ((CstString) value).toQuoted() : value.toHuman(); parsed(2, "constant_value: " + human); } return value; }
/** * Parses an {@code EnclosingMethod} attribute. */ private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length != 4) { throwBadLength(4); } ByteArray bytes = cf.getBytes(); ConstantPool pool = cf.getConstantPool(); int idx = bytes.getUnsignedShort(offset); CstType type = (CstType) pool.get(idx); idx = bytes.getUnsignedShort(offset + 2); CstNat method = (CstNat) pool.get0Ok(idx); Attribute result = new AttEnclosingMethod(type, method); if (observer != null) { observer.parsed(bytes, offset, 2, "class: " + type); observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method)); } return result; }
int handlerPc = bytes.getUnsignedShort(offset + 4); int catchTypeIdx = bytes.getUnsignedShort(offset + 6); CstType catchType = (CstType) pool.get0Ok(catchTypeIdx); catches.set(i, startPc, endPc, handlerPc, catchType); if (observer != null) {
int constantPoolSize = cf.getConstantPool().size(); maxMethodIdsInClass = constantPoolSize + cf.getMethods().size() + MAX_METHOD_ADDED_DURING_DEX_CREATION;
/** * Helper for {@link #parseValue}, which parses a constant reference * and returns the referred-to constant value. * * @return {@code non-null;} the parsed value */ private Constant parseConstant() throws IOException { int constValueIndex = input.readUnsignedShort(); Constant value = (Constant) pool.get(constValueIndex); if (observer != null) { String human = (value instanceof CstString) ? ((CstString) value).toQuoted() : value.toHuman(); parsed(2, "constant_value: " + human); } return value; }
/** * Parses an {@code EnclosingMethod} attribute. */ private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length != 4) { throwBadLength(4); } ByteArray bytes = cf.getBytes(); ConstantPool pool = cf.getConstantPool(); int idx = bytes.getUnsignedShort(offset); CstType type = (CstType) pool.get(idx); idx = bytes.getUnsignedShort(offset + 2); CstNat method = (CstNat) pool.get0Ok(idx); Attribute result = new AttEnclosingMethod(type, method); if (observer != null) { observer.parsed(bytes, offset, 2, "class: " + type); observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method)); } return result; }
int handlerPc = bytes.getUnsignedShort(offset + 4); int catchTypeIdx = bytes.getUnsignedShort(offset + 6); CstType catchType = (CstType) pool.get0Ok(catchTypeIdx); catches.set(i, startPc, endPc, handlerPc, catchType); if (observer != null) {
int constantPoolSize = cf.getConstantPool().size(); maxMethodIdsInClass = constantPoolSize + cf.getMethods().size() + MAX_METHOD_ADDED_DURING_DEX_CREATION;
/** * Helper for {@link #parseValue}, which parses a constant reference * and returns the referred-to constant value. * * @return {@code non-null;} the parsed value */ private Constant parseConstant() throws IOException { int constValueIndex = input.readUnsignedShort(); Constant value = (Constant) pool.get(constValueIndex); if (observer != null) { String human = (value instanceof CstString) ? ((CstString) value).toQuoted() : value.toHuman(); parsed(2, "constant_value: " + human); } return value; }
/** * Parses an {@code EnclosingMethod} attribute. */ private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length != 4) { throwBadLength(4); } ByteArray bytes = cf.getBytes(); ConstantPool pool = cf.getConstantPool(); int idx = bytes.getUnsignedShort(offset); CstType type = (CstType) pool.get(idx); idx = bytes.getUnsignedShort(offset + 2); CstNat method = (CstNat) pool.get0Ok(idx); Attribute result = new AttEnclosingMethod(type, method); if (observer != null) { observer.parsed(bytes, offset, 2, "class: " + type); observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method)); } return result; }
int handlerPc = bytes.getUnsignedShort(offset + 4); int catchTypeIdx = bytes.getUnsignedShort(offset + 6); CstType catchType = (CstType) pool.get0Ok(catchTypeIdx); catches.set(i, startPc, endPc, handlerPc, catchType); if (observer != null) {
private void addDependencies(DirectClassFile classFile) { for (Constant constant : classFile.getConstantPool().getEntries()) { if (constant instanceof CstType) { checkDescriptor(((CstType) constant).getClassType().getDescriptor()); } else if (constant instanceof CstFieldRef) { checkDescriptor(((CstFieldRef) constant).getType().getDescriptor()); } else if (constant instanceof CstBaseMethodRef) { checkPrototype(((CstBaseMethodRef) constant).getPrototype()); } } FieldList fields = classFile.getFields(); int nbField = fields.size(); for (int i = 0; i < nbField; i++) { checkDescriptor(fields.get(i).getDescriptor().getString()); } MethodList methods = classFile.getMethods(); int nbMethods = methods.size(); for (int i = 0; i < nbMethods; i++) { checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString())); } } private void checkPrototype(Prototype proto) {
int constantPoolSize = cf.getConstantPool().size();
/** * Helper for {@link #parseValue}, which parses a constant reference * and returns the referred-to constant value. * * @return {@code non-null;} the parsed value */ private Constant parseConstant() throws IOException { int constValueIndex = input.readUnsignedShort(); Constant value = (Constant) pool.get(constValueIndex); if (observer != null) { String human = (value instanceof CstString) ? ((CstString) value).toQuoted() : value.toHuman(); parsed(2, "constant_value: " + human); } return value; }
/** * Parses an {@code EnclosingMethod} attribute. */ private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length != 4) { throwBadLength(4); } ByteArray bytes = cf.getBytes(); ConstantPool pool = cf.getConstantPool(); int idx = bytes.getUnsignedShort(offset); CstType type = (CstType) pool.get(idx); idx = bytes.getUnsignedShort(offset + 2); CstNat method = (CstNat) pool.get0Ok(idx); Attribute result = new AttEnclosingMethod(type, method); if (observer != null) { observer.parsed(bytes, offset, 2, "class: " + type); observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method)); } return result; }