ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex(), Const.CONSTANT_NameAndType); String methodName = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex(), Const.CONSTANT_Utf8)).getBytes(); String className = cp.getConstantString(cmr.getClassIndex(), Const.CONSTANT_Class).replace('/', '.'); String methodSig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex(), Const.CONSTANT_Utf8)).getBytes();
String className = cp.getConstantString(((ConstantCP) ref).getClassIndex(), Const.CONSTANT_Class); ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(((ConstantCP) ref).getNameAndTypeIndex()); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); MethodAnnotation called = new MethodAnnotation(ClassName.toDottedClassName(className), name, signature, kind==6 /* invokestatic */);
ConstantCP desc = (ConstantCP)cp.getConstant(((GETFIELD)inst).getIndex()); ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex()); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); return new Value(value.name+"."+name, vnaDataflow.getFactAfterLocation(new Location(ih, block)).getStackValue(0), signature); ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex()); String className = cp.getConstantString(desc.getClassIndex(), CONSTANT_Class); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); if(className.equals("java/lang/Integer") && name.equals("intValue") && signature.equals("()I") ||
/** * Returns true if given constant pool probably has a reference to any of supplied methods * Useful to exclude from analysis uninteresting classes * @param cp constant pool * @param methods methods collection * @return true if method is found */ public static boolean hasInterestingMethod(ConstantPool cp, Collection<MethodDescriptor> methods) { for(Constant c : cp.getConstantPool()) { if(c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) { ConstantCP desc = (ConstantCP)c; ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex()); String className = cp.getConstantString(desc.getClassIndex(), Const.CONSTANT_Class); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); // We don't know whether method is static thus cannot use equals int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature); for(MethodDescriptor method : methods) { if (method.getNameSigHashCode() == hash && (method.getSlashedClassName().isEmpty() || method.getSlashedClassName().equals(className)) && method.getName().equals(name) && method.getSignature().equals(signature)) { return true; } } } } return false; }
ConstantNameAndType sig = (ConstantNameAndType) getConstantPool().getConstant( id.getNameAndTypeIndex()); nameConstantOperand = getStringFromIndex(sig.getNameIndex()); sigConstantOperand = getStringFromIndex(sig.getSignatureIndex()); } else if (constantRefOperand instanceof ConstantCP) { ConstantNameAndType sig = (ConstantNameAndType) getConstantPool().getConstant( cp.getNameAndTypeIndex()); nameConstantOperand = getStringFromIndex(sig.getNameIndex()); sigConstantOperand = getStringFromIndex(sig.getSignatureIndex()); refConstantOperand = null;
int nameAndTypeIdx = fieldRef.getNameAndTypeIndex(); ConstantNameAndType ntc = (ConstantNameAndType) cp.getConstant(nameAndTypeIdx); int nameIdx = ntc.getNameIndex();
String name = ((ConstantUtf8) obj.getConstantPool().getConstant(nt.getNameIndex(), Const.CONSTANT_Utf8)).getBytes(); String signature = ((ConstantUtf8) obj.getConstantPool().getConstant(nt.getSignatureIndex(), Const.CONSTANT_Utf8)) .getBytes();
i = ((ConstantNameAndType) c).getNameIndex(); v[i] = 1; j = ((ConstantNameAndType) c).getSignatureIndex();
/** * Initialize from another object. */ public ConstantNameAndType(final ConstantNameAndType c) { this(c.getNameIndex(), c.getSignatureIndex()); }
/** @return name */ public final String getName( final ConstantPool cp ) { return cp.constantToString(getNameIndex(), Const.CONSTANT_Utf8); }
/** * Initialize from another object. */ public ConstantNameAndType(ConstantNameAndType c) { this(c.getNameIndex(), c.getSignatureIndex()); }
/** @return name */ public final String getName(ConstantPool cp) { return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8); }
/** @return name of referenced method/field. */ public String getName(final ConstantPoolGen cpg) { final ConstantPool cp = cpg.getConstantPool(); final ConstantNameAndType cnat = getNameAndType(cpg); return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); }
@Override public void visitConstantNameAndType(final ConstantNameAndType obj) { if (obj.getTag() != Const.CONSTANT_NameAndType) { throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } checkIndex(obj, obj.getNameIndex(), CONST_Utf8); //checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below. checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8); } @Override
public void visitConstantNameAndType(ConstantNameAndType obj){ if (obj.getTag() != Constants.CONSTANT_NameAndType){ throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } checkIndex(obj, obj.getNameIndex(), CONST_Utf8); //checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below. checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8); } public void visitConstantUtf8(ConstantUtf8 obj){
/** @return name of referenced method/field. */ public String getName(ConstantPoolGen cpg) { ConstantPool cp = cpg.getConstantPool(); ConstantCP cmr = (ConstantCP)cp.getConstant(index); ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex()); return ((ConstantUtf8)cp.getConstant(cnat.getNameIndex())).getBytes(); }
/** @return name of referenced method/field. */ public String getName( final ConstantPoolGen cpg ) { final ConstantPool cp = cpg.getConstantPool(); final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex()); final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex()); return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); }
/** * Returns true if given constant pool probably has a reference to any of supplied methods * Useful to exclude from analysis uninteresting classes * @param cp constant pool * @param methods methods collection * @return true if method is found */ public static boolean hasInterestingMethod(ConstantPool cp, Collection<MethodDescriptor> methods) { for(Constant c : cp.getConstantPool()) { if(c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) { ConstantCP desc = (ConstantCP)c; ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(desc.getNameAndTypeIndex()); String className = cp.getConstantString(desc.getClassIndex(), CONSTANT_Class); String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameIndex())).getBytes(); String signature = ((ConstantUtf8)cp.getConstant(nameAndType.getSignatureIndex())).getBytes(); // We don't know whether method is static thus cannot use equals int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, signature); for(MethodDescriptor method : methods) { if (method.getNameSigHashCode() == hash && (method.getSlashedClassName().isEmpty() || method.getSlashedClassName().equals(className)) && method.getName().equals(name) && method.getSignature().equals(signature)) { return true; } } } } return false; }
public void visitConstantFieldref(ConstantFieldref obj){ if (obj.getTag() != Constants.CONSTANT_Fieldref){ throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!"); } int name_and_type_index = obj.getNameAndTypeIndex(); ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name if (!validFieldName(name)){ throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'."); } int class_index = obj.getClassIndex(); ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form if (! validClassName(className)){ throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); } String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor) try{ Type.getType(sig); /* Don't need the return value */ } catch (ClassFormatError cfe){ // Well, BCEL sometimes is a little harsh describing exceptional situations. throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'."); } }
@Override public void visitConstantFieldref(final ConstantFieldref obj) { if (obj.getTag() != Const.CONSTANT_Fieldref) { throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!"); } final int name_and_type_index = obj.getNameAndTypeIndex(); final ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); final String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name if (!validFieldName(name)) { throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'."); } final int class_index = obj.getClassIndex(); final ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); final String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form if (! validClassName(className)) { throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); } final String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method sig.(=descriptor) try{ Type.getType(sig); /* Don't need the return value */ } catch (final ClassFormatException cfe) { throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.", cfe); } }