コード例 #1
0
  private void initialize(Map<String, String> options) {
    if (drawer == null) {
      drawer = new CFGToDotGraph();
      drawer.setBriefLabels(PhaseOptions.getBoolean(options, briefLabelOptionName));
      drawer.setOnePage(!PhaseOptions.getBoolean(options, multipageOptionName));
      drawer.setUnexceptionalControlFlowAttr("color", "black");
      drawer.setExceptionalControlFlowAttr("color", "red");
      drawer.setExceptionEdgeAttr("color", "lightgray");
      drawer.setShowExceptions(Options.v().show_exception_dests());
      ir = CFGIntermediateRep.getIR(PhaseOptions.getString(options, irOptionName));
      graphtype = CFGGraphType.getGraphType(PhaseOptions.getString(options, graphTypeOptionName));

      AltClassLoader.v().setAltClassPath(PhaseOptions.getString(options, altClassPathOptionName));
      AltClassLoader.v()
          .setAltClasses(
              new String[] {
                "soot.toolkits.graph.ArrayRefBlockGraph",
                "soot.toolkits.graph.Block",
                "soot.toolkits.graph.Block$AllMapTo",
                "soot.toolkits.graph.BlockGraph",
                "soot.toolkits.graph.BriefBlockGraph",
                "soot.toolkits.graph.BriefUnitGraph",
                "soot.toolkits.graph.CompleteBlockGraph",
                "soot.toolkits.graph.CompleteUnitGraph",
                "soot.toolkits.graph.TrapUnitGraph",
                "soot.toolkits.graph.UnitGraph",
                "soot.toolkits.graph.ZonedBlockGraph",
              });
    }
  }
コード例 #2
0
  /**
   * Traverse the statements in the given body, looking for aggregation possibilities; that is,
   * given a def d and a use u, d has no other uses, u has no other defs, collapse d and u.
   *
   * <p>option: only-stack-locals; if this is true, only aggregate variables starting with $
   */
  protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
    StmtBody body = (StmtBody) b;
    boolean onlyStackVars = PhaseOptions.getBoolean(options, "only-stack-locals");

    int aggregateCount = 1;

    if (Options.v().time()) Timers.v().aggregationTimer.start();
    boolean changed = false;

    Map<ValueBox, Zone> boxToZone =
        new HashMap<ValueBox, Zone>(body.getUnits().size() * 2 + 1, 0.7f);

    // Determine the zone of every box
    {
      Zonation zonation = new Zonation(body);

      for (Unit u : body.getUnits()) {
        Zone zone = zonation.getZoneOf(u);

        for (ValueBox box : u.getUseBoxes()) {
          boxToZone.put(box, zone);
        }

        for (ValueBox box : u.getDefBoxes()) {
          boxToZone.put(box, zone);
        }
      }
    }

    do {
      if (Options.v().verbose())
        G.v()
            .out
            .println(
                "["
                    + body.getMethod().getName()
                    + "] Aggregating iteration "
                    + aggregateCount
                    + "...");

      // body.printTo(new java.io.PrintWriter(G.v().out, true));

      changed = internalAggregate(body, boxToZone, onlyStackVars);

      aggregateCount++;
    } while (changed);

    if (Options.v().time()) Timers.v().aggregationTimer.end();
  }
コード例 #3
0
ファイル: OnFlyCallGraph.java プロジェクト: safdariqbal/soot
 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();
 }
コード例 #4
0
ファイル: Scene.java プロジェクト: droidsec-cn/EC700-Epoch-2
  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);
    }
  }