static Value rhs(Stmt s) { AssignStmt as = (AssignStmt) s; return as.getRightOp(); }
/** * filters out the RHS of an assignmentStmt. * * @param unit * a Unit from which to extract the RHS. * @return the RHS-Value of <code>unit</code> or <code>null</code> if <code>unit</code> wasn't an assignment-stmt. */ public static Value rhs(Unit unit) { if (unit instanceof AssignStmt) { return ((AssignStmt) unit).getRightOp(); } else { return null; } }
private RWSet ntReadSet(SootMethod method, Stmt stmt) { if (stmt instanceof AssignStmt) { AssignStmt a = (AssignStmt) stmt; Value r = a.getRightOp(); if (r instanceof NewExpr) { return null; } return addValue(r, method, stmt); } return null; }
private RWSet ntReadSet(SootMethod method, Stmt stmt) { if (stmt instanceof AssignStmt) { AssignStmt a = (AssignStmt) stmt; Value r = a.getRightOp(); return addValue(r, method, stmt); } return null; }
public static PiExpr getPiExpr(Unit unit) { if (!(unit instanceof AssignStmt)) { return null; } Value right = ((AssignStmt) unit).getRightOp(); if (isPiExpr(right)) { return (PiExpr) right; } return null; }
/** * Returns the corresponding PhiExpr if the unit is a Phi node, null otherwise. **/ public static PhiExpr getPhiExpr(Unit unit) { if (!(unit instanceof AssignStmt)) { return null; } Value right = ((AssignStmt) unit).getRightOp(); if (isPhiExpr(right)) { return (PhiExpr) right; } return null; }
/** * Returns the corresponding left Local if the unit is a Shimple node, null otherwise. **/ public static Local getLhsLocal(Unit unit) { if (!(unit instanceof AssignStmt)) { return null; } Value right = ((AssignStmt) unit).getRightOp(); if (right instanceof ShimpleExpr) { Value left = ((AssignStmt) unit).getLeftOp(); return (Local) left; } return null; }
public AssignStmt newAssignStmt(AssignStmt s) { return new GAssignStmt(s.getLeftOp(), s.getRightOp()); }
@Override protected void internalTransform(Body b, String phaseName, Map options) { Iterator it = b.getUnits().iterator(); while (it.hasNext()) { Stmt s = (Stmt) it.next(); if (s instanceof ThrowStmt) { ThrowStmt ts = (ThrowStmt) s; checkThrow(b, ts); } else if (s instanceof InvokeStmt) { InvokeStmt is = (InvokeStmt) s; checkInvoke(b, is); } else if ((s instanceof AssignStmt) && (((AssignStmt) s).getRightOp() instanceof InvokeExpr)) { InvokeExpr ie = (InvokeExpr) ((AssignStmt) s).getRightOp(); checkInvokeExpr(b, ie, s); } } }
private boolean isObjectArray(Value v, Body body) { for (Unit u : body.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp() == v) { if (assign.getRightOp() instanceof NewArrayExpr) { NewArrayExpr nea = (NewArrayExpr) assign.getRightOp(); if (isObject(nea.getBaseType())) { return true; } } else if (assign.getRightOp() instanceof FieldRef) { FieldRef fr = (FieldRef) assign.getRightOp(); if (fr.getType() instanceof ArrayType) { if (isObject(((ArrayType) fr.getType()).getArrayElementType())) { return true; } } } } } } return false; }
/** * Collect all the locals which are assigned a IntConstant(0) or are used within a zero comparison. * * @param body * the body to analyze */ private Set<Local> getNumCandidates(Body body) { Set<Local> candidates = new HashSet<Local>(); for (Unit u : body.getUnits()) { if (u instanceof AssignStmt) { AssignStmt a = (AssignStmt) u; if (!(a.getLeftOp() instanceof Local)) { continue; } Local l = (Local) a.getLeftOp(); Value r = a.getRightOp(); if ((r instanceof IntConstant || r instanceof LongConstant)) { candidates.add(l); } } } return candidates; }
@Override public void caseAssignStmt(AssignStmt s) { // Dalvik only throws ArrayIndexOutOfBounds and // NullPointerException which are both handled through the // ArrayRef expressions. There is no ArrayStoreException in // Dalvik. result = result.add(mightThrow(s.getLeftOp())); result = result.add(mightThrow(s.getRightOp())); }
/** * Replace 0 with null in the given unit. * * @param u * the unit where 0 will be replaced with null. */ private void replaceWithFloatingPoint(Unit u) { if (u instanceof AssignStmt) { AssignStmt s = (AssignStmt) u; Value v = s.getRightOp(); if ((v instanceof IntConstant)) { int vVal = ((IntConstant) v).value; s.setRightOp(FloatConstant.v(Float.intBitsToFloat(vVal))); } else if (v instanceof LongConstant) { long vVal = ((LongConstant) v).value; s.setRightOp(DoubleConstant.v(Double.longBitsToDouble(vVal))); } } }
public void caseAssignStmt(AssignStmt stmt) { String varName = printValueAssignment(stmt.getLeftOp(), "lhs"); String varName2 = printValueAssignment(stmt.getRightOp(), "rhs"); printStmt(stmt, varName, varName2); }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Iterator<Unit> unitIt = b.getUnits().iterator(); unitIt.hasNext();) { Unit curUnit = unitIt.next(); if (curUnit instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) curUnit; if (assignStmt.getLeftOp() instanceof Local && assignStmt.getRightOp() instanceof CastExpr) { CastExpr ce = (CastExpr) assignStmt.getRightOp(); Type orgType = ce.getOp().getType(); Type newType = ce.getCastType(); // If this a cast such as a = (X) a, we can remove the whole line. // Otherwise, if only the types match, we can replace the typecast // with a normal assignment. if (orgType == newType) { if (assignStmt.getLeftOp() == ce.getOp()) { unitIt.remove(); } else { assignStmt.setRightOp(ce.getOp()); } } } } } }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); if (u instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) u; if (assignStmt.getRightOp() instanceof InstanceOfExpr) { InstanceOfExpr iof = (InstanceOfExpr) assignStmt.getRightOp(); // If the operand of the "instanceof" expression is null or // the zero constant, we replace the whole operation with // its outcome "false" if (iof.getOp() == NullConstant.v()) { assignStmt.setRightOp(IntConstant.v(0)); } if (iof.getOp() instanceof IntConstant && ((IntConstant) iof.getOp()).value == 0) { assignStmt.setRightOp(IntConstant.v(0)); } } } } }
/** * Checks whether after each new-instruction a constructor call follows. */ @Override public void validate(Body body, List<ValidationException> exceptions) { UnitGraph g = new BriefUnitGraph(body); for (Unit u : body.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; // First seek for a JNewExpr. if (assign.getRightOp() instanceof NewExpr) { if (!(assign.getLeftOp().getType() instanceof RefType)) { exceptions.add(new ValidationException(u, "A new-expression must be used on reference type locals", String.format("Body of method %s contains a new-expression, which is assigned to a non-reference local", body.getMethod().getSignature()))); return; } // We search for a JSpecialInvokeExpr on the local. LinkedHashSet<Local> locals = new LinkedHashSet<Local>(); locals.add((Local) assign.getLeftOp()); checkForInitializerOnPath(g, assign, exceptions); } } } }
@Override public void caseAssignStmt(AssignStmt stmt) { // Case a = 0 with a being an object if (isObject(stmt.getLeftOp().getType()) && isConstZero(stmt.getRightOp())) { stmt.setRightOp(nullConstant); return; } // Case a = (Object) 0 if (stmt.getRightOp() instanceof CastExpr) { CastExpr ce = (CastExpr) stmt.getRightOp(); if (isObject(ce.getCastType()) && isConstZero(ce.getOp())) { stmt.setRightOp(nullConstant); } } // Case a[0] = 0 if (stmt.getLeftOp() instanceof ArrayRef && isConstZero(stmt.getRightOp())) { ArrayRef ar = (ArrayRef) stmt.getLeftOp(); if (isObjectArray(ar.getBase(), body) || stmt.hasTag("ObjectOpTag")) { stmt.setRightOp(nullConstant); } } }
@Override public void caseAssignStmt(AssignStmt s) { Value lhs = s.getLeftOp(); if (lhs instanceof ArrayRef && (lhs.getType() instanceof UnknownType || lhs.getType() instanceof RefType)) { // This corresponds to an aastore byte code. result = result.add(mgr.ARRAY_STORE_EXCEPTION); } result = result.add(mightThrow(s.getLeftOp())); result = result.add(mightThrow(s.getRightOp())); }
/** Put the results of the analysis into tags in cast statements. */ protected void tagCasts() { for (Iterator<Unit> sIt = ((UnitGraph) graph).getBody().getUnits().iterator(); sIt.hasNext();) { final Stmt s = (Stmt) sIt.next(); if (s instanceof AssignStmt) { AssignStmt as = (AssignStmt) s; Value rhs = as.getRightOp(); if (rhs instanceof CastExpr) { CastExpr cast = (CastExpr) rhs; Type t = cast.getCastType(); if (t instanceof RefType) { if (cast.getOp() instanceof Local) { Local l = (Local) cast.getOp(); LocalTypeSet set = (LocalTypeSet) getFlowBefore(s); s.addTag(new CastCheckTag(set.get(set.indexOf(l, (RefType) t)))); } else { NullConstant nc = (NullConstant) cast.getOp(); s.addTag(new CastCheckTag(true)); } } } } } }