コード例 #1
0
ファイル: ThrowableSet.java プロジェクト: safdariqbal/soot
    /**
     * Returns a <code>ThrowableSet</code> representing the set of exceptions included in <code>
     * include</code> minus the set of exceptions included in <code>exclude</code>. Creates a new
     * <code>ThrowableSet</code> only if there was not already one whose contents correspond to
     * <code>include</code> - <code>exclude</code>.
     *
     * @param include A set of {@link RefLikeType} objects representing exception types included in
     *     the result; may be <code>null</code> if there are no included types.
     * @param exclude A set of {@link AnySubType} objects representing exception types excluded from
     *     the result; may be <code>null</code> if there are no excluded types.
     * @return a <code>ThrowableSet</code> representing the set of exceptions corresponding to
     *     <code>include</code> - <code>exclude</code>.
     */
    private ThrowableSet registerSetIfNew(Set include, Set exclude) {
      if (INSTRUMENTING) {
        registrationCalls++;
      }
      if (include == null) {
        include = Collections.EMPTY_SET;
      }
      if (exclude == null) {
        exclude = Collections.EMPTY_SET;
      }
      int size = include.size() + exclude.size();
      Integer sizeKey = new Integer(size);

      List sizeList = (List) sizeToSets.get(sizeKey);
      if (sizeList == null) {
        sizeList = new LinkedList();
        sizeToSets.put(sizeKey, sizeList);
      }
      for (Iterator i = sizeList.iterator(); i.hasNext(); ) {
        ThrowableSet set = (ThrowableSet) i.next();
        if (set.exceptionsIncluded.equals(include) && set.exceptionsExcluded.equals(exclude)) {
          return set;
        }
      }
      if (INSTRUMENTING) {
        registeredSets++;
      }
      ThrowableSet result = new ThrowableSet(include, exclude);
      sizeList.add(result);
      return result;
    }
コード例 #2
0
ファイル: LatestComputation.java プロジェクト: richardxx/soot
  /**
   * given a DelayabilityAnalysis and the computations of each unit, calculates the latest
   * computation-point for each expression.<br>
   * the <code>equivRhsMap</code> could be calculated on the fly, but it is <b>very</b> likely that
   * it already exists (as similar maps are used for calculating Earliestness, Delayed,...<br>
   * the shared set allows more efficient set-operations, when they the computation is merged with
   * other analyses/computations.
   *
   * @param dg a ExceptionalUnitGraph
   * @param delayed the delayability-analysis of the same graph.
   * @param equivRhsMap all computations of the graph
   * @param set the shared flowSet
   */
  public LatestComputation(
      UnitGraph unitGraph, DelayabilityAnalysis delayed, Map equivRhsMap, BoundedFlowSet set) {
    unitToLatest = new HashMap<Unit, FlowSet>(unitGraph.size() + 1, 0.7f);

    Iterator unitIt = unitGraph.iterator();
    while (unitIt.hasNext()) {
      /* create a new Earliest-list for each unit */
      Unit currentUnit = (Unit) unitIt.next();

      /* basically the latest-set is:
       * (delayed) INTERSECT (comp UNION (UNION_successors ~Delayed)) =
       * (delayed) MINUS ((INTERSECTION_successors Delayed) MINUS comp).
       */

      FlowSet delaySet = (FlowSet) delayed.getFlowBefore(currentUnit);

      /* Calculate (INTERSECTION_successors Delayed) */
      FlowSet succCompSet = (FlowSet) set.topSet();
      List succList = unitGraph.getSuccsOf(currentUnit);
      Iterator succIt = succList.iterator();
      while (succIt.hasNext()) {
        Unit successor = (Unit) succIt.next();
        succCompSet.intersection((FlowSet) delayed.getFlowBefore(successor), succCompSet);
      }
      /* remove the computation of this set: succCompSet is then:
       * ((INTERSECTION_successors Delayed) MINUS comp) */
      if (equivRhsMap.get(currentUnit) != null) succCompSet.remove(equivRhsMap.get(currentUnit));

      /* make the difference: */
      FlowSet latest = (FlowSet) delaySet.emptySet();
      delaySet.difference(succCompSet, latest);

      unitToLatest.put(currentUnit, latest);
    }
  }
