Search in sources :

Example 11 with GotoStmt

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

the class OutFlow method processTargetFixup.

/**
 * Runs through the given bbq contents performing the target fix-up pass;
 * Requires all reachable blocks to have their done flags set to true, and
 * this resets them all back to false;
 * @param bbq queue of BasicBlocks to process.
 * @see jimpleTargetFixup
 */
private void processTargetFixup(BBQ bbq) {
    BasicBlock b, p;
    Stmt s;
    while (!bbq.isEmpty()) {
        try {
            b = bbq.pull();
        } catch (NoSuchElementException e) {
            break;
        }
        s = b.getTailJStmt();
        if (s instanceof GotoStmt) {
            if (b.succ.size() == 1) {
                // Regular goto
                ((GotoStmt) s).setTarget(b.succ.firstElement().getHeadJStmt());
            } else {
                // Goto derived from a jsr bytecode
                /*
                    if((BasicBlock)(b.succ.firstElement())==b.next)
                        ((GotoStmt)s).setTarget(((BasicBlock) b.succ.elementAt(1)).getHeadJStmt());
                    else
                        ((GotoStmt)s).setTarget(((BasicBlock) b.succ.firstElement()).getHeadJStmt());	
		    */
                logger.debug("Error :");
                for (int i = 0; i < b.statements.size(); i++) logger.debug("" + b.statements.get(i));
                throw new RuntimeException(b + " has " + b.succ.size() + " successors.");
            }
        } else if (s instanceof IfStmt) {
            if (b.succ.size() != 2)
                logger.debug("How can an if not have 2 successors?");
            if ((b.succ.firstElement()) == b.next) {
                ((IfStmt) s).setTarget(b.succ.elementAt(1).getHeadJStmt());
            } else {
                ((IfStmt) s).setTarget(b.succ.firstElement().getHeadJStmt());
            }
        } else if (s instanceof TableSwitchStmt) {
            int count = 0;
            TableSwitchStmt sts = (TableSwitchStmt) s;
            for (BasicBlock basicBlock : b.succ) {
                p = (basicBlock);
                if (count == 0) {
                    sts.setDefaultTarget(p.getHeadJStmt());
                } else {
                    sts.setTarget(count - 1, p.getHeadJStmt());
                }
                count++;
            }
        } else if (s instanceof LookupSwitchStmt) {
            int count = 0;
            LookupSwitchStmt sls = (LookupSwitchStmt) s;
            for (BasicBlock basicBlock : b.succ) {
                p = (basicBlock);
                if (count == 0) {
                    sls.setDefaultTarget(p.getHeadJStmt());
                } else {
                    sls.setTarget(count - 1, p.getHeadJStmt());
                }
                count++;
            }
        }
        b.done = false;
        for (BasicBlock basicBlock : b.succ) {
            p = (basicBlock);
            if (p.done)
                bbq.push(p);
        }
    }
}
Also used : TableSwitchStmt(soot.jimple.TableSwitchStmt) IfStmt(soot.jimple.IfStmt) GotoStmt(soot.jimple.GotoStmt) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) NoSuchElementException(java.util.NoSuchElementException) GotoStmt(soot.jimple.GotoStmt) IfStmt(soot.jimple.IfStmt) IdentityStmt(soot.jimple.IdentityStmt) TableSwitchStmt(soot.jimple.TableSwitchStmt) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) Stmt(soot.jimple.Stmt)

Example 12 with GotoStmt

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

the class GotoInstruction method gotoStatement.

private GotoStmt gotoStatement() {
    GotoStmt go = Jimple.v().newGotoStmt(targetInstruction.getUnit());
    setUnit(go);
    addTags(go);
    return go;
}
Also used : GotoStmt(soot.jimple.GotoStmt)

Example 13 with GotoStmt

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

the class DalvikTyper method typeUntypedConstrantInDiv.

// this is needed because UnuesedStatementTransformer checks types in the div expressions
public void typeUntypedConstrantInDiv(final Body b) {
    for (Unit u : b.getUnits()) {
        StmtSwitch sw = new StmtSwitch() {

            @Override
            public void caseBreakpointStmt(BreakpointStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseInvokeStmt(InvokeStmt stmt) {
                changeUntypedConstantsInInvoke(stmt.getInvokeExpr());
            }

            @Override
            public void caseAssignStmt(AssignStmt stmt) {
                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 InvokeExpr) {
                    changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp());
                } else if (stmt.getRightOp() instanceof CastExpr) {
                    CastExpr ce = (CastExpr) stmt.getRightOp();
                    if (ce.getOp() instanceof UntypedConstant) {
                        UntypedConstant uc = (UntypedConstant) ce.getOp();
                        // check incoming primitive type
                        for (Tag t : stmt.getTags()) {
                            // Debug.printDbg("assign primitive type from stmt tag: ", stmt, t);
                            if (t instanceof IntOpTag) {
                                ce.setOp(uc.defineType(IntType.v()));
                                return;
                            } else if (t instanceof FloatOpTag) {
                                ce.setOp(uc.defineType(FloatType.v()));
                                return;
                            } else if (t instanceof DoubleOpTag) {
                                ce.setOp(uc.defineType(DoubleType.v()));
                                return;
                            } else if (t instanceof LongOpTag) {
                                ce.setOp(uc.defineType(LongType.v()));
                                return;
                            }
                        }
                        // 0 -> null
                        ce.setOp(uc.defineType(RefType.v("java.lang.Object")));
                    }
                }
                if (stmt.containsArrayRef()) {
                    ArrayRef ar = stmt.getArrayRef();
                    if ((ar.getIndex() instanceof UntypedConstant)) {
                        UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) ar.getIndex();
                        ar.setIndex(uc.toIntConstant());
                    }
                }
                Value r = stmt.getRightOp();
                if (r instanceof DivExpr || r instanceof RemExpr) {
                    // DivExpr de = (DivExpr) r;
                    for (Tag t : stmt.getTags()) {
                        // Debug.printDbg("div stmt tag: ", stmt, t);
                        if (t instanceof IntOpTag) {
                            checkExpr(r, IntType.v());
                            return;
                        } else if (t instanceof FloatOpTag) {
                            checkExpr(r, FloatType.v());
                            return;
                        } else if (t instanceof DoubleOpTag) {
                            checkExpr(r, DoubleType.v());
                            return;
                        } else if (t instanceof LongOpTag) {
                            checkExpr(r, LongType.v());
                            return;
                        }
                    }
                }
            }

            @Override
            public void caseIdentityStmt(IdentityStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseGotoStmt(GotoStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseIfStmt(IfStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseNopStmt(NopStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseRetStmt(RetStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseReturnStmt(ReturnStmt stmt) {
                if (stmt.getOp() instanceof UntypedConstant) {
                    UntypedConstant uc = (UntypedConstant) stmt.getOp();
                    Type type = b.getMethod().getReturnType();
                    stmt.setOp(uc.defineType(type));
                }
            }

            @Override
            public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseTableSwitchStmt(TableSwitchStmt stmt) {
            // TODO Auto-generated method stub
            }

            @Override
            public void caseThrowStmt(ThrowStmt stmt) {
                if (stmt.getOp() instanceof UntypedConstant) {
                    UntypedConstant uc = (UntypedConstant) stmt.getOp();
                    stmt.setOp(uc.defineType(RefType.v("java.lang.Object")));
                }
            }

            @Override
            public void defaultCase(Object obj) {
            // TODO Auto-generated method stub
            }
        };
        u.apply(sw);
    }
}
Also used : ExitMonitorStmt(soot.jimple.ExitMonitorStmt) InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) ReturnVoidStmt(soot.jimple.ReturnVoidStmt) IntOpTag(soot.dexpler.tags.IntOpTag) RetStmt(soot.jimple.RetStmt) Unit(soot.Unit) LongOpTag(soot.dexpler.tags.LongOpTag) BreakpointStmt(soot.jimple.BreakpointStmt) FloatOpTag(soot.dexpler.tags.FloatOpTag) ArrayRef(soot.jimple.ArrayRef) DoubleOpTag(soot.dexpler.tags.DoubleOpTag) TableSwitchStmt(soot.jimple.TableSwitchStmt) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) GotoStmt(soot.jimple.GotoStmt) CastExpr(soot.jimple.CastExpr) StmtSwitch(soot.jimple.StmtSwitch) IdentityStmt(soot.jimple.IdentityStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) DivExpr(soot.jimple.DivExpr) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) UnknownType(soot.UnknownType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) ArrayType(soot.ArrayType) PrimType(soot.PrimType) IfStmt(soot.jimple.IfStmt) NewArrayExpr(soot.jimple.NewArrayExpr) RemExpr(soot.jimple.RemExpr) NopStmt(soot.jimple.NopStmt) Value(soot.Value) LongOpTag(soot.dexpler.tags.LongOpTag) Tag(soot.tagkit.Tag) DoubleOpTag(soot.dexpler.tags.DoubleOpTag) IntOpTag(soot.dexpler.tags.IntOpTag) FloatOpTag(soot.dexpler.tags.FloatOpTag) ReturnStmt(soot.jimple.ReturnStmt) ThrowStmt(soot.jimple.ThrowStmt)

Aggregations

GotoStmt (soot.jimple.GotoStmt)13 Unit (soot.Unit)10 IfStmt (soot.jimple.IfStmt)7 IdentityStmt (soot.jimple.IdentityStmt)6 InvokeStmt (soot.jimple.InvokeStmt)6 ReturnStmt (soot.jimple.ReturnStmt)6 ReturnVoidStmt (soot.jimple.ReturnVoidStmt)6 LookupSwitchStmt (soot.jimple.LookupSwitchStmt)5 NopStmt (soot.jimple.NopStmt)5 Stmt (soot.jimple.Stmt)5 TableSwitchStmt (soot.jimple.TableSwitchStmt)5 Local (soot.Local)4 PrimType (soot.PrimType)4 AssignStmt (soot.jimple.AssignStmt)4 EnterMonitorStmt (soot.jimple.EnterMonitorStmt)4 ExitMonitorStmt (soot.jimple.ExitMonitorStmt)4 InstanceInvokeExpr (soot.jimple.InstanceInvokeExpr)4 InvokeExpr (soot.jimple.InvokeExpr)4 StaticInvokeExpr (soot.jimple.StaticInvokeExpr)4 ThrowStmt (soot.jimple.ThrowStmt)4