Java 类soot.jimple.toolkits.callgraph.Targets 实例源码

项目:JAADAS    文件:CallGraphExample.java   
public static void main(String[] args) {
   List<String> argsList = new ArrayList<String>(Arrays.asList(args));
   argsList.addAll(Arrays.asList(new String[]{
           "-w",
           "-main-class",
           "testers.CallGraphs",//main-class
           "testers.CallGraphs",//argument classes
           "testers.A"          //
   }));


   PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new SceneTransformer() {

    @Override
    protected void internalTransform(String phaseName, Map options) {
           CHATransformer.v().transform();
                      SootClass a = Scene.v().getSootClass("testers.A");

           SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
           CallGraph cg = Scene.v().getCallGraph();

           Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));
           while (targets.hasNext()) {
               SootMethod tgt = (SootMethod)targets.next();
               System.out.println(src + " may call " + tgt);
           }
    }

   }));

          args = argsList.toArray(new String[0]);

          soot.Main.main(args);
}
项目:Sus    文件:CallGraphAnalysis.java   
protected void getReachableMethodsFromThreads(Set<ThreadProperties> startedRunnables)
{
    if(this.callGraph == null)
    {
        this.callGraph = Scene.v().getCallGraph();
    }

    // Get reachable methods for all threads
    for(ThreadProperties threadProperties : startedRunnables)
    {
        Type classType = threadProperties.getRunnableType();
        SootClass runnableClass = Scene.v().loadClassAndSupport(classType.toString());
        for(SootMethod sootMethod : runnableClass.getMethods())
        {
            // Only consider run() methods
            if(!
                    (sootMethod.getDeclaration().equals("public void run()") ||
                     sootMethod.getDeclaration().equals("public static void main(java.lang.String[])")))
            {
                continue;
            }

            threadProperties.setRunMethod(sootMethod);

            // Get directly reachable and transitive targets from this function
            ReachableMethods directTargets = new ReachableMethods(this.callGraph, new Targets(callGraph.edgesOutOf(sootMethod)));
            TransitiveTargets transitiveTargets = new TransitiveTargets(this.callGraph);

            Iterator<MethodOrMethodContext> transitiveIterator = transitiveTargets.iterator(sootMethod);
            while (transitiveIterator.hasNext())
            {
                SootMethod transitiveTarget = (SootMethod) transitiveIterator.next();
                // Show all target methods not in JDK
                if(!SusHelper.isPackageInJdk(SusHelper.getClassFromSignature(transitiveTarget.getSignature())))
                {
                    // This method is directly reachable from this run()
                    if(directTargets.contains(transitiveTarget))
                    {
                        threadProperties.addDirectReachableMethod(transitiveTarget);
                        System.out.println(sootMethod + " may call " + transitiveTarget);
                    }
                    // This method is transitively reachable from this run()
                    else
                    {
                        threadProperties.addTransitiveReachableMethod(transitiveTarget);
                        System.out.println(sootMethod + " may reach " + transitiveTarget);
                    }
                }
            }
        }
    }
}