protected Object keyFor(Stmt s) { if (s.containsInvokeExpr()) { if (optionNaive) { throw new RuntimeException("shouldn't get here"); } Iterator it = cg.edgesOutOf(s); if (!it.hasNext()) { return Collections.EMPTY_LIST; } ArrayList ret = new ArrayList(); while (it.hasNext()) { ret.add(it.next()); } return ret; } else { return s; } }
/** * <p> * <b>SOOT USERS: DO NOT CALL THIS METHOD!</b> * </p> * * <p> * This method is a Soot-internal factory method for generating callgraph objects. It creates non-initialized object that * must then be initialized by a callgraph algorithm * </p> * * @return A new callgraph empty object */ public CallGraph internalMakeCallGraph() { return new CallGraph(); }
public void addStaticEdge(MethodOrMethodContext src, Unit srcUnit, SootMethod target, Kind kind) { cg.addEdge(new Edge(src, srcUnit, target, kind)); }
/** * Removes all outgoing edges that start at the given unit * * @param u * The unit from which to remove all outgoing edges * @return True if at least one edge has been removed, otherwise false */ public boolean removeAllEdgesOutOf(Unit u) { boolean hasRemoved = false; for (QueueReader<Edge> edgeRdr = listener(); edgeRdr.hasNext();) { Edge e = edgeRdr.next(); if (e.srcUnit() == u) { removeEdge(e); hasRemoved = true; } } return hasRemoved; }
/** * Swaps an invocation statement. All edges that previously went from the given statement to some callee now go from the * new statement to the same callee. This method is intended to be used when a Jimple statement is replaced, but the * replacement does not semantically affect the edges. * * @param out * The old statement * @param in * The new statement * @return True if at least one edge was affected by this operation */ public boolean swapEdgesOutOf(Stmt out, Stmt in) { boolean hasSwapped = false; for (QueueReader<Edge> edgeRdr = listener(); edgeRdr.hasNext();) { Edge e = edgeRdr.next(); if (e.srcUnit() == out) { removeEdge(e); addEdge(new Edge(e.getSrc(), in, e.getTgt())); hasSwapped = true; } } return hasSwapped; }
private void buildChainAndSuccs(CallGraph cg) { Iterator it = cg.sourceMethods(); while (it.hasNext()) { SootMethod sm = (SootMethod) it.next(); Iterator edgeIt = cg.edgesOutOf(sm); while (edgeIt.hasNext()) { Edge edge = (Edge) edgeIt.next();
Iterator<Edge> edges = cg.edgesOutOf(callsite); if (!edges.hasNext()) { csIt.remove(); cg.removeEdge(p.sootEdge);
Iterator edges = cg.edgesOutOf(s); for (Iterator momcIt = methodToContexts.get(m).iterator(); momcIt.hasNext();) { final MethodOrMethodContext momc = (MethodOrMethodContext) momcIt.next(); Iterator callerEdges = cg.edgesInto(momc); while (callerEdges.hasNext()) { Edge callEdge = (Edge) callerEdges.next();
if (!instanceInvokesFilter.wrap(cg.edgesOutOf(container)).hasNext()) { continue; Iterator targets = new Targets(instanceInvokesFilter.wrap(cg.edgesOutOf(s))); if (!targets.hasNext()) { continue; newStmt = (Stmt) newUnits.next(); Iterator edges = cg.edgesOutOf(oldStmt); while (edges.hasNext()) { Edge e = (Edge) edges.next(); cg.addEdge(new Edge(ct, newStmt, e.tgt(), e.kind())); cg.removeEdge(e); ieBox.setValue(sie); cg.addEdge(new Edge(container, s, clonedTarget));
@Override public Collection<Unit> load(SootMethod m) throws Exception { ArrayList<Unit> res = new ArrayList<Unit>(); // only retain callers that are explicit call sites or // Thread.start() Iterator<Edge> edgeIter = new EdgeFilter().wrap(cg.edgesInto(m)); while (edgeIter.hasNext()) { Edge edge = edgeIter.next(); res.add(edge.srcUnit()); } res.trimToSize(); return res; } };
public String toString() { QueueReader<Edge> reader = listener(); StringBuffer out = new StringBuffer(); while (reader.hasNext()) { Edge e = (Edge) reader.next(); out.append(e.toString() + "\n"); } return out.toString(); }
if (soot_callgraph.isEntryMethod(func) || func.isEntryMethod()) { CgEdge p = new CgEdge(Constants.SUPER_MAIN, id, null, call_graph[Constants.SUPER_MAIN]); call_graph[Constants.SUPER_MAIN] = p; QueueReader<Edge> edgeList = Scene.v().getCallGraph().listener(); while (edgeList.hasNext()) { Edge edge = edgeList.next();
public void go() { Iterator<MethodOrMethodContext> methods = cg.sourceMethods(); while (methods.hasNext()) { SootMethod m = (SootMethod) methods.next(); dfsVisit(m); } }
protected void internalTransform(Body b, String phaseName, Map options) { ClinitElimAnalysis a = new ClinitElimAnalysis(new BriefUnitGraph(b)); CallGraph cg = Scene.v().getCallGraph(); SootMethod m = b.getMethod(); Iterator edgeIt = cg.edgesOutOf(m); while (edgeIt.hasNext()) { Edge e = (Edge) edgeIt.next(); if (e.srcStmt() == null) { continue; } if (!e.isClinit()) { continue; } FlowSet methods = (FlowSet) a.getFlowBefore(e.srcStmt()); if (methods.contains(e.tgt())) { cg.removeEdge(e); } } } }
Iterator edges = cg.edgesOutOf(s); for( Iterator momcIt = methodToContexts.get(m).iterator(); momcIt.hasNext(); ) { final MethodOrMethodContext momc = (MethodOrMethodContext) momcIt.next(); Iterator callerEdges = cg.edgesInto(momc); while (callerEdges.hasNext()){ Edge callEdge = (Edge)callerEdges.next();
private ArrayList<MethInfo> getSrcMethods(SootMethod method, boolean recurse) { // logger.debug("meth for srcs: "+method); ArrayList<MethInfo> list = new ArrayList<MethInfo>(); for (Iterator momcIt = methodToContexts.get(method).iterator(); momcIt.hasNext();) { final MethodOrMethodContext momc = (MethodOrMethodContext) momcIt.next(); Iterator callerEdges = cg.edgesInto(momc); while (callerEdges.hasNext()) { Edge callEdge = (Edge) callerEdges.next(); SootMethod methodCaller = callEdge.src(); if (methodCaller.getDeclaringClass().isLibraryClass()) { if (isShowLibMeths()) { if (recurse) { list.add( new MethInfo(methodCaller, hasTgtMethods(methodCaller) | hasSrcMethods(methodCaller), callEdge.kind())); } else { list.add(new MethInfo(methodCaller, true, callEdge.kind())); } } } else { if (recurse) { list.add(new MethInfo(methodCaller, hasTgtMethods(methodCaller) | hasSrcMethods(methodCaller), callEdge.kind())); } else { list.add(new MethInfo(methodCaller, true, callEdge.kind())); } } } } return list; }
public ReachableMethods(CallGraph graph, Iterator<? extends MethodOrMethodContext> entryPoints, Filter filter) { this.filter = filter; this.cg = graph; addMethods(entryPoints); unprocessedMethods = reachables.reader(); this.edgeSource = graph.listener(); if (filter != null) { this.edgeSource = filter.wrap(this.edgeSource); } }
public void go() { Iterator methods = cg.sourceMethods(); while( methods.hasNext() ) { SootMethod m = (SootMethod) methods.next(); dfsVisit( m ); } }
protected Object keyFor(Stmt s) { if (s.containsInvokeExpr()) { if (optionNaive) { throw new RuntimeException("shouldn't get here"); } Iterator it = cg.edgesOutOf(s); if (!it.hasNext()) { return Collections.EMPTY_LIST; } ArrayList ret = new ArrayList(); while (it.hasNext()) { ret.add(it.next()); } return ret; } else { return s; } }