|
26 | 26 | import sootup.core.model.SourceType;
|
27 | 27 | import sootup.core.signatures.MethodSignature;
|
28 | 28 | import sootup.core.transform.BodyInterceptor;
|
29 |
| -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; |
30 |
| -import sootup.java.bytecode.inputlocation.JrtFileSystemAnalysisInputLocation; |
| 29 | +import sootup.interceptors.BytecodeBodyInterceptors; |
| 30 | +import sootup.java.bytecode.frontend.inputlocation.JavaClassPathAnalysisInputLocation; |
| 31 | +import sootup.java.bytecode.frontend.inputlocation.JrtFileSystemAnalysisInputLocation; |
31 | 32 | import sootup.java.core.JavaSootClass;
|
32 |
| -import sootup.java.core.JavaSootMethod; |
33 |
| -import sootup.java.core.interceptors.BytecodeBodyInterceptors; |
34 | 33 | import sootup.java.core.views.JavaView;
|
| 34 | +import sootup.jimple.frontend.JimpleStringAnalysisInputLocation; |
35 | 35 |
|
36 | 36 | // TODO: refactor as parameterized test -> update to junit 5
|
37 | 37 | public class FrameworkScopeFactory {
|
@@ -156,25 +156,30 @@ private static FrameworkScope getSootFrameworkScope(
|
156 | 156 | }
|
157 | 157 |
|
158 | 158 | SootMethod methodByName = c.getMethodByName("main");
|
| 159 | + eps.add(methodByName); |
| 160 | + |
159 | 161 | for (SootMethod m : sootTestCaseClass.getMethods()) {
|
160 | 162 | if (m.isStaticInitializer()) {
|
161 | 163 | eps.add(m);
|
162 | 164 | }
|
163 | 165 | }
|
164 | 166 |
|
165 |
| - // collect entrypoints |
166 |
| - for (SootClass inner : Scene.v().getClasses()) { |
167 |
| - classCount++; |
168 |
| - if (inner.getName().contains(sootTestCaseClass.getName())) { |
169 |
| - inner.setApplicationClass(); |
170 |
| - for (SootMethod m : inner.getMethods()) { |
171 |
| - if (m.isStaticInitializer()) { |
172 |
| - eps.add(m); |
173 |
| - } |
174 |
| - } |
175 |
| - } |
176 |
| - } |
177 |
| - eps.add(methodByName); |
| 167 | + // TODO: check if the following block is needed / correct in this branch |
| 168 | + /* |
| 169 | + // collect entrypoints |
| 170 | + for (SootClass inner : Scene.v().getClasses()) { |
| 171 | + classCount++; |
| 172 | + if (inner.getName().contains(sootTestCaseClass.getName())) { |
| 173 | + inner.setApplicationClass(); |
| 174 | + for (SootMethod m : inner.getMethods()) { |
| 175 | + if (m.isStaticInitializer()) { |
| 176 | + eps.add(m); |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | +
|
| 182 | + */ |
178 | 183 |
|
179 | 184 | if (eps.isEmpty()) {
|
180 | 185 | throw new IllegalStateException(
|
@@ -240,7 +245,6 @@ private static String getTargetClass(SootMethod sootTestMethod, String testCaseC
|
240 | 245 | return sootClass.toString();
|
241 | 246 | }
|
242 | 247 |
|
243 |
| - |
244 | 248 | /** SootUp Framework setup TODO: [ms] refactor me! */
|
245 | 249 | private static FrameworkScope getSootUpFrameworkScope(
|
246 | 250 | String pathStr,
|
@@ -273,47 +277,70 @@ private static FrameworkScope getSootUpFrameworkScope(
|
273 | 277 | classPathInputLocation, includedPackages),
|
274 | 278 | new ScopedAnalysisInputLocation.DenylistingScopedAnalysisInputLocation(
|
275 | 279 | classPathInputLocation, excludedPackages)));
|
276 |
| - JavaView javaView = new JavaView(inputLocations); |
277 | 280 |
|
| 281 | + JavaView javaView; |
278 | 282 | sootup.callgraph.CallGraph cg;
|
279 |
| - List<MethodSignature> entypointSignatures; |
280 |
| - List<JavaSootMethod> eps = Lists.newArrayList(); |
281 |
| - |
282 |
| - if (customEntrypointMethodName == null) { |
283 |
| - // collect entrypoints |
284 |
| - for (JavaSootClass sootClass : javaView.getClasses()) { |
285 |
| - String scStr = sootClass.toString(); |
286 |
| - if (scStr.equals(className) || (scStr.contains(className + "$"))) { |
287 |
| - eps.addAll(sootClass.getMethods()); |
288 |
| - } |
289 |
| - } |
| 283 | + List<MethodSignature> entypointSignatures = Lists.newArrayList(); |
290 | 284 |
|
291 |
| - } else { |
292 |
| - // build entrypoint |
293 |
| - String jimpleClassStr = "class dummyClass\n" + |
294 |
| - "{\n" + |
295 |
| - " public static void main(java.lang.String[])\n" + |
296 |
| - " {\n" + |
297 |
| - " "+ className +" dummyObj;\n" + |
298 |
| - " java.lang.String[] l0;\n" + |
299 |
| - " l0 := @parameter0: java.lang.String[];\n" + |
300 |
| - " dummyObj = new "+ className +";\n" + |
301 |
| - " virtualinvoke dummyObj.<"+ className +": void "+customEntrypointMethodName+"()>();\n" + |
302 |
| - " return;\n" + |
303 |
| - " }\n" + |
304 |
| - "}"; |
305 |
| - |
306 |
| - // new JimpleStringAnalysisInputLocation(jimpleClassStr) // currently in sootup:develop branch |
307 |
| - |
308 |
| - throw new UnsupportedOperationException("implement me!"); |
| 285 | + if (customEntrypointMethodName == null) { |
| 286 | + |
| 287 | + javaView = new JavaView(inputLocations); |
| 288 | + // collect entrypoints |
| 289 | + for (JavaSootClass sootClass : javaView.getClasses().collect(Collectors.toList())) { |
| 290 | + String scStr = sootClass.toString(); |
| 291 | + if (scStr.equals(className) || (scStr.contains(className + "$"))) { |
| 292 | + sootClass.getMethods().stream() |
| 293 | + .map(SootClassMember::getSignature) |
| 294 | + .forEach(entypointSignatures::add); |
| 295 | + } |
309 | 296 | }
|
310 | 297 |
|
311 |
| - // initialize CallGraphAlgorithm |
312 |
| - entypointSignatures = |
313 |
| - eps.stream().map(SootClassMember::getSignature).collect(Collectors.toList()); |
| 298 | + } else { |
| 299 | + |
| 300 | + // build dummy entrypoint class |
| 301 | + String jimpleClassStr = |
| 302 | + "class dummyClass\n" |
| 303 | + + "{\n" |
| 304 | + + " public static void main(java.lang.String[])\n" |
| 305 | + + " {\n" |
| 306 | + + " " |
| 307 | + + className |
| 308 | + + " dummyObj;\n" |
| 309 | + + " java.lang.String[] l0;\n" |
| 310 | + + " l0 := @parameter0: java.lang.String[];\n" |
| 311 | + + " dummyObj = new " |
| 312 | + + className |
| 313 | + + ";\n" |
| 314 | + + " virtualinvoke dummyObj.<" |
| 315 | + + className |
| 316 | + + ": void " |
| 317 | + + customEntrypointMethodName |
| 318 | + + "()>();\n" |
| 319 | + + " return;\n" |
| 320 | + + " }\n" |
| 321 | + + "}"; |
| 322 | + |
| 323 | + JimpleStringAnalysisInputLocation jimpleStringAnalysisInputLocation = |
| 324 | + new JimpleStringAnalysisInputLocation( |
| 325 | + jimpleClassStr); // currently in sootup:develop branch |
| 326 | + inputLocations.add(jimpleStringAnalysisInputLocation); |
| 327 | + javaView = new JavaView(inputLocations); |
| 328 | + |
| 329 | + MethodSignature dummyEntrypoint = |
| 330 | + javaView |
| 331 | + .getIdentifierFactory() |
| 332 | + .parseMethodSignature("<dummyClass: void main(java.lang.String[])>"); |
| 333 | + assert javaView.getMethod(dummyEntrypoint).isPresent(); |
| 334 | + |
| 335 | + entypointSignatures.add(dummyEntrypoint); |
| 336 | + } |
314 | 337 |
|
315 |
| - // TODO: adapt if: --> use spark when available |
316 |
| - CallGraphAlgorithm cga = customEntrypointMethodName == null? new ClassHierarchyAnalysisAlgorithm(javaView) : new ClassHierarchyAnalysisAlgorithm(javaView); |
| 338 | + // initialize CallGraphAlgorithm |
| 339 | + // TODO: use spark when available |
| 340 | + CallGraphAlgorithm cga = |
| 341 | + customEntrypointMethodName == null |
| 342 | + ? new ClassHierarchyAnalysisAlgorithm(javaView) |
| 343 | + : new ClassHierarchyAnalysisAlgorithm(javaView); |
317 | 344 | cg = cga.initialize(entypointSignatures);
|
318 | 345 |
|
319 | 346 | return new SootUpFrameworkScope(javaView, cg, entypointSignatures);
|
|
0 commit comments