Search in sources :

Example 6 with LocalDefs

use of soot.toolkits.scalar.LocalDefs in project soot by Sable.

the class TypeResolverBV method split_new.

private void split_new() {
    LocalDefs defs = LocalDefs.Factory.newLocalDefs(stmtBody);
    PatchingChain<Unit> units = stmtBody.getUnits();
    Stmt[] stmts = new Stmt[units.size()];
    units.toArray(stmts);
    for (Stmt stmt : stmts) {
        if (stmt instanceof InvokeStmt) {
            InvokeStmt invoke = (InvokeStmt) stmt;
            if (invoke.getInvokeExpr() instanceof SpecialInvokeExpr) {
                SpecialInvokeExpr special = (SpecialInvokeExpr) invoke.getInvokeExpr();
                if (special.getMethodRef().name().equals("<init>")) {
                    List<Unit> deflist = defs.getDefsOfAt((Local) special.getBase(), invoke);
                    while (deflist.size() == 1) {
                        Stmt stmt2 = (Stmt) deflist.get(0);
                        if (stmt2 instanceof AssignStmt) {
                            AssignStmt assign = (AssignStmt) stmt2;
                            if (assign.getRightOp() instanceof Local) {
                                deflist = defs.getDefsOfAt((Local) assign.getRightOp(), assign);
                                continue;
                            } else if (assign.getRightOp() instanceof NewExpr) {
                                // We split the local.
                                // logger.debug("split: [" + assign + "] and [" + stmt + "]");
                                Local newlocal = Jimple.v().newLocal("tmp", null);
                                stmtBody.getLocals().add(newlocal);
                                special.setBase(newlocal);
                                units.insertAfter(Jimple.v().newAssignStmt(assign.getLeftOp(), newlocal), assign);
                                assign.setLeftOp(newlocal);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}
Also used : InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) NewExpr(soot.jimple.NewExpr) Local(soot.Local) Unit(soot.Unit) LocalDefs(soot.toolkits.scalar.LocalDefs) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Example 7 with LocalDefs

use of soot.toolkits.scalar.LocalDefs in project soot by Sable.

the class TypeResolver method split_new.

private void split_new() {
    LocalDefs defs = LocalDefs.Factory.newLocalDefs(stmtBody);
    PatchingChain<Unit> units = stmtBody.getUnits();
    Stmt[] stmts = new Stmt[units.size()];
    units.toArray(stmts);
    for (Stmt stmt : stmts) {
        if (stmt instanceof InvokeStmt) {
            InvokeStmt invoke = (InvokeStmt) stmt;
            if (invoke.getInvokeExpr() instanceof SpecialInvokeExpr) {
                SpecialInvokeExpr special = (SpecialInvokeExpr) invoke.getInvokeExpr();
                if ("<init>".equals(special.getMethodRef().name())) {
                    List<Unit> deflist = defs.getDefsOfAt((Local) special.getBase(), invoke);
                    while (deflist.size() == 1) {
                        Stmt stmt2 = (Stmt) deflist.get(0);
                        if (stmt2 instanceof AssignStmt) {
                            AssignStmt assign = (AssignStmt) stmt2;
                            if (assign.getRightOp() instanceof Local) {
                                deflist = defs.getDefsOfAt((Local) assign.getRightOp(), assign);
                                continue;
                            } else if (assign.getRightOp() instanceof NewExpr) {
                                // We split the local.
                                // logger.debug("split: [" + assign + "] and [" + stmt + "]");
                                Local newlocal = Jimple.v().newLocal("tmp", null);
                                stmtBody.getLocals().add(newlocal);
                                special.setBase(newlocal);
                                units.insertAfter(Jimple.v().newAssignStmt(assign.getLeftOp(), newlocal), assign);
                                assign.setLeftOp(newlocal);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}
Also used : InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) NewExpr(soot.jimple.NewExpr) Local(soot.Local) Unit(soot.Unit) LocalDefs(soot.toolkits.scalar.LocalDefs) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Example 8 with LocalDefs

use of soot.toolkits.scalar.LocalDefs in project soot by Sable.

the class DexNullArrayRefTransformer method internalTransform.

protected void internalTransform(final Body body, String phaseName, Map<String, String> options) {
    final ExceptionalUnitGraph g = new ExceptionalUnitGraph(body, DalvikThrowAnalysis.v());
    final LocalDefs defs = LocalDefs.Factory.newLocalDefs(g);
    final LocalCreation lc = new LocalCreation(body.getLocals(), "ex");
    boolean changed = false;
    for (Iterator<Unit> unitIt = body.getUnits().snapshotIterator(); unitIt.hasNext(); ) {
        Stmt s = (Stmt) unitIt.next();
        if (s.containsArrayRef()) {
            // Check array reference
            Value base = s.getArrayRef().getBase();
            if (isAlwaysNullBefore(s, (Local) base, defs)) {
                createThrowStmt(body, s, lc);
                changed = true;
            }
        } else if (s instanceof AssignStmt) {
            AssignStmt ass = (AssignStmt) s;
            Value rightOp = ass.getRightOp();
            if (rightOp instanceof LengthExpr) {
                // Check lengthof expression
                LengthExpr l = (LengthExpr) ass.getRightOp();
                Value base = l.getOp();
                if (base instanceof IntConstant) {
                    IntConstant ic = (IntConstant) base;
                    if (ic.value == 0) {
                        createThrowStmt(body, s, lc);
                        changed = true;
                    }
                } else if (base == NullConstant.v() || isAlwaysNullBefore(s, (Local) base, defs)) {
                    createThrowStmt(body, s, lc);
                    changed = true;
                }
            }
        }
    }
    if (changed)
        UnreachableCodeEliminator.v().transform(body);
}
Also used : ExceptionalUnitGraph(soot.toolkits.graph.ExceptionalUnitGraph) LocalCreation(soot.jimple.toolkits.scalar.LocalCreation) AssignStmt(soot.jimple.AssignStmt) LengthExpr(soot.jimple.LengthExpr) Value(soot.Value) IntConstant(soot.jimple.IntConstant) Local(soot.Local) Unit(soot.Unit) LocalDefs(soot.toolkits.scalar.LocalDefs) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) DefinitionStmt(soot.jimple.DefinitionStmt)

Example 9 with LocalDefs

use of soot.toolkits.scalar.LocalDefs in project soot by Sable.

the class DexReturnValuePropagator method internalTransform.

@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
    ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body, DalvikThrowAnalysis.v(), true);
    LocalDefs localDefs = LocalDefs.Factory.newLocalDefs(graph);
    LocalUses localUses = null;
    LocalCreation localCreation = null;
    // a copy statement, we take the original operand
    for (Unit u : body.getUnits()) if (u instanceof ReturnStmt) {
        ReturnStmt retStmt = (ReturnStmt) u;
        if (retStmt.getOp() instanceof Local) {
            List<Unit> defs = localDefs.getDefsOfAt((Local) retStmt.getOp(), retStmt);
            if (defs.size() == 1 && defs.get(0) instanceof AssignStmt) {
                AssignStmt assign = (AssignStmt) defs.get(0);
                final Value rightOp = assign.getRightOp();
                final Value leftOp = assign.getLeftOp();
                // Copy over the left side if it is a local
                if (rightOp instanceof Local) {
                    // to return a;
                    if (!isRedefined((Local) rightOp, u, assign, graph))
                        retStmt.setOp(rightOp);
                } else if (rightOp instanceof Constant) {
                    retStmt.setOp(rightOp);
                } else // we rename the local to help splitting
                if (rightOp instanceof FieldRef) {
                    if (localUses == null)
                        localUses = LocalUses.Factory.newLocalUses(body, localDefs);
                    if (localUses.getUsesOf(assign).size() == 1) {
                        if (localCreation == null)
                            localCreation = new LocalCreation(body.getLocals(), "ret");
                        Local newLocal = localCreation.newLocal(leftOp.getType());
                        assign.setLeftOp(newLocal);
                        retStmt.setOp(newLocal);
                    }
                }
            }
        }
    }
}
Also used : ExceptionalUnitGraph(soot.toolkits.graph.ExceptionalUnitGraph) FieldRef(soot.jimple.FieldRef) LocalCreation(soot.jimple.toolkits.scalar.LocalCreation) AssignStmt(soot.jimple.AssignStmt) Constant(soot.jimple.Constant) Value(soot.Value) Local(soot.Local) ArrayList(java.util.ArrayList) List(java.util.List) LocalUses(soot.toolkits.scalar.LocalUses) Unit(soot.Unit) LocalDefs(soot.toolkits.scalar.LocalDefs) ReturnStmt(soot.jimple.ReturnStmt)

Aggregations

Local (soot.Local)9 Unit (soot.Unit)9 AssignStmt (soot.jimple.AssignStmt)9 LocalDefs (soot.toolkits.scalar.LocalDefs)9 Stmt (soot.jimple.Stmt)7 Value (soot.Value)5 DefinitionStmt (soot.jimple.DefinitionStmt)5 ArrayList (java.util.ArrayList)4 ValueBox (soot.ValueBox)4 FieldRef (soot.jimple.FieldRef)4 NewExpr (soot.jimple.NewExpr)4 ArrayRef (soot.jimple.ArrayRef)3 CastExpr (soot.jimple.CastExpr)3 Constant (soot.jimple.Constant)3 IntConstant (soot.jimple.IntConstant)3 InvokeExpr (soot.jimple.InvokeExpr)3 InvokeStmt (soot.jimple.InvokeStmt)3 ExceptionalUnitGraph (soot.toolkits.graph.ExceptionalUnitGraph)3 LocalUses (soot.toolkits.scalar.LocalUses)3 HashSet (java.util.HashSet)2