예제 #1
0
  @Override
  public Set<? extends IAllocNode> getPTSet(Value val, Context context) {
    // handle case for insensitive run
    if (k == 0) return getPTSetIns(val);

    final Set<AllocNode> allocNodes = new LinkedHashSet<AllocNode>();
    final Type filteringType = val.getType();

    PointsToSetInternal pts = null;

    try {
      if (val instanceof InstanceFieldRef) {
        final InstanceFieldRef ifr = (InstanceFieldRef) val;
        pts =
            (PointsToSetInternal)
                ptsProvider.reachingObjects(context, (Local) ifr.getBase(), ifr.getField());
      } else if (val instanceof ArrayRef) {
        ArrayRef arrayRef = (ArrayRef) val;
        pts =
            (PointsToSetInternal)
                ptsProvider.reachingObjectsOfArrayElement(
                    ptsProvider.reachingObjects(context, (Local) arrayRef.getBase()));
      } else if (val instanceof Local) {
        pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) val);
      } else if (val instanceof StaticFieldRef) {
        SootField field = ((StaticFieldRef) val).getField();
        pts = (PointsToSetInternal) ptsProvider.reachingObjects(field);
      } else if (val instanceof NullConstant) {
        return allocNodes;
      } else {
        logger.error("Unknown reference type for insenstive search: {} {}", val, val.getClass());
        droidsafe.main.Main.exit(1);
      }

      // visit internal points to set and grab all allocnodes
      pts.forall(
          new P2SetVisitor() {
            public void visit(Node n) {
              if (typeManager.castNeverFails(n.getType(), filteringType))
                allocNodes.add((AllocNode) n);
            }
          });

    } catch (Exception e) {
      logger.info("Some sort of error getting context insensitive points to set for {}", val, e);
      // e.printStackTrace();
    }

    return allocNodes;
  }
예제 #2
0
  /*
   * 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;
  }