コード例 #3
0
ファイル: UnitGraph.java プロジェクト: safdariqbal/soot
  /**
   * Utility method used in the construction of {@link UnitGraph}s, to be called only after the
   * unitToPreds and unitToSuccs maps have been built.
   *
   * <p><code>UnitGraph</code> provides an implementation of <code>buildHeadsAndTails()</code> which
   * defines the graph's set of heads to include the first {@link Unit} in the graph's body,
   * together with any other <tt>Unit</tt> which has no predecessors. It defines the graph's set of
   * tails to include all <tt>Unit</tt>s with no successors. Subclasses of <code>UnitGraph</code>
   * may override this method to change the criteria for classifying a node as a head or tail.
   */
  protected void buildHeadsAndTails() {
    List tailList = new ArrayList();
    List headList = new ArrayList();

    for (Iterator unitIt = unitChain.iterator(); unitIt.hasNext(); ) {
      Unit s = (Unit) unitIt.next();
      List succs = (List) unitToSuccs.get(s);
      if (succs.size() == 0) {
        tailList.add(s);
      }
      List preds = (List) unitToPreds.get(s);
      if (preds.size() == 0) {
        headList.add(s);
      }
    }

    // Add the first Unit, even if it is the target of
    // a branch.
    Unit entryPoint = (Unit) unitChain.getFirst();
    if (!headList.contains(entryPoint)) {
      headList.add(entryPoint);
    }

    tails = Collections.unmodifiableList(tailList);
    heads = Collections.unmodifiableList(headList);
  }
コード例 #4
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  private void addBoxToPatch(String aLabelName, UnitBox aUnitBox) {
    List patchList = (List) mLabelToPatchList.get(aLabelName);
    if (patchList == null) {
      patchList = new ArrayList();
      mLabelToPatchList.put(aLabelName, patchList);
    }

    patchList.add(aUnitBox);
  }
コード例 #5
0
  protected void flowThrough(Object inValue, Object unit, Object outValue) {
    FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue;

    // Perform kill
    in.difference(unitToKillSet.get(unit), out);

    // Perform generation
    out.union(unitToGenerateSet.get(unit), out);
  }
コード例 #6
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();
  }
コード例 #7
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
 protected void buildMaps(PegGraph pg) {
   exceHandlers.addAll(pg.getExceHandlers());
   startToThread.putAll(pg.getStartToThread());
   startToAllocNodes.putAll(pg.getStartToAllocNodes());
   startToBeginNodes.putAll(pg.getStartToBeginNodes());
   waitingNodes.putAll(pg.getWaitingNodes());
   notifyAll.putAll(pg.getNotifyAll());
   canNotBeCompacted.addAll(pg.getCanNotBeCompacted());
   synch.addAll(pg.getSynch());
   threadNameToStart.putAll(pg.getThreadNameToStart());
   specialJoin.addAll(pg.getSpecialJoin());
   joinStmtToThread.putAll(pg.getJoinStmtToThread());
   threadAllocSites.addAll(pg.getThreadAllocSites());
   allocNodeToThread.putAll(pg.getAllocNodeToThread());
 }
コード例 #8
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outALocalImmediate(ALocalImmediate node) {
    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);
    mProductions.addLast(l);
  }
コード例 #9
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outANonstaticInvokeExpr(ANonstaticInvokeExpr node) {
    List args;

    if (node.getArgList() != null) args = (List) mProductions.removeLast();
    else args = new ArrayList();

    SootMethodRef method = (SootMethodRef) mProductions.removeLast();

    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);

    Node invokeType = (Node) node.getNonstaticInvoke();
    Expr invokeExpr;

    if (invokeType instanceof ASpecialNonstaticInvoke) {
      invokeExpr = Jimple.v().newSpecialInvokeExpr(l, method, args);
    } else if (invokeType instanceof AVirtualNonstaticInvoke) {
      invokeExpr = Jimple.v().newVirtualInvokeExpr(l, method, args);
    } else {
      if (debug)
        if (!(invokeType instanceof AInterfaceNonstaticInvoke))
          throw new RuntimeException("expected interface invoke.");
      invokeExpr = Jimple.v().newInterfaceInvokeExpr(l, method, args);
    }

    mProductions.addLast(invokeExpr);
  }
