public static CallGraph buildZeroCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope, boolean testPAtoString) throws IllegalArgumentException, CancelException { StopwatchGC S = null; if (CHECK_FOOTPRINT) { S = new StopwatchGC("build RTA graph"); S.start(); } SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); CallGraph cg = builder.makeCallGraph(options, null); if (testPAtoString) { builder.getPointerAnalysis().toString(); } if (CHECK_FOOTPRINT) { S.stop(); System.err.println(S.report()); } return cg; }
private void testOCamlJar(String jarFile, String... args) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, InterruptedException { File F = TemporaryFile.urlToFile(jarFile.replace('.', '_') + ".jar", getClass().getClassLoader().getResource(jarFile)); F.deleteOnExit(); AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope("base.txt", CallGraphTestUtil.REGRESSION_EXCLUSIONS); scope.addToScope(ClassLoaderReference.Application, new JarFile(F, false)); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lpack/ocamljavaMain"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); options.setUseConstantSpecificKeys(true); IAnalysisCacheView cache = new AnalysisCacheImpl(); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); MethodHandles.analyzeMethodHandles(options, builder); CallGraph cg = builder.makeCallGraph(options, null); System.err.println(cg); instrument(F.getAbsolutePath()); run("pack.ocamljavaMain", null, args); checkNodes(cg, t -> { String s = t.toString(); return s.contains("Lpack/") || s.contains("Locaml/stdlib/"); }); }
public static CallGraph makeHTMLCG(URL url, Supplier<JSSourceExtractor> fExtractor) throws IllegalArgumentException, CancelException, WalaException { SSAPropagationCallGraphBuilder b = makeHTMLCGBuilder(url, fExtractor); CallGraph CG = b.makeCallGraph(b.getOptions()); dumpCG(b.getCFAContextInterpreter(), b.getPointerAnalysis(), CG); return CG; }
@Test public void testTutorialExample() throws IllegalArgumentException, IOException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "tutorial-example.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); // verifyGraphAssertions(CG, assertionsForDateProperty); }
cg = cgb.makeCallGraph(cgb.getOptions()); } catch (Exception e) { graphBuilt = false;
@Test public void testDispatch() throws IOException, IllegalArgumentException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); // JSCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); verifyGraphAssertions(CG, assertionsForDispatch); }
public static Pair<CallGraph, PointerAnalysis<InstanceKey>> makeDalvikCallGraph(URI[] androidLibs, File androidAPIJar, String mainClassName, String dexFileName) throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = makeDalvikScope(androidLibs, androidAPIJar, dexFileName); final IClassHierarchy cha = ClassHierarchyFactory.make(scope); TypeReference mainClassRef = TypeReference.findOrCreate(ClassLoaderReference.Application, mainClassName); IClass mainClass = cha.lookupClass(mainClassRef); assert mainClass != null; System.err.println("building call graph for " + mainClass + ":" + mainClass.getClass()); Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(scope, cha, mainClassName); IAnalysisCacheView cache = new AnalysisCacheImpl(new DexIRFactory()); AnalysisOptions options = new AnalysisOptions(scope, entrypoints); SSAPropagationCallGraphBuilder cgb = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); CallGraph callGraph = cgb.makeCallGraph(options); MethodReference mmr = MethodReference.findOrCreate(mainClassRef, "main", "([Ljava/lang/String;)V"); assert !callGraph.getNodes(mmr).isEmpty(); PointerAnalysis<InstanceKey> ptrAnalysis = cgb.getPointerAnalysis(); return Pair.make(callGraph, ptrAnalysis); }
@Test public void testReturnThis() throws IOException, IllegalArgumentException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); // JSCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); verifyGraphAssertions(CG, assertionsForReturnThis); }
@Test public void testSystemProperties() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "LstaticInit/TestSystemProperties"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); CallGraph cg = builder.makeCallGraph(options); for (CGNode n : cg) { if (n.toString().equals("Node: < Application, LstaticInit/TestSystemProperties, main([Ljava/lang/String;)V > Context: Everywhere")) { boolean foundToCharArray = false; for (CGNode callee : Iterator2Iterable.make(cg.getSuccNodes(n))) { if (callee.getMethod().getName().toString().equals("toCharArray")) { foundToCharArray = true; break; } } Assert.assertTrue(foundToCharArray); break; } } }
private static Pair<CallGraph,PointerAnalysis<InstanceKey>> makeJavaBuilder(String scopeFile, String mainClass) throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(scopeFile, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, mainClass); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); CallGraph CG = builder.makeCallGraph(options); return Pair.make(CG, builder.getPointerAnalysis()); }
@Ignore("need to fix this. bug from Sukyoung's group") @Test public void testLoops() throws IllegalArgumentException, IOException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "loops.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); boolean x = CAstCallGraphUtil.AVOID_DUMP; CAstCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); CAstCallGraphUtil.AVOID_DUMP = x; verifyGraphAssertions(CG, assertionsForLoops); }
@Ignore("need to fix this. bug from Sukyoung's group") @Test public void testPrimitiveStrings() throws IllegalArgumentException, IOException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "primitive_strings.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); boolean x = CAstCallGraphUtil.AVOID_DUMP; CAstCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); CAstCallGraphUtil.AVOID_DUMP = x; verifyGraphAssertions(CG, assertionsForPrimitiveStrings); }
public static Pair<CallGraph, PointerAnalysis<InstanceKey>> makeAPKCallGraph(URI[] androidLibs, File androidAPIJar, String apkFileName, IProgressMonitor monitor, ReflectionOptions policy) throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = makeDalvikScope(androidLibs, androidAPIJar, apkFileName); final IClassHierarchy cha = ClassHierarchyFactory.make(scope); IAnalysisCacheView cache = new AnalysisCacheImpl(new DexIRFactory()); List<? extends Entrypoint> es = getEntrypoints(cha); assert ! es.isEmpty(); AnalysisOptions options = new AnalysisOptions(scope, es); options.setReflectionOptions(policy); // SSAPropagationCallGraphBuilder cgb = Util.makeZeroCFABuilder(options, cache, cha, scope, null, makeDefaultInterpreter(options, cache)); SSAPropagationCallGraphBuilder cgb = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); CallGraph callGraph = cgb.makeCallGraph(options, monitor); PointerAnalysis<InstanceKey> ptrAnalysis = cgb.getPointerAnalysis(); return Pair.make(callGraph, ptrAnalysis); }
private static void doCPATest(String testClass, String testIdSignature) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, testClass); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); builder.setContextSelector(new CPAContextSelector(builder.getContextSelector())); CallGraph cg = builder.makeCallGraph(options, null); // Find id TypeReference str = TypeReference.findOrCreate(ClassLoaderReference.Application, testClass); MethodReference ct = MethodReference.findOrCreate(str, Atom.findOrCreateUnicodeAtom("id"), Descriptor.findOrCreateUTF8(testIdSignature)); Set<CGNode> idNodes = cg.getNodes(ct); System.err.println(cg); Assert.assertEquals(2, idNodes.size()); } }
@Test public void testStringPrims() throws IOException, IllegalArgumentException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-prims.js"); B.getOptions().setTraceStringConstants(true); CallGraph CG = B.makeCallGraph(B.getOptions()); // JSCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); verifyGraphAssertions(CG, assertionsForStringPrims); }
CallGraph cg = builder.makeCallGraph(options, new IProgressMonitor() { private long time = System.currentTimeMillis();
@Test(expected = CallGraphBuilderCancelException.class) public void testManyStrings() throws IllegalArgumentException, IOException, CancelException, WalaException { SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "many-strings.js"); B.getOptions().setTraceStringConstants(true); ProgressMaster monitor = ProgressMaster.make(new NullProgressMonitor(), 10000, false); monitor.beginTask("build CG", 1); CallGraph CG = B.makeCallGraph(B.getOptions(), monitor); monitor.done(); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG); }
CallGraph cg = builder.makeCallGraph(options, null);
private static void doTests(AnalysisScope scope, final ClassHierarchy cha, AnalysisOptions options) throws IllegalArgumentException, CancelException { final SSAPropagationCallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); final CallGraph oldCG = builder.makeCallGraph(options,null); final PointerAnalysis<InstanceKey> pa = builder.getPointerAnalysis();