Example #1
0
 @Test
 public void testSystemProperties()
     throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
   AnalysisScope scope =
       CallGraphTestUtil.makeJ2SEAnalysisScope(
           TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
   ClassHierarchy cha = ClassHierarchy.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(options, new AnalysisCache(), 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;
     }
   }
 }
Example #2
0
  public static Preset finalize(Preset empty, AnalysisScope scope, IClassHierarchy cha) {
    Preset p = empty;
    p.scfg.cha = cha;

    // The preliminary settings of WALAs AnalysisOptions
    p.options.setReflectionOptions(ReflectionOptions.FULL);
    AndroidEntryPointManager.MANAGER.setInstantiationBehavior(
        new DefaultInstantiationBehavior(cha));
    Util.addDefaultSelectors(p.options, cha);
    Util.addDefaultBypassLogic(p.options, scope, Util.class.getClassLoader(), cha); // ??

    // No changes to the settings of AndroidEntypointManager...
    // p.aem
    // p.entrypointLocatorFlags = EnumSet.of(LocatorFlags.EP_HEURISTIC, LocatorFlags.WITH_SUPER,
    //        LocatorFlags.INCLUDE_CALLBACKS, LocatorFlags.CB_HEURISTIC);
    p.entrypointLocatorFlags =
        EnumSet.of(
            LocatorFlags.EP_HEURISTIC, LocatorFlags.CB_HEURISTIC, LocatorFlags.INCLUDE_CALLBACKS);

    // The following selectors will be injected when Joana generates its new
    // AnalysisOptions
    // TODO: Add ReflectionContext ?
    p.ctxSel = new DefaultContextSelector(p.options, p.scfg.cha);
    p.ctxIpr = new DefaultSSAInterpreter(p.options, p.scfg.cache);
    p.instKeys = new ZeroXInstanceKeys(p.options, p.scfg.cha, p.ctxIpr, ZeroXInstanceKeys.NONE);

    return p;
  }
 /**
  * builds a call graph, and sets the corresponding heap model for analysis
  *
  * @param scope
  * @param cha
  * @param options
  * @return
  * @throws CancelException
  * @throws IllegalArgumentException
  */
 private static Pair<CallGraph, PointerAnalysis> buildCallGraph(
     AnalysisScope scope, ClassHierarchy cha, AnalysisOptions options)
     throws IllegalArgumentException, CancelException {
   CallGraph retCG = null;
   PointerAnalysis retPA = null;
   final AnalysisCache cache = new AnalysisCache();
   CallGraphBuilder builder;
   if (CHEAP_CG) {
     builder = Util.makeZeroCFABuilder(options, cache, cha, scope);
     // we want vanilla 0-1 CFA, which has one abstract loc per allocation
     heapModel = Util.makeVanillaZeroOneCFABuilder(options, cache, cha, scope);
   } else {
     builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
     heapModel = (HeapModel) builder;
   }
   ProgressMaster master = ProgressMaster.make(new NullProgressMonitor(), 360000, false);
   master.beginTask("runSolver", 1);
   try {
     retCG = builder.makeCallGraph(options, master);
     retPA = builder.getPointerAnalysis();
   } catch (CallGraphBuilderCancelException e) {
     System.err.println("TIMED OUT!!");
     retCG = e.getPartialCallGraph();
     retPA = e.getPartialPointerAnalysis();
   }
   return Pair.make(retCG, retPA);
 }
