コード例 #1
1
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void computeEdgeAndThreadNo() {
    Iterator it = iterator();
    int numberOfEdge = 0;
    while (it.hasNext()) {
      List succList = (List) getSuccsOf(it.next());

      numberOfEdge = numberOfEdge + succList.size();
    }
    numberOfEdge = numberOfEdge + startToThread.size();

    System.err.println("**number of edges: " + numberOfEdge);

    System.err.println("**number of threads: " + (startToThread.size() + 1));

    /*	Set keySet = startToThread.keySet();
    Iterator keyIt = keySet.iterator();
    while (keyIt.hasNext()){
    List list = (List)startToThread.get(keyIt.next());
    System.out.println("********start thread:");
    Iterator itit = list.iterator();
    while (itit.hasNext()){
    System.out.println(it.next());
    }
    }
    */

  }
コード例 #2
0
ファイル: Hierarchy.java プロジェクト: Hounge/apkinspector
  /**
   * Given an abstract dispatch to an object of type c and a method m, gives a list of possible
   * receiver methods.
   */
  public List resolveAbstractDispatch(SootClass c, SootMethod m) {
    c.checkLevel(SootClass.HIERARCHY);
    m.getDeclaringClass().checkLevel(SootClass.HIERARCHY);
    checkState();

    Iterator<SootClass> classesIt = null;

    if (c.isInterface()) {
      classesIt = getImplementersOf(c).iterator();
      HashSet<SootClass> classes = new HashSet<SootClass>();
      while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next()));
      classesIt = classes.iterator();
    } else classesIt = getSubclassesOfIncluding(c).iterator();

    ArraySet s = new ArraySet();

    while (classesIt.hasNext()) {
      SootClass cl = classesIt.next();
      if (Modifier.isAbstract(cl.getModifiers())) continue;
      s.add(resolveConcreteDispatch(cl, m));
    }

    List l = new ArrayList();
    l.addAll(s);
    return Collections.unmodifiableList(l);
  }
コード例 #3
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  public void outALookupswitchStatement(ALookupswitchStatement node) {
    List lookupValues = new ArrayList();
    List targets = new ArrayList();
    UnitBox defaultTarget = null;

    if (node.getCaseStmt() != null) {
      int size = node.getCaseStmt().size();

      for (int i = 0; i < size; i++) {
        Object valueTargetPair = mProductions.removeLast();
        if (valueTargetPair instanceof UnitBox) {
          if (defaultTarget != null)
            throw new RuntimeException("error: can't ;have more than 1 default stmt");

          defaultTarget = (UnitBox) valueTargetPair;
        } else {
          Object[] pair = (Object[]) valueTargetPair;

          lookupValues.add(0, pair[0]);
          targets.add(0, pair[1]);
        }
      }
    } else {
      throw new RuntimeException("error: switch stmt has no case stmts");
    }

    Value key = (Value) mProductions.removeLast();
    Unit switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget);

    mProductions.addLast(switchStmt);
  }
コード例 #4
0
  AbstractStaticInvokeExpr(SootMethodRef methodRef, List args) {
    super.methodRef = methodRef;
    super.argBoxes = new ArrayList();

    for (int i = 0; i < args.size(); i++)
      this.argBoxes.add(Jimple.v().newImmediateBox((Value) args.get(i)));
  }
コード例 #5
0
 public void addVariableDecl(VariableDecl node) {
   List<VariableDecl> list =
       (parent == null || state == null)
           ? getVariableDeclListNoTransform()
           : getVariableDeclList();
   list.addChild(node);
 }
コード例 #6
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;
    }
コード例 #7
0
ファイル: RawMethodDecl.java プロジェクト: JansenLi/soot
 /**
  * Add element to list TypeArgumentList
  *
  * @apilevel high-level
  * @ast method
  * @declaredat GenericMethods.ast:27
  */
 public void addTypeArgument(Access node) {
   List<Access> list =
       (parent == null || state == null)
           ? getTypeArgumentListNoTransform()
           : getTypeArgumentList();
   list.addChild(node);
 }
コード例 #8
0
ファイル: JThrowStmt.java プロジェクト: Hounge/apkinspector
  public List getUseBoxes() {
    List useBoxes = new ArrayList();

    useBoxes.addAll(opBox.getValue().getUseBoxes());
    useBoxes.add(opBox);

    return useBoxes;
  }
