/** * @param methodSig something like "java_cup.lexer.advance()V" * @throws IllegalArgumentException if methodSig is null */ public static MethodReference makeMethodReference(String methodSig) throws IllegalArgumentException { return makeMethodReference(Language.JAVA, methodSig); }
/** * @param methodSig something like "java_cup.lexer.advance()V" * @throws IllegalArgumentException if methodSig is null */ public static MethodReference makeMethodReference(String methodSig) throws IllegalArgumentException { return makeMethodReference(Language.JAVA, methodSig); }
@Override public SinkSpec[] getSinkSpecs() { List<SinkSpec> specs = new ArrayList<>(); Collection<IMethod> methods = cha.getPossibleTargets(StringStuff.makeMethodReference(methodSignature)); for (IField field : fields) { if (!field.isFinal()) { for (IMethod method : methods) { specs.add(new StaticFieldSinkSpec(field, method)); } } } return specs.toArray(new SinkSpec[] {}); }
public void addTestEntry(ClassHierarchy cha) { String[] methodReferences = { // "Test.Apps.Outer$PrivateInnerClass.printNum()V", //"Test.Apps.Outer$PublicInnerClass.printNum()V" //"Test.Apps.Outer.<init>()V" //"Test.Apps.Outer.getNum()I" //"Test.Apps.FixpointSolver.someMethod(LTest/Apps/GenericSink;LTest/Apps/GenericSource;)V" //"Test.Apps.Outer$PrivateInnerClass.testParameters(LTest/Apps/GenericSink;LTest/Apps/GenericSource;)V" "android.view.View.setOnClickListener(Landroid/view/View$OnClickListener;)V", }; for (String methodReference : methodReferences) { MethodReference mr = StringStuff.makeMethodReference(methodReference); for (IMethod im : cha.getPossibleTargets(mr)) { entries.add(new DefaultEntrypoint(im, cha)); } } }
@SuppressWarnings("unused") private void populateEntryPoints(ClassHierarchy cha) { String method = null; IMethod im = null; for (String[] intent: ActivityIntentList) { //method = IntentToMethod(intent[0]); method = "onCreate(Landroid/os/Bundle;)V"; im = cha.resolveMethod(StringStuff.makeMethodReference(intent[1]+ '.' +method)); if (im!=null) entries.add(new DefaultEntrypoint(im,cha)); } for (String[] intent: ReceiverIntentList) { //Seems that every broadcast receiver can be an entrypoints? // method = IntentToMethod(intent[0]); method = "onReceive(Landroid/content/Context;Landroid/content/Intent;)V"; im = cha.resolveMethod(StringStuff.makeMethodReference(intent[1]+ '.' +method)); if (im!=null) entries.add(new DefaultEntrypoint(im,cha)); } //IMethod im = cha.resolveMethod(StringStuff.makeMethodReference("android.app.Activity.onCreate(Landroid/os/Bundle;)V")); //entries.add(new DefaultEntrypoint(im, cha)); }
public void listenerEntryPoints(ClassHierarchy cha) { ArrayList<MethodReference> entryPointMRs = new ArrayList<>(); // onLocation entryPointMRs.add(StringStuff.makeMethodReference("android.location.LocationListener.onLocationChanged(Landroid/location/Location;)V")); for(MethodReference mr:entryPointMRs) for(IMethod im:cha.getPossibleTargets(mr)) { // limit to functions defined within the application if(im.getReference().getDeclaringClass().getClassLoader(). equals(ClassLoaderReference.Application)) { entries.add(new DefaultEntrypoint(im, cha)); } } }
@Test public void testIfNoException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callIfNoException()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertFalse(intraExplodedCFG.hasExceptions()); }
@Test public void testDynamicIf2Exception() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicIf2Exception()Lcfg/exc/intra/B"); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertTrue(intraExplodedCFG.hasExceptions()); }
@Test public void testDynamicIfException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicIfException()Lcfg/exc/intra/B"); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertTrue(intraExplodedCFG.hasExceptions()); }
@Test public void testIf2NoException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callIf2NoException()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertFalse(intraExplodedCFG.hasExceptions()); }
@Test public void testDynamicIf2NoException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicIf2NoException()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertFalse(intraExplodedCFG.hasExceptions()); }
@Test public void testIf2Exception() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callIf2Exception()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertTrue(intraExplodedCFG.hasExceptions()); }
@Test public void testDynamicGetException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicGetException()Lcfg/exc/intra/B"); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertTrue(intraExplodedCFG.hasExceptions()); } }
@Test public void testIfException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callIfException()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertTrue(intraExplodedCFG.hasExceptions()); }
@Test public void testDynamicIfNoException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callDynamicIfNoException()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertFalse(intraExplodedCFG.hasExceptions()); }
@Test public void testGetException() throws UnsoundGraphException, CancelException, WalaException { MethodReference mr = StringStuff.makeMethodReference("cfg.exc.inter.CallFieldAccess.callGetException()Lcfg/exc/intra/B"); InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock> interExplodedCFG = NullPointerAnalysis.computeInterprocAnalysis(cg, new NullProgressMonitor()); Assert.assertEquals(1, cg.getNodes(mr).size()); final CGNode callNode = cg.getNodes(mr).iterator().next(); ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intraExplodedCFG = interExplodedCFG.getResult(callNode); Assert.assertTrue(intraExplodedCFG.hasExceptions()); }
@Test public void testSync1() { MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync1()V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR ir = cache.getIR(m); System.out.println(ir); SSACFG controlFlowGraph = ir.getControlFlowGraph(); Assert.assertEquals(1, controlFlowGraph.getSuccNodeCount(controlFlowGraph.getBlockForInstruction(21))); }
@Test public void testIRCacheIdempotence() { MethodReference mr = StringStuff.makeMethodReference("hello.Hello.main([Ljava/lang/String;)V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR irBefore = cache.getIR(m); cache.clear(); IR irAfter = cache.getIR(m); for (int i = 0; i < irBefore.getInstructions().length; i++) { System.out.println(irBefore.getInstructions()[i]); System.out.println(irAfter.getInstructions()[i]); Assert.assertEquals(irAfter.getInstructions()[i], irBefore.getInstructions()[i]); } }
@Test public void testSync3() { MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync3()V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR ir = cache.getIR(m); SSACFG controlFlowGraph = ir.getControlFlowGraph(); Assert.assertEquals(1, controlFlowGraph.getSuccNodeCount(controlFlowGraph.getBlockForInstruction(33))); }
@Test public void testSync2() { MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync2()V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR ir = cache.getIR(m); System.out.println(ir); SSACFG controlFlowGraph = ir.getControlFlowGraph(); IntSet succs = controlFlowGraph.getSuccNodeNumbers(controlFlowGraph.getBlockForInstruction(13)); Assert.assertEquals(2, succs.size()); Assert.assertTrue(succs.contains(6)); Assert.assertTrue(succs.contains(7)); }