Search in sources :

Example 6 with ValueBox

use of soot.ValueBox in project soot by Sable.

the class DArrayInitExpr method getUseBoxes.

/*
	 * go through the elements array
	 * return useBoxes of each value plus the valuebox itself
	 */
public List<ValueBox> getUseBoxes() {
    List<ValueBox> list = new ArrayList<ValueBox>();
    for (ValueBox element : elements) {
        list.addAll(element.getValue().getUseBoxes());
        list.add(element);
    }
    return list;
}
Also used : ValueBox(soot.ValueBox) ArrayList(java.util.ArrayList)

Example 7 with ValueBox

use of soot.ValueBox in project soot by Sable.

the class TypeAssigner method replaceNullType.

/**
 * Replace statements using locals with null_type type and that would
 * throw a NullPointerException at runtime by a set of instructions
 * throwing a NullPointerException.
 *
 * This is done to remove locals with null_type type.
 *
 * @param b
 */
private void replaceNullType(Body b) {
    List<Local> localsToRemove = new ArrayList<Local>();
    boolean hasNullType = false;
    // check if any local has null_type
    for (Local l : b.getLocals()) {
        if (l.getType() instanceof NullType) {
            localsToRemove.add(l);
            hasNullType = true;
        }
    }
    // No local with null_type
    if (!hasNullType)
        return;
    // force to propagate null constants
    Map<String, String> opts = PhaseOptions.v().getPhaseOptions("jop.cpf");
    if (!opts.containsKey("enabled") || !opts.get("enabled").equals("true")) {
        logger.warn("Cannot run TypeAssigner.replaceNullType(Body). Try to enable jop.cfg.");
        return;
    }
    ConstantPropagatorAndFolder.v().transform(b);
    List<Unit> unitToReplaceByException = new ArrayList<Unit>();
    for (Unit u : b.getUnits()) {
        for (ValueBox vb : u.getUseBoxes()) {
            if (vb.getValue() instanceof Local && ((Local) vb.getValue()).getType() instanceof NullType) {
                Local l = (Local) vb.getValue();
                Stmt s = (Stmt) u;
                boolean replace = false;
                if (s.containsArrayRef()) {
                    ArrayRef r = s.getArrayRef();
                    if (r.getBase() == l) {
                        replace = true;
                    }
                } else if (s.containsFieldRef()) {
                    FieldRef r = s.getFieldRef();
                    if (r instanceof InstanceFieldRef) {
                        InstanceFieldRef ir = (InstanceFieldRef) r;
                        if (ir.getBase() == l) {
                            replace = true;
                        }
                    }
                } else if (s.containsInvokeExpr()) {
                    InvokeExpr ie = s.getInvokeExpr();
                    if (ie instanceof InstanceInvokeExpr) {
                        InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
                        if (iie.getBase() == l) {
                            replace = true;
                        }
                    }
                }
                if (replace) {
                    unitToReplaceByException.add(u);
                }
            }
        }
    }
    for (Unit u : unitToReplaceByException) {
        soot.dexpler.Util.addExceptionAfterUnit(b, "java.lang.NullPointerException", u, "This statement would have triggered an Exception: " + u);
        b.getUnits().remove(u);
    }
    // should be done on a separate phase
    DeadAssignmentEliminator.v().transform(b);
    UnusedLocalEliminator.v().transform(b);
}
Also used : FieldRef(soot.jimple.FieldRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) ArrayList(java.util.ArrayList) Local(soot.Local) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) Unit(soot.Unit) Stmt(soot.jimple.Stmt) ArrayRef(soot.jimple.ArrayRef) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) ValueBox(soot.ValueBox) InstanceFieldRef(soot.jimple.InstanceFieldRef) NullType(soot.NullType)

Example 8 with ValueBox

use of soot.ValueBox in project soot by Sable.

the class JDynamicInvokeExpr method equivTo.

public boolean equivTo(Object o) {
    if (o instanceof JDynamicInvokeExpr) {
        JDynamicInvokeExpr ie = (JDynamicInvokeExpr) o;
        if (!(getMethod().equals(ie.getMethod()) && bsmArgBoxes.length == ie.bsmArgBoxes.length))
            return false;
        int i = 0;
        for (ValueBox element : bsmArgBoxes) {
            if (!(element.getValue().equivTo(ie.getBootstrapArg(i))))
                return false;
            i++;
        }
        if (!(getMethod().equals(ie.getMethod()) && (argBoxes == null ? 0 : argBoxes.length) == (ie.argBoxes == null ? 0 : ie.argBoxes.length)))
            return false;
        if (argBoxes != null) {
            i = 0;
            for (ValueBox element : argBoxes) {
                if (!(element.getValue().equivTo(ie.getArg(i))))
                    return false;
                i++;
            }
        }
        if (!methodRef.equals(ie.methodRef))
            return false;
        if (!bsmRef.equals(ie.bsmRef))
            return false;
        return true;
    }
    return false;
}
Also used : ValueBox(soot.ValueBox)

Example 9 with ValueBox

use of soot.ValueBox in project soot by Sable.

the class JDynamicInvokeExpr method convertToBaf.

public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
    if (argBoxes != null) {
        for (ValueBox element : argBoxes) {
            ((ConvertToBaf) (element.getValue())).convertToBaf(context, out);
        }
    }
    List<Value> bsmArgs = new ArrayList<Value>();
    for (ValueBox argBox : bsmArgBoxes) {
        bsmArgs.add(argBox.getValue());
    }
    Unit u = Baf.v().newDynamicInvokeInst(bsmRef, bsmArgs, methodRef, tag);
    u.addAllTagsOf(context.getCurrentUnit());
    out.add(u);
}
Also used : ValueBox(soot.ValueBox) Value(soot.Value) ArrayList(java.util.ArrayList) ConvertToBaf(soot.jimple.ConvertToBaf) Unit(soot.Unit)

Example 10 with ValueBox

use of soot.ValueBox in project soot by Sable.

the class ArrayIndexLivenessAnalysis method getAllRelatedMaps.

private void getAllRelatedMaps(Body body) {
    Iterator unitIt = body.getUnits().iterator();
    while (unitIt.hasNext()) {
        Stmt stmt = (Stmt) unitIt.next();
        if (csin) {
            if (stmt instanceof DefinitionStmt) {
                Value rhs = ((DefinitionStmt) stmt).getRightOp();
                if (rhs instanceof BinopExpr) {
                    Value op1 = ((BinopExpr) rhs).getOp1();
                    Value op2 = ((BinopExpr) rhs).getOp2();
                    if (rhs instanceof AddExpr) {
                        // op1 + op2 --> a + b
                        if ((op1 instanceof Local) && (op2 instanceof Local)) {
                            HashSet<Value> refs = localToExpr.get(op1);
                            if (refs == null) {
                                refs = new HashSet<Value>();
                                localToExpr.put(op1, refs);
                            }
                            refs.add(rhs);
                            refs = localToExpr.get(op2);
                            if (refs == null) {
                                refs = new HashSet<Value>();
                                localToExpr.put(op2, refs);
                            }
                            refs.add(rhs);
                        }
                    } else // a * b, a * c, c * a
                    if (rhs instanceof MulExpr) {
                        HashSet<Value> refs = localToExpr.get(op1);
                        if (refs == null) {
                            refs = new HashSet<Value>();
                            localToExpr.put(op1, refs);
                        }
                        refs.add(rhs);
                        refs = localToExpr.get(op2);
                        if (refs == null) {
                            refs = new HashSet<Value>();
                            localToExpr.put(op2, refs);
                        }
                        refs.add(rhs);
                    } else if (rhs instanceof SubExpr) {
                        if (op2 instanceof Local) {
                            HashSet<Value> refs = localToExpr.get(op2);
                            if (refs == null) {
                                refs = new HashSet<Value>();
                                localToExpr.put(op2, refs);
                            }
                            refs.add(rhs);
                            if (op1 instanceof Local) {
                                refs = localToExpr.get(op1);
                                if (refs == null) {
                                    refs = new HashSet<Value>();
                                    localToExpr.put(op1, refs);
                                }
                                refs.add(rhs);
                            }
                        }
                    }
                }
            }
        }
        for (ValueBox vbox : stmt.getUseAndDefBoxes()) {
            Value v = vbox.getValue();
            if (fieldin) {
                if (v instanceof InstanceFieldRef) {
                    Value base = ((InstanceFieldRef) v).getBase();
                    SootField field = ((InstanceFieldRef) v).getField();
                    HashSet<Value> baseset = localToFieldRef.get(base);
                    if (baseset == null) {
                        baseset = new HashSet<Value>();
                        localToFieldRef.put(base, baseset);
                    }
                    baseset.add(v);
                    HashSet<Value> fieldset = fieldToFieldRef.get(field);
                    if (fieldset == null) {
                        fieldset = new HashSet<Value>();
                        fieldToFieldRef.put(field, fieldset);
                    }
                    fieldset.add(v);
                }
                if (v instanceof FieldRef)
                    allFieldRefs.add(v);
            }
            if (arrayin) {
            // a = ...   --> kill all a[x] nodes.
            // a[i] = .. --> kill all array references.
            // m(a)      --> kill all array references
            // i = ...   --> kill all array reference with index as i
            /*
                if (v instanceof ArrayRef)
                {
                    Value base = ((ArrayRef)v).getBase();
                    Value index = ((ArrayRef)v).getIndex();

                    HashSet refset = (HashSet)localToArrayRef.get(base);
                    if (refset == null)
                    {
                        refset = new HashSet();
                        localToArrayRef.put(base, refset);
                    }
                    refset.add(v);

                    if (index instanceof Local)
                    {
                        refset = (HashSet)localToArrayRef.get(index);
                        if (refset == null)
                        {
                            refset = new HashSet();
                            localToArrayRef.put(index, refset);
                        }

                        refset.add(v);
                    }           
                    allArrayRefs.add(v);
                }
                */
            }
        }
    }
}
Also used : MulExpr(soot.jimple.MulExpr) FieldRef(soot.jimple.FieldRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) StaticFieldRef(soot.jimple.StaticFieldRef) JSubExpr(soot.jimple.internal.JSubExpr) SubExpr(soot.jimple.SubExpr) Local(soot.Local) JAddExpr(soot.jimple.internal.JAddExpr) AddExpr(soot.jimple.AddExpr) IfStmt(soot.jimple.IfStmt) Stmt(soot.jimple.Stmt) DefinitionStmt(soot.jimple.DefinitionStmt) ValueBox(soot.ValueBox) Iterator(java.util.Iterator) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) SootField(soot.SootField) DefinitionStmt(soot.jimple.DefinitionStmt) BinopExpr(soot.jimple.BinopExpr) HashSet(java.util.HashSet)

Aggregations

ValueBox (soot.ValueBox)58 Value (soot.Value)43 Local (soot.Local)36 Unit (soot.Unit)33 ArrayList (java.util.ArrayList)26 Type (soot.Type)20 Stmt (soot.jimple.Stmt)20 DefinitionStmt (soot.jimple.DefinitionStmt)17 InvokeExpr (soot.jimple.InvokeExpr)15 SootMethod (soot.SootMethod)13 RefType (soot.RefType)12 AssignStmt (soot.jimple.AssignStmt)11 IntConstant (soot.jimple.IntConstant)11 HashSet (java.util.HashSet)10 IntType (soot.IntType)10 SootClass (soot.SootClass)10 FieldRef (soot.jimple.FieldRef)10 HashMap (java.util.HashMap)9 LongType (soot.LongType)9 VoidType (soot.VoidType)9