/** * 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))); } } }
@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)); } } } } }
Value nmexpr = new JNewMultiArrayExpr(atype, sizes); ((AssignStmt) startpoint).setRightOp(nmexpr); ((AssignStmt) curstmt).setRightOp(arexpr); tmpcur = (Local) leftOp; } else if ((leftOp instanceof ArrayRef) && (rightOp.equals(tmpcur))) {
PiExpr pe = Shimple.getPiExpr(u); if (pe != null) { ((AssignStmt) u).setRightOp(pe.getValue());
@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 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); } } }
BinopExpr aer = (BinopExpr) assignStmt.getRightOp(); if (isConstZero(aer.getOp1())) { assignStmt.setRightOp(aer.getOp2()); } else if (isConstZero(aer.getOp2())) { assignStmt.setRightOp(aer.getOp1()); BinopExpr aer = (BinopExpr) assignStmt.getRightOp(); if (isConstZero(aer.getOp2())) { assignStmt.setRightOp(aer.getOp1()); BinopExpr aer = (BinopExpr) assignStmt.getRightOp(); if (isConstZero(aer.getOp1())) { assignStmt.setRightOp(getZeroConst(assignStmt.getLeftOp().getType())); } else if (isConstZero(aer.getOp2())) { assignStmt.setRightOp(getZeroConst(assignStmt.getLeftOp().getType())); OrExpr orExpr = (OrExpr) assignStmt.getRightOp(); if (isConstZero(orExpr.getOp1())) { assignStmt.setRightOp(orExpr.getOp2()); } else if (isConstZero(orExpr.getOp2())) { assignStmt.setRightOp(orExpr.getOp1());
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { // Check for all assignments that perform casts on primitive constants for (Unit u : b.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getRightOp() instanceof CastExpr) { CastExpr ce = (CastExpr) assign.getRightOp(); if (ce.getOp() instanceof Constant) { // a = (float) 42 if (ce.getType() instanceof FloatType && ce.getOp() instanceof IntConstant) { IntConstant it = (IntConstant) ce.getOp(); assign.setRightOp(FloatConstant.v(it.value)); } // a = (double) 42 else if (ce.getType() instanceof DoubleType && ce.getOp() instanceof IntConstant) { IntConstant it = (IntConstant) ce.getOp(); assign.setRightOp(DoubleConstant.v(it.value)); } } } } } }
constructStmt.setRightOp(Jimple.v().newNewExpr(((NewExpr) rhs).getBaseType())); MadeNewInvokeExpr = true;
.setRightOp(Grimp.v().newNewInvokeExpr(((NewExpr) rhs).getBaseType(), oldInvoke.getMethodRef(), invokeArgs)); MadeNewInvokeExpr = true;
Local helper = expToHelper.get(rhs); if (helper != null) { ((AssignStmt) currentUnit).setRightOp(helper);
/** * 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()); } } } }
units.insertAfter(copier, origCalc); ((AssignStmt) s).setRightOp(l); copier.addTag(new StringTag("Common sub-expression")); s.addTag(new StringTag("Common sub-expression"));
((AssignStmt) currentUnit).setRightOp(helper);
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { // Some apps reference static fields as instance fields. We need to fix // this for not breaking the client analysis. for (Iterator<Unit> unitIt = b.getUnits().iterator(); unitIt.hasNext();) { Stmt s = (Stmt) unitIt.next(); if (s.containsFieldRef() && s instanceof AssignStmt) { FieldRef ref = s.getFieldRef(); // Make sure that the target class has already been loaded if (isTypeLoaded(ref.getFieldRef().type())) { try { if (ref instanceof InstanceFieldRef) { SootField fld = ref.getField(); if (fld != null && fld.isStatic()) { AssignStmt assignStmt = (AssignStmt) s; if (assignStmt.getLeftOp() == ref) { assignStmt.setLeftOp(Jimple.v().newStaticFieldRef(ref.getField().makeRef())); } else if (assignStmt.getRightOp() == ref) { assignStmt.setRightOp(Jimple.v().newStaticFieldRef(ref.getField().makeRef())); } } } } catch (ConflictingFieldRefException ex) { // That field is broken, just don't touch it } } } } }
lType = l.getType(); stmt.setRightOp(uc.defineType(lType)); } else if (stmt.getRightOp() instanceof InvokeExpr) { changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp()); ArrayType lType = (ArrayType) localTyped.get(baseLocal); Type elemType = lType.getElementType(); stmt.setRightOp(uc.defineType(elemType));
assignStmt.setRightOp(((AssignStmt) u1).getRightOp()); } else if (assignStmt.getRightOp() == u2val) { assignStmt.setRightOp(((AssignStmt) u2).getRightOp());
stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); stmt.setLeftOp(this.uv.visit(lhs, tlhs, stmt)); } else if (lhs instanceof FieldRef) { stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); } else if (rhs instanceof ArrayRef) { ArrayRef aref = (ArrayRef) rhs; stmt.setRightOp(this.uv.visit(rhs, trhs, stmt)); } else if (rhs instanceof InstanceFieldRef) { this.handleInstanceFieldRef((InstanceFieldRef) rhs, stmt); stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); } else if (rhs instanceof BinopExpr) { this.handleBinopExpr((BinopExpr) rhs, stmt, tlhs); } else if (rhs instanceof InvokeExpr) { this.handleInvokeExpr((InvokeExpr) rhs, stmt); stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); } else if (rhs instanceof CastExpr) { stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); } else if (rhs instanceof InstanceOfExpr) { InstanceOfExpr ioe = (InstanceOfExpr) rhs; ioe.setOp(this.uv.visit(ioe.getOp(), RefType.v("java.lang.Object"), stmt)); stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); } else if (rhs instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) rhs; nae.setSize(this.uv.visit(nae.getSize(), IntType.v(), stmt)); stmt.setRightOp(this.uv.visit(rhs, tlhs, stmt)); } else if (rhs instanceof NewMultiArrayExpr) { NewMultiArrayExpr nmae = (NewMultiArrayExpr) rhs;
as.setRightOp(newExpr);
as.setRightOp(e); unitsBuilt.add(as); if (neg) { as.setRightOp(e); unitsBuilt.add(as); if (neg) {