コード例 #10
0
ファイル: LatestComputation.java プロジェクト: richardxx/soot
 /**
  * given a DelayabilityAnalysis and the computations of each unit, calculates the latest
  * computation-point for each expression. the <code>equivRhsMap</code> could be calculated on the
  * fly, but it is <b>very</b> likely that it already exists (as similar maps are used for
  * calculating Earliestness, Delayed,...
  *
  * @param dg a ExceptionalUnitGraph
  * @param delayed the delayability-analysis of the same graph.
  * @param equivRhsMap all computations of the graph
  */
 public LatestComputation(UnitGraph unitGraph, DelayabilityAnalysis delayed, Map equivRhsMap) {
   this(
       unitGraph,
       delayed,
       equivRhsMap,
       new ArrayPackedSet(new CollectionFlowUniverse(equivRhsMap.values())));
 }
コード例 #11
0
ファイル: UnitGraph.java プロジェクト: safdariqbal/soot
 /**
  * Utility method for adding an edge to maps representing the CFG.
  *
  * @param unitToSuccs The {@link Map} from {@link Unit}s to {@link List}s of their successors.
  * @param unitToPreds The {@link Map} from {@link Unit}s to {@link List}s of their successors.
  * @param head The {@link Unit} from which the edge starts.
  * @param tail The {@link Unit} to which the edge flows.
  */
 protected void addEdge(Map unitToSuccs, Map unitToPreds, Unit head, Unit tail) {
   List headsSuccs = (List) unitToSuccs.get(head);
   if (headsSuccs == null) {
     headsSuccs = new ArrayList(3); // We expect this list to
     // remain short.
     unitToSuccs.put(head, headsSuccs);
   }
   if (!headsSuccs.contains(tail)) {
     headsSuccs.add(tail);
     List tailsPreds = (List) unitToPreds.get(tail);
     if (tailsPreds == null) {
       tailsPreds = new ArrayList();
       unitToPreds.put(tail, tailsPreds);
     }
     tailsPreds.add(head);
   }
 }
コード例 #12
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outAIdentityNoTypeStatement(AIdentityNoTypeStatement node) {
    mProductions.removeLast(); // get rid of @caughtexception string presently on top of the stack
    Value local =
        (Value) mLocals.get(mProductions.removeLast()); // the local ref from it's identifier

    Unit u = Jimple.v().newIdentityStmt(local, Jimple.v().newCaughtExceptionRef());
    mProductions.addLast(u);
  }
コード例 #13
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outAArrayRef(AArrayRef node) {
    Value immediate = (Value) mProductions.removeLast();
    String identifier = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(identifier);
    if (l == null) throw new RuntimeException("did not find local: " + identifier);

    mProductions.addLast(Jimple.v().newArrayRef(l, immediate));
  }
コード例 #14
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outALocalFieldRef(ALocalFieldRef node) {
    SootFieldRef field = (SootFieldRef) mProductions.removeLast();

    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);

    mProductions.addLast(Jimple.v().newInstanceFieldRef(l, field));
  }
コード例 #15
0
  protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
    initialize(options);
    SootMethod meth = b.getMethod();

    if ((methodsToPrint == null)
        || (meth.getDeclaringClass().getName() == methodsToPrint.get(meth.getName()))) {
      Body body = ir.getBody((JimpleBody) b);
      print_cfg(body);
    }
  }