コード例 #9
0
  public Object clone() {
    List argList = new ArrayList(getArgCount());

    for (int i = 0; i < getArgCount(); i++) {
      argList.add(i, Jimple.cloneIfNecessary(getArg(i)));
    }

    return new JInterfaceInvokeExpr(Jimple.cloneIfNecessary(getBase()), methodRef, argList);
  }
コード例 #10
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);
  }
コード例 #11
0
  public List getUseBoxes() {
    List list = new ArrayList();

    for (int i = 0; i < argBoxes.size(); i++) {
      list.addAll(getArg(i).getUseBoxes());
      list.add(getArgBox(i));
    }

    return list;
  }
コード例 #12
0
ファイル: Hierarchy.java プロジェクト: Hounge/apkinspector
  /** Returns a list of subinterfaces of c, including itself. */
  public List<SootClass> getSubinterfacesOfIncluding(SootClass c) {
    c.checkLevel(SootClass.HIERARCHY);
    if (!c.isInterface()) throw new RuntimeException("interface needed!");

    List<SootClass> l = new ArrayList<SootClass>();
    l.addAll(getSubinterfacesOf(c));
    l.add(c);

    return Collections.unmodifiableList(l);
  }
コード例 #13
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  private void insertAfter(JPegStmt node, JPegStmt after) {
    // System.out.println("node: "+node);
    // System.out.println("after: "+after);
    //		System.out.println("succs of node: "+getSuccsOf(node));

    // this must be done first because the succs of node will be chanaged lately
    List succOfAfter = new ArrayList();
    succOfAfter.addAll(getSuccsOf(node));
    unitToSuccs.put(after, succOfAfter);

    Iterator succsIt = getSuccsOf(node).iterator();
    while (succsIt.hasNext()) {
      Object succ = succsIt.next();
      List pred = getPredsOf(succ);
      pred.remove(node);
      pred.add(after);
    }

    List succOfNode = new ArrayList();
    succOfNode.add(after);
    unitToSuccs.put(node, succOfNode);

    List predOfAfter = new ArrayList();
    predOfAfter.add(node);
    unitToPreds.put(after, predOfAfter);

    //	buildPredecessor(Chain pegChain);
  }
コード例 #14
0
ファイル: Hierarchy.java プロジェクト: Hounge/apkinspector
  /** Returns a list of possible targets for the given method and set of receiver types. */
  public List resolveAbstractDispatch(List classes, SootMethod m) {
    m.getDeclaringClass().checkLevel(SootClass.HIERARCHY);
    ArraySet s = new ArraySet();
    Iterator classesIt = classes.iterator();

    while (classesIt.hasNext()) s.addAll(resolveAbstractDispatch((SootClass) classesIt.next(), m));

    List l = new ArrayList();
    l.addAll(s);
    return Collections.unmodifiableList(l);
  }
コード例 #15
0
 private static List<Unit> searchIfStmts(Body b) {
   List<Unit> searchResult = new ArrayList<Unit>();
   PatchingChain<Unit> statements = b.getUnits();
   Iterator<Unit> unitIt = statements.iterator();
   // iterate through the Units of the body
   while (unitIt.hasNext()) {
     Unit tempUnit = unitIt.next();
     // if the unit is a "if statement"
     if (tempUnit instanceof soot.jimple.internal.JIfStmt) searchResult.add(tempUnit);
   }
   return searchResult;
 }
コード例 #16
0
ファイル: VarDeclStmt.java プロジェクト: Bludge0n/AREsoft
 private List createVariableDeclarationList() {
   List varList = new List();
   for (int j = 0; j < getNumVariableDecl(); j++) {
     VariableDeclaration v =
         getVariableDecl(j)
             .createVariableDeclarationFrom(
                 (Modifiers) getModifiers().fullCopy(), (Access) getTypeAccess().fullCopy());
     if (j == 0) v.setStart(start);
     varList.add(v);
   }
   return varList;
 }
コード例 #17
0
ファイル: Hierarchy.java プロジェクト: Hounge/apkinspector
  /** Returns a list of direct subclasses of c, including c. */
  public List<SootClass> getDirectSubclassesOfIncluding(SootClass c) {
    c.checkLevel(SootClass.HIERARCHY);
    if (c.isInterface()) throw new RuntimeException("class needed!");

    checkState();

    List<SootClass> l = new ArrayList<SootClass>();
    l.addAll(classToDirSubclasses.get(c));
    l.add(c);

    return Collections.unmodifiableList(l);
  }
