protected String getStringFromIndex(int i) { ConstantUtf8 name = (ConstantUtf8) constantPool.getConstant(i); return name.getBytes(); }
private String getMemberName(JavaClass c, String className, int memberNameIndex, int signatureIndex) { return className + "." + ((ConstantUtf8) c.getConstantPool().getConstant(memberNameIndex, Const.CONSTANT_Utf8)).getBytes() + " : " + ((ConstantUtf8) c.getConstantPool().getConstant(signatureIndex, Const.CONSTANT_Utf8)).getBytes(); }
private String getStringFromIndex(DismantleBytecode dbc, int i) { ConstantUtf8 name = (ConstantUtf8) dbc.getConstantPool().getConstant(i); return name.getBytes(); }
public static boolean hasInterestingClass(ConstantPool cp, Collection<String> classes) { for(Constant c : cp.getConstantPool()) { if(c instanceof ConstantClass) { String className = ((ConstantUtf8)cp.getConstant(((ConstantClass)c).getNameIndex())).getBytes(); if(classes.contains(className)) { return true; } } } return false; }
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();
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); if (!javaClass.getPackageName().contains(".pages")) { return; } //The package contains ".pages" and has some references to tapestry // then it must be an endpoint. //The constants pool contains all references that are reused in the bytecode // including full class name and interface name. if (javaClass.getPackageName().contains(".pages")) { ConstantPool constants = javaClass.getConstantPool(); for (Constant c : constants.getConstantPool()) { if (c instanceof ConstantUtf8) { ConstantUtf8 utf8 = (ConstantUtf8) c; String constantValue = String.valueOf(utf8.getBytes()); if (constantValue.startsWith("Lorg/apache/tapestry5/annotations")) { bugReporter.reportBug(new BugInstance(this, TAPESTRY_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) // .addClass(javaClass)); return; } } } } }
/** * 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; }
ConstantUtf8 typeCons = (ConstantUtf8) cp.getConstant(ntc.getSignatureIndex()); if (alreadyReported.contains(nameCons.getBytes())) { return; alreadyReported.add(nameCons.getBytes()); bugReporter.reportBug(new BugInstance(this, STRUTS_ACTION_NAME.equals(mtClassName) ? "MTIA_SUSPECT_STRUTS_INSTANCE_FIELD" : "MTIA_SUSPECT_SERVLET_INSTANCE_FIELD", LOW_PRIORITY) .addField( new FieldAnnotation(getDottedClassName(), nameCons.getBytes(), typeCons.getBytes(), false)).addClass(this).addSourceLine(this));
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 */); calledMethods.add(called);
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") || className.equals("java/lang/Long") && name.equals("longValue") && signature.equals("()J") ||
@Override public void visitClassContext(ClassContext classContext) { JavaClass jclass = classContext.getJavaClass(); // We can ignore classes that were compiled for anything // less than JDK 1.5. This should avoid lots of unnecessary work // when analyzing code for older VM targets. if (BCELUtil.preTiger(jclass)) { return; } boolean sawUtilConcurrentLocks = false; for (Constant c : jclass.getConstantPool().getConstantPool()) { if (c instanceof ConstantMethodref) { ConstantMethodref m = (ConstantMethodref) c; ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex()); ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex()); String nameAsString = name.getBytes(); if (nameAsString.startsWith("java/util/concurrent/locks")) { sawUtilConcurrentLocks = true; } } } if (sawUtilConcurrentLocks) { super.visitClassContext(classContext); } }
/** * @return Name of object, i.e., method name or field name */ public final String getName() { ConstantUtf8 c; c = (ConstantUtf8) constant_pool.getConstant(name_index, Const.CONSTANT_Utf8); return c.getBytes(); }
/** * @return the annotation type name */ public String getAnnotationType() { final ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(type_index, Const.CONSTANT_Utf8); return c.getBytes(); }
/** * @return PMG name. */ public final String getPMGName() { ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_index, Constants.CONSTANT_Utf8); return c.getBytes(); }
/** * @return Source file name. */ public final String getSourceFileName() { final ConstantUtf8 c = (ConstantUtf8) super.getConstantPool().getConstant(sourcefile_index, Const.CONSTANT_Utf8); return c.getBytes(); }
public String getEnumTypeString() { final ConstantUtf8 cu8 = (ConstantUtf8) super.getConstantPool().getConstant(typeIdx, Const.CONSTANT_Utf8); return cu8.getBytes();// Utility.signatureToString(cu8.getBytes()); }
/** This method casually visits ConstantClass references. */ public void visitConstantClass(ConstantClass obj){ Constant c = cp.getConstant(obj.getNameIndex()); if (c instanceof ConstantUtf8){ //Ignore the case where it's not a ConstantUtf8 here, we'll find out later. String classname = ((ConstantUtf8) c).getBytes(); if (classname.startsWith(jc.getClassName().replace('.','/')+"$")){ hasInnerClass = true; } } } }
/** @return signature of referenced method/field. */ public String getSignature(final ConstantPoolGen cpg) { final ConstantPool cp = cpg.getConstantPool(); final ConstantNameAndType cnat = getNameAndType(cpg); return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); }