Skip to content

Commit e17f753

Browse files
committed
Add page for framewokr scopes
1 parent ef1c1ef commit e17f753

File tree

6 files changed

+121
-7
lines changed

6 files changed

+121
-7
lines changed

docs/boomerang/allocation_sites.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public class ExtendedAllocationSite implements IAllocationSite {
4949
}
5050
```
5151

52-
53-
54-
5552
Last, to use our self-defined allocation site, we need to add it to the options:
5653

5754
```java
@@ -103,6 +100,8 @@ public class SimpleAllocationSite implements IAllocationSite {
103100
}
104101
```
105102

103+
Using this allocation site implementation, Boomerang returns values that are either *new expressions* (e.g. `new java.lang.Object`) or *constants* (e.g. int, String etc.).
104+
106105
## Allocation Site with DataFlowScope
107106

108107
In many cases, we are interested in finding an allocation site to analyze it.

docs/boomerang/boomerang_setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In the following sections, we give an overview of relevant constructs and API ca
88

99
Boomerang uses *backward queries* to compute relevant points-to information. A **BackwardQuery** consists of a statement `s` and a variable `v`. `s` is the starting statement where the backwards analysis starts and `v` is the data-flow fact to solve for.
1010

11-
Backward queries can be easily constructed. However, due to Boomerang's scope implementation, we need to specify the corresponding control-flow graph edge with the starting statement `s` as target (see the [Boomerang Scopes](./../general/boomerang_scopes.md)). With that, we can construct a backward query as follows:
11+
Backward queries can be easily constructed. However, due to Boomerang's scope implementation, we need to specify the corresponding control-flow graph edge with the starting statement `s` as target (see the [Boomerang Scopes](./../general/boomerang_scope.md)). With that, we can construct a backward query as follows:
1212

1313
```java
1414
public void createBackwardQuery(ControlFlowGraph.Edge, edge, Val fact) {
@@ -78,7 +78,7 @@ public void extractAllocationSites(BackwardBoomerangResults<NoWeight> results) {
7878

7979
## Extracting Aliases
8080

81-
Beside the allocation sites, we can use the results to compute the aliases for the query variable. An alias is represented by an `AccessPath` that holds the base variable and the field chain. For example, an alias `x.f.g` is represented by an `AccessPath` with the base `x` and the field chain `[f, g]. We can compute the access paths as follows:
81+
Beside the allocation sites, we can use the results to compute the aliases for the query variable. An alias is represented by an `AccessPath` that holds the base variable and the field chain. For example, an alias `x.f.g` is represented by an `AccessPath` with the base `x` and the field chain `[f, g]`. We can compute the access paths as follows:
8282

8383
```java
8484
public void extractAliases(BackwardBoomerangResults<NoWeight> results) {

docs/general/boomerang_scope.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Boomerang Scope
2+
3+
## AnalysisScope

docs/general/boomerang_scopes.md

Whitespace-only changes.

docs/general/framework_scopes.md

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
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+
```

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ nav:
77
- Home: index.md
88
- General:
99
- Installation: general/installation.md
10-
- Boomerang Scopes: general/boomerang_scopes.md
10+
- Boomerang Scopes: general/boomerang_scope.md
1111
- Framework Scopes: general/framework_scopes.md
1212
- Boomerang:
1313
- Boomerang Setup: boomerang/boomerang_setup.md

0 commit comments

Comments
 (0)