Java 类soot.jimple.Constant 实例源码

项目:FuzzDroid    文件:JimpleStmtVisitorImpl.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    //in case of return CONSTANT, we do nothing; unfortunately, this is part of FlowDroid's path
    if(stmt.getOp() instanceof Constant)
        return;
    int index = jimpleDataFlowStatements.indexOf(stmt);
    AccessPath ap = accessPathPath.get(index);
    Local local = ap.getPlainValue();

    SMTBinding lhs = createNewBindingForValue(local);
    addValueBindingToVariableDeclaration(local, lhs);

    if(!hasBindingForValue(stmt.getOp()))
        throw new RuntimeException("There has to be a tainted value");
    SMTBinding rhs = getLatestBindingForValue(stmt.getOp());

    SMTSimpleAssignment simpleAss = new SMTSimpleAssignment(lhs, new SMTBindingValue(rhs));
    SMTAssertStatement assertStmt = new SMTAssertStatement(simpleAss);
    addAssertStmtToAllPrograms(assertStmt); 
}
项目:boomerang    文件:PreparationTransformer.java   
private Map<Unit, Body> getStmtsWithConstants() {
  Map<Unit, Body> retMap = new LinkedHashMap<Unit, Body>();
  for (SootClass sc : Scene.v().getClasses()) {
    for (SootMethod sm : sc.getMethods()) {
      if (!sm.hasActiveBody())
        continue;
      Body methodBody = sm.retrieveActiveBody();
      for (Unit u : methodBody.getUnits()) {
        if (u instanceof ReturnStmt) {
          if (((ReturnStmt) u).getOp() instanceof Constant) {
            retMap.put(u, methodBody);
          }
        } else if (((Stmt) u).containsInvokeExpr()) {
          InvokeExpr ie = ((Stmt) u).getInvokeExpr();
          for (Value arg : ie.getArgs()) {
            if (arg instanceof StringConstant || arg instanceof NumericConstant) {
              retMap.put(u, methodBody);
              break;
            }
          }
        }
      }
    }
  }
  return retMap;
}
项目:JAADAS    文件:Aliasing.java   
/**
 * Gets whether two values may potentially point to the same runtime object
 * @param val1 The first value
 * @param val2 The second value
 * @return True if the two values may potentially point to the same runtime
 * object, otherwise false
 */
