Beispiel #1
0
 public OnFlyCallGraph(PAG pag) {
   this.pag = pag;
   CGOptions options = new CGOptions(PhaseOptions.v().getPhaseOptions("cg"));
   if (options.all_reachable()) {
     List entryPoints = new ArrayList();
     entryPoints.addAll(EntryPoints.v().all());
     entryPoints.addAll(EntryPoints.v().methodsOfApplicationClasses());
     Scene.v().setEntryPoints(entryPoints);
   }
   callGraph = new CallGraph();
   Scene.v().setCallGraph(callGraph);
   ContextManager cm = CallGraphBuilder.makeContextManager(callGraph);
   reachableMethods = Scene.v().getReachableMethods();
   ofcgb = new OnFlyCallGraphBuilder(cm, reachableMethods);
   reachablesReader = reachableMethods.listener();
   callEdges = cm.callGraph().listener();
 }
Beispiel #2
0
  private void addReflectionTraceClasses() {
    CGOptions options = new CGOptions(PhaseOptions.v().getPhaseOptions("cg"));
    String log = options.reflection_log();

    Set<String> classNames = new HashSet<String>();
    if (log != null && log.length() > 0) {
      BufferedReader reader = null;
      String line = "";
      try {
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(log)));
        while ((line = reader.readLine()) != null) {
          if (line.length() == 0) continue;
          String[] portions = line.split(";", -1);
          String kind = portions[0];
          String target = portions[1];
          String source = portions[2];
          String sourceClassName = source.substring(0, source.lastIndexOf("."));
          classNames.add(sourceClassName);
          if (kind.equals("Class.forName")) {
            classNames.add(target);
          } else if (kind.equals("Class.newInstance")) {
            classNames.add(target);
          } else if (kind.equals("Method.invoke") || kind.equals("Constructor.newInstance")) {
            classNames.add(signatureToClass(target));
          } else if (kind.equals("Field.set*") || kind.equals("Field.get*")) {
            classNames.add(signatureToClass(target));
          } else throw new RuntimeException("Unknown entry kind: " + kind);
        }
      } catch (Exception e) {
        throw new RuntimeException("Line: '" + line + "'", e);
      } finally {
        if (reader != null)
          try {
            reader.close();
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
      }
    }

    for (String c : classNames) {
      addBasicClass(c, SootClass.BODIES);
    }
  }