|
| 1 | +# Boomerang for Android Applications |
| 2 | + |
| 3 | +Boomerang can be applied to Android applications using [FlowDroid](https://github.com/secure-software-engineering/FlowDroid). |
| 4 | +FlowDroid is a static analysis tool that computes call graphs and data flows in Android applications. |
| 5 | +Since it is based on Soot, one can use the Soot scope to instantiate a [FrameworkScope](../general/framework_scopes.md). |
| 6 | + |
| 7 | +## Dependencies |
| 8 | + |
| 9 | +To use FlowDroid with Boomerang, include the FlowDroid and the Soot scope dependencies in your project: |
| 10 | + |
| 11 | +``` |
| 12 | +<!-- BoomerangScope for Soot (Make sure to use the most recent Boomerang version) --> |
| 13 | +<dependency> |
| 14 | + <groupId>de.fraunhofer.iem</groupId> |
| 15 | + <artifactId>boomerangScope-Soot</artifactId> |
| 16 | + <version>a.b.c</version> |
| 17 | +</dependency> |
| 18 | +
|
| 19 | +<!-- FlowDroid dependencies (Make sure to choose the most recent FlowDroid version) --> |
| 20 | +<dependency> |
| 21 | + <groupId>de.fraunhofer.sit.sse.flowdroid</groupId> |
| 22 | + <artifactId>soot-infoflow</artifactId> |
| 23 | + <version>x.y.z</version> |
| 24 | +</dependency> |
| 25 | +<dependency> |
| 26 | + <groupId>de.fraunhofer.sit.sse.flowdroid</groupId> |
| 27 | + <artifactId>soot-infoflow-summaries</artifactId> |
| 28 | + <version>x.y.z</version> |
| 29 | +</dependency> |
| 30 | +<dependency> |
| 31 | + <groupId>de.fraunhofer.sit.sse.flowdroid</groupId> |
| 32 | + <artifactId>soot-infoflow-android</artifactId> |
| 33 | + <version>x.y.z</version> |
| 34 | +</dependency> |
| 35 | +``` |
| 36 | + |
| 37 | +## Setting up FlowDroid |
| 38 | + |
| 39 | +To instantiate the `SootFrameworkScope`, we have to compute a call graph. |
| 40 | +However, instead of setting up Soot (as described [here](../general/framework_scopes.md)), we use FlowDroid to construct a call graph that takes Android's activity lifecycle into account. |
| 41 | +For example, we can use the following FlowDroid setup: |
| 42 | + |
| 43 | +```java |
| 44 | +InfoflowAndroidConfiguration config = new InfoFLowAndroidConfiguration(); |
| 45 | + |
| 46 | +// Use CHA as call graph algorithm |
| 47 | +config.setCallgraphAlgorithm(InfoflowAndroidConfiguration.CallgraphAlgorithm.CHA); |
| 48 | + |
| 49 | +// Set the target app and the platforms for the SDK(s) |
| 50 | +config.getAnalysisFileConfig().setTargetAPKFile(<pathToTheAPKFile>); |
| 51 | +config.getAnalysisFileConfig().setAndroidPlatformDir(<pathToThePlatformsDir>); |
| 52 | + |
| 53 | +// Further setup: Do not eliminate unreachable code and keep the original line numbers |
| 54 | +config.setCodeEliminationMode(InfoflowConfiguration.CodeEliminationMode.NoCodeElimination); |
| 55 | +config.setEnableLineNumbers(true); |
| 56 | + |
| 57 | +// Configure FlowDroid |
| 58 | +SetupApplication app = new SetupApplication(); |
| 59 | +app.setSootConfig(new SootConfigForAndroid() { |
| 60 | + @Override |
| 61 | + public void setSootOptions(Options options, InfoFlowConfiguration config) { |
| 62 | + options.setPhaseOptions("jb.sils", "enabled:false"); |
| 63 | + |
| 64 | + // By default, FlowDroid loads the Android packages which makes the call graph very large |
| 65 | + // and the analysis slow. Only include them, if they are really needed |
| 66 | + options.set_exclude(List.of("android.*", "androidx.*")); |
| 67 | + } |
| 68 | +}) |
| 69 | +``` |
| 70 | + |
| 71 | +With the configured `SetupApplication`, we can now construct the call graph and instantiate the `SootFrameworkScope` as follows: |
| 72 | + |
| 73 | +```java |
| 74 | +// Construct the Android specific call graph |
| 75 | +app.constructCallGraph(); |
| 76 | + |
| 77 | +// Do not forget to apply the PreTransformer |
| 78 | +BoomerangPretransformer.v().reset(); |
| 79 | +BoomerangPretransformer.v().apply(); |
| 80 | + |
| 81 | +// Framework scope objects |
| 82 | +DataFlowScope dataFlowScope = DataFlowScope.EXCLUDE_PHANTOM_CLASSES; |
| 83 | +CallGraph callGraph = Scene.v().getCallGraph(); |
| 84 | +Collection<SootMethod> entryPoints = Scene.v().getEntryPoints(); |
| 85 | + |
| 86 | +// Setup up the framework scope |
| 87 | +FrameworkScope scope = new SootFrameworkScope(Scene.v(), callGraph, entryPoints, dataFlowScope); |
| 88 | +``` |
| 89 | + |
| 90 | +With the `scope`, we can continue with [Boomerang](../boomerang/boomerang_setup.md) and [IDEal](). |
0 commit comments