コード例 #16
0
ファイル: UnitGraph.java プロジェクト: safdariqbal/soot
  /**
   * Utility method for <tt>UnitGraph</tt> constructors. It computes the edges corresponding to
   * unexceptional control flow.
   *
   * @param unitToSuccs A {@link Map} from {@link Unit}s to {@link List}s of {@link Unit}s. This is
   *     an ``out parameter''; callers must pass an empty {@link Map}.
   *     <tt>buildUnexceptionalEdges</tt> will add a mapping for every <tt>Unit</tt> in the body to
   *     a list of its unexceptional successors.
   * @param unitToPreds A {@link Map} from {@link Unit}s to {@link List}s of {@link Unit}s. This is
   *     an ``out parameter''; callers must pass an empty {@link Map}.
   *     <tt>buildUnexceptionalEdges</tt> will add a mapping for every <tt>Unit</tt> in the body to
   *     a list of its unexceptional predecessors.
   */
  protected void buildUnexceptionalEdges(Map unitToSuccs, Map unitToPreds) {

    // Initialize the predecessor sets to empty
    for (Iterator unitIt = unitChain.iterator(); unitIt.hasNext(); ) {
      unitToPreds.put(unitIt.next(), new ArrayList());
    }

    Iterator unitIt = unitChain.iterator();
    Unit currentUnit, nextUnit;

    nextUnit = unitIt.hasNext() ? (Unit) unitIt.next() : null;

    while (nextUnit != null) {
      currentUnit = nextUnit;
      nextUnit = unitIt.hasNext() ? (Unit) unitIt.next() : null;

      List successors = new ArrayList();

      if (currentUnit.fallsThrough()) {
        // Add the next unit as the successor
        if (nextUnit != null) {
          successors.add(nextUnit);
          ((List) unitToPreds.get(nextUnit)).add(currentUnit);
        }
      }

      if (currentUnit.branches()) {
        for (Iterator targetIt = currentUnit.getUnitBoxes().iterator(); targetIt.hasNext(); ) {
          Unit target = ((UnitBox) targetIt.next()).getUnit();
          // Arbitrary bytecode can branch to the same
          // target it falls through to, so we screen for duplicates:
          if (!successors.contains(target)) {
            successors.add(target);
            ((List) unitToPreds.get(target)).add(currentUnit);
          }
        }
      }

      // Store away successors
      unitToSuccs.put(currentUnit, successors);
    }
  }
コード例 #17
0
ファイル: UnitGraph.java プロジェクト: safdariqbal/soot
 /**
  * Utility method that replaces the values of a {@link Map}, which must be instances of {@link
  * List}, with unmodifiable equivalents.
  *
  * @param map The map whose values are to be made unmodifiable.
  */
 protected static void makeMappedListsUnmodifiable(Map map) {
   for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
     Map.Entry entry = (Map.Entry) it.next();
     List value = (List) entry.getValue();
     if (value.size() == 0) {
       entry.setValue(Collections.EMPTY_LIST);
     } else {
       entry.setValue(Collections.unmodifiableList(value));
     }
   }
 }
コード例 #18
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  public void computeMonitorObjs() {
    Set maps = monitor.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();

      FlowSet fs = (FlowSet) entry.getValue();
      Iterator it = fs.iterator();
      while (it.hasNext()) {
        Object obj = it.next();
        if (!monitorObjs.contains(obj)) monitorObjs.add(obj);
      }
    }
  }
コード例 #19
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void testJoinStmtToThread() {
    System.out.println("=====test JoinStmtToThread");
    Set maps = threadNameToStart.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      Object key = entry.getKey();

      System.out.println("---key=  " + key);

      System.out.println("value: " + entry.getValue());
    }
    System.out.println("=========JoinStmtToThread--ends--------");
  }
コード例 #20
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outADeclaration(ADeclaration node) {
    List localNameList = (List) mProductions.removeLast();
    Type type = (Type) mProductions.removeLast();
    Iterator it = localNameList.iterator();
    List localList = new ArrayList();

    while (it.hasNext()) {
      Local l = Jimple.v().newLocal((String) it.next(), type);
      mLocals.put(l.getName(), l);
      localList.add(l);
    }
    mProductions.addLast(localList);
  }
コード例 #21
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void testThreadNameToStart() {
    System.out.println("=====test ThreadNameToStart");
    Set maps = threadNameToStart.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      Object key = entry.getKey();

      System.out.println("---key=  " + key);
      JPegStmt stmt = (JPegStmt) entry.getValue();
      Tag tag1 = (Tag) stmt.getTags().get(0);
      System.out.println("value: " + tag1 + " " + stmt);
    }
    System.out.println("=========ThreadNameToStart--ends--------");
  }
