Search in sources :

Example 1 with Insn11x

use of soot.toDex.instructions.Insn11x in project soot by Sable.

the class StmtVisitor method caseThrowStmt.

@Override
public void caseThrowStmt(ThrowStmt stmt) {
    Value exception = stmt.getOp();
    constantV.setOrigStmt(stmt);
    Register exceptionReg = regAlloc.asImmediate(exception, constantV);
    addInsn(new Insn11x(Opcode.THROW, exceptionReg), stmt);
}
Also used : Value(soot.Value) Insn11x(soot.toDex.instructions.Insn11x)

Example 2 with Insn11x

use of soot.toDex.instructions.Insn11x in project soot by Sable.

the class ExprVisitor method caseNewMultiArrayExpr.

@Override
public void caseNewMultiArrayExpr(NewMultiArrayExpr nmae) {
    constantV.setOrigStmt(origStmt);
    // get array dimensions
    if (nmae.getSizeCount() > 255) {
        throw new RuntimeException("number of dimensions is too high (> 255) for the filled-new-array* opcodes: " + nmae.getSizeCount());
    }
    short dimensions = (short) nmae.getSizeCount();
    // get array base type
    ArrayType arrayType = ArrayType.v(nmae.getBaseType().baseType, dimensions);
    TypeReference arrayTypeItem = DexPrinter.toTypeReference(arrayType);
    // get the dimension size registers
    List<Register> dimensionSizeRegs = new ArrayList<Register>();
    for (int i = 0; i < dimensions; i++) {
        Value currentDimensionSize = nmae.getSize(i);
        Register currentReg = regAlloc.asImmediate(currentDimensionSize, constantV);
        dimensionSizeRegs.add(currentReg);
    }
    // create filled-new-array instruction, depending on the dimension sizes
    if (dimensions <= 5) {
        Register[] paddedRegs = pad35cRegs(dimensionSizeRegs);
        stmtV.addInsn(new Insn35c(Opcode.FILLED_NEW_ARRAY, dimensions, paddedRegs[0], paddedRegs[1], paddedRegs[2], paddedRegs[3], paddedRegs[4], arrayTypeItem), null);
    } else {
        stmtV.addInsn(new Insn3rc(Opcode.FILLED_NEW_ARRAY_RANGE, dimensionSizeRegs, dimensions, arrayTypeItem), null);
    }
    // check for > 255 is done already
    // move the resulting array into the destination register
    stmtV.addInsn(new Insn11x(Opcode.MOVE_RESULT_OBJECT, destinationReg), origStmt);
}
Also used : Insn35c(soot.toDex.instructions.Insn35c) Insn3rc(soot.toDex.instructions.Insn3rc) ArrayList(java.util.ArrayList) ArrayType(soot.ArrayType) Value(soot.Value) TypeReference(org.jf.dexlib2.iface.reference.TypeReference) Insn11x(soot.toDex.instructions.Insn11x)

Example 3 with Insn11x

use of soot.toDex.instructions.Insn11x in project soot by Sable.

the class StmtVisitor method caseReturnStmt.

@Override
public void caseReturnStmt(ReturnStmt stmt) {
    Value returnValue = stmt.getOp();
    constantV.setOrigStmt(stmt);
    Register returnReg = regAlloc.asImmediate(returnValue, constantV);
    Opcode opc;
    Type retType = returnValue.getType();
    if (SootToDexUtils.isObject(retType)) {
        opc = Opcode.RETURN_OBJECT;
    } else if (SootToDexUtils.isWide(retType)) {
        opc = Opcode.RETURN_WIDE;
    } else {
        opc = Opcode.RETURN;
    }
    addInsn(new Insn11x(opc, returnReg), stmt);
}
Also used : ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) ArrayType(soot.ArrayType) Value(soot.Value) Opcode(org.jf.dexlib2.Opcode) Insn11x(soot.toDex.instructions.Insn11x)

Example 4 with Insn11x

use of soot.toDex.instructions.Insn11x in project soot by Sable.

the class StmtVisitor method caseIdentityStmt.

@Override
public void caseIdentityStmt(IdentityStmt stmt) {
    Local lhs = (Local) stmt.getLeftOp();
    Value rhs = stmt.getRightOp();
    if (rhs instanceof CaughtExceptionRef) {
        // save the caught exception with move-exception
        Register localReg = regAlloc.asLocal(lhs);
        addInsn(new Insn11x(Opcode.MOVE_EXCEPTION, localReg), stmt);
        this.insnRegisterMap.put(insns.get(insns.size() - 1), LocalRegisterAssignmentInformation.v(localReg, lhs));
    } else if (rhs instanceof ThisRef || rhs instanceof ParameterRef) {
        /*
			 * do not save the ThisRef or ParameterRef in a local, because it
			 * always has a parameter register already. at least use the local
			 * for further reference in the statements
			 */
        Local localForThis = lhs;
        regAlloc.asParameter(belongingMethod, localForThis);
        parameterInstructionsList.add(LocalRegisterAssignmentInformation.v(regAlloc.asLocal(localForThis).clone(), localForThis));
    } else {
        throw new Error("unknown Value as right-hand side of IdentityStmt: " + rhs);
    }
}
Also used : ParameterRef(soot.jimple.ParameterRef) CaughtExceptionRef(soot.jimple.CaughtExceptionRef) ThisRef(soot.jimple.ThisRef) Value(soot.Value) Local(soot.Local) Insn11x(soot.toDex.instructions.Insn11x)

Example 5 with Insn11x

use of soot.toDex.instructions.Insn11x in project soot by Sable.

the class StmtVisitor method buildMonitorInsn.

private Insn buildMonitorInsn(MonitorStmt stmt, Opcode opc) {
    Value lockValue = stmt.getOp();
    constantV.setOrigStmt(stmt);
    // When leaving a monitor, we must make sure to re-use the old
    // register. If we assign the same class constant to a new register
    // before leaving the monitor, Android's bytecode verifier will assume
    // that this constant assignment can throw an exception, leaving us
    // with a dangling monitor. Imprecise static analyzers ftw.
    Register lockReg = null;
    if (lockValue instanceof Constant)
        if ((lockReg = monitorRegs.get(lockValue)) != null)
            lockReg = lockReg.clone();
    if (lockReg == null) {
        lockReg = regAlloc.asImmediate(lockValue, constantV);
        regAlloc.lockRegister(lockReg);
        if (lockValue instanceof Constant) {
            monitorRegs.put((Constant) lockValue, lockReg);
            regAlloc.lockRegister(lockReg);
        }
    }
    return new Insn11x(opc, lockReg);
}
Also used : Constant(soot.jimple.Constant) LongConstant(soot.jimple.LongConstant) DoubleConstant(soot.jimple.DoubleConstant) IntConstant(soot.jimple.IntConstant) ClassConstant(soot.jimple.ClassConstant) FloatConstant(soot.jimple.FloatConstant) Value(soot.Value) Insn11x(soot.toDex.instructions.Insn11x)

Aggregations

Value (soot.Value)5 Insn11x (soot.toDex.instructions.Insn11x)5 ArrayType (soot.ArrayType)2 ArrayList (java.util.ArrayList)1 Opcode (org.jf.dexlib2.Opcode)1 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)1 BooleanType (soot.BooleanType)1 ByteType (soot.ByteType)1 CharType (soot.CharType)1 DoubleType (soot.DoubleType)1 FloatType (soot.FloatType)1 IntType (soot.IntType)1 Local (soot.Local)1 LongType (soot.LongType)1 ShortType (soot.ShortType)1 Type (soot.Type)1 CaughtExceptionRef (soot.jimple.CaughtExceptionRef)1 ClassConstant (soot.jimple.ClassConstant)1 Constant (soot.jimple.Constant)1 DoubleConstant (soot.jimple.DoubleConstant)1