示例#1
0
 public void outAFullIdentNonvoidType(AFullIdentNonvoidType node) {
   String typeName = (String) mProductions.removeLast();
   Type t = RefType.v(typeName);
   int dim = node.getArrayBrackets().size();
   if (dim > 0) t = ArrayType.v(t, dim);
   mProductions.addLast(t);
 }
示例#2
0
  /** Given a set of definite receiver types, returns a list of possible targets. */
  public List resolveConcreteDispatch(List classes, SootMethod m) {
    m.getDeclaringClass().checkLevel(SootClass.HIERARCHY);
    checkState();

    ArraySet s = new ArraySet();
    Iterator classesIt = classes.iterator();

    while (classesIt.hasNext()) {
      Object cls = classesIt.next();
      if (cls instanceof RefType) s.add(resolveConcreteDispatch(((RefType) cls).getSootClass(), m));
      else if (cls instanceof ArrayType) {
        s.add(resolveConcreteDispatch((RefType.v("java.lang.Object")).getSootClass(), m));
      } else throw new RuntimeException("Unable to resolve concrete dispatch of type " + cls);
    }

    List l = new ArrayList();
    l.addAll(s);
    return Collections.unmodifiableList(l);
  }
示例#3
0
 public void outAClassNameBaseType(AClassNameBaseType node) {
   String type = (String) mProductions.removeLast();
   if (type.equals("int")) throw new RuntimeException();
   mProductions.addLast(RefType.v(type));
 }
  /*
   * Generates the sequence of instructions needed to instrument ifStmtUnit
   *
   * @param ifStmtUnit: the unit to be instrumented
   * @return A Chain of Units that represent the instrumentation of ifStmtUnit
   */
  private static Chain<Unit> generateInstrumentationUnits(Unit ifStmtUnit, Body b) {

    AbstractBinopExpr expression =
        (AbstractBinopExpr)
            ((JIfStmt) ifStmtUnit).getCondition(); // implementation of AbstractBinopExpr
    Value operand1 = expression.getOp1();
    Value operand2 = expression.getOp2();

    JimpleLocal op1Local = (JimpleLocal) operand1;

    // Local localOperand = Jimple.v().newLocal("op1", operand1.getType());
    // b.getLocals().add(localOperand);

    // We need to use these operand as Locals or constants
    /**
     * JimpleLocal test; if(operand1 instanceof soot.jimple.internal.JimpleLocal) test =
     * (JimpleLocal)operand1; else test = null;
     */
    String op = expression.getClass().toString();

    Chain<Unit> resultUnits = new HashChain<Unit>();
    Local tmpRef;
    // Add locals directely on the top of the body, java.io.printStream tmpRef
    tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream"));
    b.getLocals().addFirst(tmpRef);

    // add "tmpRef = java.lang.System.out"
    resultUnits.add(
        Jimple.v()
            .newAssignStmt(
                tmpRef,
                Jimple.v()
                    .newStaticFieldRef(
                        Scene.v()
                            .getField("<java.lang.System: java.io.PrintStream out>")
                            .makeRef())));
    {
      SootMethod toCall =
          Scene.v().getMethod("<java.io.PrintStream: void println(java.lang.String)>");
      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operande 1: "))));
      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef,
                          toCall.makeRef(),
                          StringConstant.v(operand1.getClass().toString()))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operande 2:"))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef,
                          toCall.makeRef(),
                          StringConstant.v(operand2.getClass().toString()))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operateur: "))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v(op))));
    }

    return resultUnits;
  }