コード例 #18
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);
  }
コード例 #19
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  /*
    throws_clause =
    throws class_name_list;
  */
  public void outAThrowsClause(AThrowsClause node) {
    List l = (List) mProductions.removeLast();

    Iterator it = l.iterator();
    List exceptionClasses = new ArrayList(l.size());

    while (it.hasNext()) {
      String className = (String) it.next();

      exceptionClasses.add(mResolver.makeClassRef(className));
    }

    mProductions.addLast(exceptionClasses);
  }
コード例 #20
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
 protected void buildPreds() {
   buildPredecessor(mainPegChain);
   Set maps = getStartToThread().entrySet();
   for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
     Map.Entry entry = (Map.Entry) iter.next();
     List runMethodChainList = (List) entry.getValue();
     Iterator it = runMethodChainList.iterator();
     while (it.hasNext()) {
       Chain chain = (Chain) it.next();
       //	System.out.println("chain is null: "+(chain == null));
       buildPredecessor(chain);
     }
   }
 }
コード例 #21
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();
 }
コード例 #22
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
 protected void testList(List list) {
   //		System.out.println("test list");
   Iterator listIt = list.iterator();
   while (listIt.hasNext()) {
     System.out.println(listIt.next());
   }
 }
コード例 #23
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  protected int processModifiers(List l) {
    int modifier = 0;
    Iterator it = l.iterator();

    while (it.hasNext()) {
      Object t = it.next();
      if (t instanceof AAbstractModifier) modifier |= Modifier.ABSTRACT;
      else if (t instanceof AFinalModifier) modifier |= Modifier.FINAL;
      else if (t instanceof ANativeModifier) modifier |= Modifier.NATIVE;
      else if (t instanceof APublicModifier) modifier |= Modifier.PUBLIC;
      else if (t instanceof AProtectedModifier) modifier |= Modifier.PROTECTED;
      else if (t instanceof APrivateModifier) modifier |= Modifier.PRIVATE;
      else if (t instanceof AStaticModifier) modifier |= Modifier.STATIC;
      else if (t instanceof ASynchronizedModifier) modifier |= Modifier.SYNCHRONIZED;
      else if (t instanceof ATransientModifier) modifier |= Modifier.TRANSIENT;
      else if (t instanceof AVolatileModifier) modifier |= Modifier.VOLATILE;
      else if (t instanceof AEnumModifier) modifier |= Modifier.ENUM;
      else if (t instanceof AAnnotationModifier) modifier |= Modifier.ANNOTATION;
      else
        throw new RuntimeException(
            "Impossible: modifier unknown - Have you added a new modifier and not updated this file?");
    }

    return modifier;
  }
コード例 #24
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();
 }
コード例 #25
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  public String toString() {
    Iterator it = iterator();
    StringBuffer buf = new StringBuffer();
    while (it.hasNext()) {
      JPegStmt u = (JPegStmt) it.next();
      buf.append("u is: " + u + "\n");
      List l = new ArrayList();
      l.addAll(getPredsOf(u));
      buf.append("preds: " + l + "\n");
      // buf.append(u.toString() + '\n');
      l = new ArrayList();
      l.addAll(getSuccsOf(u));
      buf.append("succs: " + l + "\n");
    }

    return buf.toString();
  }
コード例 #26
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  private boolean removeBeginNode() {
    List heads = getHeads();
    if (heads.size() != 1) {
      // System.out.println("heads: "+heads);
      // System.out.println("Error: the size of heads is not equal to 1!");
      return false;
      //	    System.exit(1);
    } else {
      JPegStmt head = (JPegStmt) heads.get(0);
      // System.out.println("test head: "+head);
      if (!head.getName().equals("begin")) {
        System.err.println("Error: the head is not begin node!");
        System.exit(1);
      }
      // remove begin node from heads list
      heads.remove(0);
      // set the preds list of the succs of head to a new list and put succs of head into heads
      Iterator succOfHeadIt = getSuccsOf(head).iterator();
      while (succOfHeadIt.hasNext()) {

        JPegStmt succOfHead = (JPegStmt) succOfHeadIt.next();

        unitToPreds.put(succOfHead, new ArrayList());
        // put succs of head into heads
        heads.add(succOfHead);
      }
      // remove begin node from inlinee Peg
      if (!mainPegChain.remove(head)) {
        System.err.println("fail to remove begin node in from mainPegChain!");
        System.exit(1);
      }
      if (!allNodes.contains(head)) {
        System.err.println("fail to find begin node in FlowSet allNodes!");
        System.exit(1);
      } else {
        allNodes.remove(head);
      }

      // remove begin node from unitToSuccs
      if (unitToSuccs.containsKey(head)) {
        unitToSuccs.remove(head);
      }
    }

    return true;
  }
