Search in sources :

Example 6 with AssignStmt

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

the class ConstructorFolder method internalTransform.

/**
 * This method change all new Obj/<init>(args) pairs to new Obj(args) idioms.
 */
protected void internalTransform(Body b, String phaseName, Map options) {
    GrimpBody body = (GrimpBody) b;
    if (Options.v().verbose())
        logger.debug("[" + body.getMethod().getName() + "] Folding constructors...");
    Chain units = body.getUnits();
    List<Unit> stmtList = new ArrayList<Unit>();
    stmtList.addAll(units);
    Iterator<Unit> it = stmtList.iterator();
    LocalUses localUses = LocalUses.Factory.newLocalUses(b);
    /* fold in NewExpr's with specialinvoke's */
    while (it.hasNext()) {
        Stmt s = (Stmt) it.next();
        if (!(s instanceof AssignStmt))
            continue;
        /* this should be generalized to ArrayRefs */
        Value lhs = ((AssignStmt) s).getLeftOp();
        if (!(lhs instanceof Local))
            continue;
        Value rhs = ((AssignStmt) s).getRightOp();
        if (!(rhs instanceof NewExpr))
            continue;
        /* TO BE IMPLEMENTED LATER: move any copy of the object reference
             for lhs down beyond the NewInvokeExpr, with the rationale
             being that you can't modify the object before the constructor
             call in any case.

             Also, do note that any new's (object creation) without
             corresponding constructors must be dead. */
        List lu = localUses.getUsesOf(s);
        Iterator luIter = lu.iterator();
        boolean MadeNewInvokeExpr = false;
        while (luIter.hasNext()) {
            Unit use = ((UnitValueBoxPair) (luIter.next())).unit;
            if (!(use instanceof InvokeStmt))
                continue;
            InvokeStmt is = (InvokeStmt) use;
            if (!(is.getInvokeExpr() instanceof SpecialInvokeExpr) || lhs != ((SpecialInvokeExpr) is.getInvokeExpr()).getBase())
                continue;
            SpecialInvokeExpr oldInvoke = ((SpecialInvokeExpr) is.getInvokeExpr());
            LinkedList invokeArgs = new LinkedList();
            for (int i = 0; i < oldInvoke.getArgCount(); i++) invokeArgs.add(oldInvoke.getArg(i));
            AssignStmt constructStmt = Grimp.v().newAssignStmt((AssignStmt) s);
            constructStmt.setRightOp(Grimp.v().newNewInvokeExpr(((NewExpr) rhs).getBaseType(), oldInvoke.getMethodRef(), invokeArgs));
            MadeNewInvokeExpr = true;
            use.redirectJumpsToThisTo(constructStmt);
            units.insertBefore(constructStmt, use);
            units.remove(use);
        }
        if (MadeNewInvokeExpr) {
            units.remove(s);
        }
    }
}
Also used : Chain(soot.util.Chain) InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) ArrayList(java.util.ArrayList) Local(soot.Local) SimpleLocalUses(soot.toolkits.scalar.SimpleLocalUses) LocalUses(soot.toolkits.scalar.LocalUses) Unit(soot.Unit) LinkedList(java.util.LinkedList) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) Value(soot.Value) NewExpr(soot.jimple.NewExpr) Iterator(java.util.Iterator) UnitValueBoxPair(soot.toolkits.scalar.UnitValueBoxPair) GrimpBody(soot.grimp.GrimpBody) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 7 with AssignStmt

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

the class IputInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    TwoRegisterInstruction i = (TwoRegisterInstruction) instruction;
    int source = i.getRegisterA();
    int object = i.getRegisterB();
    FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference();
    InstanceFieldRef instanceField = Jimple.v().newInstanceFieldRef(body.getRegisterLocal(object), getSootFieldRef(f));
    Local sourceValue = body.getRegisterLocal(source);
    AssignStmt assign = getAssignStmt(body, sourceValue, instanceField);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        DalvikTyper.v().setType(assign.getRightOpBox(), instanceField.getType(), true);
    }
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) AssignStmt(soot.jimple.AssignStmt) InstanceFieldRef(soot.jimple.InstanceFieldRef) Local(soot.Local) TwoRegisterInstruction(org.jf.dexlib2.iface.instruction.TwoRegisterInstruction)

Example 8 with AssignStmt

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

the class NewArrayInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction22c))
        throw new IllegalArgumentException("Expected Instruction22c but got: " + instruction.getClass());
    Instruction22c newArray = (Instruction22c) instruction;
    int dest = newArray.getRegisterA();
    Value size = body.getRegisterLocal(newArray.getRegisterB());
    Type t = DexType.toSoot((TypeReference) newArray.getReference());
    // NewArrayExpr needs the ElementType as it increases the array dimension by 1
    Type arrayType = ((ArrayType) t).getElementType();
    NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(arrayType, size);
    Local l = body.getRegisterLocal(dest);
    AssignStmt assign = Jimple.v().newAssignStmt(l, newArrayExpr);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().setType(newArrayExpr.getSizeBox(), IntType.v(), true);
        DalvikTyper.v().setType(assign.getLeftOpBox(), newArrayExpr.getType(), false);
    }
}
Also used : ArrayType(soot.ArrayType) Instruction22c(org.jf.dexlib2.iface.instruction.formats.Instruction22c) ArrayType(soot.ArrayType) IntType(soot.IntType) Type(soot.Type) DexType(soot.dexpler.DexType) NewArrayExpr(soot.jimple.NewArrayExpr) AssignStmt(soot.jimple.AssignStmt) Value(soot.Value) Local(soot.Local)

Example 9 with AssignStmt

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

the class MoveResultInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    // if (local != null && expr != null)
    // throw new RuntimeException("Both local and expr are set to move.");
    int dest = ((OneRegisterInstruction) instruction).getRegisterA();
    // if (local != null)
    // assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), local);
    // else if (expr != null)
    // assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
    // else
    // throw new RuntimeException("Neither local and expr are set to move.");
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), body.getStoreResultLocal());
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        JAssignStmt jassign = (JAssignStmt) assign;
        DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
    }
}
Also used : OneRegisterInstruction(org.jf.dexlib2.iface.instruction.OneRegisterInstruction) JAssignStmt(soot.jimple.internal.JAssignStmt) AssignStmt(soot.jimple.AssignStmt) JAssignStmt(soot.jimple.internal.JAssignStmt)

Example 10 with AssignStmt

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

the class NewInstanceInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    Instruction21c i = (Instruction21c) instruction;
    int dest = i.getRegisterA();
    String className = dottedClassName(((TypeReference) (i.getReference())).toString());
    RefType type = RefType.v(className);
    NewExpr n = Jimple.v().newNewExpr(type);
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), n);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        // DalvikTyper.v().captureAssign((JAssignStmt)assign, op); // TODO: ref. type may be null!
        DalvikTyper.v().setType(assign.getLeftOpBox(), type, false);
    }
}
Also used : RefType(soot.RefType) Instruction21c(org.jf.dexlib2.iface.instruction.formats.Instruction21c) AssignStmt(soot.jimple.AssignStmt) NewExpr(soot.jimple.NewExpr)

Aggregations

AssignStmt (soot.jimple.AssignStmt)83 Local (soot.Local)50 Value (soot.Value)44 Unit (soot.Unit)40 Type (soot.Type)28 Stmt (soot.jimple.Stmt)24 InvokeExpr (soot.jimple.InvokeExpr)20 RefType (soot.RefType)19 ArrayRef (soot.jimple.ArrayRef)19 ArrayType (soot.ArrayType)17 CastExpr (soot.jimple.CastExpr)17 InvokeStmt (soot.jimple.InvokeStmt)17 ArrayList (java.util.ArrayList)15 IdentityStmt (soot.jimple.IdentityStmt)15 DefinitionStmt (soot.jimple.DefinitionStmt)13 FieldRef (soot.jimple.FieldRef)13 InstanceFieldRef (soot.jimple.InstanceFieldRef)13 IntConstant (soot.jimple.IntConstant)13 ReturnStmt (soot.jimple.ReturnStmt)13 HashSet (java.util.HashSet)12