コード例 #22
0
ファイル: ThrowableSet.java プロジェクト: safdariqbal/soot
 /**
  * Report the counts collected by instrumentation (for now, at least, there is no need to
  * provide access to the individual values as numbers).
  *
  * @return a string listing the counts.
  */
 public String reportInstrumentation() {
   int setCount = 0;
   for (Iterator it = sizeToSets.values().iterator(); it.hasNext(); ) {
     List sizeList = (List) it.next();
     setCount += sizeList.size();
   }
   if (setCount != registeredSets) {
     throw new IllegalStateException(
         "ThrowableSet.reportInstrumentation() assertion failure: registeredSets != list count");
   }
   StringBuffer buf =
       new StringBuffer("registeredSets: ")
           .append(setCount)
           .append("\naddsOfRefType: ")
           .append(addsOfRefType)
           .append("\naddsOfAnySubType: ")
           .append(addsOfAnySubType)
           .append("\naddsOfSet: ")
           .append(addsOfSet)
           .append("\naddsInclusionFromMap: ")
           .append(addsInclusionFromMap)
           .append("\naddsInclusionFromMemo: ")
           .append(addsInclusionFromMemo)
           .append("\naddsInclusionFromSearch: ")
           .append(addsInclusionFromSearch)
           .append("\naddsInclusionInterrupted: ")
           .append(addsInclusionInterrupted)
           .append("\naddsExclusionWithoutSearch: ")
           .append(addsExclusionWithoutSearch)
           .append("\naddsExclusionWithSearch: ")
           .append(addsExclusionWithSearch)
           .append("\nremovesOfAnySubType: ")
           .append(removesOfAnySubType)
           .append("\nremovesFromMap: ")
           .append(removesFromMap)
           .append("\nremovesFromMemo: ")
           .append(removesFromMemo)
           .append("\nremovesFromSearch: ")
           .append(removesFromSearch)
           .append("\nregistrationCalls: ")
           .append(registrationCalls)
           .append("\ncatchableAsQueries: ")
           .append(catchableAsQueries)
           .append("\ncatchableAsFromMap: ")
           .append(catchableAsFromMap)
           .append("\ncatchableAsFromSearch: ")
           .append(catchableAsFromSearch)
           .append('\n');
   return buf.toString();
 }
コード例 #23
0
  /**
   * Computes the analysis given a UnitGraph computed from a method body. It is recommended that a
   * ExceptionalUnitGraph (or similar) be provided for correct results in the case of exceptional
   * control flow.
   *
   * @param g a graph on which to compute the analysis.
   * @see ExceptionalUnitGraph
   */
  public SimpleLiveLocals(UnitGraph graph) {
    if (Options.v().time()) Timers.v().liveTimer.start();

    if (Options.v().verbose())
      G.v()
          .out
          .println(
              "["
                  + graph.getBody().getMethod().getName()
                  + "]     Constructing SimpleLiveLocals...");

    SimpleLiveLocalsAnalysis analysis = new SimpleLiveLocalsAnalysis(graph);

    if (Options.v().time()) Timers.v().livePostTimer.start();

    // Build unitToLocals map
    {
      unitToLocalsAfter = new HashMap<Unit, List>(graph.size() * 2 + 1, 0.7f);
      unitToLocalsBefore = new HashMap<Unit, List>(graph.size() * 2 + 1, 0.7f);

      Iterator unitIt = graph.iterator();

      while (unitIt.hasNext()) {
        Unit s = (Unit) unitIt.next();

        FlowSet set = (FlowSet) analysis.getFlowBefore(s);
        unitToLocalsBefore.put(s, Collections.unmodifiableList(set.toList()));

        set = (FlowSet) analysis.getFlowAfter(s);
        unitToLocalsAfter.put(s, Collections.unmodifiableList(set.toList()));
      }
    }

    if (Options.v().time()) Timers.v().livePostTimer.end();

    if (Options.v().time()) Timers.v().liveTimer.end();
  }
コード例 #24
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  public void testMonitor() {
    System.out.println("=====test monitor size: " + monitor.size());
    Set maps = monitor.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      String key = (String) entry.getKey();

      System.out.println("---key=  " + key);
      FlowSet list = (FlowSet) entry.getValue();
      if (list.size() > 0) {

        System.out.println("**set:  " + list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
          Object obj = it.next();
          if (obj instanceof JPegStmt) {
            JPegStmt stmt = (JPegStmt) obj;
            Tag tag1 = (Tag) stmt.getTags().get(0);
            System.out.println(tag1 + " " + stmt);
          } else {
            System.out.println("---list---");
            Iterator listIt = ((List) obj).iterator();
            while (listIt.hasNext()) {
              Object oo = listIt.next();
              if (oo instanceof JPegStmt) {
                JPegStmt unit = (JPegStmt) oo;
                Tag tag = (Tag) unit.getTags().get(0);
                System.out.println(tag + " " + unit);
              } else System.out.println(oo);
            }
            System.out.println("---list--end-");
          }
        }
      }
    }
    System.out.println("=========monitor--ends--------");
  }
