1 19 20 package soot.jimple.spark.builder; 21 import soot.jimple.spark.*; 22 import soot.jimple.spark.pag.*; 23 import soot.jimple.toolkits.callgraph.*; 24 import soot.jimple.toolkits.pointer.util.NativeMethodDriver; 25 import soot.jimple.toolkits.pointer.util.NativeHelper; 26 import soot.jimple.toolkits.pointer.DumbPointerAnalysis; 27 import soot.*; 28 import java.util.*; 29 import soot.jimple.*; 30 import soot.jimple.spark.internal.*; 31 import soot.jimple.spark.sets.PointsToSetInternal; 32 import soot.jimple.spark.solver.OnFlyCallGraph; 33 import soot.util.queue.*; 34 import soot.options.*; 35 36 39 public class ContextInsensitiveBuilder { 40 public void preJimplify() { 41 boolean change = true; 42 while( change ) { 43 change = false; 44 for( Iterator cIt = new ArrayList(Scene.v().getClasses()).iterator(); cIt.hasNext(); ) { 45 final SootClass c = (SootClass) cIt.next(); 46 for( Iterator mIt = c.methodIterator(); mIt.hasNext(); ) { 47 final SootMethod m = (SootMethod) mIt.next(); 48 if( !m.isConcrete() ) continue; 49 if( m.isNative() ) continue; 50 if( m.isPhantom() ) continue; 51 if( !m.hasActiveBody() ) { 52 change = true; 53 m.retrieveActiveBody(); 54 } 55 } 56 } 57 } 58 } 59 60 public PAG setup( SparkOptions opts ) { 61 pag = new PAG( opts ); 62 if( opts.simulate_natives() ) { 63 pag.nativeMethodDriver = new NativeMethodDriver(new SparkNativeHelper(pag)); 64 } 65 if( opts.on_fly_cg() && !opts.vta() ) { 66 ofcg = new OnFlyCallGraph( (PAG) pag ); 67 pag.setOnFlyCallGraph( ofcg ); 68 } else { 69 cgb = new CallGraphBuilder( DumbPointerAnalysis.v() ); 70 } 71 return pag; 72 } 73 74 public void build() { 75 QueueReader callEdges; 76 if( ofcg != null ) { 77 callEdges = ofcg.callGraph().listener(); 78 ofcg.build(); 79 reachables = ofcg.reachableMethods(); 80 reachables.update(); 81 } else { 82 callEdges = cgb.getCallGraph().listener(); 83 cgb.build(); 84 reachables = cgb.reachables(); 85 } 86 for( Iterator cIt = Scene.v().getClasses().iterator(); cIt.hasNext(); ) { 87 final SootClass c = (SootClass) cIt.next(); 88 handleClass( c ); 89 } 90 Stmt s = null; 91 while(callEdges.hasNext()) { 92 Edge e = (Edge) callEdges.next(); 93 MethodPAG.v( pag, e.tgt() ).addToPAG(null); 94 pag.addCallTarget( e ); 95 } 96 97 if( pag.getOpts().verbose() ) { 98 G.v().out.println( "Total methods: "+totalMethods ); 99 G.v().out.println( "Initially reachable methods: "+analyzedMethods ); 100 G.v().out.println( "Classes with at least one reachable method: "+classes ); 101 } 102 } 103 104 105 106 protected void handleClass( SootClass c ) { 107 boolean incedClasses = false; 108 Iterator methodsIt = c.methodIterator(); 109 while( methodsIt.hasNext() ) 110 { 111 SootMethod m = (SootMethod) methodsIt.next(); 112 if( !m.isConcrete() && !m.isNative() ) continue; 113 totalMethods++; 114 if( reachables.contains( m ) ) { 115 MethodPAG mpag = MethodPAG.v( pag, m ); 116 mpag.build(); 117 mpag.addToPAG(null); 118 analyzedMethods++; 119 if( !incedClasses ) { 120 incedClasses = true; 121 classes++; 122 } 123 } 124 } 125 } 126 127 128 private PAG pag; 129 private CallGraphBuilder cgb; 130 private OnFlyCallGraph ofcg; 131 private ReachableMethods reachables; 132 int classes = 0; 133 int totalMethods = 0; 134 int analyzedMethods = 0; 135 int stmts = 0; 136 } 137 138 | Popular Tags |