Example #4
0
  /**
   * Check consistency of a callgraph, and check that this call graph is a subset of a super-graph
   *
   * @param warnings object to track warnings
   * @param cg
   * @param superCG
   * @param superMethods
   * @param thisAlgorithm
   * @return a squashed version of cg
   */
  private static Graph<MethodReference> checkCallGraph(
      CallGraph cg,
      Graph<MethodReference> superCG,
      Set<MethodReference> superMethods,
      String thisAlgorithm) {
    try {
      GraphIntegrity.check(cg);
    } catch (UnsoundGraphException e1) {
      Assert.assertTrue(e1.getMessage(), false);
    }
    Set<MethodReference> callGraphMethods = CallGraphStats.collectMethods(cg);
    System.err.println(thisAlgorithm + " methods reached: " + callGraphMethods.size());
    System.err.println(CallGraphStats.getStats(cg));

    Graph<MethodReference> thisCG = squashCallGraph(thisAlgorithm, cg);

    if (superCG != null) {
      com.ibm.wala.ipa.callgraph.impl.Util.checkGraphSubset(superCG, thisCG);
    } else {
      // SJF: RTA has rotted a bit since it doesn't handle LoadClass instructions.
      // Commenting this out for now.
      // if (!superMethods.containsAll(callGraphMethods)) {
      // Set<MethodReference> temp = HashSetFactory.make();
      // temp.addAll(callGraphMethods);
      // temp.removeAll(superMethods);
      // System.err.println("Violations");
      // for (MethodReference m : temp) {
      // System.err.println(m);
      // }
      // Assertions.UNREACHABLE();
      // }
    }

    return thisCG;
  }
  private static DemandRefinementPointsTo makeDemandPointerAnalysis(
      String scopeFile, String mainClass, String benchName)
      throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
    AnalysisScope scope =
        CallGraphTestUtil.makeJ2SEAnalysisScope(scopeFile, getExclusions(benchName));
    // build a type hierarchy
    ClassHierarchy cha = ClassHierarchy.make(scope);

    // set up call graph construction options; mainly what should be considered
    // entrypoints?
    Iterable<Entrypoint> entrypoints =
        com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, mainClass);
    AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);

    System.err.print("constructing call graph...");
    final Pair<CallGraph, PointerAnalysis> cgAndPA = buildCallGraph(scope, cha, options);
    CallGraph cg = cgAndPA.fst;
    System.err.println("done");
    System.err.println(CallGraphStats.getStats(cg));
    MemoryAccessMap fam = new SimpleMemoryAccessMap(cg, cgAndPA.snd.getHeapModel(), false);
    DemandRefinementPointsTo fullDemandPointsTo =
        DemandRefinementPointsTo.makeWithDefaultFlowGraph(
            cg, heapModel, fam, cha, options, makeStateMachineFactory());
    fullDemandPointsTo.setRefinementPolicyFactory(chooseRefinePolicyFactory(cha));
    return fullDemandPointsTo;
  }
Example #6
0
 @Test
 public void testStaticInit()
     throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
   AnalysisScope scope =
       CallGraphTestUtil.makeJ2SEAnalysisScope(
           TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
   ClassHierarchy cha = ClassHierarchy.make(scope);
   Iterable<Entrypoint> entrypoints =
       com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(
           scope, cha, "LstaticInit/TestStaticInit");
   AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
   CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCache(), cha, scope, false);
   boolean foundDoNothing = false;
   for (CGNode n : cg) {
     if (n.toString().contains("doNothing")) {
       foundDoNothing = true;
       break;
     }
   }
   Assert.assertTrue(foundDoNothing);
   options.setHandleStaticInit(false);
   cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCache(), cha, scope, false);
   for (CGNode n : cg) {
     Assert.assertTrue(!n.toString().contains("doNothing"));
   }
 }
  public static SSAPropagationCallGraphBuilder makeVanillaZeroOneCFABuilder(
      AnalysisOptions options,
      AnalysisCache cache,
      IClassHierarchy cha,
      AnalysisScope scope,
      ContextSelector customSelector,
      SSAContextInterpreter customInterpreter,
      InputStream summariesStream,
      MethodSummary extraSummary) {

    if (options == null) {
      throw new IllegalArgumentException("options is null");
    }
    Util.addDefaultSelectors(options, cha);
    // addDefaultBypassLogic(options, scope, Util.class.getClassLoader(),
    // cha);
    // addBypassLogic(options, scope,
    // AndroidAppLoader.class.getClassLoader(), methodSpec, cha);
    addBypassLogic(options, scope, summariesStream, cha, extraSummary);

    return ZeroXCFABuilder.make(
        cha,
        options,
        cache,
        customSelector,
        customInterpreter,
        ZeroXInstanceKeys.ALLOCATIONS | ZeroXInstanceKeys.CONSTANT_SPECIFIC);
  }
  public static ExceptionPruneAnalysis createBarcodeTest()
      throws WalaException, IOException, IllegalArgumentException, CallGraphBuilderCancelException {
    com.ibm.wala.ipa.callgraph.impl.Util.setNativeSpec("test_lib/natives_empty.xml");

    AnalysisScope scope = AnalysisScopeReader.makePrimordialScope(null);

    SetOfClasses exclusions = new FileOfClasses(new ByteArrayInputStream("com/sun/.*".getBytes()));
    scope.setExclusions(exclusions);

    ClassLoaderReference primordial = scope.getLoader(AnalysisScope.PRIMORDIAL);
    AnalysisScopeReader.addClassPathToScope("test_lib/jSDG-stubs-j2me2.0.jar", scope, primordial);
    AnalysisScopeReader.addClassPathToScope("test_lib/primordial.jar", scope, primordial);
    ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
    AnalysisScopeReader.addClassPathToScope(classPath, scope, loader);

    // Klassenhierarchie berechnen
    System.out.println("Creating class hierarchy...");
    ClassHierarchy cha = ClassHierarchy.make(scope);
    System.out.println("Done.");

    AnalysisCache cache = new AnalysisCache();

    Iterable<Entrypoint> entries = Util.makeMainEntrypoints(scope, cha, "LMainEmulator");
    //        MethodReference mr = StringStuff.makeMethodReference(Language.JAVA, methodSig);
    //        IMethod m = cha.resolveMethod(mr);
    if (entries == null || !entries.iterator().hasNext()) {
      throw new IllegalStateException("Could not find main method in MainEmulator");
    }

    //        Set<Entrypoint> entries = HashSetFactory.make();
    //        entries.add(new DefaultEntrypoint(m, cha));
    AnalysisOptions options = new AnalysisOptions();
    options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes());
    options.setEntrypoints(entries);
    CallGraphBuilder builder = Util.makeZeroCFABuilder(options, cache, cha, scope);

    System.out.println("Creating call graph...");
    CallGraph cg = builder.makeCallGraph(options, null);
    System.out.println("Done.");

    PointerAnalysis pta = builder.getPointerAnalysis();

    ExceptionPruneAnalysis mCFG = new ExceptionPruneAnalysis(cg, pta, cache);

    return mCFG;
  }
Example #9
0
  private static void runComputeModule(
      final String binDir, final Config cfg, final String outputDir)
      throws IOException, IllegalArgumentException, CancelException, PDGFormatException,
          WalaException {
    Main.checkOrCreateOutputDir(outputDir);

    System.out.print("Setting up analysis scope... ");

    // Fuegt die normale Java Bibliothek zum Scope hinzu
    AnalysisScope scope = AnalysisScopeReader.makePrimordialScope(null);

    if (cfg.nativesXML != null) {
      com.ibm.wala.ipa.callgraph.impl.Util.setNativeSpec(cfg.nativesXML);
    }

    // if use stubs
    if (cfg.stubs != null) {
      scope.addToScope(ClassLoaderReference.Primordial, new JarFile(cfg.stubs));
    }

    // Nimmt unnoetige Klassen raus
    SetOfClasses exclusions =
        new FileOfClasses(new ByteArrayInputStream(cfg.exclusions.getBytes()));
    scope.setExclusions(exclusions);

    ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
    AnalysisScopeReader.addClassPathToScope(binDir, scope, loader);

    System.out.println("done.");

    ClassHierarchy cha = ClassHierarchy.make(scope);

    System.out.print("Creating MoJo... ");

    MoJo mojo = MoJo.create(cha);

    System.out.println("done.");

    for (IClass cls : cha) {
      for (IMethod im : cls.getDeclaredMethods()) {
        if (im.getDeclaringClass().isInterface() || im.isAbstract()) {
          // skip methods without a body
          continue;
        }

        MethodInfo nfo = cfg.extern.checkForModuleMethod(im);
        if (nfo != null) {
          System.out.println("Found " + nfo + " for " + im);
          final String sig = Dictionary.extractSignature(im);
          final String outputMethodDir =
              outputDir + (outputDir.endsWith(File.separator) ? "" : File.separator) + "m_" + sig;
          Main.checkOrCreateOutputDir(outputMethodDir);
          computeVariants(mojo, im, nfo, outputMethodDir);
        }
      }
    }
  }
Example #10
0
 @Test
 public void testZeroOneContainerCopyOf()
     throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException {
   AnalysisScope scope =
       CallGraphTestUtil.makeJ2SEAnalysisScope(
           TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
   ClassHierarchy cha = ClassHierarchy.make(scope);
   Iterable<Entrypoint> entrypoints =
       Util.makeMainEntrypoints(scope, cha, "Ldemandpa/TestArraysCopyOf");
   AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
   AnalysisCache cache = new AnalysisCache();
   CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
   CallGraph cg = builder.makeCallGraph(options, null);
   PointerAnalysis pa = builder.getPointerAnalysis();
   CGNode mainMethod = AbstractPtrTest.findMainMethod(cg);
   PointerKey keyToQuery = AbstractPtrTest.getParam(mainMethod, "testThisVar", pa.getHeapModel());
   OrdinalSet<? extends InstanceKey> pointsToSet = pa.getPointsToSet(keyToQuery);
   Assert.assertEquals(1, pointsToSet.size());
 }
Example #11
0
  @Test
  public void testJLex()
      throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
    AnalysisScope scope =
        CallGraphTestUtil.makeJ2SEAnalysisScope(
            TestConstants.JLEX, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
    ClassHierarchy cha = ClassHierarchy.make(scope);
    Iterable<Entrypoint> entrypoints =
        com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(
            scope, cha, TestConstants.JLEX_MAIN);
    AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);

    doCallGraphs(options, new AnalysisCache(), cha, scope);
  }
Example #12
0
  /**
   * Usage: ScopeFileCallGraph -sourceDir file_path -mainClass class_name
   *
   * <p>If given -mainClass, uses main() method of class_name as entrypoint. Class name should start
   * with an 'L'.
   *
   * <p>Example args: -sourceDir /tmp/srcTest -mainClass LFoo
   */
  public static void main(String[] args)
      throws ClassHierarchyException, IllegalArgumentException, CallGraphBuilderCancelException,
          IOException {
    long start = System.currentTimeMillis();
    Properties p = CommandLine.parse(args);
    String sourceDir = p.getProperty("sourceDir");
    String mainClass = p.getProperty("mainClass");
    AnalysisScope scope = new JavaSourceAnalysisScope();
    // add standard libraries to scope
    String[] stdlibs = WalaProperties.getJ2SEJarFiles();
    for (int i = 0; i < stdlibs.length; i++) {
      scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlibs[i]));
    }
    // add the source directory
    scope.addToScope(
        JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir)));

    // build the class hierarchy
    IClassHierarchy cha =
        ClassHierarchy.make(scope, new ECJClassLoaderFactory(scope.getExclusions()));
    System.out.println(cha.getNumberOfClasses() + " classes");
    System.out.println(Warnings.asString());
    Warnings.clear();
    AnalysisOptions options = new AnalysisOptions();
    Iterable<Entrypoint> entrypoints =
        Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE, cha, new String[] {mainClass});
    options.setEntrypoints(entrypoints);
    // you can dial down reflection handling if you like
    //    options.setReflectionOptions(ReflectionOptions.NONE);
    AnalysisCache cache = new AnalysisCache(AstIRFactory.makeDefaultFactory());
    // CallGraphBuilder builder = new ZeroCFABuilderFactory().make(options, cache, cha, scope,
    // false);
    CallGraphBuilder builder =
        new ZeroOneContainerCFABuilderFactory().make(options, cache, cha, scope, false);
    System.out.println("building call graph...");
    CallGraph cg = builder.makeCallGraph(options, null);
    long end = System.currentTimeMillis();
    System.out.println("done");
    System.out.println("took " + (end - start) + "ms");
    System.out.println(CallGraphStats.getStats(cg));
  }
  /**
   * @param options options that govern call graph construction
   * @param cha governing class hierarchy
   * @param scope representation of the analysis scope
   * @param customSelector user-defined context selector, or null if none
   * @param customInterpreter user-defined context interpreter, or null if none
   * @return a 0-CFA Call Graph Builder.
   * @throws IllegalArgumentException if options is null
   *     <p>TODO: move
   */
  public static SSAPropagationCallGraphBuilder makeZeroCFABuilder(
      AnalysisOptions options,
      AnalysisCache cache,
      IClassHierarchy cha,
      AnalysisScope scope,
      ContextSelector customSelector,
      SSAContextInterpreter customInterpreter,
      Collection<InputStream> summariesStreams,
      MethodSummary extraSummary) {

    if (options == null) {
      throw new IllegalArgumentException("options is null");
    }
    Util.addDefaultSelectors(options, cha);
    for (InputStream stream : summariesStreams) {
      addBypassLogic(options, scope, stream, cha, extraSummary);
    }

    return ZeroXCFABuilder.make(
        cha, options, cache, customSelector, customInterpreter, ZeroXInstanceKeys.NONE);
  }
  public static ExceptionPruneAnalysis create(String methodSig)
      throws WalaException, IOException, IllegalArgumentException, CallGraphBuilderCancelException {
    AnalysisScope scope = AnalysisScopeReader.makePrimordialScope(null);

    SetOfClasses exclusions =
        new FileOfClasses(new ByteArrayInputStream(exclusionRegExp.getBytes()));
    scope.setExclusions(exclusions);

    ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
    AnalysisScopeReader.addClassPathToScope(classPath, scope, loader);

    // Klassenhierarchie berechnen
    ClassHierarchy cha = ClassHierarchy.make(scope);

    AnalysisCache cache = new AnalysisCache();

    MethodReference mr = StringStuff.makeMethodReference(Language.JAVA, methodSig);
    IMethod m = cha.resolveMethod(mr);
    if (m == null) {
      throw new IllegalStateException("Could not resolve " + mr);
    }

    Set<Entrypoint> entries = HashSetFactory.make();
    entries.add(new DefaultEntrypoint(m, cha));
    AnalysisOptions options = new AnalysisOptions();
    options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes());
    options.setEntrypoints(entries);
    CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
    CallGraph cg = builder.makeCallGraph(options, null);

    PointerAnalysis pta = builder.getPointerAnalysis();

    ExceptionPruneAnalysis mCFG = new ExceptionPruneAnalysis(cg, pta, cache);

    return mCFG;
  }
Example #15
0
  private static Result getOrigSDG(Config cfg, IProgressMonitor progress)
      throws IllegalArgumentException, CancelException, PDGFormatException, IOException,
          WalaException, InvalidClassFileException {
    progress.beginTask(Messages.getString("Analyzer.Task_Prepare_IR"), -1); // $NON-NLS-1$

    com.ibm.wala.ipa.callgraph.impl.Util.setNativeSpec(cfg.nativesXML);

    progress.subTask(Messages.getString("Analyzer.SubTask_Analysis_Scope")); // $NON-NLS-1$

    ClassLoader loader = cfg.getClass().getClassLoader();
    AnalysisScope scope = Util.makeAnalysisScope(cfg, loader);
    // AnalysisScopeReader.makeJavaBinaryAnalysisScope(cfg.scopeFile, cfg.classpath, null);
    progress.done();

    ClassHierarchy cha = ClassHierarchy.make(scope, progress);

    Iterable<Entrypoint> entrypoints =
        com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, cfg.mainClass);
    AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
    AnalysisCache cache = new AnalysisCache();

    progress.subTask(
        Messages.getString("Analyzer.SubTask_Call_Graph_Builder") + cfg.pointsTo); // $NON-NLS-1$
    SSAPropagationCallGraphBuilder builder =
        SDGFactory.getCallGraphBuilder(cfg.pointsTo, options, cache, cha, scope);

    /**
     * Change the wala internal pointer and instancekeyfactory of the callgraph builder to our
     * adapter. So we can keep track of the created InstanceKeys and PointerKeys. This information
     * is used later on when creating subobject trees for accessed field variables.
     */
    InstanceAndPointerKeyFactoryAdapter adapter = null;
    InstanceKeyFactory ikFact = builder.getInstanceKeys();
    PointerKeyFactory pkFact = builder.getPointerKeyFactory();
    adapter = new InstanceAndPointerKeyFactoryAdapter(ikFact, pkFact);

    builder.setInstanceKeys(adapter);
    builder.setPointerKeyFactory(adapter);

    progress.done();

    progress.subTask(Messages.getString("Analyzer.SubTask_Call_Graph")); // $NON-NLS-1$
    CallGraph cg = builder.makeCallGraph(options, progress);

    if (cfg.optimizeCg >= 0) {
      CallGraphPruning opt = new CallGraphPruning(cg);
      System.out.println("Call Graph has " + cg.getNumberOfNodes() + " Nodes.");
      Set<CGNode> sopt = opt.findApplicationNodes(cfg.optimizeCg);
      cg = new PrunedCallGraph(cg, sopt);
      System.out.println("Optimized Call Graph has " + cg.getNumberOfNodes() + " Nodes.");
    }

    if (Debug.Var.DUMP_CALLGRAPH.isSet()) {
      Util.dumpCallGraph(cg, cfg.mainClass.replace('/', '.').substring(1), progress);
    }

    if (Debug.Var.DUMP_HEAP_GRAPH.isSet()) {
      PointerAnalysis pta = builder.getPointerAnalysis();
      HeapGraph hg = pta.getHeapGraph();
      Util.dumpHeapGraph(
          cfg.mainClass.replace('/', '.').substring(1) + "." + cfg.pointsTo, hg, null);
    }

    PointerAnalysis pta = builder.getPointerAnalysis();
    progress.done();

    DemandRefinementPointsTo demandPts = null;
    if (cfg.useDemandPts) {
      throw new UnsupportedOperationException();
      //		    MemoryAccessMap mam = new PABasedMemoryAccessMap(cg, builder.getPointerAnalysis());
      //			demandPts = new DemandRefinementPointsTo(cg,
      //				new ThisFilteringHeapModel(builder,cha), mam, cha, options, getStateMachineFactory());
    }

    IPointerAnalysis pts = new PointsToWrapper(demandPts, pta);

    progress.subTask(Messages.getString("Analyzer.SubTask_Search_Main")); // $NON-NLS-1$
    IMethod main =
        edu.kit.joana.deprecated.jsdg.util.Util.searchMethod(
            entrypoints, "main([Ljava/lang/String;)V"); // $NON-NLS-1$
    progress.done();

    progress.done();

    SDG sdg = SDG.create(main, cg, cache, adapter, pts, cfg, progress);
    sdg.setAnalysisScope(scope);
    sdg.setPointerAnalysis(pta);

    progress.done();

    if (Debug.Var.PRINT_FIELD_PTS_INFO.isSet()) {
      Log.info("search for field allocs called " + PDG.searchFieldAllocs + " times.");
    }

    if (Debug.Var.PRINT_UNRESOLVED_CLASSES.isSet()) {
      for (TypeReference tRef : cg.getClassHierarchy().getUnresolvedClasses()) {
        Log.warn("Could not resolve: " + Util.typeName(tRef.getName()));
      }
    }

    return new Result(null, sdg, cg, pta, null);
  }
Example #16
0
 public static void addDefaultJ2EEBypassLogic(
     AnalysisOptions options, AnalysisScope scope, ClassLoader cl, IClassHierarchy cha) {
   com.ibm.wala.ipa.callgraph.impl.Util.addDefaultBypassLogic(options, scope, cl, cha);
   com.ibm.wala.ipa.callgraph.impl.Util.addBypassLogic(options, scope, cl, benignExtSpec, cha);
 }
Example #17
0
  /**
   * Default settings as described below.
   *
   * <p>These settings contain: * a relatively basic setting for the context-sensitivity * no
   * entrypoints have been set(!)
   *
   * @return a bunch of settings
   */
  public static Preset makeDefault(AnalysisScope scope, IClassHierarchy cha) {
    final Preset p = new Preset(scope);

    // The following settings are used by Joana. Based on them new settings of
    // WALAs AnalysisOptions will be generated by Joana.
    applyPrettyCLIOutput(p);
    p.scfg.cache = new AnalysisCache((IRFactory<IMethod>) new DexIRFactory());
    p.scfg.cha = cha;

    // On external stuff. These settings have little effect on the result.
    p.scfg.ext = makeStandardExternalCallCheck();
    p.scfg.accessPath = false; // Setting this to true overrides other settings

    // On debugging
    p.scfg.showTypeNameInValue = false; // on true: Second type-inference often breaks
    p.scfg.debugManyGraphsDotOutput = false;

    p.scfg.immutableNoOut = Main.IMMUTABLE_NO_OUT;
    p.scfg.immutableStubs = Main.IMMUTABLE_STUBS;
    p.scfg.ignoreStaticFields = Main.IGNORE_STATIC_FIELDS;

    // What to considder
    // p.scfg.exceptions = ExceptionAnalysis.ALL_NO_ANALYSIS;
    p.scfg.exceptions = ExceptionAnalysis.IGNORE_ALL;
    p.scfg.staticInitializers =
        StaticInitializationTreatment.SIMPLE; // Do not use ACCURATE: Is defunct

    // Precision
    p.scfg.pts = PointsToPrecision.INSTANCE_BASED;

    p.scfg.prunecg = Main.DEFAULT_PRUNE_CG;
    // p.scfg.fieldPropagation = FieldPropagation.OBJ_GRAPH;   // Do not use OBJ_TREE: Is outdated
    // p.scfg.fieldPropagation = FieldPropagation.OBJ_GRAPH_SIMPLE_PROPAGATION;
    p.scfg.fieldPropagation = FieldPropagation.OBJ_GRAPH_NO_FIELD_MERGE;
    p.scfg.computeInterference = false;

    // The preliminary settings of WALAs AnalysisOptions
    p.options.setReflectionOptions(ReflectionOptions.FULL);
    AndroidEntryPointManager.MANAGER.setInstantiationBehavior(
        new DefaultInstantiationBehavior(cha));
    Util.addDefaultSelectors(p.options, cha);
    Util.addDefaultBypassLogic(p.options, scope, Util.class.getClassLoader(), cha); // ??

    // No changes to the settings of AndroidEntypointManager...
    // p.aem
    // p.entrypointLocatorFlags = EnumSet.of(LocatorFlags.EP_HEURISTIC, LocatorFlags.WITH_SUPER,
    //        LocatorFlags.INCLUDE_CALLBACKS, LocatorFlags.CB_HEURISTIC);
    p.entrypointLocatorFlags =
        EnumSet.of(
            LocatorFlags.EP_HEURISTIC, LocatorFlags.CB_HEURISTIC, LocatorFlags.INCLUDE_CALLBACKS);

    // The following selectors will be injected when Joana generates its new
    // AnalysisOptions
    // TODO: Add ReflectionContext ?
    p.ctxSel = new DefaultContextSelector(p.options, p.scfg.cha);
    p.ctxIpr = new DefaultSSAInterpreter(p.options, p.scfg.cache);
    p.instKeys = new ZeroXInstanceKeys(p.options, p.scfg.cha, p.ctxIpr, ZeroXInstanceKeys.NONE);

    LogLevels.setLevels();

    Preset.aem.setOverrides(AndroidEntryPointManager.DEFAULT_INTENT_OVERRIDES);
    // XXX TEMP:
    Preset.aem.setDoBootSequence(false);

    return p;
  }