示例#1
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);
        }
      }
    }
  }
示例#2
0
  /**
   * @param args
   * @throws CancelException
   * @throws UnsoundGraphException
   * @throws IOException
   * @throws WalaException
   * @throws PDGFormatException
   * @throws IllegalArgumentException
   */
  public static void main(String[] args)
      throws IOException, UnsoundGraphException, CancelException, IllegalArgumentException,
          PDGFormatException, WalaException {
    // check for ifc annotations

    System.out.print("Parsing source files for ifc annotations... ");
    List<ClassInfo> clsInfos = MoJo.parseSourceFiles("../joana.wala.modular.testdata/src");
    System.out.println("done.");
    System.out.print("Checking for syntactic errors... ");
    final int errors = MoJo.prepareFlowLessStmts(clsInfos);
    if (errors > 0) {
      System.out.print("(" + errors + " errors) ");
    }
    System.out.println("done.");

    // prepare base sdg

    MethodListCheck mlc = new MethodListCheck(null, "./out/", /* do debug output */ false);

    for (ClassInfo cls : clsInfos) {
      for (MethodInfo m : cls.getMethods()) {
        if (m.hasIFCStmts()) {
          // mark as external call targets
          //					System.err.println(m.toString());
          mlc.addMethod(m);
        }
      }
    }

    //		mlc.addMethod("module.Module.encrypt(II)I");
    //		mlc.addMethod("module.Module.encrypt(Lmodule/Module$Message;I)Lmodule/Module$Message;");

    Config cfg =
        new Config(
            "program",
            "program.Program.main([Ljava/lang/String;)V",
            "../joana.wala.modular.testdata/dist/mojo-test-program.jar",
            PointsToPrecision.CONTEXT_SENSITIVE,
            ExceptionAnalysis.INTRAPROC,
            false,
            Main.STD_EXCLUSION_REG_EXP,
            "../../contrib/lib/stubs/natives_empty.xml",
            "../../contrib/lib/stubs/jSDG-stubs-jre1.4.jar",
            mlc,
            "./out/",
            FieldPropagation.FLAT);

    Main.run(System.out, cfg);

    // precompute library methods
    final String binlib1 = "../joana.wala.modular.testdata/dist/mojo-test-modules1.jar";
    runComputeModule(binlib1, cfg, "./out/lib_module1");

    final String binlib2 = "../joana.wala.modular.testdata/dist/mojo-test-modules2.jar";
    runComputeModule(binlib2, cfg, "./out/lib_module2");

    // merge precomputed dependency graphs
    final ModuleCFG mainModule =
        new ModuleCFG(
            "program.Program.main([Ljava/lang/String;)V",
            "../joana.wala.modular.testdata/dist/mojo-test-program.jar");
    final ModuleCFG[] otherModules1 =
        new ModuleCFG[] {
          new ModuleCFG("module1", "../joana.wala.modular.testdata/dist/mojo-test-modules1.jar")
        };
    MergeModules.runMergeModules("merge_modules1", "./out/", mainModule, otherModules1, mlc);

    final ModuleCFG[] otherModules2 =
        new ModuleCFG[] {
          new ModuleCFG("module2", "../joana.wala.modular.testdata/dist/mojo-test-modules2.jar")
        };
    MergeModules.runMergeModules("merge_modules2", "./out/", mainModule, otherModules2, mlc);
  }