Search in sources :

Example 6 with IfStmt

use of soot.jimple.IfStmt in project soot by Sable.

the class IfTestzInstruction method ifStatement.

@Override
protected IfStmt ifStatement(DexBody body) {
    Instruction21t i = (Instruction21t) instruction;
    BinopExpr condition = getComparisonExpr(body, i.getRegisterA());
    IfStmt jif = Jimple.v().newIfStmt(condition, targetInstruction.getUnit());
    // setUnit() is called in ConditionalJumpInstruction
    addTags(jif);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
    // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ jif);
    /*
           int op = instruction.getOpcode().value;
           switch (op) {
           case 0x38:
           case 0x39:
             //DalvikTyper.v().addConstraint(condition.getOp1Box(), condition.getOp2Box());
             break;
           case 0x3a:
           case 0x3b:
           case 0x3c:
           case 0x3d:
             DalvikTyper.v().setType(condition.getOp1Box(), BooleanType.v(), true);
             break;
           default:
             throw new RuntimeException("error: unknown op: 0x"+ Integer.toHexString(op));
           }
           */
    }
    return jif;
}
Also used : Instruction21t(org.jf.dexlib2.iface.instruction.formats.Instruction21t) IfStmt(soot.jimple.IfStmt) BinopExpr(soot.jimple.BinopExpr)

Example 7 with IfStmt

use of soot.jimple.IfStmt in project soot by Sable.

the class UnitThrowAnalysisTest method testJIfStmt.

@Test
public void testJIfStmt() {
    IfStmt s = Jimple.v().newIfStmt(Jimple.v().newEqExpr(IntConstant.v(1), IntConstant.v(1)), (Unit) null);
    // A very tight infinite loop.
    s.setTarget(s);
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
Also used : IfStmt(soot.jimple.IfStmt) Test(org.junit.Test)

Example 8 with IfStmt

use of soot.jimple.IfStmt in project soot by Sable.

the class UnitThrowAnalysisTest method testGIfStmt.

@Test
public void testGIfStmt() {
    IfStmt s = Grimp.v().newIfStmt(Grimp.v().newEqExpr(IntConstant.v(1), IntConstant.v(1)), (Unit) null);
    // A very tight infinite loop.
    s.setTarget(s);
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
Also used : IfStmt(soot.jimple.IfStmt) Test(org.junit.Test)

Example 9 with IfStmt

use of soot.jimple.IfStmt in project soot by Sable.

the class DexIfTransformer method getNullIfCandidates.

/**
 * Collect all the if statements comparing two locals with an Eq or Ne
 * expression
 *
 * @param body
 *            the body to analyze
 */
private Set<IfStmt> getNullIfCandidates(Body body) {
    Set<IfStmt> candidates = new HashSet<IfStmt>();
    Iterator<Unit> i = body.getUnits().iterator();
    while (i.hasNext()) {
        Unit u = i.next();
        if (u instanceof IfStmt) {
            ConditionExpr expr = (ConditionExpr) ((IfStmt) u).getCondition();
            boolean isTargetIf = false;
            if (((expr instanceof EqExpr) || (expr instanceof NeExpr))) {
                if (expr.getOp1() instanceof Local && expr.getOp2() instanceof Local) {
                    isTargetIf = true;
                }
            }
            if (isTargetIf) {
                candidates.add((IfStmt) u);
            }
        }
    }
    return candidates;
}
Also used : IfStmt(soot.jimple.IfStmt) EqExpr(soot.jimple.EqExpr) NeExpr(soot.jimple.NeExpr) ConditionExpr(soot.jimple.ConditionExpr) Local(soot.Local) Unit(soot.Unit) HashSet(java.util.HashSet)

Example 10 with IfStmt

use of soot.jimple.IfStmt in project soot by Sable.

the class DexJumpChainShortener method internalTransform.

@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 GotoStmt) {
            GotoStmt stmt = (GotoStmt) u;
            while (stmt.getTarget() instanceof GotoStmt) {
                GotoStmt nextTarget = (GotoStmt) stmt.getTarget();
                stmt.setTarget(nextTarget.getTarget());
            }
        } else if (u instanceof IfStmt) {
            IfStmt stmt = (IfStmt) u;
            while (stmt.getTarget() instanceof GotoStmt) {
                GotoStmt nextTarget = (GotoStmt) stmt.getTarget();
                stmt.setTarget(nextTarget.getTarget());
            }
        }
    }
}
Also used : IfStmt(soot.jimple.IfStmt) GotoStmt(soot.jimple.GotoStmt) Unit(soot.Unit)

Aggregations

IfStmt (soot.jimple.IfStmt)26 Unit (soot.Unit)17 Local (soot.Local)13 Value (soot.Value)13 Stmt (soot.jimple.Stmt)12 IdentityStmt (soot.jimple.IdentityStmt)10 ReturnStmt (soot.jimple.ReturnStmt)10 AssignStmt (soot.jimple.AssignStmt)9 InvokeStmt (soot.jimple.InvokeStmt)9 GotoStmt (soot.jimple.GotoStmt)8 InvokeExpr (soot.jimple.InvokeExpr)8 LookupSwitchStmt (soot.jimple.LookupSwitchStmt)8 TableSwitchStmt (soot.jimple.TableSwitchStmt)8 ThrowStmt (soot.jimple.ThrowStmt)8 Type (soot.Type)7 BinopExpr (soot.jimple.BinopExpr)7 EnterMonitorStmt (soot.jimple.EnterMonitorStmt)7 ExitMonitorStmt (soot.jimple.ExitMonitorStmt)7 InstanceInvokeExpr (soot.jimple.InstanceInvokeExpr)7 ReturnVoidStmt (soot.jimple.ReturnVoidStmt)7