Ejemplo n.º 1
0
 public static int getLine(Unit unit) {
   SourceLnPosTag tag = (SourceLnPosTag) unit.getTag("SourceLnPosTag");
   if (tag != null) return tag.startLn();
   LineNumberTag lnTag = (LineNumberTag) unit.getTag("LineNumberTag");
   if (lnTag != null) return lnTag.getLineNumber();
   return -1;
 }
Ejemplo n.º 2
0
  public void internalTransform(String phaseName, Map opts) {

    Iterator it = Scene.v().getApplicationClasses().iterator();
    while (it.hasNext()) {
      SootClass sc = (SootClass) it.next();
      // make map of first line to each method
      HashMap<Integer, SootMethod> lineToMeth = new HashMap<Integer, SootMethod>();
      Iterator methIt = sc.getMethods().iterator();
      while (methIt.hasNext()) {
        SootMethod meth = (SootMethod) methIt.next();
        if (!meth.isConcrete()) continue;
        Body body = meth.retrieveActiveBody();
        Stmt s = (Stmt) body.getUnits().getFirst();
        while (s instanceof IdentityStmt) {
          s = (Stmt) body.getUnits().getSuccOf(s);
        }
        if (s.hasTag("LineNumberTag")) {
          LineNumberTag tag = (LineNumberTag) s.getTag("LineNumberTag");
          lineToMeth.put(new Integer(tag.getLineNumber()), meth);
        }
      }
      Iterator methIt2 = sc.getMethods().iterator();
      while (methIt2.hasNext()) {
        SootMethod meth = (SootMethod) methIt2.next();
        if (!meth.isConcrete()) continue;
        Body body = meth.retrieveActiveBody();
        Stmt s = (Stmt) body.getUnits().getFirst();
        while (s instanceof IdentityStmt) {
          s = (Stmt) body.getUnits().getSuccOf(s);
        }
        if (s.hasTag("LineNumberTag")) {
          LineNumberTag tag = (LineNumberTag) s.getTag("LineNumberTag");
          int line_num = tag.getLineNumber() - 1;
          // already taken
          if (lineToMeth.containsKey(new Integer(line_num))) {
            meth.addTag(new LineNumberTag(line_num + 1));
          }
          // still available - so use it for this meth
          else {
            meth.addTag(new LineNumberTag(line_num));
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
 public static int getStatementLineNumber(Stmt s) {
   List<Tag> tags = s.getTags();
   int line = -1;
   for (Tag tag : tags) {
     if (tag instanceof SourceLnNamePosTag) {
       SourceLnNamePosTag lineTag = (SourceLnNamePosTag) tag;
       line = lineTag.startLn();
     } else if (tag instanceof LineNumberTag) {
       LineNumberTag lineTag = (LineNumberTag) tag;
       line = lineTag.getLineNumber();
     }
   }
   return line;
 }
Ejemplo n.º 4
0
  /**
   * @param lineNum line number in source code
   * @param sm soot method contains the specified line
   * @return
   */
  public RdProgramPoint getProgramPoint(String lineNum, SootMethod sm) {
    Body body = sm.getActiveBody();
    RdProgramPoint result = null;
    int line = 0;
    for (Unit u : body.getUnits()) {

      int lineNumInt = Integer.parseInt(lineNum);
      LineNumberTag tag = (LineNumberTag) u.getTag("LineNumberTag");
      if (tag != null) {
        line = tag.getLineNumber();
      }

      if (line == lineNumInt) { // the interested line
        result = new RdProgramPoint(u, sm, false);
      }
    }

    return result;
  }
Ejemplo n.º 5
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private Set<SootField> collectBlockField(JavaCriticalSection cs) {
    Set result = new HashSet();
    int startLine = cs.getStartLine();
    int endLine = cs.getEndline();
    Body body = cs.getSootMethod().getActiveBody();
    PatchingChain<Unit> units = body.getUnits();
    for (Unit u : units) {
      Stmt s = (Stmt) u;
      LineNumberTag linetag = (LineNumberTag) s.getTag("LineNumberTag");
      if (linetag == null) continue;
      int line = linetag.getLineNumber();
      if (line < startLine || line > endLine) {
        continue;
      }

      List<ValueBox> Fieldslist = u.getUseBoxes();
      Fieldslist.addAll(u.getDefBoxes());
      for (ValueBox box : Fieldslist) {
        Value v = box.getValue();
        if (v instanceof JInstanceFieldRef) {
          result.add(((JInstanceFieldRef) v).getField());
        }
      }
      if (s.containsInvokeExpr()) {
        // 用调用图获得调用目标
        Callees callees = new Callees(getCallGragh(), u);
        for (SootMethod invokeMethod : callees.explicits()) {
          if (invokeMethod == null) continue;
          Collection use = scaner.getUseInstanceFields(invokeMethod);
          Collection mod = new HashSet();
          if (needMod) {
            mod.addAll(scaner.getModInstanceFields(invokeMethod));
          }
          if (use != null) result.addAll(use);
          result.addAll(mod);
        }
      }
    }
    return result;
  }