コード例 #25
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outAIdentityStatement(AIdentityStatement node) {
    Type identityRefType = (Type) mProductions.removeLast();
    String atClause = (String) mProductions.removeLast();
    Value local =
        (Value) mLocals.get(mProductions.removeLast()); // the local ref from it's identifier

    Value ref = null;
    if (atClause.startsWith("@this")) {
      ref = Jimple.v().newThisRef((RefType) identityRefType);
    } else if (atClause.startsWith("@parameter")) {
      int index = Integer.parseInt(atClause.substring(10, atClause.length() - 1));

      ref = Jimple.v().newParameterRef(identityRefType, index);
    } else
      throw new RuntimeException(
          "shouldn't @caughtexception be handled by outAIdentityNoTypeStatement: got" + atClause);

    Unit u = Jimple.v().newIdentityStmt(local, ref);
    mProductions.addLast(u);
  }
コード例 #26
0
ファイル: UnitGraph.java プロジェクト: safdariqbal/soot
  /**
   * Utility method that produces a new map from the {@link Unit}s of this graph's body to the union
   * of the values stored in the two argument {@link Map}s, used to combine the maps of exceptional
   * and unexceptional predecessors and successors into maps of all predecessors and successors. The
   * values stored in both argument maps must be {@link List}s of {@link Unit}s, which are assumed
   * not to contain any duplicate <tt>Unit</tt>s.
   *
   * @param mapA The first map to be combined.
   * @param mapB The second map to be combined.
   */
  protected Map combineMapValues(Map mapA, Map mapB) {
    // The duplicate screen
    Map result = new HashMap(mapA.size() * 2 + 1, 0.7f);
    for (Iterator chainIt = unitChain.iterator(); chainIt.hasNext(); ) {
      Unit unit = (Unit) chainIt.next();
      List listA = (List) mapA.get(unit);
      if (listA == null) {
        listA = Collections.EMPTY_LIST;
      }
      List listB = (List) mapB.get(unit);
      if (listB == null) {
        listB = Collections.EMPTY_LIST;
      }

      int resultSize = listA.size() + listB.size();
      if (resultSize == 0) {
        result.put(unit, Collections.EMPTY_LIST);
      } else {
        List resultList = new ArrayList(resultSize);
        Iterator listIt = null;
        // As a minor optimization of the duplicate screening,
        // copy the longer list first.
        if (listA.size() >= listB.size()) {
          resultList.addAll(listA);
          listIt = listB.iterator();
        } else {
          resultList.addAll(listB);
          listIt = listA.iterator();
        }
        while (listIt.hasNext()) {
          Object element = listIt.next();
          // It is possible for there to be both an exceptional
          // and an unexceptional edge connecting two Units
          // (though probably not in a class generated by
          // javac), so we need to screen for duplicates. On the
          // other hand, we expect most of these lists to have
          // only one or two elements, so it doesn't seem worth
          // the cost to build a Set to do the screening.
          if (!resultList.contains(element)) {
            resultList.add(element);
          }
        }
        result.put(unit, Collections.unmodifiableList(resultList));
      }
    }
    return result;
  }
コード例 #27
0
ファイル: ThrowableSet.java プロジェクト: safdariqbal/soot
 /**
  * Returns a <code>ThrowableSet</code> which contains all the exceptions in <code>s</code> in
  * addition to those in this <code>ThrowableSet</code>.
  *
  * @param s set of exceptions to add to this set.
  * @return the union of this set with <code>s</code>
  * @throws ThrowableSet.AlreadyHasExclusionsException if this <code>ThrowableSet</code> or <code>s
  *     </code> is the result of a {@link #whichCatchableAs(RefType)} operation, so that it is not
  *     possible to represent the addition of <code>s</code> to this <code>ThrowableSet</code>.
  */
 public ThrowableSet add(ThrowableSet s) throws ThrowableSet.AlreadyHasExclusionsException {
   if (INSTRUMENTING) {
     Manager.v().addsOfSet++;
   }
   if (exceptionsExcluded.size() > 0 || s.exceptionsExcluded.size() > 0) {
     throw new AlreadyHasExclusionsException(
         "ThrowableSet.Add(ThrowableSet): attempt to add to ["
             + this.toString()
             + "] after removals recorded.");
   }
   ThrowableSet result = getMemoizedAdds(s);
   if (result == null) {
     if (INSTRUMENTING) {
       Manager.v().addsInclusionFromSearch++;
       Manager.v().addsExclusionWithoutSearch++;
     }
     result = this.add(s.exceptionsIncluded);
     memoizedAdds.put(s, result);
   } else if (INSTRUMENTING) {
     Manager.v().addsInclusionFromMemo++;
     Manager.v().addsExclusionWithoutSearch++;
   }
   return result;
 }
