/** * Parse the class file into a JavaClass object. If successful, the new * JavaClass is entered into the Repository. * * @return the parsed JavaClass * @throws IOException * if the class cannot be parsed */ public JavaClass parse() throws IOException { JavaClass jclass = classParser.parse(); Repository.addClass(jclass); return jclass; } }
private boolean isImageIOInputStream() { try { if (lastCallClass.startsWith("[")) { return false; } return Repository.instanceOf(lastCallClass, "javax.imageio.stream.ImageInputStream"); } catch (ClassNotFoundException e) { return false; } }
/** * Find a field with given name defined in given class. * * @param className * the name of the class * @param fieldName * the name of the field * @return the Field, or null if no such field could be found */ public static Field findField(String className, String fieldName) throws ClassNotFoundException { JavaClass jclass = Repository.lookupClass(className); while (jclass != null) { Field[] fieldList = jclass.getFields(); for (Field field : fieldList) { if (field.getName().equals(fieldName)) { return field; } } jclass = jclass.getSuperClass(); } return null; }
public static @DottedClassName String findSuperImplementor(@DottedClassName String clazz, String name, String signature, BugReporter bugReporter) { try { JavaClass c = findImplementor(Repository.getSuperClasses(clazz), name, signature); return (c != null) ? c.getClassName() : clazz; } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); return clazz; } }
/** * Look up the method referenced by given InvokeInstruction. This method * does <em>not</em> look for implementations in super or subclasses * according to the virtual dispatch rules. * * @param inv * the InvokeInstruction * @param cpg * the ConstantPoolGen used by the class the InvokeInstruction * belongs to * @param chooser * JavaClassAndMethodChooser to use to pick the method from among * the candidates * @return the JavaClassAndMethod, or null if no such method is defined in * the class */ public static JavaClassAndMethod findExactMethod(InvokeInstruction inv, ConstantPoolGen cpg, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); JavaClass jclass = Repository.lookupClass(className); return findMethod(jclass, methodName, methodSig, chooser); }
private Set<JavaClass> getMtClasses() { if (mtClasses != null) { return mtClasses; } mtClasses = new HashSet<>(); try { mtClasses.add(Repository.lookupClass(STRUTS_ACTION_NAME)); } catch (ClassNotFoundException cnfe) { // probably would be annoying to report } try { mtClasses.add(Repository.lookupClass(SERVLET_NAME)); } catch (ClassNotFoundException cnfe) { // probably would be annoying to report } return mtClasses; }
@Override public void sawOpcode(int seen) { System.out.printf("%3d %-15s %s%n", getPC(), Const.getOpcodeName(seen), stack); }
/** * Clear the BCEL Repository in preparation for analysis. */ public void clearRepository() { // Set the backing store for the BCEL Repository to // be the AnalysisCache. Repository.setRepository(new AnalysisCacheToRepositoryAdapter()); }
public BadAppletConstructor(BugReporter bugReporter) { this.bugReporter = bugReporter; JavaClass appletClass = null; try { appletClass = Repository.lookupClass("java.applet.Applet"); } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } this.appletClass = appletClass; }
@Override public String toString() { StringBuilder buf = new StringBuilder("["); for (int i = nextSetBit(0); i >= 0; i = nextSetBit(i + 1)) { buf.append(Const.getOpcodeName(i)).append(", "); } buf.setLength(buf.length() - 2); buf.append("]"); return buf.toString(); }
private boolean isBufferedInputStream() { try { if (lastCallClass.startsWith("[")) { return false; } return Repository.instanceOf(lastCallClass, "java.io.BufferedInputStream"); } catch (ClassNotFoundException e) { return false; } }
/** Returns null for primitive and arrays */ public @CheckForNull JavaClass getJavaClass() throws ClassNotFoundException { String baseSig; if (isPrimitive() || isArray()) { return null; } baseSig = signature; if (baseSig.length() == 0) { return null; } baseSig = baseSig.substring(1, baseSig.length() - 1); baseSig = baseSig.replace('/', '.'); return Repository.lookupClass(baseSig); }
public static boolean areOppositeBranches(int opcode1, int opcode2) { if (!isBranch(opcode1)) { throw new IllegalArgumentException(Const.getOpcodeName(opcode1) + " isn't a branch"); throw new IllegalArgumentException(Const.getOpcodeName(opcode2) + " isn't a branch");
public static double isDeepRemote(String refSig) { if (remote == null) { return 0.1; } String refName = getComponentClass(refSig); if ("java.lang.Object".equals(refName)) { return 0.99; } JavaClass refJavaClass; try { refJavaClass = Repository.lookupClass(refName); return deepInstanceOf(refJavaClass, remote); } catch (ClassNotFoundException e) { return 0.99; } }
@Override public void afterOpcode(int seen) { if(DEBUG) { System.out.printf("%3d: %8s %s%n", getPC(), Const.getOpcodeName(seen), getStack()); } if (getPC() == targetPC) { throw new EarlyExitException(stack); } super.afterOpcode(seen); }
public static double isDeepRemote(String refSig) { if (remote == null) { return 0.1; } String refName = getComponentClass(refSig); if ("java.lang.Object".equals(refName)) { return 0.99; } JavaClass refJavaClass; try { refJavaClass = Repository.lookupClass(refName); return Analyze.deepInstanceOf(refJavaClass, remote); } catch (ClassNotFoundException e) { return 0.99; } }
/** * @param seen * @param item */ private void reportVacuousBitOperation(int seen, OpcodeStack.Item item) { if (item.getConstant() == null) { accumulator .accumulateBug( new BugInstance(this, "INT_VACUOUS_BIT_OPERATION", NORMAL_PRIORITY) .addClassAndMethod(this) .addString(Const.getOpcodeName(seen)) .addOptionalAnnotation( LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), item, getPC())), this); } }
public static double isDeepSerializable(String refSig) throws ClassNotFoundException { if (storedException != null) { throw storedException; } if (isPrimitiveComponentClass(refSig)) { return 1.0; } String refName = getComponentClass(refSig); if ("java.lang.Object".equals(refName)) { return 0.99; } JavaClass refJavaClass = Repository.lookupClass(refName); return isDeepSerializable(refJavaClass); }
public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Usage: " + ClassFeatureSet.class.getName() + " <class 1> <class 2>"); System.exit(1); } JavaClass a = Repository.lookupClass(args[0]); JavaClass b = Repository.lookupClass(args[1]); ClassFeatureSet aFeatures = new ClassFeatureSet().initialize(a); ClassFeatureSet bFeatures = new ClassFeatureSet().initialize(b); System.out.println("Similarity is " + similarity(aFeatures, bFeatures)); System.out.println("Classes are" + (aFeatures.similarTo(bFeatures) ? "" : " not") + " similar"); }
public static double isDeepSerializable(@DottedClassName String refSig) throws ClassNotFoundException { if (storedException != null) { throw storedException; } if (isPrimitiveComponentClass(refSig)) { if (DEBUG) { System.out.println("regSig \"" + refSig + "\" is primitive component class"); } return 1.0; } String refName = getComponentClass(refSig); if ("java.lang.Object".equals(refName)) { return 0.99; } JavaClass refJavaClass = Repository.lookupClass(refName); return isDeepSerializable(refJavaClass); }