|
1 | | -# Framework Setup |
| 1 | +# Framework Scopes |
| 2 | + |
| 3 | +We provide an implementation of the BoomerangScope for the static analysis frameworks [Soot](https://github.com/soot-oss/soot), [SootUp](https://github.com/soot-oss/sootup) and [Opal](https://github.com/opalj/opal). |
| 4 | +Depending on the framework that you plan to use, include the following dependencies in your project (replace `x.y.z` with the most recent version): |
| 5 | + |
| 6 | +=== "Soot" |
| 7 | + ``` |
| 8 | + <dependency> |
| 9 | + <groupId>de.fraunhofer.iem</groupId> |
| 10 | + <artifactId>boomerangScope-Soot</artifactId> |
| 11 | + <version>x.y.z</version> |
| 12 | + </dependency> |
| 13 | + ``` |
| 14 | + |
| 15 | +=== "SootUp" |
| 16 | + ``` |
| 17 | + <dependency> |
| 18 | + <groupId>de.fraunhofer.iem</groupId> |
| 19 | + <artifactId>boomerangScope-SootUp</artifactId> |
| 20 | + <version>x.y.z</version> |
| 21 | + </dependency> |
| 22 | + ``` |
| 23 | + |
| 24 | +=== "Opal" |
| 25 | + ``` |
| 26 | + <dependency> |
| 27 | + <groupId>de.fraunhofer.iem</groupId> |
| 28 | + <artifactId>boomerangScope-Opal</artifactId> |
| 29 | + <version>x.y.z</version> |
| 30 | + </dependency> |
| 31 | + ``` |
| 32 | + |
| 33 | +## Setting up a Framework Scope |
| 34 | + |
| 35 | +Each framework scope consists of the following objects: |
| 36 | + |
| 37 | +- The static analysis framework's main instance: |
| 38 | + - Soot: `Scene` |
| 39 | + - SootUp: `View` |
| 40 | + - Opal: `Project` |
| 41 | +- A call graph computed from the main instance |
| 42 | +- A data-flow scope |
| 43 | +- An optional set of entry point methods |
| 44 | + |
| 45 | +Boomerang uses the framework scope to access the main instance, call graph and data-flow scope during the analysis. |
| 46 | +Additionally, you may specify a set of entry point methods that define the starting points when using the [AnalysisScope](boomerang_scope.md#AnalysisScope). |
| 47 | + |
| 48 | +The following snippets show an example of the instantiation of the framework scope for each static analysis framework. |
| 49 | +Thereby, we construct the call graphs using the CHA algorithm, and we use a data-flow scope that excludes all methods from classes that are not loaded (*phantom* classes). |
| 50 | + |
| 51 | +=== "Soot" |
| 52 | + ```java |
| 53 | + // Soot setup |
| 54 | + G.reset(); |
| 55 | + Options.v().set_whole_program(true); |
| 56 | + Options.v().set_output_format(Options.output_format_none); |
| 57 | + Options.v().set_no_bodies_for_excluded(true); |
| 58 | + Options.v().set_allow_phantom_refs(true); |
| 59 | + Options.v().set_keep_line_number(true); |
| 60 | + Options.v().set_soot_classpath("VIRTUAL_FS_FOR_JDK" + File.pathSeparator + "path/to/app"); |
| 61 | + Options.v().setPhaseOption("jb.sils", "enabled:false"); |
| 62 | + Options.v().setPhaseOption("jb", "use-original-names:true"); |
| 63 | + |
| 64 | + // Compute call graph |
| 65 | + Options.v().setPhaseOption("cg.cha", "on"); |
| 66 | + PackManager.v().getPack("cg").apply(); |
| 67 | + |
| 68 | + // Do not forget the PreTransformer |
| 69 | + BoomerangPretransformer.v().reset(); |
| 70 | + BoomerangPretransformer.v().apply(); |
| 71 | + |
| 72 | + // Framework scope setup |
| 73 | + DataFlowScope dataFlowScope = DataFlowScope.EXCLUDE_PHANTOM_CLASSES; |
| 74 | + CallGraph callGraph = Scene.v().getCallGraph(); |
| 75 | + Collection<SootMethod> entryPoints = EntryPoints.v().mainsOfApplicationClasses(); |
| 76 | + |
| 77 | + FrameworkScope scope = new SootFrameworkScope(Scene.v(), callGraph, dataFlowScope entryPoints); |
| 78 | + ``` |
| 79 | + |
| 80 | +=== "SootUp" |
| 81 | + ```java |
| 82 | + // SootUp setup (Do not forget the PreInterceptor) |
| 83 | + AnalysisInputLocation inputLocation = new JavaClassPathAnalysisInputLocation("path/to/project", SourceType.Application, List.of(new BoomerangPreInterceptor())); |
| 84 | + JavaView view = new JavaView(inputLocation); |
| 85 | + |
| 86 | + // Construct call graph |
| 87 | + ClassHierarchyAnalysisAlgorithm cha = new ClassHierarchyAnalysisAlgorithm(view); |
| 88 | + MethodSignature mainMethod = cha.findMainMethod(); |
| 89 | + CallGraph callGraph = cha.initialize(List.of(mainMethod)); |
| 90 | + |
| 91 | + // Framework scope setup |
| 92 | + DataFlowScope dataFlowScope = DataFlowScope.EXCLUDE_PHANTOM_CLASSES; |
| 93 | + Optional<JavaSootMethod> entryPoint = view.getMethod(mainMethod); |
| 94 | + if (entryPoint.isEmpty()) { |
| 95 | + throw new RuntimeException("No main method present"); |
| 96 | + } |
| 97 | + |
| 98 | + FrameworkScope scope = new SootUpFrameworkScope(view, callGraph, dataFlowScope, Collections.singleton(entryPoint.get())); |
| 99 | + ``` |
| 100 | + |
| 101 | +=== "Opal" |
| 102 | + ```scala |
| 103 | + // Opal setup |
| 104 | + val project = Project(new File("path/to/project")) |
| 105 | + |
| 106 | + // Compute call graph |
| 107 | + val callGraph = project.get(CHACallGraphKey) |
| 108 | + |
| 109 | + // Framework scope setup |
| 110 | + val dataFlowScope = DataFlowScope.EXCLUDE_PHANTOM_CLASSES |
| 111 | + val entryPoints = project.allMethodsWithBody.toSet |
| 112 | + val scope = new OpalFrameworkScope(project, callGraph, dataFlowScope, entryPoints) |
| 113 | + ``` |
0 commit comments