public static Process run(String[] args) throws IOException {
    try {
      validateCommandLine(args);
      String classpath = args[CLASSPATH_INDEX];
      AnalysisScope scope =
          AnalysisScopeReader.makeJavaBinaryAnalysisScope(
              classpath, (new FileProvider()).getFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS));

      // invoke WALA to build a class hierarchy
      ClassHierarchy cha = ClassHierarchy.make(scope);

      Graph<IClass> g = typeHierarchy2Graph(cha);

      g = pruneForAppLoader(g);
      String dotFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + DOT_FILE;
      String pdfFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + PDF_FILE;
      String dotExe = p.getProperty(WalaExamplesProperties.DOT_EXE);
      String gvExe = p.getProperty(WalaExamplesProperties.PDFVIEW_EXE);
      DotUtil.dotify(g, null, dotFile, pdfFile, dotExe);
      return PDFViewUtil.launchPDFView(pdfFile, gvExe);

    } catch (WalaException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    }
  }
Beispiel #2
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"));
   }
 }
Beispiel #3
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;
     }
   }
 }
  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;
  }
Beispiel #5
0
 @BeforeClass
 public static void before() throws IOException, ClassHierarchyException {
   AnalysisScope scope =
       AnalysisScopeReader.readJavaScope(
           TestConstants.WALA_TESTDATA,
           (new FileProvider()).getFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS),
           AnnotationTest.class.getClassLoader());
   cha = ClassHierarchy.make(scope);
 }
Beispiel #6
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);
        }
      }
    }
  }
Beispiel #7
0
  @Test
  public void testIO()
      throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
    AnalysisScope scope =
        CallGraphTestUtil.makeJ2SEAnalysisScope(
            "primordial.txt", CallGraphTestUtil.REGRESSION_EXCLUSIONS);
    ClassHierarchy cha = ClassHierarchy.make(scope);
    Iterable<Entrypoint> entrypoints = makePrimordialPublicEntrypoints(scope, cha, "java/io");
    AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);

    CallGraphTestUtil.buildZeroCFA(options, new AnalysisCache(), cha, scope, false);
  }
Beispiel #8
0
  @Test
  public void testHelloAllEntrypoints()
      throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
    if (analyzingJar()) return;
    AnalysisScope scope =
        CallGraphTestUtil.makeJ2SEAnalysisScope(
            TestConstants.HELLO, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
    ClassHierarchy cha = ClassHierarchy.make(scope);
    Iterable<Entrypoint> entrypoints = new AllApplicationEntrypoints(scope, cha);
    AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);

    doCallGraphs(options, new AnalysisCache(), cha, scope);
  }
Beispiel #9
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);
  }
  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;
  }
Beispiel #11
0
 /**
  * @param cha governing class hierarchy
  * @return the Set of CMR fields for this bean, including inherited CMRs
  */
 public static Set<Object> getCMRFields(
     BeanMetaData bean, DeploymentMetaData dmd, ClassHierarchy cha) {
   Set<Object> result = HashSetFactory.make(5);
   TypeReference T = bean.getEJBClass();
   while (T != null) {
     BeanMetaData B = dmd.getBeanMetaData(T);
     if (B != null) {
       result.addAll(B.getCMRFields());
     }
     IClass klass = cha.lookupClass(T);
     assert klass != null;
     IClass superKlass = klass.getSuperclass();
     T = (superKlass == null) ? null : superKlass.getReference();
   }
   return result;
 }
  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;
  }
Beispiel #13
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());
 }
Beispiel #14
0
  @Test
  public void testPrimordial()
      throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
    if (useShortProfile()) {
      return;
    }

    AnalysisScope scope =
        CallGraphTestUtil.makeJ2SEAnalysisScope(
            "primordial.txt",
            (System.getProperty("os.name").equals("Mac OS X"))
                ? "Java60RegressionExclusions.txt"
                : "GUIExclusions.txt");
    ClassHierarchy cha = ClassHierarchy.make(scope);
    Iterable<Entrypoint> entrypoints = makePrimordialMainEntrypoints(scope, cha);
    AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);

    CallGraphTestUtil.buildZeroCFA(options, new AnalysisCache(), cha, scope, false);
  }
  /**
   * Returns all concrete classes implementing the given interface or any subinterfaces
   *
   * @param iRoot
   * @return
   */
  public Collection<IClass> concreteClassesForInterface(IClass iRoot) {
    Set<IClass> clazzes = HashSetFactory.make();
    Set<IClass> done = HashSetFactory.make();
    Deque<IClass> todo = Queues.newArrayDeque();
    todo.push(iRoot);

    while (!todo.isEmpty()) {
      IClass i = todo.pop();
      for (IClass clazz : cha.getImplementors(i.getReference())) {
        if (clazz.isInterface() && !done.contains(clazz)) {
          done.add(i);
          todo.push(clazz);
        } else if (!clazz.isAbstract()) {
          clazzes.add(clazz);
        }
      }
    }

    return clazzes;
  }
Beispiel #16
0
  public JSCallGraph buildCG(URL url, BuilderType builderType, IProgressMonitor monitor)
      throws IOException, WalaException, CancelException {
    JavaScriptLoaderFactory loaders = makeLoaderFactory(url);
    SourceModule[] scripts;
    if (url.getFile().endsWith(".js")) {
      scripts =
          new SourceModule[] {
            new SourceURLModule(url), JSCallGraphBuilderUtil.getPrologueFile("prologue.js")
          };
    } else {
      scripts = JSCallGraphBuilderUtil.makeHtmlScope(url, loaders);
    }

    CAstAnalysisScope scope =
        new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS));
    IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS);
    Util.checkForFrontEndErrors(cha);
    Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha);
    FieldBasedCallGraphBuilder builder = null;

    AnalysisCache cache = new AnalysisCache(AstIRFactory.makeDefaultFactory());
    switch (builderType) {
      case PESSIMISTIC:
        builder =
            new PessimisticCallGraphBuilder(
                cha, JSCallGraphUtil.makeOptions(scope, cha, roots), cache);
        break;
      case OPTIMISTIC:
        builder =
            new OptimisticCallgraphBuilder(
                cha, JSCallGraphUtil.makeOptions(scope, cha, roots), cache);
        break;
      case OPTIMISTIC_WORKLIST:
        builder =
            new WorklistBasedOptimisticCallgraphBuilder(
                cha, JSCallGraphUtil.makeOptions(scope, cha, roots), cache);
        break;
    }

    return builder.buildCallGraph(roots, monitor).fst;
  }
Beispiel #17
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 exclusions
   * @param classpath
   * @param packagename
   * @throws IOException
   * @throws IllegalArgumentException
   * @throws CancelException
   * @throws ClassHierarchyException
   * @throws URISyntaxException
   */
  public AndroidAnalysisContext(ISCanDroidOptions options, String exclusions)
      throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException,
          URISyntaxException {
    logger.debug(DefaultSCanDroidOptions.dumpString(options));
    this.options = options;
    scope =
        AndroidAnalysisScope.setUpAndroidAnalysisScope(
            options.getClasspath(),
            exclusions,
            getClass().getClassLoader(),
            options.getAndroidLibrary());

    cha = ClassHierarchy.make(scope);

    if (options.classHierarchyWarnings()) {
      // log ClassHierarchy warnings
      for (Iterator<Warning> wi = Warnings.iterator(); wi.hasNext(); ) {
        Warning w = wi.next();
        logger.warn(w.getMsg());
      }
    }
    Warnings.clear();
  }
Beispiel #19
0
  @Test
  public void testCornerCases()
      throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
    AnalysisScope scope =
        CallGraphTestUtil.makeJ2SEAnalysisScope(
            TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
    ClassHierarchy cha = ClassHierarchy.make(scope);
    Iterable<Entrypoint> entrypoints = new AllApplicationEntrypoints(scope, cha);
    AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);

    doCallGraphs(options, new AnalysisCache(), cha, scope);

    // we expect a warning or two about class Abstract1, which has no concrete
    // subclasses
    String ws = Warnings.asString();
    Assert.assertTrue(
        "failed to report a warning about Abstract1", ws.indexOf("cornerCases/Abstract1") > -1);

    // we do not expect a warning about class Abstract2, which has a concrete
    // subclasses
    Assert.assertTrue(
        "reported a warning about Abstract2", ws.indexOf("cornerCases/Abstract2") == -1);
  }
Beispiel #20
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);
  }