-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathCallGraphTest.java
More file actions
165 lines (129 loc) · 5.94 KB
/
Copy pathCallGraphTest.java
File metadata and controls
165 lines (129 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package sootup.apk.frontend;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import sootup.apk.frontend.main.AndroidVersionInfo;
import sootup.callgraph.CallGraph;
import sootup.callgraph.CallGraphAlgorithm;
import sootup.callgraph.ClassHierarchyAnalysisAlgorithm;
import sootup.callgraph.RapidTypeAnalysisAlgorithm;
import sootup.core.signatures.MethodSignature;
import sootup.java.bytecode.frontend.inputlocation.JavaClassPathAnalysisInputLocation;
import sootup.java.core.JavaSootClass;
import sootup.java.core.views.JavaView;
public class CallGraphTest {
public static JavaView view;
public static JavaView locationLeakView;
public static JavaView cryptoView;
String flowSensitivityClassName = "de.ecspride.MainActivity";
String locationLeakClassName = "de.ecspride.LocationLeak1";
String cryptoClassName = "com.example.MainActivity";
String methodName = "onCreate";
List<String> methodParameters = List.of("android.os.Bundle");
String methodReturnType = "void";
@BeforeAll
public static void createView() {
view = createViewForApk("src/test/resources/FlowSensitivity1.apk");
locationLeakView = createViewForApk("src/test/resources/LocationLeak1.apk");
cryptoView = createViewForApk("src/test/resources/Crypto.apk");
}
private static JavaView createViewForApk(String apkPathString) {
Path apkPath = Paths.get(apkPathString);
String androidPlatformsPath = "src/test/resources/platforms";
AndroidVersionInfo androidVersionInfo = new AndroidVersionInfo(apkPath, androidPlatformsPath);
ApkAnalysisInputLocation sootClassApkAnalysisInputLocation =
new ApkAnalysisInputLocation(
apkPath, androidVersionInfo, DexBodyInterceptors.Default.bodyInterceptors());
JavaClassPathAnalysisInputLocation classPathAnalysisInputLocation =
new JavaClassPathAnalysisInputLocation(
androidPlatformsPath
+ File.separator
+ "android-"
+ androidVersionInfo.getApi_version()
+ File.separator
+ "android.jar");
return new JavaView(List.of(sootClassApkAnalysisInputLocation, classPathAnalysisInputLocation));
}
@Test
public void testCHACallGraphAlgorithm() {
MethodSignature onCreateMethodSignature =
view.getIdentifierFactory()
.getMethodSignature(
flowSensitivityClassName, methodName, methodReturnType, methodParameters);
CallGraphAlgorithm cha = new ClassHierarchyAnalysisAlgorithm(view);
CallGraph cg = cha.initialize(List.of(onCreateMethodSignature));
assertTrue(cg.containsMethod(onCreateMethodSignature));
assertEquals(9, cg.callsFrom(onCreateMethodSignature).size());
}
@Test
public void testRTACallGraphAlgorithm() {
MethodSignature onCreateMethodSignature =
view.getIdentifierFactory()
.getMethodSignature(
flowSensitivityClassName, methodName, methodReturnType, methodParameters);
CallGraphAlgorithm rta =
new RapidTypeAnalysisAlgorithm(
view, view.getClasses().map(JavaSootClass::getType).collect(Collectors.toSet()));
CallGraph cg = rta.initialize(List.of(onCreateMethodSignature));
assertTrue(cg.containsMethod(onCreateMethodSignature));
assertEquals(9, cg.callsFrom(onCreateMethodSignature).size());
}
@Test
public void testLocationLeakCHACallGraphAlgorithm() {
MethodSignature onCreateMethodSignature =
locationLeakView
.getIdentifierFactory()
.getMethodSignature(
locationLeakClassName, methodName, methodReturnType, methodParameters);
CallGraphAlgorithm cha = new ClassHierarchyAnalysisAlgorithm(locationLeakView);
CallGraph cg = cha.initialize(List.of(onCreateMethodSignature));
assertTrue(cg.containsMethod(onCreateMethodSignature));
assertEquals(5, cg.callsFrom(onCreateMethodSignature).size());
}
@Test
public void testLocationLeakRTACallGraphAlgorithm() {
MethodSignature onCreateMethodSignature =
locationLeakView
.getIdentifierFactory()
.getMethodSignature(
locationLeakClassName, methodName, methodReturnType, methodParameters);
CallGraphAlgorithm rta =
new RapidTypeAnalysisAlgorithm(
locationLeakView,
locationLeakView.getClasses().map(JavaSootClass::getType).collect(Collectors.toSet()));
CallGraph cg = rta.initialize(List.of(onCreateMethodSignature));
assertTrue(cg.containsMethod(onCreateMethodSignature));
assertEquals(5, cg.callsFrom(onCreateMethodSignature).size());
}
@Test
public void testCryptoCHACallGraphAlgorithm() {
MethodSignature onCreateMethodSignature =
cryptoView
.getIdentifierFactory()
.getMethodSignature(cryptoClassName, methodName, methodReturnType, methodParameters);
CallGraphAlgorithm cha = new ClassHierarchyAnalysisAlgorithm(cryptoView);
CallGraph cg = cha.initialize(List.of(onCreateMethodSignature));
assertTrue(cg.containsMethod(onCreateMethodSignature));
assertEquals(3, cg.callsFrom(onCreateMethodSignature).size());
}
@Test
public void testCryptoRTACallGraphAlgorithm() {
MethodSignature onCreateMethodSignature =
cryptoView
.getIdentifierFactory()
.getMethodSignature(cryptoClassName, methodName, methodReturnType, methodParameters);
CallGraphAlgorithm rta =
new RapidTypeAnalysisAlgorithm(
cryptoView,
cryptoView.getClasses().map(JavaSootClass::getType).collect(Collectors.toSet()));
CallGraph cg = rta.initialize(List.of(onCreateMethodSignature));
assertTrue(cg.containsMethod(onCreateMethodSignature));
assertEquals(3, cg.callsFrom(onCreateMethodSignature).size());
}
}