Exemplo n.º 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);
        }
      }
    }
  }
 public Set<String> getSetOfLinesRelatedToAddedMethods() {
   Set<String> lineNumbersOfAddedMethods = new HashSet<String>();
   for (IMethod method : getAddedMethods()) {
     int getLineNumberOfFirstLineOfMethod = 0;
     try {
       getLineNumberOfFirstLineOfMethod =
           method.getLineNumber(1); // getMethodStartLineNumber(method);
     } catch (Exception e) {
     }
     lineNumbersOfAddedMethods.add(
         getClassName(method.getDeclaringClass()) + "," + getLineNumberOfFirstLineOfMethod);
   }
   return lineNumbersOfAddedMethods;
 }
Exemplo n.º 3
0
 /**
  * @param m a method reference
  * @return a SyntheticMethod corresponding to m; or null if none is available.
  */
 protected SyntheticMethod findOrCreateSyntheticMethod(IMethod m, boolean isStatic) {
   MethodReference ref = m.getReference();
   if (syntheticMethods.containsKey(ref)) {
     return syntheticMethods.get(ref);
   } else {
     MethodSummary summ = null;
     if (canIgnore(ref)) {
       summ = generateNoOp(ref, isStatic);
     } else {
       summ = findSummary(ref);
     }
     if (summ != null) {
       SummarizedMethod n = new SummarizedMethod(ref, summ, m.getDeclaringClass());
       syntheticMethods.put(ref, n);
       return n;
     } else {
       syntheticMethods.put(ref, null);
       return null;
     }
   }
 }
 public LocalCallSSAVisitor(IMethod method, SymbolTable symtab, DefUse du, FlowGraph flowgraph) {
   super(method, symtab, du);
   this.flowgraph = flowgraph;
   this.factory = flowgraph.getVertexFactory();
   this.caller = this.factory.makeFuncVertex(method.getDeclaringClass());
 }
Exemplo n.º 5
0
  private static SDGNode convertNode(SDGBuilder sdg, PDGNode node) {
    Operation op = null;
    Kind kind = null;
    int[] allocNodes = null;

    switch (node.getKind()) {
      case ACTUAL_IN:
        op = Operation.ACTUAL_IN;
        kind = Kind.ACTUAL_IN;
        break;
      case ACTUAL_OUT:
        op = Operation.ACTUAL_OUT;
        kind = Kind.ACTUAL_OUT;
        break;
      case CALL:
        op = Operation.CALL;
        kind = Kind.CALL;
        if (sdg.cfg.computeInterference) {
          TIntSet allocNodesAsSet = sdg.getAllocationNodes(node);
          if (allocNodesAsSet != null) {
            allocNodes = allocNodesAsSet.toArray();
          }
        }
        break;
      case ENTRY:
        op = Operation.ENTRY;
        kind = Kind.ENTRY;
        break;
      case EXIT:
        op = Operation.EXIT;
        kind = Kind.EXIT;
        break;
      case EXPRESSION:
        op = Operation.ASSIGN;
        kind = Kind.EXPRESSION;
        break;
      case FOLDED:
        op = Operation.COMPOUND;
        kind = Kind.FOLDED;
        break;
      case FORMAL_IN:
        op = Operation.FORMAL_IN;
        kind = Kind.FORMAL_IN;
        break;
      case FORMAL_OUT:
        op = Operation.FORMAL_OUT;
        kind = Kind.FORMAL_OUT;
        break;
      case HREAD:
        op = Operation.REFERENCE;
        kind = Kind.EXPRESSION;
        break;
      case HWRITE:
        op = Operation.MODIFY;
        kind = Kind.EXPRESSION;
        break;
      case JOIN:
        op = Operation.COMPOUND;
        kind = Kind.JOIN;
        break;
      case NEW:
        op = Operation.DECLARATION;
        kind = Kind.NORMAL;
        break;
      case NORMAL:
        op = Operation.COMPOUND;
        kind = Kind.NORMAL;
        break;
      case PHI:
        op = Operation.ASSIGN;
        kind = Kind.EXPRESSION;
        break;
      case PREDICATE:
        op = Operation.IF;
        kind = Kind.PREDICATE;
        break;
      case SYNCHRONIZATION:
        op = Operation.MONITOR;
        kind = Kind.SYNCHRONIZATION;
        break;
      default:
        throw new IllegalStateException("Unknown node kind: " + node.getKind().name());
    }
    SourceLocation sloc = node.getSourceLocation();

    SDGNode sn =
        new SecurityNode(
            node.getId(),
            op,
            node.getLabel(),
            node.getPdgId(),
            node.getType(),
            sloc.getSourceFile(),
            sloc.getStartRow(),
            sloc.getStartColumn(),
            sloc.getEndRow(),
            sloc.getEndColumn(),
            node.getBytecodeName(),
            node.getBytecodeIndex());

    if (node.getKind() == PDGNode.Kind.ENTRY) {
      PDG pdg = sdg.getPDGforId(node.getPdgId());
      IMethod im = pdg.getMethod();

      if (im != null) {
        IClass cls = im.getDeclaringClass();

        if (cls != null) {
          String clsLoader = cls.getClassLoader().toString();
          sn.setClassLoader(clsLoader);
        }
      }
    }

    if (allocNodes != null) {
      sn.setAllocationSites(allocNodes);
    }

    if (node.getAliasDataSources() != null) {
      sn.setAliasDataSources(node.getAliasDataSources());
    }

    assert sn.getKind() == kind;

    return sn;
  }
Exemplo n.º 6
0
 /** @param method An arbitrary method declared on a template class annotated with `@Capsule`. */
 public static boolean isProcedure(IMethod method) {
   assert isCapsuleTemplate(method.getDeclaringClass());
   return method.isPublic() == true // Only a capsule's public methods are procedures.
       && isSpecialCapsuleDecl(method) == false; // Don't count special decls as procedures.
 }
Exemplo n.º 7
0
 /** @param method An arbitrary method on a template class annotated with `@Capsule`. */
 public static boolean isSpecialCapsuleDecl(IMethod method) {
   assert isCapsuleTemplate(method.getDeclaringClass());
   return isNamed(method, "init") || isNamed(method, "design") || isNamed(method, "run");
 }
Exemplo n.º 8
0
 public static boolean isRemoteProcedure(IMethod method) {
   return isCapsuleInterface(method.getDeclaringClass());
 }