private void printBinaryExpr(BinopExpr v) { String className = v.getClass().getSimpleName(); if (className.charAt(0) == 'J') { className = className.substring(1); } String oldName = varName; Value left = v.getOp1(); String v1 = printValueAssignment(left, "left"); Value right = v.getOp2(); String v2 = printValueAssignment(right, "right"); p.println("Value " + oldName + " = Jimple.v().new" + className + "(" + v1 + "," + v2 + ");"); varName = oldName; }
private void handleBinopExpr(BinopExpr be, Stmt stmt, Type tlhs) { Value opl = be.getOp1(), opr = be.getOp2(); Type tl = AugEvalFunction.eval_(this.tg, opl, stmt, this.jb), tr = AugEvalFunction.eval_(this.tg, opr, stmt, this.jb); if (be instanceof AddExpr || be instanceof SubExpr || be instanceof MulExpr || be instanceof DivExpr || be instanceof RemExpr || be instanceof GeExpr || be instanceof GtExpr || be instanceof LeExpr || be instanceof LtExpr || be instanceof ShlExpr || be instanceof ShrExpr || be instanceof UshrExpr) { if (tlhs instanceof IntegerType) { be.setOp1(this.uv.visit(opl, IntType.v(), stmt)); be.setOp2(this.uv.visit(opr, IntType.v(), stmt)); } } else if (be instanceof CmpExpr || be instanceof CmpgExpr || be instanceof CmplExpr) { // No checks in the original assigner } else if (be instanceof AndExpr || be instanceof OrExpr || be instanceof XorExpr) { be.setOp1(this.uv.visit(opl, tlhs, stmt)); be.setOp2(this.uv.visit(opr, tlhs, stmt)); } else if (be instanceof EqExpr || be instanceof NeExpr) { if (tl instanceof BooleanType && tr instanceof BooleanType) { } else if (tl instanceof Integer1Type || tr instanceof Integer1Type) { } else if (tl instanceof IntegerType) { be.setOp1(this.uv.visit(opl, IntType.v(), stmt)); be.setOp2(this.uv.visit(opr, IntType.v(), stmt)); } } }
@Override public void caseIfStmt(IfStmt stmt) { // add constraint Value c = stmt.getCondition(); if (c instanceof BinopExpr) { BinopExpr bo = (BinopExpr) c; Value op1 = bo.getOp1(); Value op2 = bo.getOp2(); if (op1 instanceof Local && op2 instanceof Local) { DalvikTyper.v().addConstraint(bo.getOp1Box(), bo.getOp2Box()); } } }
protected void checkExpr(Value v, Type t) { for (ValueBox vb : v.getUseBoxes()) { Value value = vb.getValue(); if (value instanceof Local) { // special case where the second operand is always of type integer if ((v instanceof ShrExpr || v instanceof ShlExpr || v instanceof UshrExpr) && ((BinopExpr) v).getOp2() == value) { // Debug.printDbg("setting type of operand two of shift expression to integer", value); DalvikTyper.v().setType(vb, IntType.v(), true); continue; } DalvikTyper.v().setType(vb, t, true); } else if (value instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) value; // special case where the second operand is always of type integer if ((v instanceof ShrExpr || v instanceof ShlExpr || v instanceof UshrExpr) && ((BinopExpr) v).getOp2() == value) { UntypedIntOrFloatConstant ui = (UntypedIntOrFloatConstant) uc; vb.setValue(ui.toIntConstant()); continue; } vb.setValue(uc.defineType(t)); } } }
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; } }
private void caseBinopDivExpr(BinopExpr expr) { // Factors out code common to caseDivExpr and caseRemExpr. // The checks against constant divisors would perhaps be // better performed in a later pass, post-constant-propagation. Value divisor = expr.getOp2(); Type divisorType = divisor.getType(); if (divisorType instanceof UnknownType) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } else if ((divisorType instanceof IntegerType) && ((!(divisor instanceof IntConstant)) || (((IntConstant) divisor).equals(INT_CONSTANT_ZERO)))) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } else if ((divisorType == LongType.v()) && ((!(divisor instanceof LongConstant)) || (((LongConstant) divisor).equals(LONG_CONSTANT_ZERO)))) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } caseBinopExpr(expr); }
if (c instanceof BinopExpr) { BinopExpr be = (BinopExpr) c; Value op1 = be.getOp1(); Value op2 = be.getOp2(); if (op1 instanceof UntypedConstant || op2 instanceof UntypedConstant) { be.setOp2(uc.defineType(t)); } else if (op2 instanceof Local) { Type t = localTyped.get(op2); be.setOp1(uc.defineType(t)); } else if (op1 instanceof UntypedConstant && op2 instanceof UntypedConstant) { if (op1 instanceof UntypedIntOrFloatConstant && op2 instanceof UntypedIntOrFloatConstant) { UntypedIntOrFloatConstant uc1 = (UntypedIntOrFloatConstant) op1; UntypedIntOrFloatConstant uc2 = (UntypedIntOrFloatConstant) op2; be.setOp1(uc1.toIntConstant()); // to int or float, it does not matter be.setOp2(uc2.toIntConstant()); } else if (op1 instanceof UntypedLongOrDoubleConstant && op2 instanceof UntypedLongOrDoubleConstant) { UntypedLongOrDoubleConstant uc1 = (UntypedLongOrDoubleConstant) op1; UntypedLongOrDoubleConstant uc2 = (UntypedLongOrDoubleConstant) op2; be.setOp1(uc1.toLongConstant()); // to long or double, it does not matter be.setOp2(uc2.toLongConstant()); } else { throw new RuntimeException("error: expected same type of untyped constants. Got " + stmt); if (op1 instanceof UntypedConstant) { UntypedConstant uc = (UntypedConstant) op1; be.setOp1(uc.defineType(op2.getType())); } else if (op2 instanceof UntypedConstant) {
private void caseBinopDivExpr(BinopExpr expr) { // Factors out code common to caseDivExpr and caseRemExpr. // The checks against constant divisors would perhaps be // better performed in a later pass, post-constant-propagation. Value divisor = expr.getOp2(); Type divisorType = divisor.getType(); if (divisorType instanceof UnknownType) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } else if ((divisorType instanceof IntegerType) && ((! (divisor instanceof IntConstant)) || (((IntConstant) divisor).equals(INT_CONSTANT_ZERO)))) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } else if ((divisorType == LongType.v()) && ((! (divisor instanceof LongConstant)) || (((LongConstant) divisor).equals(LONG_CONSTANT_ZERO)))) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } caseBinopExpr(expr); }
private void caseBinopDivExpr(BinopExpr expr) { // Factors out code common to caseDivExpr and caseRemExpr. // The checks against constant divisors would perhaps be // better performed in a later pass, post-constant-propagation. Value divisor = expr.getOp2(); Type divisorType = divisor.getType(); if (divisorType instanceof UnknownType) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } else if ((divisorType instanceof IntegerType) && ((! (divisor instanceof IntConstant)) || (((IntConstant) divisor).equals(INT_CONSTANT_ZERO)))) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } else if ((divisorType == LongType.v()) && ((! (divisor instanceof LongConstant)) || (((LongConstant) divisor).equals(LONG_CONSTANT_ZERO)))) { result = result.add(mgr.ARITHMETIC_EXCEPTION); } caseBinopExpr(expr); }