Java Code Examples for soot.jimple.toolkits.callgraph.ReachableMethods#update()

The following examples show how to use soot.jimple.toolkits.callgraph.ReachableMethods#update() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Infoflow.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private Collection<SootMethod> getMethodsForSeeds(IInfoflowCFG icfg) {
	List<SootMethod> seeds = new LinkedList<SootMethod>();
	// If we have a callgraph, we retrieve the reachable methods. Otherwise,
	// we have no choice but take all application methods as an approximation
	if (Scene.v().hasCallGraph()) {
		List<MethodOrMethodContext> eps = new ArrayList<MethodOrMethodContext>(Scene.v().getEntryPoints());
		ReachableMethods reachableMethods = new ReachableMethods(Scene.v().getCallGraph(), eps.iterator(), null);
		reachableMethods.update();
		for (Iterator<MethodOrMethodContext> iter = reachableMethods.listener(); iter.hasNext();)
			seeds.add(iter.next().method());
	}
	else {
		long beforeSeedMethods = System.nanoTime();
		Set<SootMethod> doneSet = new HashSet<SootMethod>();
		for (SootMethod sm : Scene.v().getEntryPoints())
			getMethodsForSeedsIncremental(sm, doneSet, seeds, icfg);
		logger.info("Collecting seed methods took {} seconds", (System.nanoTime() - beforeSeedMethods) / 1E9);
	}
	return seeds;
}
 
Example 2
Source File: AnalyzeJimpleClass.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void analyzeRechableMethods(SootClass lifecycleElement, List<MethodOrMethodContext> methods) {
	ReachableMethods rm = new ReachableMethods(Scene.v().getCallGraph(), methods);
	rm.update();

	// Scan for listeners in the class hierarchy
	Iterator<MethodOrMethodContext> reachableMethods = rm.listener();
	while (reachableMethods.hasNext()) {
		SootMethod method = reachableMethods.next().method();
		analyzeMethodForCallbackRegistrations(lifecycleElement, method);
		analyzeMethodForDynamicBroadcastReceiver(method);
	}
}
 
Example 3
Source File: LocalMustAliasAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
    * Computes the set of {@link EquivalentValue}s of all field references that are used
    * in this method but not set by the method or any method transitively called by this method.
    */
   private Set<Value> trackableFields() {
   	Set<Value> usedFieldRefs = new HashSet<Value>();
       //add all field references that are in use boxes
       for (Unit unit : this.graph) {
		Stmt s = (Stmt) unit;
		List<ValueBox> useBoxes = s.getUseBoxes();
		for (ValueBox useBox : useBoxes) {
			Value val = useBox.getValue();
			if(val instanceof FieldRef) {
				FieldRef fieldRef = (FieldRef) val;
				if(fieldRef.getType() instanceof RefLikeType)
					usedFieldRefs.add(new EquivalentValue(fieldRef));						
			}
		}
	}
       
       //prune all fields that are written to
       if(!usedFieldRefs.isEmpty()) {
   	
    	if(!Scene.v().hasCallGraph()) {
    		throw new IllegalStateException("No call graph found!");
    	}
    	    	
		CallGraph cg = Scene.v().getCallGraph();
		ReachableMethods reachableMethods = new ReachableMethods(cg,Collections.<MethodOrMethodContext>singletonList(container));
		reachableMethods.update();
		for (Iterator<MethodOrMethodContext> iterator = reachableMethods.listener(); iterator.hasNext();) {
			SootMethod m = (SootMethod) iterator.next();
			if(m.hasActiveBody() &&
			//exclude static initializer of same class (assume that it has already been executed)
			 !(m.getName().equals(SootMethod.staticInitializerName) && m.getDeclaringClass().equals(container.getDeclaringClass()))) {				
				for (Unit u : m.getActiveBody().getUnits()) {
					List<ValueBox> defBoxes = u.getDefBoxes();
					for (ValueBox defBox : defBoxes) {
						Value value = defBox.getValue();
						if(value instanceof FieldRef) {
							usedFieldRefs.remove(new EquivalentValue(value));
						}
					}
				}
			}
		}
       }
       
	return usedFieldRefs;
}
 
Example 4
Source File: PropagationSceneTransformerFilePrinter.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void print(PropagationSolver solver) {
  try {
    BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
    String newLine = System.getProperty("line.separator");
    List<MethodOrMethodContext> eps =
        new ArrayList<MethodOrMethodContext>(Scene.v().getEntryPoints());
    ReachableMethods reachableMethods =
        new ReachableMethods(Scene.v().getCallGraph(), eps.iterator(), null);
    reachableMethods.update();
    for (Iterator<MethodOrMethodContext> iter = reachableMethods.listener(); iter.hasNext();) {
      SootMethod ep = iter.next().method();
      if (!ep.isConcrete() || !ep.hasActiveBody()
      // || ep.getName().contains("dummy")
      /* || Model.v().isExcludedClass(ep.getDeclaringClass().getName()) */) {
        continue;
      }
      writer.write(ep.getActiveBody() + newLine);

      writer.write("----------------------------------------------" + newLine);
      writer.write("At end of: " + ep.getSignature() + newLine);
      writer.write("Variables:" + newLine);
      writer.write("----------------------------------------------" + newLine);

      for (Unit ret : ep.getActiveBody().getUnits()) {

        for (Map.Entry<Value, BasePropagationValue> l : solver.resultsAt(ret).entrySet()) {
          Value symbol = l.getKey();
          if (filter.filterOut(symbol)) {
            continue;
          }
          writer.write(symbol + " contains value " + l.getValue() + newLine);
        }

        writer.write("**" + ret + newLine);
      }
    }
    writer.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}