/** * 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 soot.jimple.AssignStmt newAssignStmt(Value variable, Value rvalue, ASTNode location) { soot.jimple.AssignStmt stmt = Jimple.v().newAssignStmt(variable, rvalue); soot.tagkit.Tag left = getTag(variable); if(left != null) stmt.getLeftOpBox().addTag(left); soot.tagkit.Tag right = getTag(rvalue); if(right != null) stmt.getRightOpBox().addTag(right); return stmt; }
@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()); } } } } } }
/** * 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 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); } } }
AssignStmt assign = (AssignStmt) stmt2; if (assign.getRightOp() instanceof Local) { deflist = defs.getDefsOfAt((Local) assign.getRightOp(), assign); continue; } else if (assign.getRightOp() instanceof NewExpr) { units.insertAfter(Jimple.v().newAssignStmt(assign.getLeftOp(), newlocal), assign); assign.setLeftOp(newlocal);
@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 } } } } }
Value lhs = ((AssignStmt) s).getLeftOp(); if (!(lhs instanceof Local)) { continue; Value rhs = ((AssignStmt) s).getRightOp(); if (!(rhs instanceof NewExpr)) { continue; constructStmt.setRightOp(Jimple.v().newNewExpr(((NewExpr) rhs).getBaseType())); MadeNewInvokeExpr = true; constructStmt.addTag(s.getTag("SourceLnPosTag"));
Value l = stmt.getLeftOp(); Value r = stmt.getRightOp(); if (stmt.containsArrayRef()) { ArrayRef ar = stmt.getArrayRef(); ValueBox sb = ar.getIndexBox(); if (sb.getValue() instanceof Local) { DalvikTyper.v().addConstraint(stmt.getLeftOpBox(), stmt.getRightOpBox()); return; if (stmt.containsInvokeExpr()) { DalvikTyper.v().setInvokeType(stmt.getInvokeExpr()); Type leftType = stmt.getLeftOp().getType(); if (l instanceof ArrayRef && leftType instanceof UnknownType) { DalvikTyper.v().setType(stmt.getRightOpBox(), leftType, true); return; for (Tag t : stmt.getTags()) { DalvikTyper.v().setType(stmt.getLeftOpBox(), IntType.v(), false); return; } else if (t instanceof FloatOpTag) { checkExpr(r, FloatType.v()); DalvikTyper.v().setType(stmt.getLeftOpBox(), FloatType.v(), false); return; } else if (t instanceof DoubleOpTag) {
if (stmt.getRightOp() instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) stmt.getRightOp(); if (nae.getSize() instanceof UntypedConstant) { UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) nae.getSize(); nae.setSize(uc.defineType(IntType.v())); } else if (stmt.getRightOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getRightOp(); Value l = stmt.getLeftOp(); Type lType = null; if (l instanceof ArrayRef) { stmt.setRightOp(uc.defineType(lType)); } else if (stmt.getRightOp() instanceof InvokeExpr) { changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp()); if (!stmt.containsArrayRef()) { return; ArrayRef ar = stmt.getArrayRef(); if ((ar.getIndex() instanceof UntypedConstant)) { UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) ar.getIndex(); if (stmt.getLeftOp() instanceof ArrayRef && stmt.getRightOp() instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) stmt.getRightOp(); Local baseLocal = (Local) stmt.getArrayRef().getBase(); ArrayType lType = (ArrayType) localTyped.get(baseLocal); Type elemType = lType.getElementType(); stmt.setRightOp(uc.defineType(elemType));
if (use instanceof AssignStmt) { AssignStmt ass2 = (AssignStmt) use; l2 = ass2.getLeftOp(); r2 = ass2.getRightOp(); if (!(l2 instanceof Local) || !(r2 instanceof Local || r2 instanceof ArrayRef)) { DalvikTyper.v().setType(ass2.getLeftOpBox(), newType, true); Value l = ass.getLeftOp(); Value r = ass.getRightOp(); ArrayRef ar = null; Local loc = null; continue; } else { DalvikTyper.v().setType(ar == l ? ass.getRightOpBox() : ass.getLeftOpBox(), t, true); todoUnits.remove(u); if (!(ass.getLeftOp() instanceof Local)) { continue; if (!(ass.getRightOp() instanceof UntypedConstant)) { continue; UntypedConstant uc = (UntypedConstant) ass.getRightOp(); ass.setRightOp(uc.defineType(localTyped.get(ass.getLeftOp()))); Value right = a.getRightOp(); if (right instanceof CastExpr) {
Value lhs = s.getLeftOp(); if (!(lhs instanceof Local)) { continue; if (boxToZone.get(s.getRightOpBox()) != boxToZone.get(usepair.valueBox)) { continue; for (ValueBox vb : s.getUseBoxes()) { Value v = vb.getValue(); if (v instanceof Local) { Value aggregatee = s.getRightOp();
static Value rhs(Stmt s) { AssignStmt as = (AssignStmt) s; return as.getRightOp(); }
if (assignStmt.getLeftOp() instanceof ArrayRef) { if (u1 != null && u2 != null && u2.getBoxesPointingToThis().isEmpty() && assignStmt.getBoxesPointingToThis().isEmpty()) { ArrayRef arrayRef = (ArrayRef) assignStmt.getLeftOp(); arrayRef.setIndex(((AssignStmt) u1).getRightOp()); } else if (arrayRef.getIndex() == u2val) { arrayRef.setIndex(((AssignStmt) u2).getRightOp()); if (assignStmt.getRightOp() == u1val) { assignStmt.setRightOp(((AssignStmt) u1).getRightOp()); } else if (assignStmt.getRightOp() == u2val) { assignStmt.setRightOp(((AssignStmt) u2).getRightOp()); if (!(assignStmt.getRightOp() instanceof Constant)) { u1 = null; u2 = null; Value op1 = ((AssignStmt) u1).getLeftOp(); if (op1 == ((AssignStmt) u2).getLeftOp()) { u1 = u2; u2 = null;
static Value lhs(Stmt s) { AssignStmt as = (AssignStmt) s; return as.getLeftOp(); }
UnitValueBoxPair p = new UnitValueBoxPair(containingStmt, ((AssignStmt) containingStmt).getRightOpBox()); EquivalentValue ev = new EquivalentValue(v); pairsBefore.add(p); UnitValueBoxPair p = new UnitValueBoxPair(containingStmt, ((AssignStmt) containingStmt).getRightOpBox()); EquivalentValue ev = new EquivalentValue(v); pairsAfter.add(p);
@Override 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); AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr); assign.addTag(getTag()); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { /* * 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); */ } }
PiExpr pe = Shimple.getPiExpr(u); if (pe != null) { ((AssignStmt) u).setRightOp(pe.getValue());
AssignStmt assign = (AssignStmt) stmt2; if (assign.getRightOp() instanceof Local) { deflist = defs.getDefsOfAt((Local) assign.getRightOp(), assign); continue; } else if (assign.getRightOp() instanceof NewExpr) { units.insertAfter(Jimple.v().newAssignStmt(assign.getLeftOp(), newlocal), assign); assign.setLeftOp(newlocal);
Chain availExprs = ae.getAvailableEquivsBefore(s); Value v = ((AssignStmt) s).getRightOp(); EquivalentValue ev = new EquivalentValue(v); Value origLHS = origCalc.getLeftOp(); origCalc.setLeftOp(l); ((AssignStmt) s).setRightOp(l); copier.addTag(new StringTag("Common sub-expression")); s.addTag(new StringTag("Common sub-expression"));