Search in sources :

Example 71 with AssignStmt

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

the class FilledNewArrayRangeInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction3rc))
        throw new IllegalArgumentException("Expected Instruction3rc but got: " + instruction.getClass());
    Instruction3rc filledNewArrayInstr = (Instruction3rc) instruction;
    // NopStmt nopStmtBeginning = Jimple.v().newNopStmt();
    // body.add(nopStmtBeginning);
    int usedRegister = filledNewArrayInstr.getRegisterCount();
    Type t = DexType.toSoot((TypeReference) filledNewArrayInstr.getReference());
    // NewArrayExpr needs the ElementType as it increases the array dimension by 1
    Type arrayType = ((ArrayType) t).getElementType();
    NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(arrayType, IntConstant.v(usedRegister));
    Local arrayLocal = body.getStoreResultLocal();
    AssignStmt assignStmt = Jimple.v().newAssignStmt(arrayLocal, arrayExpr);
    body.add(assignStmt);
    for (int i = 0; i < usedRegister; i++) {
        ArrayRef arrayRef = Jimple.v().newArrayRef(arrayLocal, IntConstant.v(i));
        AssignStmt assign = Jimple.v().newAssignStmt(arrayRef, body.getRegisterLocal(i + filledNewArrayInstr.getStartRegister()));
        addTags(assign);
        body.add(assign);
    }
    // NopStmt nopStmtEnd = Jimple.v().newNopStmt();
    // body.add(nopStmtEnd);
    // defineBlock(nopStmtBeginning,nopStmtEnd);
    setUnit(assignStmt);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        // Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assignStmt);
        DalvikTyper.v().setType(assignStmt.getLeftOpBox(), arrayExpr.getType(), false);
    // DalvikTyper.v().addConstraint(assignStmt.getLeftOpBox(), assignStmt.getRightOpBox());
    }
}
Also used : ArrayType(soot.ArrayType) ArrayRef(soot.jimple.ArrayRef) Instruction3rc(org.jf.dexlib2.iface.instruction.formats.Instruction3rc) ArrayType(soot.ArrayType) Type(soot.Type) DexType(soot.dexpler.DexType) NewArrayExpr(soot.jimple.NewArrayExpr) AssignStmt(soot.jimple.AssignStmt) Local(soot.Local)

Example 72 with AssignStmt

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

the class IgetInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    TwoRegisterInstruction i = (TwoRegisterInstruction) instruction;
    int dest = i.getRegisterA();
    int object = i.getRegisterB();
    FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference();
    final Jimple jimple = Jimple.v();
    InstanceFieldRef r = jimple.newInstanceFieldRef(body.getRegisterLocal(object), getSootFieldRef(f));
    AssignStmt assign = jimple.newAssignStmt(body.getRegisterLocal(dest), r);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().setType(assign.getLeftOpBox(), r.getType(), false);
    }
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) AssignStmt(soot.jimple.AssignStmt) InstanceFieldRef(soot.jimple.InstanceFieldRef) TwoRegisterInstruction(org.jf.dexlib2.iface.instruction.TwoRegisterInstruction) Jimple(soot.jimple.Jimple)

Example 73 with AssignStmt

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

the class FillArrayDataInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    if (!(instruction instanceof Instruction31t))
        throw new IllegalArgumentException("Expected Instruction31t but got: " + instruction.getClass());
    Instruction31t fillArrayInstr = (Instruction31t) instruction;
    int destRegister = fillArrayInstr.getRegisterA();
    int offset = fillArrayInstr.getCodeOffset();
    int targetAddress = codeAddress + offset;
    Instruction referenceTable = body.instructionAtAddress(targetAddress).instruction;
    if (!(referenceTable instanceof ArrayPayload)) {
        throw new RuntimeException("Address " + targetAddress + "refers to an invalid PseudoInstruction.");
    }
    ArrayPayload arrayTable = (ArrayPayload) referenceTable;
    // NopStmt nopStmtBeginning = Jimple.v().newNopStmt();
    // body.add(nopStmtBeginning);
    Local arrayReference = body.getRegisterLocal(destRegister);
    List<Number> elements = arrayTable.getArrayElements();
    int numElements = elements.size();
    Stmt firstAssign = null;
    for (int i = 0; i < numElements; i++) {
        ArrayRef arrayRef = Jimple.v().newArrayRef(arrayReference, IntConstant.v(i));
        NumericConstant element = getArrayElement(elements.get(i), body, destRegister);
        if (// array was not defined -> element type can not be found (obfuscated bytecode?)
        element == null)
            break;
        AssignStmt assign = Jimple.v().newAssignStmt(arrayRef, element);
        addTags(assign);
        body.add(assign);
        if (i == 0) {
            firstAssign = assign;
        }
    }
    if (firstAssign == null) {
        // if numElements == 0. Is it possible?
        firstAssign = Jimple.v().newNopStmt();
        body.add(firstAssign);
    }
    // NopStmt nopStmtEnd = Jimple.v().newNopStmt();
    // body.add(nopStmtEnd);
    // defineBlock(nopStmtBeginning, nopStmtEnd);
    setUnit(firstAssign);
}
Also used : ArrayPayload(org.jf.dexlib2.iface.instruction.formats.ArrayPayload) AssignStmt(soot.jimple.AssignStmt) Local(soot.Local) Instruction(org.jf.dexlib2.iface.instruction.Instruction) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) ArrayRef(soot.jimple.ArrayRef) NumericConstant(soot.jimple.NumericConstant) Instruction31t(org.jf.dexlib2.iface.instruction.formats.Instruction31t)

Example 74 with AssignStmt

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

the class MoveInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    TwoRegisterInstruction i = (TwoRegisterInstruction) instruction;
    int dest = i.getRegisterA();
    int source = i.getRegisterB();
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), body.getRegisterLocal(source));
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
    }
}
Also used : AssignStmt(soot.jimple.AssignStmt) TwoRegisterInstruction(org.jf.dexlib2.iface.instruction.TwoRegisterInstruction)

Example 75 with AssignStmt

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

the class SgetInstruction method jimplify.

@Override
public void jimplify(DexBody body) {
    int dest = ((OneRegisterInstruction) instruction).getRegisterA();
    FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference();
    StaticFieldRef r = Jimple.v().newStaticFieldRef(getStaticSootFieldRef(f));
    AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), r);
    setUnit(assign);
    addTags(assign);
    body.add(assign);
    if (IDalvikTyper.ENABLE_DVKTYPER) {
        DalvikTyper.v().setType(assign.getLeftOpBox(), r.getType(), false);
    }
}
Also used : OneRegisterInstruction(org.jf.dexlib2.iface.instruction.OneRegisterInstruction) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) AssignStmt(soot.jimple.AssignStmt) StaticFieldRef(soot.jimple.StaticFieldRef)

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