Ejemplo n.º 1
0
  public static void main(String args[])
      throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {

    if (args.length != 1) {
      System.out.println("Usage: <URL of html page to analyze>");
      System.exit(1);
    }
    boolean domless = false;

    URL url = new URL(args[0]);

    // computing CG + PA
    JSCallGraphBuilderUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
    JavaScriptLoader.addBootstrapFile(WebUtil.preamble);

    SourceModule[] sources = getSources(domless, url);

    JSCFABuilder builder =
        makeCGBuilder(
            new WebPageLoaderFactory(translatorFactory),
            sources,
            CGBuilderType.ZERO_ONE_CFA,
            AstIRFactory.makeDefaultFactory());
    builder.setBaseURL(url);

    CallGraph cg = builder.makeCallGraph(builder.getOptions());
    PointerAnalysis pa = builder.getPointerAnalysis();

    new JsViewer(cg, pa);
  }
Ejemplo n.º 2
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;
  }