コード例 #27
0
ファイル: JimpleLocal.java プロジェクト: richardxx/soot
 public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
   Unit u = Baf.v().newLoadInst(getType(), context.getBafLocalOfJimpleLocal(this));
   out.add(u);
   Iterator it = context.getCurrentUnit().getTags().iterator();
   while (it.hasNext()) {
     u.addTag((Tag) it.next());
   }
 }
コード例 #28
0
ファイル: IfElseBreaker.java プロジェクト: GeneBlue/JAADAS
  /*
    The purpose of this method is to replace the ASTIfElseNode
    given by the var nodeNumber with the new ASTIfNode
    and to add the remianing list of bodies after this ASTIfNode

    The new body is then returned;

  */
  public List<Object> createNewBody(List<Object> oldSubBody, int nodeNumber) {
    if (newIfNode == null) return null;

    List<Object> newSubBody = new ArrayList<Object>();

    if (oldSubBody.size() <= nodeNumber) {
      // something is wrong since the oldSubBody has lesser nodes than nodeNumber
      return null;
    }

    Iterator<Object> oldIt = oldSubBody.iterator();
    int index = 0;
    while (index != nodeNumber) {
      newSubBody.add(oldIt.next());
      index++;
    }

    // check to see that the next is an ASTIfElseNode
    ASTNode temp = (ASTNode) oldIt.next();
    if (!(temp instanceof ASTIfElseNode)) return null;

    newSubBody.add(newIfNode);

    newSubBody.addAll(remainingBody);

    // copy any remaining nodes
    while (oldIt.hasNext()) {
      newSubBody.add(oldIt.next());
    }

    return newSubBody;
  }
コード例 #29
0
ファイル: IfElseBreaker.java プロジェクト: GeneBlue/JAADAS
  private boolean checkStmt(ASTNode onlyNode, ASTIfElseNode node) {
    if (!(onlyNode instanceof ASTStatementSequenceNode)) {
      // only interested in StmtSeq nodes
      return false;
    }

    ASTStatementSequenceNode stmtNode = (ASTStatementSequenceNode) onlyNode;
    List<Object> statements = stmtNode.getStatements();
    if (statements.size() != 1) {
      // need one stmt only
      return false;
    }

    AugmentedStmt as = (AugmentedStmt) statements.get(0);
    Stmt stmt = as.get_Stmt();

    if (!(stmt instanceof DAbruptStmt)) {
      // interested in abrupt stmts only
      return false;
    }
    DAbruptStmt abStmt = (DAbruptStmt) stmt;
    if (!(abStmt.is_Break() || abStmt.is_Continue())) {
      // interested in breaks and continues only
      return false;
    }

    // make sure that the break is not that of the if
    // unliekly but good to check
    SETNodeLabel ifLabel = ((ASTLabeledNode) node).get_Label();

    if (ifLabel != null) {
      if (ifLabel.toString() != null) {
        if (abStmt.is_Break()) {
          String breakLabel = abStmt.getLabel().toString();
          if (breakLabel != null) {
            if (breakLabel.compareTo(ifLabel.toString()) == 0) {
              // is a break of this label
              return false;
            }
          }
        }
      }
    }
    return true;
  }
コード例 #30
0
ファイル: SETIfElseNode.java プロジェクト: GeneBlue/JAADAS
  public ASTNode emit_AST() {
    List<Object> astBody0 = emit_ASTBody(body2childChain.get(ifBody)),
        astBody1 = emit_ASTBody(body2childChain.get(elseBody));

    ConditionExpr ce =
        (ConditionExpr) ((IfStmt) get_CharacterizingStmt().get_Stmt()).getCondition();

    if (astBody0.isEmpty()) {
      List<Object> tbody = astBody0;
      astBody0 = astBody1;
      astBody1 = tbody;

      ce = ConditionFlipper.flip(ce);
    }

    if (astBody1.isEmpty()) return new ASTIfNode(get_Label(), ce, astBody0);
    else return new ASTIfElseNode(get_Label(), ce, astBody0, astBody1);
  }