@Override public AnalysisOptions getDefaultOptions(Iterable<Entrypoint> entrypoints) { AnalysisOptions options = new AnalysisOptions(getScope(), entrypoints); SSAOptions ssaOptions = new SSAOptions(); ssaOptions.setDefaultValues(SymbolTable::getDefaultValue); options.setSSAOptions(ssaOptions); return options; }
public SSAInstruction[] getStatements() { return getStatements(SSAOptions.defaultOptions()); }
DexSSABuilder builder = DexSSABuilder.make(method, newCfg, cfg, newInstrs, symbolTable, buildLocalMap, options.getPiNodePolicy()); builder.build(); if (buildLocalMap)
@Test public void testLocalNamesWithPiNodes() { SSAPiNodePolicy save = options.getSSAOptions().getPiNodePolicy(); options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes()); MethodReference mref = scope.findMethod(AnalysisScope.APPLICATION, "LcornerCases/Locals", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("([Ljava/lang/String;)V"))); Assert.assertNotNull("method not found", mref); IMethod imethod = cha.resolveMethod(mref); Assert.assertNotNull("imethod not found", imethod); IAnalysisCacheView cache = new AnalysisCacheImpl(options.getSSAOptions()); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); options.getSSAOptions().setPiNodePolicy(save); // v1 should be the parameter "a" at pc 0 String[] names = ir.getLocalNames(0, 1); Assert.assertTrue("failed local name resolution for v1@0", names != null); Assert.assertTrue("incorrect number of local names for v1@0: " + names.length, names.length == 1); Assert.assertTrue("incorrect local name resolution for v1@0: " + names[0], names[0].equals("a")); // v2 is a compiler-induced temporary Assert.assertTrue("didn't expect name for v2 at pc 2", ir.getLocalNames(2, 2) == null); // at pc 5, v1 should represent the locals "a" and "b" names = ir.getLocalNames(5, 1); Assert.assertTrue("failed local name resolution for v1@5", names != null); Assert.assertTrue("incorrect number of local names for v1@5: " + names.length, names.length == 2); Assert.assertTrue("incorrect local name resolution #0 for v1@5: " + names[0], names[0].equals("a")); Assert.assertTrue("incorrect local name resolution #1 for v1@5: " + names[1], names[1].equals("b")); } }
@Test public void testLocalNamesWithoutPiNodes() { SSAPiNodePolicy save = options.getSSAOptions().getPiNodePolicy(); options.getSSAOptions().setPiNodePolicy(null); MethodReference mref = scope.findMethod(AnalysisScope.APPLICATION, "LcornerCases/Locals", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("([Ljava/lang/String;)V"))); Assert.assertNotNull("method not found", mref); IMethod imethod = cha.resolveMethod(mref); Assert.assertNotNull("imethod not found", imethod); IAnalysisCacheView cache = new AnalysisCacheImpl(options.getSSAOptions()); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); options.getSSAOptions().setPiNodePolicy(save); // v1 should be the parameter "a" at pc 0 String[] names = ir.getLocalNames(0, 1); Assert.assertTrue("failed local name resolution for v1@0", names != null); Assert.assertTrue("incorrect number of local names for v1@0: " + names.length, names.length == 1); Assert.assertTrue("incorrect local name resolution for v1@0: " + names[0], names[0].equals("a")); // v2 is a compiler-induced temporary Assert.assertTrue("didn't expect name for v2 at pc 2", ir.getLocalNames(2, 2) == null); // at pc 5, v1 should represent the locals "a" and "b" names = ir.getLocalNames(5, 1); Assert.assertTrue("failed local name resolution for v1@5", names != null); Assert.assertTrue("incorrect number of local names for v1@5: " + names.length, names.length == 2); Assert.assertTrue("incorrect local name resolution #0 for v1@5: " + names[0], names[0].equals("a")); Assert.assertTrue("incorrect local name resolution #1 for v1@5: " + names[1], names[1].equals("b")); }
protected static void printIRsForCHA(IClassHierarchy cha, Predicate<String> exclude) { // for constructing IRs IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory(); for (IClass klass : cha) { // ignore models of built-in JavaScript methods String name = klass.getName().toString(); if (exclude.test(name)) continue; // get the IMethod representing the code IMethod m = klass.getMethod(AstMethodReference.fnSelector); if (m != null) { IR ir = factory.makeIR(m, Everywhere.EVERYWHERE, new SSAOptions()); System.out.println(ir); if (m instanceof AstMethod) { AstMethod astMethod = (AstMethod) m; System.out.println(astMethod.getSourcePosition()); } System.out.println("===================================================\n"); } } }
private static CallGraph doGraph(boolean usePiNodes) 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, TestConstants.PI_TEST_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPiNodePolicy policy = usePiNodes ? SSAOptions.getAllBuiltInPiNodes() : null; options.getSSAOptions().setPiNodePolicy(policy); return CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(new DefaultIRFactory(), options.getSSAOptions()), cha, scope, false); }
protected AbstractSSAConversion(IR ir, SSAOptions options) { this.CFG = ir.getControlFlowGraph(); this.DF = new DominanceFrontiers<>(ir.getControlFlowGraph(), ir.getControlFlowGraph().entry()); this.dominatorTree = DF.dominatorTree(); this.flags = new int[2 * ir.getControlFlowGraph().getNumberOfNodes()]; this.instructions = getInstructions(ir); this.phiCounts = new int[CFG.getNumberOfNodes()]; this.symbolTable = ir.getSymbolTable(); this.defaultValues = options.getDefaultValues(); }
DexSSABuilder builder = DexSSABuilder.make(method, newCfg, cfg, newInstrs, symbolTable, buildLocalMap, options.getPiNodePolicy()); builder.build(); if (buildLocalMap)
@Test public void testMultiNewArray1() throws IOException, ClassHierarchyException { AnalysisScope scope = null; scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, (new FileProvider()).getFile("J2SEClassHierarchyExclusions.txt"), MY_CLASSLOADER); ClassHierarchy cha = ClassHierarchyFactory.make(scope); IClass klass = cha.lookupClass(TypeReference.findOrCreate(ClassLoaderReference.Application, TestConstants.MULTI_DIM_MAIN)); Assert.assertTrue(klass != null); IMethod m = klass.getMethod(Selector.make(Language.JAVA, "testNewMultiArray()V")); Assert.assertTrue(m != null); IAnalysisCacheView cache = new AnalysisCacheImpl(); IR ir = cache.getIRFactory().makeIR(m, Everywhere.EVERYWHERE, new SSAOptions()); Assert.assertTrue(ir != null); SSAInstruction[] instructions = ir.getInstructions(); for (SSAInstruction instr : instructions) { if (instr instanceof SSANewInstruction) { System.err.println(instr.toString(ir.getSymbolTable())); Assert.assertTrue(instr.getNumberOfUses() == 2); Assert.assertTrue(ir.getSymbolTable().getIntValue(instr.getUse(0)) == 3); Assert.assertTrue(ir.getSymbolTable().getIntValue(instr.getUse(1)) == 4); } } } }
options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes()); IAnalysisCacheView cache = makeAnalysisCache(options.getSSAOptions()); IR ir = cache.getIR(m, Everywhere.EVERYWHERE);
protected AbstractSSAConversion(IR ir, SSAOptions options) { this.CFG = ir.getControlFlowGraph(); this.DF = new DominanceFrontiers<>(ir.getControlFlowGraph(), ir.getControlFlowGraph().entry()); this.dominatorTree = DF.dominatorTree(); this.flags = new int[2 * ir.getControlFlowGraph().getNumberOfNodes()]; this.instructions = getInstructions(ir); this.phiCounts = new int[CFG.getNumberOfNodes()]; this.symbolTable = ir.getSymbolTable(); this.defaultValues = options.getDefaultValues(); }
public SSAInstruction[] getStatements() { return getStatements(SSAOptions.defaultOptions()); }
@Override public AnalysisOptions getDefaultOptions(Iterable<Entrypoint> entrypoints) { AnalysisOptions options = new AnalysisOptions(getScope(), entrypoints); SSAOptions ssaOptions = new SSAOptions(); ssaOptions.setDefaultValues(SymbolTable::getDefaultValue); options.setSSAOptions(ssaOptions); return options; }
.getPiNodePolicy()); builder.build(); if (buildLocalMap)
options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes()); IAnalysisCacheView cache = new AnalysisCacheImpl(options.getSSAOptions()); IR ir = cache.getIR(m, Everywhere.EVERYWHERE );
private boolean returnsThis(IMethod method) { MethodReference mref = method.getReference(); if(method.getNumberOfParameters() < 1) return false; Boolean b = returnsThis_cache.get(mref); if(b != null) return b; for(SSAInstruction inst : factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()).getInstructions()) { if(inst instanceof SSAReturnInstruction) { SSAReturnInstruction ret = (SSAReturnInstruction)inst; if(ret.getResult() == 2) { returnsThis_cache.put(mref, true); return true; } } } returnsThis_cache.put(mref, false); return false; }
@Override public AnalysisOptions getDefaultOptions(Iterable<Entrypoint> entrypoints) { AnalysisOptions options = new AnalysisOptions(getScope(), entrypoints); SSAOptions ssaOptions = new SSAOptions(); ssaOptions.setDefaultValues(SymbolTable::getDefaultValue); options.setSSAOptions(ssaOptions); return options; } }
.getPiNodePolicy()); builder.build(); if (buildLocalMap)
options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes());