static Value lhs(Stmt s) { AssignStmt as = (AssignStmt) s; return as.getLeftOp(); }
private RWSet ntWriteSet(SootMethod method, Stmt stmt) { if (stmt instanceof AssignStmt) { AssignStmt a = (AssignStmt) stmt; Value l = a.getLeftOp(); return addValue(l, method, stmt); } return null; }
private RWSet ntWriteSet(SootMethod method, Stmt stmt) { if (stmt instanceof AssignStmt) { AssignStmt a = (AssignStmt) stmt; Value l = a.getLeftOp(); return addValue(l, method, stmt); } 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; }
private void printOutput(List<Unit> unitsBuilt) { if (!output) { return; } out.println(" after as: "); for (Unit uu : unitsBuilt) { out.println( "\t" + uu + "\ttype : " + (uu instanceof AssignStmt ? ((AssignStmt) uu).getLeftOp().getType().toString() : "")); } }
/** * 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; }
public AssignStmt newAssignStmt(AssignStmt s) { return new GAssignStmt(s.getLeftOp(), s.getRightOp()); }
private boolean sameCondLocal(Stmt s1, Stmt s2) { AssignStmt as1 = (AssignStmt) s1; IfStmt is2 = (IfStmt) s2; if (is2.getCondition() instanceof BinopExpr) { BinopExpr bs2 = (BinopExpr) is2.getCondition(); if (as1.getLeftOp().equals(bs2.getOp1())) { return true; } } return false; } }
@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())); }
/** * 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 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())); }
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()); } } } } } }
protected void ensureProcessed(SootMethod m) { if (processedMethods.contains(m)) { return; } processedMethods.add(m); if (!m.isConcrete()) { return; } if (m.isPhantom()) { return; } for (Iterator sIt = m.retrieveActiveBody().getUnits().iterator(); sIt.hasNext();) { final Stmt s = (Stmt) sIt.next(); if (s instanceof AssignStmt) { AssignStmt as = (AssignStmt) s; Value l = as.getLeftOp(); if (l instanceof FieldRef) { methodToWrite.put(m, ((FieldRef) l).getField()); } Value r = as.getRightOp(); if (r instanceof FieldRef) { methodToRead.put(m, ((FieldRef) r).getField()); } } } }
/** * Replace 0 with null in the given unit. * * @param u * the unit where 0 will be replaced with null. */ protected void replaceWithNull(Unit u) { if (u instanceof IfStmt) { ConditionExpr expr = (ConditionExpr) ((IfStmt) u).getCondition(); if (isZeroComparison(expr)) { expr.setOp2(NullConstant.v()); } } else if (u instanceof AssignStmt) { AssignStmt s = (AssignStmt) u; Value v = s.getRightOp(); if ((v instanceof IntConstant && ((IntConstant) v).value == 0) || (v instanceof LongConstant && ((LongConstant) v).value == 0)) { // If this is a field assignment, double-check the type. We // might have a.f = 2 with a being a null candidate, but a.f // being an int. if (!(s.getLeftOp() instanceof InstanceFieldRef) || ((InstanceFieldRef) s.getLeftOp()).getFieldRef().type() instanceof RefLikeType) { s.setRightOp(NullConstant.v()); } } } }
/** * Returns true if the statement <code>stmt</code> contains an illegal access to a field or method, assuming the statement * is in method <code>container</code> * * @param container * @param stmt * @return */ public static boolean isAccessLegal(SootMethod container, Stmt stmt) { if (stmt.containsInvokeExpr()) { return AccessManager.isAccessLegal(container, stmt.getInvokeExpr().getMethod()); } else if (stmt instanceof AssignStmt) { AssignStmt as = (AssignStmt) stmt; if (as.getRightOp() instanceof FieldRef) { FieldRef r = (FieldRef) as.getRightOp(); return AccessManager.isAccessLegal(container, r.getField()); } if (as.getLeftOp() instanceof FieldRef) { FieldRef r = (FieldRef) as.getLeftOp(); return AccessManager.isAccessLegal(container, r.getField()); } } return true; }
@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 FlowFunction<Local> getNormalFlowFunction(Unit src, Unit dest) { if (src instanceof IdentityStmt && interproceduralCFG().getMethodOf(src) == Scene.v().getMainMethod()) { IdentityStmt is = (IdentityStmt) src; Local leftLocal = (Local) is.getLeftOp(); Value right = is.getRightOp(); if (right instanceof ParameterRef) { return new Gen<Local>(leftLocal, zeroValue()); } } if (src instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) src; Value right = assignStmt.getRightOp(); if (assignStmt.getLeftOp() instanceof Local) { final Local leftLocal = (Local) assignStmt.getLeftOp(); if (right instanceof Local) { final Local rightLocal = (Local) right; return new Transfer<Local>(leftLocal, rightLocal); } else { return new Kill<Local>(leftLocal); } } } return Identity.v(); }
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; }