Search in sources :

Example 61 with AssignStmt

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

the class AgetInstruction method jimplify.

@Override
public void jimplify(DexBody body) throws InvalidDalvikBytecodeException {
    if (!(instruction instanceof Instruction23x))
        throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass());
    Instruction23x aGetInstr = (Instruction23x) instruction;
    int dest = aGetInstr.getRegisterA();
    Local arrayBase = body.getRegisterLocal(aGetInstr.getRegisterB());
    Local index = body.getRegisterLocal(aGetInstr.getRegisterC());
    ArrayRef arrayRef = Jimple.v().newArrayRef(arrayBase, index);
    Local l = body.getRegisterLocal(dest);
    AssignStmt assign = Jimple.v().newAssignStmt(l, arrayRef);
    if (aGetInstr.getOpcode() == Opcode.AGET_OBJECT)
        assign.addTag(new ObjectOpTag());
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
        DalvikTyper.v().setType(arrayRef.getIndexBox(), IntType.v(), true);
    }
}
Also used : ArrayRef(soot.jimple.ArrayRef) AssignStmt(soot.jimple.AssignStmt) Local(soot.Local) Instruction23x(org.jf.dexlib2.iface.instruction.formats.Instruction23x) ObjectOpTag(soot.dexpler.tags.ObjectOpTag)

Example 62 with AssignStmt

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

the class BinopLitInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction22s) && !(instruction instanceof Instruction22b))
        throw new IllegalArgumentException("Expected Instruction22s or Instruction22b but got: " + instruction.getClass());
    NarrowLiteralInstruction binOpLitInstr = (NarrowLiteralInstruction) this.instruction;
    int dest = ((TwoRegisterInstruction) instruction).getRegisterA();
    int source = ((TwoRegisterInstruction) instruction).getRegisterB();
    Local source1 = body.getRegisterLocal(source);
    IntConstant constant = IntConstant.v(binOpLitInstr.getNarrowLiteral());
    Value expr = getExpression(source1, constant);
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
    assign.addTag(getTag());
    setUnit(assign);
    addTags(assign);
    body.add(assign);
/*if (IDalvikTyper.ENABLE_DVKTYPER) {
			Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
			
            int op = (int)instruction.getOpcode().value;
          if (op >= 0xd8) {
            op -= 0xd8;
          } else {
            op -= 0xd0;
          }
          BinopExpr bexpr = (BinopExpr)expr;
          //body.dvkTyper.setType((op == 1) ? bexpr.getOp2Box() : bexpr.getOp1Box(), op1BinType[op]);
          DalvikTyper.v().setType(((JAssignStmt)assign).leftBox, op1BinType[op], false);
          
        }*/
}
Also used : Instruction22s(org.jf.dexlib2.iface.instruction.formats.Instruction22s) Instruction22b(org.jf.dexlib2.iface.instruction.formats.Instruction22b) AssignStmt(soot.jimple.AssignStmt) Value(soot.Value) Local(soot.Local) IntConstant(soot.jimple.IntConstant) NarrowLiteralInstruction(org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction) TwoRegisterInstruction(org.jf.dexlib2.iface.instruction.TwoRegisterInstruction)

Example 63 with AssignStmt

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

the class CheckCastInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction21c))
        throw new IllegalArgumentException("Expected Instruction21c but got: " + instruction.getClass());
    Instruction21c checkCastInstr = (Instruction21c) instruction;
    Local castValue = body.getRegisterLocal(checkCastInstr.getRegisterA());
    Type checkCastType = DexType.toSoot((TypeReference) checkCastInstr.getReference());
    CastExpr castExpr = Jimple.v().newCastExpr(castValue, checkCastType);
    // generate "x = (Type) x"
    // splitter will take care of the rest
    AssignStmt assign = Jimple.v().newAssignStmt(castValue, castExpr);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().setType(assign.getLeftOpBox(), checkCastType, false);
    }
}
Also used : Instruction21c(org.jf.dexlib2.iface.instruction.formats.Instruction21c) Type(soot.Type) DexType(soot.dexpler.DexType) AssignStmt(soot.jimple.AssignStmt) CastExpr(soot.jimple.CastExpr) Local(soot.Local)

Example 64 with AssignStmt

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

the class Util method emptyBody.

/**
 * Remove all statements except from IdentityStatements for parameters.
 * Return default value (null or zero or nothing depending on the return
 * type).
 *
 * @param jBody
 */
public static void emptyBody(Body jBody) {
    // identity statements
    List<Unit> idStmts = new ArrayList<Unit>();
    List<Local> idLocals = new ArrayList<Local>();
    for (Unit u : jBody.getUnits()) {
        if (u instanceof IdentityStmt) {
            IdentityStmt i = (IdentityStmt) u;
            if (i.getRightOp() instanceof ParameterRef || i.getRightOp() instanceof ThisRef) {
                idStmts.add(u);
                idLocals.add((Local) i.getLeftOp());
            }
        }
    }
    jBody.getUnits().clear();
    jBody.getLocals().clear();
    jBody.getTraps().clear();
    final LocalGenerator lg = new LocalGenerator(jBody);
    for (Unit u : idStmts) jBody.getUnits().add(u);
    for (Local l : idLocals) jBody.getLocals().add(l);
    Type rType = jBody.getMethod().getReturnType();
    jBody.getUnits().add(Jimple.v().newNopStmt());
    if (rType instanceof VoidType) {
        jBody.getUnits().add(Jimple.v().newReturnVoidStmt());
    } else {
        Type t = jBody.getMethod().getReturnType();
        Local l = lg.generateLocal(t);
        AssignStmt ass = null;
        if (t instanceof RefType || t instanceof ArrayType) {
            ass = Jimple.v().newAssignStmt(l, NullConstant.v());
        } else if (t instanceof LongType) {
            ass = Jimple.v().newAssignStmt(l, LongConstant.v(0));
        } else if (t instanceof FloatType) {
            ass = Jimple.v().newAssignStmt(l, FloatConstant.v(0.0f));
        } else if (t instanceof IntType) {
            ass = Jimple.v().newAssignStmt(l, IntConstant.v(0));
        } else if (t instanceof DoubleType) {
            ass = Jimple.v().newAssignStmt(l, DoubleConstant.v(0));
        } else if (t instanceof BooleanType || t instanceof ByteType || t instanceof CharType || t instanceof ShortType) {
            ass = Jimple.v().newAssignStmt(l, IntConstant.v(0));
        } else {
            throw new RuntimeException("error: return type unknown: " + t + " class: " + t.getClass());
        }
        jBody.getUnits().add(ass);
        jBody.getUnits().add(Jimple.v().newReturnStmt(l));
    }
}
Also used : VoidType(soot.VoidType) LocalGenerator(soot.javaToJimple.LocalGenerator) LongType(soot.LongType) AssignStmt(soot.jimple.AssignStmt) ShortType(soot.ShortType) ArrayList(java.util.ArrayList) BooleanType(soot.BooleanType) Local(soot.Local) ByteType(soot.ByteType) Unit(soot.Unit) FloatType(soot.FloatType) IntType(soot.IntType) RefType(soot.RefType) ArrayType(soot.ArrayType) RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) CharType(soot.CharType) LongType(soot.LongType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) ArrayType(soot.ArrayType) Type(soot.Type) VoidType(soot.VoidType) ParameterRef(soot.jimple.ParameterRef) ThisRef(soot.jimple.ThisRef) DoubleType(soot.DoubleType) CharType(soot.CharType) IdentityStmt(soot.jimple.IdentityStmt)

Example 65 with AssignStmt

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

the class Binop2addrInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction12x))
        throw new IllegalArgumentException("Expected Instruction12x but got: " + instruction.getClass());
    Instruction12x binOp2AddrInstr = (Instruction12x) instruction;
    int dest = binOp2AddrInstr.getRegisterA();
    Local source1 = body.getRegisterLocal(binOp2AddrInstr.getRegisterA());
    Local source2 = body.getRegisterLocal(binOp2AddrInstr.getRegisterB());
    Value expr = getExpression(source1, source2);
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
    assign.addTag(getTag());
    setUnit(assign);
    addTags(assign);
    body.add(assign);
/*
        if (IDalvikTyper.ENABLE_DVKTYPER) {
          BinopExpr bexpr = (BinopExpr)expr;
          short op = instruction.getOpcode().value;
          DalvikTyper.v().setType(bexpr.getOp1Box(), op1BinType[op-0xb0], true);
          DalvikTyper.v().setType(bexpr.getOp2Box(), op2BinType[op-0xb0], true);
          DalvikTyper.v().setType(assign.getLeftOpBox(), resBinType[op-0xb0], false);
        }
          */
}
Also used : AssignStmt(soot.jimple.AssignStmt) Value(soot.Value) Local(soot.Local) Instruction12x(org.jf.dexlib2.iface.instruction.formats.Instruction12x)

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