public PrimitiveConstant getPrimitiveConstant(int index) { PrimitiveConstant cn = (PrimitiveConstant)getConstant(index); if (cn != null && interceptor != null) { if (cn.type == CodeConstants.CONSTANT_Class) { String newName = buildNewClassname(cn.getString()); if (newName != null) { cn = new PrimitiveConstant(CodeConstants.CONSTANT_Class, newName); } } } return cn; }
@Override public void resolveConstant(ConstantPool pool) { if (type == CONSTANT_Class || type == CONSTANT_String || type == CONSTANT_MethodType) { value = pool.getPrimitiveConstant(index).getString(); initConstant(); } }
public LinkConstant(int type, String classname, String elementname, String descriptor) { super(type); this.classname = classname; this.elementname = elementname; this.descriptor = descriptor; initConstant(); }
@Override public void resolveConstant(ConstantPool pool) { if (type == CONSTANT_NameAndType) { elementname = pool.getPrimitiveConstant(index1).getString(); descriptor = pool.getPrimitiveConstant(index2).getString(); } else if (type == CONSTANT_MethodHandle) { LinkConstant ref_info = pool.getLinkConstant(index2); classname = ref_info.classname; elementname = ref_info.elementname; descriptor = ref_info.descriptor; } else { if (type != CONSTANT_InvokeDynamic) { classname = pool.getPrimitiveConstant(index1).getString(); } LinkConstant nametype = pool.getLinkConstant(index2); elementname = nametype.elementname; descriptor = nametype.descriptor; } initConstant(); }
public String getExcClassname(int index, ConstantPool pool) { return pool.getPrimitiveConstant(throwsExceptions.get(index)).getString(); }
public LinkConstant getLinkConstant(int index) { LinkConstant ln = (LinkConstant)getConstant(index); if (ln != null && interceptor != null && (ln.type == CodeConstants.CONSTANT_Fieldref || ln.type == CodeConstants.CONSTANT_Methodref || ln.type == CodeConstants.CONSTANT_InterfaceMethodref)) { String newClassName = buildNewClassname(ln.classname); String newElement = interceptor.getName(ln.classname + ' ' + ln.elementname + ' ' + ln.descriptor); String newDescriptor = buildNewDescriptor(ln.type == CodeConstants.CONSTANT_Fieldref, ln.descriptor); //TODO: Fix newElement being null caused by ln.classname being a leaf class instead of the class that declared the field/method. //See the comments of IDEA-137253 for more information. if (newClassName != null || newElement != null || newDescriptor != null) { String className = newClassName == null ? ln.classname : newClassName; String elementName = newElement == null ? ln.elementname : newElement.split(" ")[1]; String descriptor = newDescriptor == null ? ln.descriptor : newDescriptor; ln = new LinkConstant(ln.type, className, elementName, descriptor); } } return ln; }
@Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { int classIndex = data.readUnsignedShort(); int methodIndex = data.readUnsignedShort(); className = pool.getPrimitiveConstant(classIndex).getString(); if (methodIndex != 0) { LinkConstant lk = pool.getLinkConstant(methodIndex); methodName = lk.elementname; methodDescriptor = lk.descriptor; } }
public String[] getClassElement(int elementType, String className, int nameIndex, int descriptorIndex) { String elementName = ((PrimitiveConstant)getConstant(nameIndex)).getString(); String descriptor = ((PrimitiveConstant)getConstant(descriptorIndex)).getString(); if (interceptor != null) { String oldClassName = interceptor.getOldName(className); if (oldClassName != null) { className = oldClassName; } String newElement = interceptor.getName(className + ' ' + elementName + ' ' + descriptor); if (newElement != null) { elementName = newElement.split(" ")[1]; } String newDescriptor = buildNewDescriptor(elementType == FIELD, descriptor); if (newDescriptor != null) { descriptor = newDescriptor; } } return new String[]{elementName, descriptor}; }
pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Utf8, in.readUTF())); break; pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Integer, Integer.valueOf(in.readInt()))); break; pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Float, in.readFloat())); break; pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Long, in.readLong())); pool.add(null); i++; pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Double, in.readDouble())); pool.add(null); i++; case CodeConstants.CONSTANT_String: case CodeConstants.CONSTANT_MethodType: pool.add(new PrimitiveConstant(tag, in.readUnsignedShort())); nextPass[0].set(i); break; pool.add(new LinkConstant(tag, in.readUnsignedShort(), in.readUnsignedShort())); nextPass[0].set(i); break; case CodeConstants.CONSTANT_InterfaceMethodref: case CodeConstants.CONSTANT_InvokeDynamic:
@Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { int method_number = data.readUnsignedShort(); for (int i = 0; i < method_number; ++i) { int bootstrap_method_ref = data.readUnsignedShort(); int num_bootstrap_arguments = data.readUnsignedShort(); List<PooledConstant> list_arguments = new ArrayList<>(); for (int j = 0; j < num_bootstrap_arguments; ++j) { int bootstrap_argument_ref = data.readUnsignedShort(); list_arguments.add(pool.getConstant(bootstrap_argument_ref)); } methodRefs.add(pool.getLinkConstant(bootstrap_method_ref)); methodArguments.add(list_arguments); } }
public StructMethod(DataInputFullStream in, StructClass clStruct) throws IOException { classStruct = clStruct; accessFlags = in.readUnsignedShort(); int nameIndex = in.readUnsignedShort(); int descriptorIndex = in.readUnsignedShort(); ConstantPool pool = clStruct.getPool(); String[] values = pool.getClassElement(ConstantPool.METHOD, clStruct.qualifiedName, nameIndex, descriptorIndex); name = values[0]; descriptor = values[1]; attributes = readAttributes(in, pool); if (codeAttributes != null) { attributes.putAll(codeAttributes); codeAttributes = null; } }
public PrimitiveConstant(int type, Object value) { super(type); this.value = value; initConstant(); }
private void initConstant() { if (type == CONSTANT_Class) { String className = getString(); isArray = (className.length() > 0 && className.charAt(0) == '['); // empty string for a class name seems to be possible in some android files } }
public ConstantPool loadPool(String classname) { try (DataInputFullStream in = getClassStream(classname)) { if (in != null) { in.discard(8); return new ConstantPool(in); } return null; } catch (IOException ex) { throw new RuntimeException(ex); } }
@Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { int index = data.readUnsignedShort(); signature = pool.getPrimitiveConstant(index).getString(); }
public StructField(DataInputFullStream in, StructClass clStruct) throws IOException { accessFlags = in.readUnsignedShort(); int nameIndex = in.readUnsignedShort(); int descriptorIndex = in.readUnsignedShort(); ConstantPool pool = clStruct.getPool(); String[] values = pool.getClassElement(ConstantPool.FIELD, clStruct.qualifiedName, nameIndex, descriptorIndex); name = values[0]; descriptor = values[1]; attributes = readAttributes(in, pool); }
@Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { int len = data.readUnsignedShort(); if (len > 0) { entries = new ArrayList<>(len); for (int i = 0; i < len; i++) { int innerNameIdx = data.readUnsignedShort(); int outerNameIdx = data.readUnsignedShort(); int simpleNameIdx = data.readUnsignedShort(); int accessFlags = data.readUnsignedShort(); String innerName = pool.getPrimitiveConstant(innerNameIdx).getString(); String outerName = outerNameIdx != 0 ? pool.getPrimitiveConstant(outerNameIdx).getString() : null; String simpleName = simpleNameIdx != 0 ? pool.getPrimitiveConstant(simpleNameIdx).getString() : null; entries.add(new Entry(outerNameIdx, simpleNameIdx, accessFlags, innerName, outerName, simpleName)); } } else { entries = Collections.emptyList(); } }
public static AnnotationExprent parseAnnotation(DataInputStream data, ConstantPool pool) throws IOException { String className = pool.getPrimitiveConstant(data.readUnsignedShort()).getString(); List<String> names; List<Exprent> values; int len = data.readUnsignedShort(); if (len > 0) { names = new ArrayList<>(len); values = new ArrayList<>(len); for (int i = 0; i < len; i++) { names.add(pool.getPrimitiveConstant(data.readUnsignedShort()).getString()); values.add(parseAnnotationElement(data, pool)); } } else { names = Collections.emptyList(); values = Collections.emptyList(); } return new AnnotationExprent(new VarType(className).value, names, values); }
@Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { int len = data.readUnsignedByte(); List<Entry> entries; if (len > 0) { entries = new ArrayList<>(len); for (int i = 0; i < len; i++) { int nameIndex = data.readUnsignedShort(); String name = nameIndex != 0 ? pool.getPrimitiveConstant(nameIndex).getString() : null; int access_flags = data.readUnsignedShort(); entries.add(new Entry(name, access_flags)); } } else { entries = Collections.emptyList(); } myEntries = Collections.unmodifiableList(entries); }
@Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { int len = data.readUnsignedShort(); if (len > 0) { localVariables = new ArrayList<>(len); for (int i = 0; i < len; i++) { int start_pc = data.readUnsignedShort(); int length = data.readUnsignedShort(); int nameIndex = data.readUnsignedShort(); int descriptorIndex = data.readUnsignedShort(); int varIndex = data.readUnsignedShort(); localVariables.add(new LocalVariable(start_pc, length, pool.getPrimitiveConstant(nameIndex).getString(), pool.getPrimitiveConstant(descriptorIndex).getString(), varIndex)); } } else { localVariables = Collections.emptyList(); } }