public SSAInstruction[] getStatements() { return getStatements(SSAOptions.defaultOptions()); }
public SSAInstruction[] getStatements() { return getStatements(SSAOptions.defaultOptions()); }
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; }
protected IAnalysisCacheView makeAnalysisCache() { return makeAnalysisCache(SSAOptions.defaultOptions()); }
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; }
/** * @return an IR that encodes the behavior of the clone method for a given type. */ private IR makeIR(IMethod method, Context context, IClass klass) { assert klass != null; SSAInstruction instrs[] = makeStatements(klass); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null); }
private static IR makeIR(IMethod method, Context context) { SSAInstruction instrs[] = makeStatements(context); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null); }
/** * @return an IR that encodes the behavior of the clone method for a given type. */ private IR makeIR(IMethod method, Context context, IClass klass) { assert klass != null; SSAInstruction instrs[] = makeStatements(klass); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null); }
private static IR makeIR(IMethod method, Context context) { SSAInstruction instrs[] = makeStatements(context); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null); }
private static IR makeIR(IMethod method, Context context) { SSAInstruction instrs[] = makeStatements(context); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null); }
private static IR makeIR(IMethod method, Context context) { SSAInstruction instrs[] = makeStatements(context); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null); }
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(SourceModule[] scripts_array) throws ClassHierarchyException { JSCallGraphUtil.setTranslatorFactory(translatorFactory); JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null); CAstAnalysisScope scope = new CAstAnalysisScope(scripts_array, loaders, Collections.singleton(JavaScriptLoader.JS)); IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS); try { com.ibm.wala.cast.util.Util.checkForFrontEndErrors(cha); } catch (WalaException e) { return Collections.emptyMap(); } IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory(); Map<IMethod, CorrelationSummary> correlations = HashMapFactory.make(); for(IClass klass : cha) { for(IMethod method : klass.getAllMethods()) { IR ir = factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()); CorrelationSummary summary = findCorrelatedAccesses(method, ir); if(!summary.getCorrelations().isEmpty()) correlations.put(method, summary); } } return correlations; }
public Map<IMethod, CorrelationSummary> findCorrelatedAccesses(SourceModule[] scripts_array) throws ClassHierarchyException { JSCallGraphUtil.setTranslatorFactory(translatorFactory); JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null); CAstAnalysisScope scope = new CAstAnalysisScope(scripts_array, loaders, Collections.singleton(JavaScriptLoader.JS)); IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS); try { com.ibm.wala.cast.util.Util.checkForFrontEndErrors(cha); } catch (WalaException e) { return Collections.emptyMap(); } IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory(); Map<IMethod, CorrelationSummary> correlations = HashMapFactory.make(); for(IClass klass : cha) { for(IMethod method : klass.getAllMethods()) { IR ir = factory.makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()); CorrelationSummary summary = findCorrelatedAccesses(method, ir); if(!summary.getCorrelations().isEmpty()) correlations.put(method, summary); } } return correlations; }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }
@Override public IR getIR(CGNode node) { if (node == null) { throw new IllegalArgumentException("node is null"); } assert understands(node); if (DEBUG) { System.err.println("generating IR for " + node); } IMethod method = node.getMethod(); Context context = node.getContext(); Map<Integer,ConstantValue> constants = HashMapFactory.make(); if (method.getReference().equals(GET_METHOD)) { Atom name = Atom.findOrCreateAsciiAtom(((NameItem)(context.get(ContextKey.NAME))).name()); SSAInstruction instrs[] = makeGetMethodStatements(context,constants,name); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), constants); } if (method.getReference().equals(GET_DECLARED_METHOD)) { Atom name = Atom.findOrCreateAsciiAtom(((NameItem)(context.get(ContextKey.NAME))).name()); SSAInstruction instrs[] = makeGetDeclaredMethodStatements(context,constants,name); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), constants); } Assertions.UNREACHABLE("Unexpected method " + node); return null; }
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null);
@Override public IR getIR(CGNode node) { if (node == null) { throw new IllegalArgumentException("node is null"); } assert understands(node); if (DEBUG) { System.err.println("generating IR for " + node); } IMethod method = node.getMethod(); Context context = node.getContext(); Map<Integer,ConstantValue> constants = HashMapFactory.make(); if (method.getReference().equals(GET_METHOD)) { Atom name = Atom.findOrCreateAsciiAtom(((NameItem)(context.get(ContextKey.NAME))).name()); SSAInstruction instrs[] = makeGetMethodStatements(context,constants,name); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), constants); } if (method.getReference().equals(GET_DECLARED_METHOD)) { Atom name = Atom.findOrCreateAsciiAtom(((NameItem)(context.get(ContextKey.NAME))).name()); SSAInstruction instrs[] = makeGetDeclaredMethodStatements(context,constants,name); return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), constants); } Assertions.UNREACHABLE("Unexpected method " + node); return null; }
@Test public void testIntraproc1() { IAnalysisCacheView cache = new AnalysisCacheImpl(); final MethodReference ref = MethodReference.findOrCreate(ClassLoaderReference.Application, "Ldataflow/StaticDataflow", "test1", "()V"); IMethod method = cha.resolveMethod(ref); IR ir = cache.getIRFactory().makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()); ExplodedControlFlowGraph ecfg = ExplodedControlFlowGraph.make(ir); IntraprocReachingDefs reachingDefs = new IntraprocReachingDefs(ecfg, cha); BitVectorSolver<IExplodedBasicBlock> solver = reachingDefs.analyze(); for (IExplodedBasicBlock ebb : ecfg) { if (ebb.getNumber() == 4) { IntSet out = solver.getOut(ebb).getValue(); Assert.assertEquals(1, out.size()); Assert.assertTrue(out.contains(1)); } } }
@Test public void testIntraproc2() { IAnalysisCacheView cache = new AnalysisCacheImpl(); final MethodReference ref = MethodReference.findOrCreate(ClassLoaderReference.Application, "Ldataflow/StaticDataflow", "test2", "()V"); IMethod method = cha.resolveMethod(ref); IR ir = cache.getIRFactory().makeIR(method, Everywhere.EVERYWHERE, SSAOptions.defaultOptions()); ExplodedControlFlowGraph ecfg = ExplodedControlFlowGraph.make(ir); IntraprocReachingDefs reachingDefs = new IntraprocReachingDefs(ecfg, cha); BitVectorSolver<IExplodedBasicBlock> solver = reachingDefs.analyze(); for (IExplodedBasicBlock ebb : ecfg) { if (ebb.getNumber() == 10) { IntSet out = solver.getOut(ebb).getValue(); Assert.assertEquals(2, out.size()); Assert.assertTrue(out.contains(0)); Assert.assertTrue(out.contains(2)); } } }