private void load() {

    classCorr = getClassCorrespondence();
    addedClasses.addAll(classCorr.getAddedClasses());
    for (IClass cls : classCorr.getAddedClasses()) {
      addedMethods.addAll(cls.getDeclaredMethods());
      for (IMethod method : cls.getDeclaredMethods()) {
        addToMethodMap(method);
      }
    }
    deletedClasses.addAll(classCorr.getDeletedClasses());
    for (IClass cls : classCorr.getDeletedClasses()) {
      for (IMethod method : cls.getDeclaredMethods()) {
        addToMethodMap(method);
      }
    }
    Collection<Pair<IClass>> matchedClasses = classCorr.getMatchedClassPairs();
    for (Pair<IClass> matchedCls : matchedClasses) {
      boolean isClsMod = false;
      MethodCorrespondence methodCorr =
          new MethodCorrespondence(matchedCls.getFirst(), matchedCls.getSecond());
      for (IMethod method : methodCorr.getAddedMethods()) {
        addedMethods.add(method);
        addToMethodMap(method);
        isClsMod = true;
      }
      for (IMethod method : methodCorr.getDeletedMethods()) {
        deletedMethods.add(method);
        addToMethodMap(method);
        isClsMod = true;
      }
      Collection<Pair<IMethod>> matchedMethods = methodCorr.getMatchedMethodPairs();
      for (Pair<IMethod> matchedMeth : matchedMethods) {
        IMethod method1 = matchedMeth.getFirst();
        IMethod method2 = matchedMeth.getSecond();
        CFGNodeCorrespondence nodeCorr = new CFGNodeCorrespondence(method1, method2);
        if (nodeCorr.isMethodModified()) {
          modifiedMethods.add(matchedMeth);
          isClsMod = true;
        }
        addToMethodMap(nodeCorr.getMethodOneInfo());
        addToMethodMap(nodeCorr.getMethodTwoInfo());
      }
      if (isClsMod) {
        modifiedClasses.add(matchedCls);
      } else {
        unmodifiedClasses.add(matchedCls);
      }
    }
  }
 /**
  * Get all non-constructor, non-class-initializer methods declared by a class if their name is
  * equal to the specified name.
  *
  * @param cls the class
  * @param name the name
  */
 private Collection<IMethod> getDeclaredNormalMethods(IClass cls, Atom name) {
   Collection<IMethod> result = HashSetFactory.make();
   for (IMethod m : cls.getDeclaredMethods()) {
     if (!m.isInit() && !m.isClinit() && m.getSelector().getName().equals(name)) {
       result.add(m);
     }
   }
   return result;
 }
 public Collection<IMethod> getApp2Methods() {
   if (app2Methods == null) {
     app2Methods = new ArrayList<IMethod>();
     for (IClass cls : app2Classes) {
       app2Methods.addAll(cls.getDeclaredMethods());
     }
   }
   return app2Methods;
 }
Exemple #4
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);
        }
      }
    }
  }
 // add inter-procedural flow for local calls
 private void resolveLocalCalls(FlowGraph flowgraph) {
   for (IClass klass : cha) {
     for (IMethod method : klass.getDeclaredMethods()) {
       if (filterFunction(method)) {
         IR ir = cache.getIR(method);
         ir.visitAllInstructions(
             new LocalCallSSAVisitor(method, ir.getSymbolTable(), cache.getDefUse(ir), flowgraph));
       }
     }
   }
 }
  public static Iterable<Entrypoint> makePrimordialPublicEntrypoints(
      AnalysisScope scope, ClassHierarchy cha, String pkg) {
    final HashSet<Entrypoint> result = HashSetFactory.make();
    for (IClass clazz : cha) {

      if (clazz.getName().toString().indexOf(pkg) != -1
          && !clazz.isInterface()
          && !clazz.isAbstract()) {
        for (IMethod method : clazz.getDeclaredMethods()) {
          if (method.isPublic() && !method.isAbstract()) {
            System.out.println("Entry:" + method.getReference());
            result.add(new DefaultEntrypoint(method, cha));
          }
        }
      }
    }
    return new Iterable<Entrypoint>() {
      @Override
      public Iterator<Entrypoint> iterator() {
        return result.iterator();
      }
    };
  }