Refine search
private void build(CFG cfg) { int count = 0; for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Integer number = count++; Location location = i.next(); locationToNumberMap.put(location, number); numberToLocationMap.put(number, location); } } }
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location location = nextLocation(i, cpg); Instruction inst = location.getHandle().getInstruction(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location location = nextLocation(i, cpg); Instruction inst = location.getHandle().getInstruction();
/** * Returns a collection of locations, ordered according to the compareTo * ordering over locations. If you want to list all the locations in a CFG * for debugging purposes, this is a good order to do so in. * * @return collection of locations */ public Collection<Location> orderedLocations() { TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc); } return tree; }
@CheckForNull Location findLocation(CFG cfg, InstructionHandle handle) { for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location loc = i.next(); if (loc.getHandle() == handle) { return loc; } } return null; }
@CheckForNull Location findLocation(CFG cfg, int pc) { for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location loc = i.next(); if (loc.getHandle().getPosition() == pc) { return loc; } } return null; }
public static void dumpLiveLocalStoreDataflow(MethodDescriptor method, CFG cfg, LiveLocalStoreDataflow dataflow) throws DataflowAnalysisException { System.out.println("\n\n{ LiveLocalStore analysis for " + method); TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc); } for (Location loc : tree) { System.out.println("\n Pre: " + dataflow.getFactAfterLocation(loc)); System.out.println("Location: " + loc); System.out.println("Post: " + dataflow.getFactAtLocation(loc)); } System.out.println("}\n\n"); }
/** * Get a Collection of Locations which specify the instruction at given * bytecode offset. * * @param offset * the bytecode offset * @return all Locations referring to the instruction at that offset */ public Collection<Location> getLocationsContainingInstructionWithOffset(int offset) { LinkedList<Location> result = new LinkedList<>(); for (Iterator<Location> i = locationIterator(); i.hasNext();) { Location location = i.next(); if (location.getHandle().getPosition() == offset) { result.add(location); } } return result; }
public static void dumpTypeDataflow(Method method, CFG cfg, TypeDataflow typeDataflow) throws DataflowAnalysisException { System.out.println("\n\n{ Type analysis for " + cfg.getMethodGen().getClassName() + "." + method.getName() + method.getSignature()); TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc); } for (Location loc : tree) { System.out.println("\n Pre: " + typeDataflow.getFactAtLocation(loc)); System.out.println("Location: " + loc); System.out.println("Post: " + typeDataflow.getFactAfterLocation(loc)); } System.out.println("}\n\n"); }
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException { MethodGen methodGen = classContext.getMethodGen(method); CFG cfg = classContext.getCFG(method); LockDataflow dataflow = classContext.getLockDataflow(method); for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) { Location location = j.next(); visitLocation(classContext, location, methodGen, dataflow); } }
private static Map<InstructionHandle, Call> buildCallMap(CFG cfg, ConstantPoolGen cpg) { Map<InstructionHandle, Call> callMap = new HashMap<>(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { InstructionHandle handle = i.next().getHandle(); Instruction ins = handle.getInstruction(); if (ins instanceof InvokeInstruction) { InvokeInstruction inv = (InvokeInstruction) ins; Call call = new Call(inv.getClassName(cpg), inv.getName(cpg), inv.getSignature(cpg)); callMap.put(handle, call); } } return callMap; }
private boolean mightCloseResource(ClassContext classContext, Method method, ResourceTrackerType resourceTracker) throws CFGBuilderException, DataflowAnalysisException { CFG cfg = classContext.getCFG(method); ConstantPoolGen cpg = classContext.getConstantPoolGen(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); if (resourceTracker.mightCloseResource(location.getBasicBlock(), location.getHandle(), cpg)) { return true; } } return false; }
/** * Get a Location matching the given PC value. Because of JSR subroutines, * there may be multiple Locations referring to the given instruction. This * method simply returns one of them arbitrarily. * * @param classContext * the ClassContext containing the method * @param method * the method * @param pc * a PC value of an instruction in the method * @return a Location corresponding to the PC value, or null if no such * Location can be found * @throws CFGBuilderException */ private static Location pcToLocation(ClassContext classContext, Method method, int pc) throws CFGBuilderException { CFG cfg = classContext.getCFG(method); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); if (location.getHandle().getPosition() == pc) { return location; } } return null; }
TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc);
private boolean hasManyPreceedingNullTests(int pc) { int ifNullTests = 0; BitSet seen = new BitSet(); try { for (Iterator<Location> i = classContext.getCFG(method).locationIterator(); i.hasNext();) { Location loc = i.next(); int pc2 = loc.getHandle().getPosition(); if (pc2 >= pc || pc2 < pc - 30) { continue; } Instruction ins = loc.getHandle().getInstruction(); if ((ins instanceof IFNONNULL || ins instanceof IFNULL || ins instanceof NullnessConversationInstruction) && !seen.get(pc2)) { ifNullTests++; seen.set(pc2); } } boolean result = ifNullTests > 2; // System.out.println("Preceding null tests " + ifNullTests + " " + // ifNonnullTests + " " + result); return result; } catch (CFGBuilderException e) { return false; } }
private ResourceCollection<Resource> buildResourceCollection(ClassContext classContext, Method method, ResourceTrackerType resourceTracker) throws CFGBuilderException, DataflowAnalysisException { ResourceCollection<Resource> resourceCollection = new ResourceCollection<>(); CFG cfg = classContext.getCFG(method); ConstantPoolGen cpg = classContext.getConstantPoolGen(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Resource resource = resourceTracker.isResourceCreation(location.getBasicBlock(), location.getHandle(), cpg); if (resource != null) { resourceCollection.addCreatedResource(location, resource); } } return resourceCollection; }
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next();
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, ClassNotFoundException, DataflowAnalysisException { CFG cfg = classContext.getCFG(method); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Instruction ins = location.getHandle().getInstruction(); if (ins instanceof InvokeInstruction) { if (TARGET_METHOD != null && !((InvokeInstruction) ins).getMethodName(classContext.getConstantPoolGen()).equals(TARGET_METHOD)) { continue; } System.out.println("\n*******************************************************\n"); System.out.println("Method invocation: " + location.getHandle()); System.out.println("\tInvoking: " + SignatureConverter.convertMethodSignature((InvokeInstruction) ins, classContext.getConstantPoolGen())); JavaClassAndMethod proto = Hierarchy.findInvocationLeastUpperBound((InvokeInstruction) ins, classContext.getConstantPoolGen()); if (proto == null) { System.out.println("\tUnknown prototype method"); } else { System.out.println("\tPrototype method: class=" + proto.getJavaClass().getClassName() + ", method=" + proto.getMethod()); } Set<JavaClassAndMethod> calledMethodSet = Hierarchy.resolveMethodCallTargets((InvokeInstruction) ins, classContext.getTypeDataflow(method).getFactAtLocation(location), classContext.getConstantPoolGen()); System.out.println("\tTarget method set: " + calledMethodSet); } } }
private void registerInstructionSinks() throws DataflowAnalysisException { TypeQualifierAnnotation returnValueAnnotation = null; if (!xmethod.getSignature().endsWith(")V")) { returnValueAnnotation = TypeQualifierApplications.getEffectiveTypeQualifierAnnotation(xmethod, typeQualifierValue); } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Instruction ins = location.getHandle().getInstruction(); if (ins instanceof ReturnInstruction && !(ins instanceof RETURN)) { // Return instruction which returns a value modelReturn(returnValueAnnotation, location); } else { short opcode = ins.getOpcode(); if (opcode == Const.PUTFIELD || opcode == Const.PUTSTATIC) { modelFieldStore(location); } else if (location.getHandle().getInstruction() instanceof InvokeInstruction) { modelArguments(location); } } } }
if (ClassContext.DUMP_DATAFLOW_ANALYSIS) { TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc);
stringAppendState.setSawInitialTaint(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); InstructionHandle handle = location.getHandle(); Instruction ins = handle.getInstruction();