コード例 #28
0
ファイル: UnitGraph.java プロジェクト: safdariqbal/soot
  public List getSuccsOf(Object u) {
    if (!unitToSuccs.containsKey(u)) throw new RuntimeException("Invalid unit " + u);

    return (List) unitToSuccs.get(u);
  }
コード例 #29
0
ファイル: ThrowableSet.java プロジェクト: safdariqbal/soot
  /**
   * Returns a <code>ThrowableSet</code> which contains <code>e</code> and all of its subclasses as
   * well as the exceptions in this set.
   *
   * <p><code>e</code> should be an instance of {@link AnySubType} if you know that the compile-time
   * type of the exception you are representing is <code>e</code>, but the exception may be
   * instantiated at run-time by a subclass of <code>e</code>.
   *
   * <p>For example, if you were recording the type of the exception thrown by
   *
   * <pre>
   * catch (IOException e) {
   *    throw e;
   * }
   * </pre>
   *
   * you would call
   *
   * <pre>
   * <code>add(AnySubtype.v(Scene.v().getRefType("java.lang.Exception.IOException")))</code>
   * </pre>
   *
   * since the handler might rethrow any subclass of <code>IOException</code>.
   *
   * @param e represents a subtree of the exception class hierarchy to add to this set.
   * @return a set containing <code>e</code> and all its subclasses, as well as the exceptions
   *     represented by this set.
   * @throws ThrowableSet.AlreadyHasExclusionsException if this <code>ThrowableSet</code> is the
   *     result of a {@link #whichCatchableAs(RefType)} operation and, thus, unable to represent the
   *     addition of <code>e</code>.
   */
  public ThrowableSet add(AnySubType e) throws ThrowableSet.AlreadyHasExclusionsException {
    if (INSTRUMENTING) {
      Manager.v().addsOfAnySubType++;
    }

    ThrowableSet result = getMemoizedAdds(e);
    if (result != null) {
      if (INSTRUMENTING) {
        Manager.v().addsInclusionFromMemo++;
        Manager.v().addsExclusionWithoutSearch++;
      }
      return result;
    } else {
      FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();
      RefType newBase = e.getBase();

      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() != 0) {
          Manager.v().addsExclusionWithSearch++;
        } else {
          Manager.v().addsExclusionWithoutSearch++;
        }
      }
      for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
        RefType exclusionBase = ((AnySubType) i.next()).getBase();
        if (hierarchy.canStoreType(newBase, exclusionBase)
            || hierarchy.canStoreType(exclusionBase, newBase)) {
          if (INSTRUMENTING) {
            // To ensure that the subcategories total properly:
            Manager.v().addsInclusionInterrupted++;
          }
          throw new AlreadyHasExclusionsException(
              "ThrowableSet.add("
                  + e.toString()
                  + ") to the set [ "
                  + this.toString()
                  + "] where "
                  + exclusionBase.toString()
                  + " is excluded.");
        }
      }

      if (this.exceptionsIncluded.contains(e)) {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromMap++;
        }
        return this;

      } else {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromSearch++;
        }

        int changes = 0;
        boolean addNewException = true;
        Set resultSet = new HashSet();

        for (Iterator i = this.exceptionsIncluded.iterator(); i.hasNext(); ) {
          RefLikeType incumbent = (RefLikeType) i.next();
          if (incumbent instanceof RefType) {
            if (hierarchy.canStoreType(incumbent, newBase)) {
              // Omit incumbent from result.
              changes++;
            } else {
              resultSet.add(incumbent);
            }
          } else if (incumbent instanceof AnySubType) {
            RefType incumbentBase = ((AnySubType) incumbent).getBase();
            // We have to use the base types in these hierarchy calls
            // because we want to know if _all_ possible
            // types represented by e can be represented by
            // the incumbent, or vice versa.
            if (hierarchy.canStoreType(newBase, incumbentBase)) {
              addNewException = false;
              resultSet.add(incumbent);
            } else if (hierarchy.canStoreType(incumbentBase, newBase)) {
              // Omit incumbent from result;
              changes++;
            } else {
              resultSet.add(incumbent);
            }
          } else { // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.add(AnySubType): Set element "
                    + incumbent.toString()
                    + " is neither a RefType nor an AnySubType.");
          }
        }
        if (addNewException) {
          resultSet.add(e);
          changes++;
        }
        if (changes > 0) {
          result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
        } else {
          result = this;
        }
        memoizedAdds.put(e, result);
        return result;
      }
    }
  }
