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); } }
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; }
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 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_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(); }
case CodeConstants.opc_ldc_w: case CodeConstants.opc_ldc2_w: PooledConstant constant = pool.getConstant(instr.operand(0)); switch (constant.type) { case CodeConstants.CONSTANT_Integer: stack.pop(); case CodeConstants.opc_getstatic: ck = pool.getLinkConstant(instr.operand(0)); var1 = new VarType(ck.descriptor); stack.push(var1); stack.pop(); case CodeConstants.opc_putstatic: ck = pool.getLinkConstant(instr.operand(0)); var1 = new VarType(ck.descriptor); stack.pop(var1.stackSize); case CodeConstants.opc_invokedynamic: if (instr.opcode != CodeConstants.opc_invokedynamic || instr.bytecodeVersion >= CodeConstants.BYTECODE_JAVA_7) { ck = pool.getLinkConstant(instr.operand(0)); MethodDescriptor md = MethodDescriptor.parseDescriptor(ck.descriptor); for (int i = 0; i < md.params.length; i++) { cn = pool.getPrimitiveConstant(instr.operand(0)); stack.push(new VarType(CodeConstants.TYPE_OBJECT, 0, cn.getString())); break; case CodeConstants.opc_instanceof:
pool = new ConstantPool(in); ConstantPool.skipPool(in); int descriptorIndex = in.readUnsignedShort(); String[] values = pool.getClassElement(ConstantPool.METHOD, className, nameIndex, descriptorIndex); if (!mt.getName().equals(values[0]) || !mt.getDescriptor().equals(values[1])) { skipAttributes(in); for (int j = 0; j < attrSize; j++) { int attrNameIndex = in.readUnsignedShort(); String attrName = pool.getPrimitiveConstant(attrNameIndex).getString(); if (!StructGeneralAttribute.ATTRIBUTE_CODE.getName().equals(attrName)) { in.discard(in.readInt());
public String getExcClassname(int index, ConstantPool pool) { return pool.getPrimitiveConstant(throwsExceptions.get(index)).getString(); }
@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 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}; }
majorVersion = in.readUnsignedShort(); pool = new ConstantPool(in); qualifiedName = pool.getPrimitiveConstant(thisClassIdx).getString(); superClass = pool.getPrimitiveConstant(superClassIdx); for (int i = 0; i < length; i++) { interfaces[i] = in.readUnsignedShort(); interfaceNames[i] = pool.getPrimitiveConstant(interfaces[i]).getString();
LinkConstant invoke_dynamic = cl.getPool().getLinkConstant(instr.operand(0));
case opc_ldc_w: case opc_ldc2_w: PooledConstant cn = pool.getConstant(instr.operand(0)); if (cn instanceof PrimitiveConstant) { pushEx(stack, exprlist, new ConstExprent(consts[cn.type - CONSTANT_Integer], ((PrimitiveConstant)cn).value, bytecode_offsets)); case opc_checkcast: case opc_instanceof: stack.push(new ConstExprent(new VarType(pool.getPrimitiveConstant(instr.operand(0)).getString(), true), null, null)); case opc_arraylength: pushEx(stack, exprlist, new FunctionExprent(mapConsts.get(instr.opcode), stack, bytecode_offsets)); case opc_getfield: pushEx(stack, exprlist, new FieldExprent(pool.getLinkConstant(instr.operand(0)), instr.opcode == opc_getstatic ? null : stack.pop(), bytecode_offsets)); break; Exprent valfield = stack.pop(); Exprent exprfield = new FieldExprent(pool.getLinkConstant(instr.operand(0)), instr.opcode == opc_putstatic ? null : stack.pop(), bytecode_offsets); exprlist.add(new AssignmentExprent(exprfield, valfield, bytecode_offsets)); case opc_invokedynamic: if (instr.opcode != opc_invokedynamic || instr.bytecodeVersion >= CodeConstants.BYTECODE_JAVA_7) { LinkConstant invoke_constant = pool.getLinkConstant(instr.operand(0)); case opc_multianewarray:
pool = new ConstantPool(in); ConstantPool.skipPool(in); int descriptorIndex = in.readUnsignedShort(); String[] values = pool.getClassElement(ConstantPool.METHOD, className, nameIndex, descriptorIndex); if (!mt.getName().equals(values[0]) || !mt.getDescriptor().equals(values[1])) { skipAttributes(in); for (int j = 0; j < attrSize; j++) { int attrNameIndex = in.readUnsignedShort(); String attrName = pool.getPrimitiveConstant(attrNameIndex).getString(); if (!StructGeneralAttribute.ATTRIBUTE_CODE.equals(attrName)) { in.discard(in.readInt());
@Override public void resolveConstant(ConstantPool pool) { if (type == CONSTANT_Class || type == CONSTANT_String || type == CONSTANT_MethodType) { value = pool.getPrimitiveConstant(index).getString(); initConstant(); } }
@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 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 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 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}; }
majorVersion = in.readUnsignedShort(); pool = new ConstantPool(in); qualifiedName = pool.getPrimitiveConstant(thisClassIdx).getString(); superClass = pool.getPrimitiveConstant(superClassIdx); for (int i = 0; i < length; i++) { interfaces[i] = in.readUnsignedShort(); interfaceNames[i] = pool.getPrimitiveConstant(interfaces[i]).getString();