public boolean mayAlias(Value val1, Value val2) {
    // What cannot be represented in an access path cannot alias
    if (!AccessPath.canContainValue(val1) || !AccessPath.canContainValue(val2))
        return false;

    // Constants can never alias
    if (val1 instanceof Constant || val2 instanceof Constant)
        return false;

    // If the two values are equal, they alias by definition
    if (val1 == val2)
        return true;

    // If we have an interactive aliasing algorithm, we check that as well
    if (aliasingStrategy.isInteractive())
        return aliasingStrategy.mayAlias(new AccessPath(val1, false), new AccessPath(val2, false));

    return false;       
}
项目:JAADAS    文件:EasyTaintWrapper.java   
@Override
public boolean supportsCallee(Stmt callSite) {
    // We need an invocation expression
    if (!callSite.containsInvokeExpr())
        return false;

    SootMethod method = callSite.getInvokeExpr().getMethod();
    if (!supportsCallee(method))
        return false;

    // We need a method that can create a taint
    if (!aggressiveMode) {
        // Check for a cached wrap type
        final MethodWrapType wrapType = methodWrapCache.getUnchecked(method);
        if (wrapType != MethodWrapType.CreateTaint)
            return false;
    }

    // We need at least one non-constant argument or a tainted base
    if (callSite.getInvokeExpr() instanceof InstanceInvokeExpr)
        return true;
    for (Value val : callSite.getInvokeExpr().getArgs())
        if (!(val instanceof Constant))
            return true;
    return false;
}
项目:JAADAS    文件:BLookupSwitchInst.java   
public void toString(UnitPrinter up) {
    up.literal( "lookupswitch" );
    up.newline();
    up.literal("{");
    up.newline();

    for(int i = 0; i < lookupValues.size(); i++)
    {
        up.literal("    case ");
        up.constant( (Constant) lookupValues.get(i) );
        up.literal(": goto ");
        targetBoxes[i].toString(up);
        up.literal(";");
        up.newline();
    }

    up.literal("    default: goto ");
    defaultTargetBox.toString(up);
    up.literal(";");
    up.newline();
    up.literal("}");
}
项目:JAADAS    文件:ConstInstruction.java   
public void jimplify (DexBody body) {
    int dest = ((OneRegisterInstruction) instruction).getRegisterA();

    Constant cst = getConstant(dest, body);
    assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
    setUnit(assign);
    addTags(assign);
    body.add(assign);

    if (IDalvikTyper.ENABLE_DVKTYPER) {
        Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        int op = (int)instruction.getOpcode().value;
        if (cst instanceof UntypedConstant) {
            DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
        } else {
            DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
        }
    }
}
项目:JAADAS    文件:ConstClassInstruction.java   
public void jimplify (DexBody body) {
      if(!(instruction instanceof Instruction21c))
          throw new IllegalArgumentException("Expected Instruction21c but got: "+instruction.getClass());

      ReferenceInstruction constClass = (ReferenceInstruction) this.instruction;

      TypeReference tidi = (TypeReference)(constClass.getReference());
      String type = tidi.getType();
      if (type.startsWith("L") && type.endsWith(";"))
        type = type.replaceAll("^L", "").replaceAll(";$", "");

      int dest = ((OneRegisterInstruction) instruction).getRegisterA();
      Constant cst = ClassConstant.v(type);
      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
      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); //TODO: classtype could be null!
        DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
      }
  }
项目:JAADAS    文件:APIVulnManager.java   
@Override
public void isParamVulnAndStore(SootMethod originMethod, Stmt originStmt, Value reachedValue) { //avoid sideeffect
    //constant already guaranteed by caller
    System.out.println(originStmt);
    String funcSig = originStmt.getInvokeExpr().getMethod().getSignature();
    String valueString = reachedValue.toString();
    if (evaluateResult(funcSig, valueString)) {
        if(DEBUG) {
            System.out.println("result found");
            System.out.println("originstmt: " + originStmt + " reachedValue: " + reachedValue);
        }
        this.results.add(new Pair<>(originMethod, new Pair<>(originStmt, valueString)));
    }
    if(DEBUG) {
        if (reachedValue instanceof Constant || reachedValue instanceof StaticFieldRef) {
            System.out.println("originstmt: " + originStmt + " reachedValue: " + reachedValue);
        }
    }
}
项目:FlowTwist    文件:GenericCallerSensitive.java   
@Override
public KillGenInfo processBackwardCallToReturn(Trackable taint, Stmt callSite, InvokeExpr ie) {
    SootMethod method = ie.getMethod();
    List<Taint> taints = Lists.newLinkedList();
    if (ie instanceof InstanceInvokeExpr) {
        Value receiver = ((InstanceInvokeExpr) ie).getBase();
        taints.add(new Taint(callSite, taint, receiver, receiver.getType()));
    }

    for (int i = 0; i < method.getParameterCount(); i++) {
        Type parameterType = method.getParameterType(i);
        if (!(parameterType instanceof PrimType) && !(ie.getArg(i) instanceof Constant)) {
            taints.add(new Taint(callSite, taint, ie.getArg(i), parameterType));
        }
    }

    if (taints.isEmpty())
        return kill();
    else
        return propagate(taints.toArray(new Taint[taints.size()]));
}
项目:FlowTwist    文件:ReturnValuePropagator.java   
@Override
public KillGenInfo propagateNormalFlow(Trackable trackable, Unit curr, Unit succ) {
    if (curr instanceof ReturnStmt) {
        Value retValue = getBase(((ReturnStmt) curr).getOp());
        if (retValue instanceof Constant) {
            return kill();
        } else {
            ReturnValueTaint retValTaint = (ReturnValueTaint) trackable;
            if (AnalysisUtil.isAssignable(retValTaint.type, retValue.getType()))
                return propagate(new Taint(curr, trackable, retValue, retValTaint.type));
            else
                return kill();
        }
    } else if (curr instanceof ThrowStmt)
        return kill();

    throw new IllegalStateException();
}
项目:FlowTwist    文件:DefaultTaintPropagator.java   
@Override
public KillGenInfo propagateCallFlow(Trackable trackable, Unit callStmt, SootMethod destinationMethod) {
    Taint taint = (Taint) trackable;

    if (callStmt instanceof AssignStmt) {
        AssignStmt assignStmt = (AssignStmt) callStmt;
        if (taint.value.equals(assignStmt.getLeftOp())) {
            if (AnalysisUtil.isAssignable(taint.type, destinationMethod.getReturnType())) {
                for (Unit u : context.icfg.getStartPointsOf(destinationMethod)) {
                    if (u instanceof ReturnStmt) {
                        ReturnStmt returnStmt = (ReturnStmt) u;
                        Value retValue = returnStmt.getOp();

                        if (retValue instanceof Constant)
                            continue;

                        // There is at least one non constant return stmt
                        return propagate(new ReturnValueTaint(callStmt, trackable, taint.type));
                    }
                }
            }
        }
    }

    return kill();
}
项目:vasco    文件:CopyConstantAnalysis.java   
private void assign(Local lhs, Value rhs, Map<Local, Constant> input, Map<Local, Constant> output) {
    // First remove casts, if any.
    if (rhs instanceof CastExpr) {
        rhs = ((CastExpr) rhs).getOp();
    }
    // Then check if the RHS operand is a constant or local
    if (rhs instanceof Constant) {
        // If RHS is a constant, it is a direct gen
        output.put(lhs, (Constant) rhs);
    } else if (rhs instanceof Local) {
        // Copy constant-status of RHS to LHS (indirect gen), if exists
        if(input.containsKey(rhs)) {
            output.put(lhs, input.get(rhs));
        }
    } else {
        // RHS is some compound expression, then LHS is non-constant (only kill)
        output.put(lhs, null);
    }           
}
项目:vasco    文件:CopyConstantAnalysis.java   
@Override
public Map<Local, Constant> callEntryFlowFunction(Context<SootMethod, Unit, Map<Local, Constant>> context, SootMethod calledMethod, Unit unit, Map<Local, Constant> inValue) {
    // Initialise result to empty map
    Map<Local, Constant> entryValue = topValue();
    // Map arguments to parameters
    InvokeExpr ie = ((Stmt) unit).getInvokeExpr();
    for (int i = 0; i < ie.getArgCount(); i++) {
        Value arg = ie.getArg(i);
        Local param = calledMethod.getActiveBody().getParameterLocal(i);
        assign(param, arg, inValue, entryValue);
    }
    // And instance of the this local
    if (ie instanceof InstanceInvokeExpr) {
        Value instance = ((InstanceInvokeExpr) ie).getBase();
        Local thisLocal = calledMethod.getActiveBody().getThisLocal();
        assign(thisLocal, instance, inValue, entryValue);
    }
    // Return the entry value at the called method
    return entryValue;
}
项目:vasco    文件:CopyConstantAnalysis.java   
@Override
public Map<Local, Constant> meet(Map<Local, Constant> op1, Map<Local, Constant> op2) {
    Map<Local, Constant> result;
    // First add everything in the first operand
    result = new HashMap<Local, Constant>(op1);
    // Then add everything in the second operand, bottoming out the common keys with different values
    for (Local x : op2.keySet()) {
        if (op1.containsKey(x)) {
            // Check the values in both operands
            Constant c1 = op1.get(x);
            Constant c2 = op2.get(x);
            if (c1 != null && c1.equals(c2) == false) {
                // Set to non-constant
                result.put(x, null);
            }
        } else {
            // Only in second operand, so add as-is
            result.put(x, op2.get(x));
        }
    }
    return result;
}
项目:vasco    文件:CopyConstantTest.java   
@Override
protected void internalTransform(String arg0, @SuppressWarnings("rawtypes") Map arg1) {
    analysis = new CopyConstantAnalysis();
    analysis.doAnalysis();
    DataFlowSolution<Unit,Map<Local,Constant>> solution = analysis.getMeetOverValidPathsSolution();
    System.out.println("----------------------------------------------------------------");
    for (SootMethod sootMethod : analysis.getMethods()) {
        System.out.println(sootMethod);
        for (Unit unit : sootMethod.getActiveBody().getUnits()) {
            System.out.println("----------------------------------------------------------------");
            System.out.println(unit);
            System.out.println("IN:  " + formatConstants(solution.getValueBefore(unit)));
            System.out.println("OUT: " + formatConstants(solution.getValueAfter(unit)));
        }
        System.out.println("----------------------------------------------------------------");
    }       
}
项目:cheetah    文件:FlowAbstraction.java   
public boolean hasPrefix(Value v) { // if this has prefix v
    if (v instanceof Local) {
        if (local == null)
            return false;
        else
            return (local.equals(v));

    } else if (v instanceof InstanceFieldRef) {
        InstanceFieldRef ifr = (InstanceFieldRef) v;
        if (local == null) {
            if (ifr.getBase() != null)
                return false;
        } else if (!local.equals(ifr.getBase()))
            return false;
        if (fields.length > 0 && ifr.getField() == fields[0])
            return true;
        return false;

    } else if (v instanceof StaticFieldRef) {
        StaticFieldRef sfr = (StaticFieldRef) v;
        if (local != null)
            return false;
        if (fields.length > 0 && sfr.getField() == fields[0])
            return true;
        return false;

    } else if (v instanceof ArrayRef) {
        ArrayRef ar = (ArrayRef) v;
        if (local == null)
            return false;
        else
            return (local.equals(ar.getBase()));

    } else if (v instanceof Constant) {
        return false;
    } else
        throw new RuntimeException("Unexpected left side " + v.getClass());
}
项目:JAADAS    文件:InterproceduralConstantValuePropagator.java   
/**
 * Gets the number of non-constant arguments to the given method call
 * @param s A call site
 * @return The number of non-constant arguments in the given call site
 */
private int getNonConstParamCount(Stmt s) {
    int cnt = 0;
    for (Value val : s.getInvokeExpr().getArgs())
        if (!(val instanceof Constant))
            cnt++;
    return cnt;
}
项目:JAADAS    文件:RegisterAllocator.java   
public Register asImmediate(Value v, ConstantVisitor constantV) {
    if (v instanceof Constant) {
         return asConstant(v, constantV);
    } else if (v instanceof Local) {
        return asLocal(v);
    } else {
        throw new RuntimeException("expected Immediate (Constant or Local), but was: " + v.getClass());
    }
}
项目:JAADAS    文件:DavaBody.java   
private void javafy(ValueBox vb) {
    Value v = vb.getValue();

    if (v instanceof Expr)
        javafy_expr(vb);
    else if (v instanceof Ref)
        javafy_ref(vb);
    else if (v instanceof Local)
        javafy_local(vb);
    else if (v instanceof Constant)
        javafy_constant(vb);
}
项目:JAADAS    文件:DavaUnitPrinter.java   
@Override
public void constant( Constant c ) {
  if (c instanceof ClassConstant) {
    handleIndent();
    String fullClassName =
      ((ClassConstant)c).value.replaceAll("/", ".");
    output.append(fullClassName + ".class");
  } else {
    super.constant(c);
  }
}
项目:JAADAS    文件:AsmMethodSource.java   
private Operand popImmediate(Operand o) {
    Value v = o.value;
    Local l = o.stack;
    if (l == null && !(v instanceof Local) && !(v instanceof Constant)) {
        l = o.stack = newStackLocal();
        setUnit(o.insn, Jimple.v().newAssignStmt(l, v));
        o.updateBoxes();
    }
    return o;
}
项目:JAADAS    文件:AsmMethodSource.java   
private Operand popStackConst(Operand o) {
    Value v = o.value;
    Local l = o.stack;
    if (l == null && !(v instanceof Constant)) {
        l = o.stack = newStackLocal();
        setUnit(o.insn, Jimple.v().newAssignStmt(l, v));
        o.updateBoxes();
    }
    return o;
}
项目:JAADAS    文件:ConstantInitializerToTagTransformer.java   
private ConstantValueTag createConstantTagFromValue(Constant rightOp) {
    if (rightOp instanceof DoubleConstant)
        return new DoubleConstantValueTag(((DoubleConstant) rightOp).value);
    else if (rightOp instanceof FloatConstant)
        return new FloatConstantValueTag(((FloatConstant) rightOp).value);
    else if (rightOp instanceof IntConstant)
        return new IntegerConstantValueTag(((IntConstant) rightOp).value);
    else if (rightOp instanceof LongConstant)
        return new LongConstantValueTag(((LongConstant) rightOp).value);
    else if (rightOp instanceof StringConstant)
        return new StringConstantValueTag(((StringConstant) rightOp).value);
    else
        return null;
}
项目:JAADAS    文件:ConstantInitializerToTagTransformer.java   
private boolean checkConstantValue(ConstantValueTag t, Constant rightOp) {
    if (t == null || rightOp == null)
        return true;

    if (t instanceof DoubleConstantValueTag) {
        if (!(rightOp instanceof DoubleConstant))
            return false;
        return ((DoubleConstantValueTag) t).getDoubleValue() == ((DoubleConstant) rightOp).value;
    }
    else if (t instanceof FloatConstantValueTag) {
        if (!(rightOp instanceof FloatConstant))
            return false;
        return ((FloatConstantValueTag) t).getFloatValue() == ((FloatConstant) rightOp).value;
    }
    else if (t instanceof IntegerConstantValueTag) {
        if (!(rightOp instanceof IntConstant))
            return false;
        return ((IntegerConstantValueTag) t).getIntValue() == ((IntConstant) rightOp).value;
    }
    else if (t instanceof LongConstantValueTag) {
        if (!(rightOp instanceof LongConstant))
            return false;
        return ((LongConstantValueTag) t).getLongValue() == ((LongConstant) rightOp).value;
    }
    else if (t instanceof StringConstantValueTag) {
        if (!(rightOp instanceof StringConstant))
            return false;
        return ((StringConstantValueTag) t).getStringValue().equals(((StringConstant) rightOp).value);
    }
    else
        // We don't know the type, so we assume it's alright
        return true;
}
项目:petablox    文件:FGStmtSwitch.java   
public final void caseReturnStmt(ReturnStmt s) {
statement = s; 
Value op = s.getOp();
if( op.getType() instanceof RefType 
|| op.getType() instanceof ArrayType ) { 
    if( op instanceof Constant ) {
    caseReturnConstStmt( (Constant) op );
    } else {
    caseReturnStmt( (Local) op );
    }
} else {
    caseReturnStmt( (Local) null );
}
  }
项目:soot-inflow    文件:AbstractInfoflowProblem.java   
/**
 * we cannot rely just on "real" heap objects, but must also inspect locals because of Jimple's representation ($r0 =... )
 * @param val the value which gets tainted
 * @param source the source from which the taints comes from. Important if not the value, but a field is tainted
 * @return true if a reverseFlow should be triggered or an inactive taint should be propagated (= resulting object is stored in heap = alias)
 */
public boolean triggerInaktiveTaintOrReverseFlow(Value val, Abstraction source){
    if(val == null){
        return false;
    }
    //no string
    if(!(val instanceof InstanceFieldRef) && !(val instanceof ArrayRef) 
            && val.getType() instanceof RefType && ((RefType)val.getType()).getClassName().equals("java.lang.String")){
        return false;
    }
    if(val instanceof InstanceFieldRef && ((InstanceFieldRef)val).getBase().getType() instanceof RefType &&
             ((RefType)((InstanceFieldRef)val).getBase().getType()).getClassName().equals("java.lang.String")){
        return false;
    }
    if(val.getType() instanceof PrimType){
        return false;
    }
    if(val instanceof Constant)
        return false;

    if(DataTypeHandler.isFieldRefOrArrayRef(val)
            || source.getAccessPath().isInstanceFieldRef()
            || source.getAccessPath().isStaticFieldRef())
        return true;

    return false;
}
项目:matos-tool    文件:MethodSpyAnalysis.java   
/**
 * Analyze a Soot value.
 * @param arg the value to analyze
 * @param typ the type of the value
 * @param stmt the instruction analyzed
 * @param seen Set of instructions already treated.
 * @return The abstract value approximating the contents of the value
 */
AbsValue treatValue(Value arg, Type typ, Unit stmt,  Set<Unit> seen) {
    if (arg instanceof Local) 
        return analyzeLocal((Local) arg, stmt,seen);
    else if (arg instanceof StringConstant)
        return new StringValue(((StringConstant) arg).value);
    else if (arg instanceof Constant)
        return new ConstantValue((Constant) arg,typ);
    else {
        Out.getLog().println("Weird value to treat" + arg);
        return new UnknownValue (arg.toString());
    }
}
项目:matos-tool    文件:MethodSpyAnalysis.java   
private AbsValue analyzeArg(Value v) {
    if (v instanceof Local) {
        PointsToSet p2s = pag.reachingObjects((Local) v);
        return P2SAux.p2sContents(cc.nodeTable, p2s);
    } else if (v instanceof StringConstant)
        return new StringValue(((StringConstant) v).value);
    else if (v instanceof Constant) {
        Constant co = (Constant) v;
        return new ConstantValue(co,co.getType());
    } else {
        Out.getLog().println("Weird argument to analyze : " + v);
        return new UnknownValue(v.toString());
    }
}
项目:matos-tool    文件:MethodSpyAnalysis.java   
/**
 * Analyze an expression (a value) and computes an abstract value representing its contents.
 * @param r the expression to analyse.
 * @param u The unit that encapsulate the value.
 * @param seen What has already be seen (avoid loops).
 * @return
 */
public AbsValue analyze_expr(Value r, Unit u,  Set<Unit> seen) {
    AbsValue result;
    if (r instanceof Local) {
        result = analyzeLocal((Local) r, u, seen);
    } else if (r instanceof StringConstant)
        result = new StringValue(((StringConstant) r).value);
    else if (r instanceof Constant) 
        result = new ConstantValue((Constant) r,((Constant) r).getType());
    else if (r instanceof InvokeExpr) {
        result = analyzeInvoke((InvokeExpr) r,u,seen);
    } else if (r instanceof CastExpr) {
        result = analyze_expr(((CastExpr) r).getOp(),u,seen);
    } else if (r instanceof ParameterRef) {
        result = analyzeParameterRef((ParameterRef) r, u, seen);
    } else if (r instanceof ConditionExpr) {
        result = analyzeConditionExpr((ConditionExpr) r, u, seen);
    } else if (r instanceof InstanceOfExpr) {
        result = analyzeInstanceOfExpr((InstanceOfExpr) r, u, seen);
    } else if (r instanceof StaticFieldRef) {
        result = analyzeStaticFieldRef((StaticFieldRef) r,u,seen);
    } else if (r instanceof InstanceFieldRef) {
        result = analyzeInstanceFieldRef((InstanceFieldRef) r,u,seen);
    } else if (r instanceof ArrayRef) {
        result = analyzeArrayRef((ArrayRef) r,u,seen);
    } else if (r instanceof NewExpr) {
        result = analyzeNewExpr((NewExpr) r, u, seen);
    } else {
        result = new UnknownValue(r.toString());
    }
    return solve_init(result,u,seen);
}
项目:matos-tool    文件:ConstantValue.java   
/**
 * Builds a representation of a constant from its value expressed as
 * a Soot constant and its Soot type. It is transformed in an equivalent
 * pair of strings.
 * @param v the value of the constant
 * @param t its type.
 */
public ConstantValue(Constant v, Type t) { 
    if (v instanceof IntConstant) {
        int n = ((IntConstant) v).value;
        if (t instanceof CharType) {
            rep_t = CHAR_TYPE;
            rep_v = Character.toString((char) n);
        } else if (t instanceof BooleanType) {
            rep_t = BOOLEAN_TYPE;
            rep_v = Boolean.toString((n != 0));
        } else {
            rep_t = INT_TYPE;
            rep_v = Integer.toString(n);
        }
    } else if (v instanceof LongConstant) {
        rep_t = LONG_TYPE;
        rep_v = Long.toString(((LongConstant) v).value);
    } else if (v instanceof FloatConstant) {
        rep_t = FLOAT_TYPE;
        rep_v = Float.toString(((FloatConstant) v).value);
    } else if (v instanceof NullConstant) {
        rep_t = NULL;
        rep_v = NULL;
    } else {
        rep_t = t.toString();
        rep_v = "";
    }
}
项目:FlowTwist    文件:Taint.java   
public Taint(Unit sourceUnit, Trackable predecessor, Value value, Type type) {
    super(sourceUnit, predecessor);

    if (value instanceof Constant) {
        throw new IllegalArgumentException("Constant value has been tainted.");
    }

    this.value = value;
    this.type = type;
}
项目:FlowTwist    文件:DefaultTaintPropagator.java   
@Override
public KillGenInfo propagateNormalFlow(Trackable trackable, Unit curr, Unit succ) {
    if (!(curr instanceof DefinitionStmt))
        return identity();

    Taint taint = (Taint) trackable;
    DefinitionStmt defStmt = (DefinitionStmt) curr;
    // extract "base" locals of array refs
    Value leftBase = AnalysisUtil.getBackwardsBase(defStmt.getLeftOp());
    Value rightBase = AnalysisUtil.getBackwardsBase(defStmt.getRightOp());

    if (!AnalysisUtil.maybeSameLocation(taint.value, leftBase))
        return identity();
    if (leftBase.equals(rightBase)) // x = x; or x[i] = x[j]; -> do nothing
        return identity();

    if (defStmt.getLeftOp() instanceof Local) { // Local
        if (defStmt.getRightOp() instanceof Constant || !AnalysisUtil.isAssignable(taint.type, rightBase.getType()))
            return kill();

        return propagate(taint.createAlias(rightBase, curr));
    } else { // Field
        if (defStmt.getRightOp() instanceof Constant || !AnalysisUtil.isAssignable(taint.type, rightBase.getType()))
            return identity();

        // if the stmt defines a local then we know that this value we
        // definitely overwritten;
        // if it does not define a local (but, say, a FieldRef) then the
        // value *may* have been
        // overwritten; hence we need to track the source, too
        return gen(taint.createAlias(rightBase, curr));
    }
}
项目:jgs    文件:AnnotationStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    logger.fine("\n > > > Return statement identified < < <");
    valueSwitch.callingStmt = stmt;
    logger.finer("Use boxes: " + stmt.getUseBoxes().toString());
    Value val = stmt.getUseBoxes().get(0).getValue();
    if (val instanceof Constant) {
        JimpleInjector.returnConstant(stmt);
    } else if (val instanceof Local) {
        JimpleInjector.returnLocal((Local) val, stmt);
    }
}
项目:jgs    文件:AnnotationStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    logger.fine("\n > > > Return statement identified < < <");
    logger.finer("Use boxes: " + stmt.getUseBoxes().toString());
    Value val = stmt.getUseBoxes().get(0).getValue();
    // JimpleInjector.popGlobalPC();
    if (val instanceof Constant) {
        JimpleInjector.returnConstant(stmt);
    } else if (val instanceof Local) {

        JimpleInjector.returnLocal((Local) val, stmt);
    }
}
项目:vasco    文件:CopyConstantAnalysis.java   
@Override
public Map<Local, Constant> callExitFlowFunction(Context<SootMethod, Unit, Map<Local, Constant>> context, SootMethod calledMethod, Unit unit, Map<Local, Constant> exitValue) {
    // Initialise result to an empty value
    Map<Local, Constant> afterCallValue = topValue();
    // Only propagate constants for return values
    if (unit instanceof AssignStmt) {
        Value lhsOp = ((AssignStmt) unit).getLeftOp();
        assign((Local) lhsOp, RETURN_LOCAL, exitValue, afterCallValue);
    }
    // Return the map with the returned value's constant
    return afterCallValue;
}
项目:vasco    文件:CopyConstantAnalysis.java   
@Override
public Map<Local, Constant> callLocalFlowFunction(Context<SootMethod, Unit, Map<Local, Constant>> context, Unit unit, Map<Local, Constant> inValue) {
    // Initialise result to the input
    Map<Local, Constant> afterCallValue = copy(inValue);
    // Remove information for return value (as it's value will flow from the call)
    if (unit instanceof AssignStmt) {
        Value lhsOp = ((AssignStmt) unit).getLeftOp();
        afterCallValue.remove(lhsOp);
    }
    // Rest of the map remains the same
    return afterCallValue;

}
项目:vasco    文件:PointsToGraph.java   
/**
 * Assigns a constant to a root variable.
 */
public void assignConstant(Local lhs, Constant rhs) {
    // Get the allocation site of this constant
    NewExpr newExpr = constantNewExpr(rhs);
    // If it was a null constant, assign null, otherwise assign alloc site
    if (newExpr == null) {
        assign(lhs, null);
    } else {
        assignNew(lhs, newExpr);
    }
}
项目:vasco    文件:PointsToGraph.java   
/**
 * Creates a new node for a constant.
 */
private NewExpr constantNewExpr(Constant constant) {
    if (constant instanceof StringConstant) {
        return STRING_SITE;
    } else if (constant instanceof ClassConstant) {
        return CLASS_SITE;
    } else if (constant instanceof NullConstant) {
        return null;
    } else {
        throw new RuntimeException(constant.toString());
    }
}
项目:vasco    文件:PointsToGraph.java   
/**
 * Stores a constant into a field of objects pointed-to by a root variable.
 */
public void setFieldConstant(Local lhs, SootField field, Constant rhs) {
    // Find out the alloc site of the constant
    NewExpr newExpr = constantNewExpr(rhs);
    // If null, do nothing, as we handle only weak updates,
    // otherwise, add the edge
    if (newExpr != null) {
        setFieldNew(lhs, field, newExpr);
    }
}
项目:vasco    文件:CopyConstantTest.java   
public static String formatConstants(Map<Local, Constant> value) {
    if (value == null) {
        return "";
    }
    StringBuffer sb = new StringBuffer();
    for (Map.Entry<Local,Constant> entry : value.entrySet()) {
        Local local = entry.getKey();
        Constant constant = entry.getValue();
        if (constant != null) {
            sb.append("(").append(local).append("=").append(constant).append(") ");
        }
    }
    return sb.toString();
}