コード例 #30
0
ファイル: ThrowableSet.java プロジェクト: safdariqbal/soot
  /**
   * Returns a <code>ThrowableSet</code> which contains <code>e</code> in addition to the exceptions
   * in this <code>ThrowableSet</code>.
   *
   * <p>Add <code>e</code> as a {@link RefType} when you know that the run-time class of the
   * exception you are representing is necessarily <code>e</code> and cannot be a subclass of <code>
   * e</code>.
   *
   * <p>For example, if you were recording the type of the exception thrown by
   *
   * <pre>
   * throw new IOException("Permission denied");
   * </pre>
   *
   * you would call
   *
   * <pre>
   * <code>add(Scene.v().getRefType("java.lang.Exception.IOException"))</code>
   * </pre>
   *
   * since the class of the exception is necessarily <code>IOException</code>.
   *
   * @param e the exception class
   * @return a set containing <code>e</code> as well as the exceptions in this set.
   * @throws {@link ThrowableSet.IllegalStateException} if this <code>ThrowableSet</code> is the
   *     result of a {@link #whichCatchableAs(RefType)} operation and, thus, unable to represent the
   *     addition of <code>e</code>.
   */
  public ThrowableSet add(RefType e) throws ThrowableSet.AlreadyHasExclusionsException {
    if (INSTRUMENTING) {
      Manager.v().addsOfRefType++;
    }
    if (this.exceptionsIncluded.contains(e)) {
      if (INSTRUMENTING) {
        Manager.v().addsInclusionFromMap++;
        Manager.v().addsExclusionWithoutSearch++;
      }
      return this;
    } else {
      ThrowableSet result = getMemoizedAdds(e);
      if (result != null) {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromMemo++;
          Manager.v().addsExclusionWithoutSearch++;
        }
        return result;
      } else {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromSearch++;
          if (exceptionsExcluded.size() != 0) {
            Manager.v().addsExclusionWithSearch++;
          } else {
            Manager.v().addsExclusionWithoutSearch++;
          }
        }
        FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();

        for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
          RefType exclusionBase = ((AnySubType) i.next()).getBase();
          if (hierarchy.canStoreType(e, exclusionBase)) {
            throw new AlreadyHasExclusionsException(
                "ThrowableSet.add(RefType): adding"
                    + e.toString()
                    + " to the set [ "
                    + this.toString()
                    + "] where "
                    + exclusionBase.toString()
                    + " is excluded.");
          }
        }

        for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
          RefLikeType incumbent = (RefLikeType) i.next();
          if (incumbent instanceof AnySubType) {
            // Need to use incumbent.getBase() because
            // hierarchy.canStoreType() assumes that parent
            // is not an AnySubType.
            RefType incumbentBase = ((AnySubType) incumbent).getBase();
            if (hierarchy.canStoreType(e, incumbentBase)) {
              memoizedAdds.put(e, this);
              return this;
            }
          } else if (!(incumbent instanceof RefType)) {
            // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.add(RefType): Set element "
                    + incumbent.toString()
                    + " is neither a RefType nor an AnySubType.");
          }
        }
        Set resultSet = new HashSet(this.exceptionsIncluded);
        resultSet.add(e);
        result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
        memoizedAdds.put(e, result);
        return result;
      }
    }
  }