Java 类soot.jimple.internal.JCastExpr 实例源码

项目:JAADAS    文件:NullnessAssumptionAnalysis.java   
private void handleRefTypeAssignment(DefinitionStmt assignStmt,
        AnalysisInfo rhsInfo, AnalysisInfo out) {
    Value left = assignStmt.getLeftOp();
    Value right = assignStmt.getRightOp();

    //unbox casted value
    if(right instanceof JCastExpr) {
        JCastExpr castExpr = (JCastExpr) right;
        right = castExpr.getOp();
    }

    // An assignment invalidates any assumptions of null/non-null for lhs
    // We COULD be more accurate by assigning those assumptions to the rhs prior to this statement
    rhsInfo.put(right,BOTTOM);

    //assign from rhs to lhs
    out.put(left,rhsInfo.get(right));
}
项目:JAADAS    文件:UnopInstruction.java   
public void jimplify (DexBody body) {
      if(!(instruction instanceof Instruction12x))
          throw new IllegalArgumentException("Expected Instruction12x but got: "+instruction.getClass());

      Instruction12x cmpInstr = (Instruction12x)instruction;
      int dest = cmpInstr.getRegisterA();

      Local source = body.getRegisterLocal(cmpInstr.getRegisterB());
      Value expr = getExpression(source);

      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);

      setUnit(assign);
      addTags(assign);
      body.add(assign);

if (IDalvikTyper.ENABLE_DVKTYPER) {
    Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        int op = (int)instruction.getOpcode().value;
        //DalvikTyper.v().captureAssign((JAssignStmt)assign, op);
        JAssignStmt jass = (JAssignStmt)assign;
        DalvikTyper.v().setType((expr instanceof JCastExpr) ? ((JCastExpr) expr).getOpBox() : ((UnopExpr) expr).getOpBox(), opUnType[op - 0x7b], true);
        DalvikTyper.v().setType(jass.leftBox, resUnType[op - 0x7b], false);
      }
  }
项目:petablox    文件:RelMcheckCastInst.java   
public void visitCastInst(Unit q) {
    if(q instanceof JAssignStmt){
        JAssignStmt j = (JAssignStmt)q;
        Value left = j.leftBox.getValue();
        Value right = j.rightBox.getValue();
        if(right instanceof JCastExpr){
            JCastExpr jce = (JCastExpr)right;
            Type t = jce.getCastType();
            if(jce.getOp() instanceof Local && t instanceof RefLikeType){
            Local src = (Local)jce.getOp();
            Local dst = (Local)left;
            int mIdx = domM.indexOf(ctnrMethod);
             assert (mIdx >= 0);
             int lIdx = domV.indexOf(dst);
             assert (lIdx >= 0);
             int tIdx = domT.indexOf(t);
             assert (tIdx >= 0);
             int rIdx = domV.indexOf(src);
             assert (rIdx >= 0);
             add(mIdx, lIdx, tIdx, rIdx);
        }
        }
    }
}
项目:soot-inflow    文件:BaseSelector.java   
/**
 * the operations that are not relevant for analysis like "not" or casts
 * are removed - array refs are only removed if explicitly stated
 * @param val the value which should be pruned
 * @param keepArrayRef if false then array refs are pruned to the base array object
 * @return the value (possibly pruned to base object)
 */ //we want to keep ArrayRef for objects on the right side of the assignment
public static Value selectBase(Value val, boolean keepArrayRef){
    //we taint base of array instead of array elements
    if (val instanceof ArrayRef && !keepArrayRef) {
        return selectBase(((ArrayRef) val).getBase(), keepArrayRef);
    }

    if (val instanceof JCastExpr) {
        return selectBase(((JCastExpr) val).getOpBox().getValue(), keepArrayRef);
    }

    // Check for unary operators like "not" or "length"
    if (val instanceof UnopExpr)
        return selectBase(((UnopExpr) val).getOp(), keepArrayRef);

    return val;
}
项目:JAADAS    文件:NullnessAnalysis.java   
private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) {
    Value left = assignStmt.getLeftOp();
    Value right = assignStmt.getRightOp();

    //unbox casted value
    if(right instanceof JCastExpr) {
        JCastExpr castExpr = (JCastExpr) right;
        right = castExpr.getOp();
    }

    //if we have a definition (assignment) statement to a ref-like type, handle it,
    if ( isAlwaysNonNull(right)
    || right instanceof NewExpr || right instanceof NewArrayExpr
    || right instanceof NewMultiArrayExpr || right instanceof ThisRef
    || right instanceof StringConstant || right instanceof ClassConstant
    || right instanceof CaughtExceptionRef) {
        //if we assign new... or @this, the result is non-null
        out.put(left,NON_NULL);
    } else if(right==NullConstant.v()) {
        //if we assign null, well, it's null
        out.put(left, NULL);
    } else if(left instanceof Local && right instanceof Local) {
        out.put(left, out.get(right));
    } else {
        out.put(left, TOP);
    }
}
项目:petablox    文件:RelPobjNullAsgnInst.java   
public void visitCastInst(Unit q) {
if(q instanceof JAssignStmt){
    JAssignStmt j = (JAssignStmt)q;
    if(j.rightBox.getValue() instanceof JCastExpr){
        JCastExpr jce = (JCastExpr)j.rightBox.getValue();
        Local l = (Local)j.leftBox.getValue();
        Value r = jce.getOp();
        if(r instanceof NullConstant && l.getType() instanceof RefLikeType){
            add(q, l);
        }
    }
}
  }
项目:petablox    文件:RelMobjVarAsgnInst.java   
public void visitCastInst(Unit q) {
    if(q instanceof JAssignStmt){
        JAssignStmt j = (JAssignStmt)q;
        Value left = j.leftBox.getValue();
        Value right = j.rightBox.getValue();
        if(right instanceof JCastExpr){
            Local l = (Local)left;
            Value rv = ((JCastExpr)right).getOp();
            if(rv.getType() instanceof RefLikeType && rv instanceof Local){
                Local r = (Local)rv;
                add(ctnrMethod, l, r);
            }
        }
    }
}
项目:petablox    文件:RelPobjVarCastInst.java   
public void visitCastInst(Unit q) {
    if(q instanceof JAssignStmt){
        JAssignStmt j = (JAssignStmt)q;
        if(j.rightBox.getValue() instanceof JCastExpr){
            JCastExpr jce = (JCastExpr)j.rightBox.getValue();
            if(jce.getOp() instanceof Local){
            Local r = (Local)jce.getOp();
            if(r.getType() instanceof RefLikeType){
                Local l = (Local)j.leftBox.getValue();
                add(q, l, r);
            }
            }
        }
    }
}
项目:matos-tool    文件:ArrayAnalysis.java   
/**
 * Tries to extract a constant integer value from a Soot Value. It
 * must be positive (array index or array size). If it fails, UNKNOWN_CONTENTS is
 * given back.
 * @param locanalysis Local def/use analysis of the body
 * @param stmt Statement containing ref to value
 * @param v the value itself
 * @return a positive integer or -1
 */
private int getConstantValue(LocalAnalysis locanalysis, Stmt stmt, Value v) {
    if (v instanceof Local) {
        Local l = (Local) v;

        List <Unit> result = locanalysis.getDefsOfAt(l, stmt);
        if (result.size() != 1) return UNKNOWN_CONTENTS;
        Unit content = result.get(0);
        if (content instanceof AssignStmt) {
            AssignStmt ast = (AssignStmt) content;
            Value right = ast.getRightOp();
            if (right instanceof IntConstant) {
                return ((IntConstant) right).value;
            }
            if (right instanceof JCastExpr) {
                Value casted = ((JCastExpr) right).getOp();
                return getConstantValue(locanalysis, ast, casted);
            }
            if (right instanceof Local) {
                return getConstantValue(locanalysis, ast, right);
            }
            return UNKNOWN_CONTENTS;
        } else return UNKNOWN_CONTENTS;
    } else if (v instanceof IntConstant) {
        return ((IntConstant) v).value;
    } else return UNKNOWN_CONTENTS;
}