Advertisement
Guest User

Soot

a guest
Aug 19th, 2014
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.33 KB | None | 0 0
  1. public class FlowDroidTest {
  2.     private static HashMap<SootMethod,HashSet<SootMethod>> hm;
  3.     private static HashSet<String> classes;
  4.     private static DotGraph dot = new DotGraph("CallGraph");
  5.     private static DotGraph sub = dot;
  6.     private static HashMap<String, DotGraph> SubGraphs = new HashMap<String, DotGraph>();
  7.    
  8.     private static HashMap<String, Boolean> visited = new HashMap<String, Boolean>();
  9.     private static HashMap<Component, String> entryPoints = new HashMap<Component, String>();
  10.    
  11.     private static AndroidModel androidModel = null;
  12.    
  13.     public static void main(String[] args) throws IOException, XmlPullParserException {
  14.        
  15.         SetupApplication app = new SetupApplication
  16.             ("/Users/neji/Documents/Uni-Stuff/Master-Thesis/android-platforms",
  17.              "/Users/neji/Desktop/AndroidSpecific_DirectLeak1.apk");
  18.         app.calculateSourcesSinksEntrypoints("/Users/neji/Documents/Uni-Stuff/Master-Thesis/FlowDroid/SourcesAndSinks.txt");
  19.                        
  20.         app.setComputeResultPaths(true);
  21.         app.setTaintWrapper(new EasyTaintWrapper("/Users/neji/Documents/Uni-Stuff/Master-
  22.             Thesis/FlowDroid/EasyTaintWrapperSource.txt"));
  23.         app.setEnableImplicitFlows(true);
  24.        
  25.         soot.G.reset();
  26.                        
  27.         Options.v().set_src_prec(Options.src_prec_apk);
  28.         Options.v().set_process_dir(Collections.singletonList("/Users/neji/Desktop/AndroidSpecific_DirectLeak1.apk"));
  29.         Options.v().set_android_jars("/Users/neji/Documents/Uni-Stuff/Master-Thesis/android-platforms");
  30.         Options.v().set_whole_program(true);
  31.         Options.v().set_allow_phantom_refs(true);
  32.         Options.v().set_output_format(Options.output_format_class);
  33.         Options.v().setPhaseOption("cg.spark", "on");
  34.                        
  35.         Scene.v().loadNecessaryClasses();
  36.                    
  37.         InfoflowResults res = app.runInfoflow();
  38.        
  39.         SootMethod entryPoint =
  40.         app.getEntryPointCreator().createDummyMain();
  41.         Options.v().set_main_class(entryPoint.getSignature());
  42.        
  43.         Scene.v().setEntryPoints(Collections.singletonList(entryPoint));
  44.        
  45.         PackManager.v().runPacks();
  46.         CallGraph cg = Scene.v().getCallGraph();
  47.        
  48.         findEntryPoint(cg, entryPoint);
  49.          
  50.         androidModel.SaveModel();
  51.        
  52.         Set<SourceInfo> srcInfo = getPath(res);
  53.         if(!srcInfo.isEmpty()){
  54.             for(SourceInfo s: srcInfo){
  55.                 String sourceSignature = s.getContext().getInvokeExpr().getMethod().getSignature();
  56.                 System.out.println("Searching Source in cg ("+ sourceSignature+")");
  57.                
  58.                 @SuppressWarnings("unchecked")
  59.                 Iterator<SootMethod> it = new Sources(cg.edgesInto(s.getContext().getInvokeExpr().getMethod()));
  60.                 while(it.hasNext()){
  61.                     SootMethod src = (SootMethod)it.next();
  62.                     System.out.println(sourceSignature + " might be called by :" + src);
  63.                 }
  64.                
  65.                 System.out.println("On Path");
  66.                 for (Stmt st : s.getPath())
  67.                 {
  68.                     if(st.containsInvokeExpr())
  69.                         if(st.getInvokeExpr().getMethod().getSignature() != sourceSignature)
  70.                             System.out.println(" -> " + st.getInvokeExpr().getMethod().getSignature());
  71.                    
  72.                            
  73.                 }
  74.                 //System.out.println("SourceInfo:" + s.toString());
  75.                
  76.             }
  77.         }
  78.    
  79.         dot.plot("/Users/neji/Desktop/graph"+ DotGraph.DOT_EXTENSION);
  80.  
  81.         System.out.println("The End");
  82.        
  83.     }
  84.    
  85.     private static Set<SourceInfo> getPath(InfoflowResults res){
  86.         Map<SinkInfo,Set<SourceInfo>> info = res.getResults();
  87.         Set<SourceInfo> ret = null;
  88.         for (Entry<SinkInfo, Set<SourceInfo>> e : info.entrySet())
  89.         {
  90.             ret = e.getValue();    
  91.         }
  92.         return ret;
  93.     }
  94.    
  95.     public static void findEntryPoint(CallGraph cg, SootMethod k)
  96.     {
  97.         String actCmp = "";
  98.         Boolean newSubGraph = true;
  99.        
  100.         Iterator<MethodOrMethodContext> ctargets = new Targets(cg.edgesOutOf(k));
  101.        
  102.         if(!ctargets.hasNext()) bfs(cg,k);
  103.         else System.out.println("no next");
  104.            
  105.     if(ctargets != null){
  106.             while(ctargets.hasNext()){
  107.                 SootMethod c = (SootMethod) ctargets.next();
  108.                
  109.                 if(c == null) System.out.println("c is null");
  110.                 if(getComponent(c.getDeclaringClass().toString()) != null){
  111.                     System.out.println("Start analysis of Component : " + c.getDeclaringClass() + ": " + c.getDeclaration());
  112.                    
  113.                     Component cmp = bfs(cg, c);
  114.                    
  115.                     newSubGraph = !cmp.getImplementationClass().equals(actCmp);
  116.                     if(newSubGraph) actCmp = cmp.getImplementationClass();
  117.                    
  118.                     //PrintDotGraph(cmp,newSubGraph);
  119.                     PrintDotGraph1(cmp);
  120.                    
  121.                 }
  122.             }
  123.         }
  124.     }
  125.    
  126.    
  127.    
  128.    
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement