Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FlowDroidTest {
- private static HashMap<SootMethod,HashSet<SootMethod>> hm;
- private static HashSet<String> classes;
- private static DotGraph dot = new DotGraph("CallGraph");
- private static DotGraph sub = dot;
- private static HashMap<String, DotGraph> SubGraphs = new HashMap<String, DotGraph>();
- private static HashMap<String, Boolean> visited = new HashMap<String, Boolean>();
- private static HashMap<Component, String> entryPoints = new HashMap<Component, String>();
- private static AndroidModel androidModel = null;
- public static void main(String[] args) throws IOException, XmlPullParserException {
- SetupApplication app = new SetupApplication
- ("/Users/neji/Documents/Uni-Stuff/Master-Thesis/android-platforms",
- "/Users/neji/Desktop/AndroidSpecific_DirectLeak1.apk");
- app.calculateSourcesSinksEntrypoints("/Users/neji/Documents/Uni-Stuff/Master-Thesis/FlowDroid/SourcesAndSinks.txt");
- app.setComputeResultPaths(true);
- app.setTaintWrapper(new EasyTaintWrapper("/Users/neji/Documents/Uni-Stuff/Master-
- Thesis/FlowDroid/EasyTaintWrapperSource.txt"));
- app.setEnableImplicitFlows(true);
- soot.G.reset();
- Options.v().set_src_prec(Options.src_prec_apk);
- Options.v().set_process_dir(Collections.singletonList("/Users/neji/Desktop/AndroidSpecific_DirectLeak1.apk"));
- Options.v().set_android_jars("/Users/neji/Documents/Uni-Stuff/Master-Thesis/android-platforms");
- Options.v().set_whole_program(true);
- Options.v().set_allow_phantom_refs(true);
- Options.v().set_output_format(Options.output_format_class);
- Options.v().setPhaseOption("cg.spark", "on");
- Scene.v().loadNecessaryClasses();
- InfoflowResults res = app.runInfoflow();
- SootMethod entryPoint =
- app.getEntryPointCreator().createDummyMain();
- Options.v().set_main_class(entryPoint.getSignature());
- Scene.v().setEntryPoints(Collections.singletonList(entryPoint));
- PackManager.v().runPacks();
- CallGraph cg = Scene.v().getCallGraph();
- findEntryPoint(cg, entryPoint);
- androidModel.SaveModel();
- Set<SourceInfo> srcInfo = getPath(res);
- if(!srcInfo.isEmpty()){
- for(SourceInfo s: srcInfo){
- String sourceSignature = s.getContext().getInvokeExpr().getMethod().getSignature();
- System.out.println("Searching Source in cg ("+ sourceSignature+")");
- @SuppressWarnings("unchecked")
- Iterator<SootMethod> it = new Sources(cg.edgesInto(s.getContext().getInvokeExpr().getMethod()));
- while(it.hasNext()){
- SootMethod src = (SootMethod)it.next();
- System.out.println(sourceSignature + " might be called by :" + src);
- }
- System.out.println("On Path");
- for (Stmt st : s.getPath())
- {
- if(st.containsInvokeExpr())
- if(st.getInvokeExpr().getMethod().getSignature() != sourceSignature)
- System.out.println(" -> " + st.getInvokeExpr().getMethod().getSignature());
- }
- //System.out.println("SourceInfo:" + s.toString());
- }
- }
- dot.plot("/Users/neji/Desktop/graph"+ DotGraph.DOT_EXTENSION);
- System.out.println("The End");
- }
- private static Set<SourceInfo> getPath(InfoflowResults res){
- Map<SinkInfo,Set<SourceInfo>> info = res.getResults();
- Set<SourceInfo> ret = null;
- for (Entry<SinkInfo, Set<SourceInfo>> e : info.entrySet())
- {
- ret = e.getValue();
- }
- return ret;
- }
- public static void findEntryPoint(CallGraph cg, SootMethod k)
- {
- String actCmp = "";
- Boolean newSubGraph = true;
- Iterator<MethodOrMethodContext> ctargets = new Targets(cg.edgesOutOf(k));
- if(!ctargets.hasNext()) bfs(cg,k);
- else System.out.println("no next");
- if(ctargets != null){
- while(ctargets.hasNext()){
- SootMethod c = (SootMethod) ctargets.next();
- if(c == null) System.out.println("c is null");
- if(getComponent(c.getDeclaringClass().toString()) != null){
- System.out.println("Start analysis of Component : " + c.getDeclaringClass() + ": " + c.getDeclaration());
- Component cmp = bfs(cg, c);
- newSubGraph = !cmp.getImplementationClass().equals(actCmp);
- if(newSubGraph) actCmp = cmp.getImplementationClass();
- //PrintDotGraph(cmp,newSubGraph);
- PrintDotGraph1(cmp);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement