Search in sources :

Example 66 with AssignStmt

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

the class DexDefUseAnalysis method collectDefinitionsWithAliases.

/**
 * Collect definitions of l in body including the definitions of aliases of
 * l. This analysis exploits that the problem is flow-insensitive anyway.
 *
 * In this context an alias is a local that propagates its value to l.
 *
 * @param l
 *            the local whose definitions are to collect
 */
protected Set<Unit> collectDefinitionsWithAliases(Local l) {
    Set<Unit> defs = localToDefsWithAliases.get(l);
    if (defs == null) {
        Set<Local> seenLocals = new HashSet<Local>();
        defs = new HashSet<Unit>();
        List<Local> newLocals = new ArrayList<Local>();
        newLocals.add(l);
        while (!newLocals.isEmpty()) {
            Local curLocal = newLocals.remove(0);
            // Definition of l?
            BitSet bsDefs = localToDefsBits[localToNumber.get(curLocal)];
            if (bsDefs != null) {
                for (int i = bsDefs.nextSetBit(0); i >= 0; i = bsDefs.nextSetBit(i + 1)) {
                    Unit u = unitList.get(i);
                    defs.add(u);
                    DefinitionStmt defStmt = (DefinitionStmt) u;
                    if (defStmt.getRightOp() instanceof Local && seenLocals.add((Local) defStmt.getRightOp()))
                        newLocals.add((Local) defStmt.getRightOp());
                }
            }
            // Use of l?
            BitSet bsUses = localToUsesBits[localToNumber.get(curLocal)];
            if (bsUses != null) {
                for (int i = bsUses.nextSetBit(0); i >= 0; i = bsUses.nextSetBit(i + 1)) {
                    Unit use = unitList.get(i);
                    if (use instanceof AssignStmt) {
                        AssignStmt assignUse = (AssignStmt) use;
                        if (assignUse.getRightOp() == curLocal && assignUse.getLeftOp() instanceof Local && seenLocals.add((Local) assignUse.getLeftOp()))
                            newLocals.add((Local) assignUse.getLeftOp());
                    }
                }
            }
        }
        localToDefsWithAliases.put(l, defs);
    }
    return defs;
}
Also used : AssignStmt(soot.jimple.AssignStmt) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) Local(soot.Local) Unit(soot.Unit) DefinitionStmt(soot.jimple.DefinitionStmt) HashSet(java.util.HashSet)

Example 67 with AssignStmt

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

the class ConstInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    int dest = ((OneRegisterInstruction) instruction).getRegisterA();
    Constant cst = getConstant(dest, body);
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        if (cst instanceof UntypedConstant) {
            DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
        } else {
            DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
        }
    }
}
Also used : OneRegisterInstruction(org.jf.dexlib2.iface.instruction.OneRegisterInstruction) IntConstant(soot.jimple.IntConstant) UntypedIntOrFloatConstant(soot.dexpler.typing.UntypedIntOrFloatConstant) UntypedConstant(soot.dexpler.typing.UntypedConstant) Constant(soot.jimple.Constant) LongConstant(soot.jimple.LongConstant) UntypedLongOrDoubleConstant(soot.dexpler.typing.UntypedLongOrDoubleConstant) AssignStmt(soot.jimple.AssignStmt) UntypedConstant(soot.dexpler.typing.UntypedConstant)

Example 68 with AssignStmt

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

the class CastInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    TwoRegisterInstruction i = (TwoRegisterInstruction) instruction;
    int dest = i.getRegisterA();
    int source = i.getRegisterB();
    Type targetType = getTargetType();
    CastExpr cast = Jimple.v().newCastExpr(body.getRegisterLocal(source), targetType);
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cast);
    assign.addTag(getTag());
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().setType(assign.getLeftOpBox(), cast.getType(), false);
    // DalvikTyper.v().captureAssign((JAssignStmt)assign, op);
    }
}
Also used : ByteType(soot.ByteType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) Type(soot.Type) ShortType(soot.ShortType) CharType(soot.CharType) LongType(soot.LongType) AssignStmt(soot.jimple.AssignStmt) CastExpr(soot.jimple.CastExpr) TwoRegisterInstruction(org.jf.dexlib2.iface.instruction.TwoRegisterInstruction)

Example 69 with AssignStmt

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

the class CmpInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction23x))
        throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass());
    Instruction23x cmpInstr = (Instruction23x) instruction;
    int dest = cmpInstr.getRegisterA();
    Local first = body.getRegisterLocal(cmpInstr.getRegisterB());
    Local second = body.getRegisterLocal(cmpInstr.getRegisterC());
    // Expr cmpExpr;
    // Type type = null
    Opcode opcode = instruction.getOpcode();
    Expr cmpExpr = null;
    Type type = null;
    switch(opcode) {
        case CMPL_DOUBLE:
            setTag(new DoubleOpTag());
            type = DoubleType.v();
            cmpExpr = Jimple.v().newCmplExpr(first, second);
            break;
        case CMPL_FLOAT:
            setTag(new FloatOpTag());
            type = FloatType.v();
            cmpExpr = Jimple.v().newCmplExpr(first, second);
            break;
        case CMPG_DOUBLE:
            setTag(new DoubleOpTag());
            type = DoubleType.v();
            cmpExpr = Jimple.v().newCmpgExpr(first, second);
            break;
        case CMPG_FLOAT:
            setTag(new FloatOpTag());
            type = FloatType.v();
            cmpExpr = Jimple.v().newCmpgExpr(first, second);
            break;
        case CMP_LONG:
            setTag(new LongOpTag());
            type = LongType.v();
            cmpExpr = Jimple.v().newCmpExpr(first, second);
            break;
        default:
            throw new RuntimeException("no opcode for CMP: " + opcode);
    }
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cmpExpr);
    assign.addTag(getTag());
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        getTag().getName();
        BinopExpr bexpr = (BinopExpr) cmpExpr;
        DalvikTyper.v().setType(bexpr.getOp1Box(), type, true);
        DalvikTyper.v().setType(bexpr.getOp2Box(), type, true);
        DalvikTyper.v().setType(((JAssignStmt) assign).leftBox, IntType.v(), false);
    }
}
Also used : JAssignStmt(soot.jimple.internal.JAssignStmt) AssignStmt(soot.jimple.AssignStmt) Local(soot.Local) Opcode(org.jf.dexlib2.Opcode) LongOpTag(soot.dexpler.tags.LongOpTag) FloatOpTag(soot.dexpler.tags.FloatOpTag) DoubleOpTag(soot.dexpler.tags.DoubleOpTag) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) Type(soot.Type) LongType(soot.LongType) Expr(soot.jimple.Expr) BinopExpr(soot.jimple.BinopExpr) Instruction23x(org.jf.dexlib2.iface.instruction.formats.Instruction23x) BinopExpr(soot.jimple.BinopExpr)

Example 70 with AssignStmt

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

the class ConstClassInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction21c))
        throw new IllegalArgumentException("Expected Instruction21c but got: " + instruction.getClass());
    ReferenceInstruction constClass = (ReferenceInstruction) this.instruction;
    TypeReference tidi = (TypeReference) (constClass.getReference());
    Constant cst = ClassConstant.v(tidi.getType());
    int dest = ((OneRegisterInstruction) instruction).getRegisterA();
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        // DalvikTyper.v().captureAssign((JAssignStmt)assign, op); //TODO:
        // classtype could be null!
        DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
    }
}
Also used : OneRegisterInstruction(org.jf.dexlib2.iface.instruction.OneRegisterInstruction) Instruction21c(org.jf.dexlib2.iface.instruction.formats.Instruction21c) ClassConstant(soot.jimple.ClassConstant) Constant(soot.jimple.Constant) AssignStmt(soot.jimple.AssignStmt) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

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