Search in sources :

Example 1 with Insn12x

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

the class ExprVisitor method caseLengthExpr.

@Override
public void caseLengthExpr(LengthExpr le) {
    Value array = le.getOp();
    constantV.setOrigStmt(origStmt);
    // In buggy code, the parameter could be a NullConstant.
    // This is why we use .asImmediate() and not .asLocal()
    Register arrayReg = regAlloc.asImmediate(array, constantV);
    stmtV.addInsn(new Insn12x(Opcode.ARRAY_LENGTH, destinationReg, arrayReg), origStmt);
}
Also used : Insn12x(soot.toDex.instructions.Insn12x) Value(soot.Value)

Example 2 with Insn12x

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

the class ExprVisitor method build2AddrBinaryInsn.

private Insn build2AddrBinaryInsn(final String binaryOperation, Register secondOpReg) {
    String localTypeString = destinationReg.getTypeString();
    localTypeString = fixIntTypeString(localTypeString);
    Opcode opc = Opcode.valueOf(binaryOperation + "_" + localTypeString.toUpperCase() + "_2ADDR");
    return new Insn12x(opc, destinationReg, secondOpReg);
}
Also used : Insn12x(soot.toDex.instructions.Insn12x) Opcode(org.jf.dexlib2.Opcode)

Example 3 with Insn12x

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

the class ExprVisitor method caseNegExpr.

@Override
public void caseNegExpr(NegExpr ne) {
    Value source = ne.getOp();
    constantV.setOrigStmt(origStmt);
    Register sourceReg = regAlloc.asImmediate(source, constantV);
    Opcode opc;
    Type type = source.getType();
    if (type instanceof IntegerType) {
        opc = Opcode.NEG_INT;
    } else if (type instanceof FloatType) {
        opc = Opcode.NEG_FLOAT;
    } else if (type instanceof DoubleType) {
        opc = Opcode.NEG_DOUBLE;
    } else if (type instanceof LongType) {
        opc = Opcode.NEG_LONG;
    } else {
        throw new RuntimeException("unsupported value type for neg-* opcode: " + type);
    }
    stmtV.addInsn(new Insn12x(opc, destinationReg, sourceReg), origStmt);
}
Also used : IntegerType(soot.IntegerType) RefType(soot.RefType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) LongType(soot.LongType) NullType(soot.NullType) ArrayType(soot.ArrayType) IntegerType(soot.IntegerType) PrimType(soot.PrimType) LongType(soot.LongType) Insn12x(soot.toDex.instructions.Insn12x) DoubleType(soot.DoubleType) Value(soot.Value) Opcode(org.jf.dexlib2.Opcode) FloatType(soot.FloatType)

Example 4 with Insn12x

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

the class ExprVisitor method castPrimitive.

private void castPrimitive(Register sourceReg, Value source, Type castSootType) {
    PrimitiveType castType = PrimitiveType.getByName(castSootType.toString());
    // than sorry and it's easy to fix it here.
    if (castType == PrimitiveType.INT && source.getType() instanceof NullType)
        source = IntConstant.v(0);
    // select fitting conversion opcode, depending on the source and cast
    // type
    Type srcType = source.getType();
    if (srcType instanceof RefType)
        throw new RuntimeException("Trying to cast reference type " + srcType + " to a primitive");
    PrimitiveType sourceType = PrimitiveType.getByName(srcType.toString());
    if (castType == PrimitiveType.BOOLEAN) {
        // there is no "-to-boolean" opcode, so just pretend to move an int
        // to an int
        castType = PrimitiveType.INT;
        sourceType = PrimitiveType.INT;
    }
    if (shouldCastFromInt(sourceType, castType)) {
        // pretend to cast from int since that is OK
        sourceType = PrimitiveType.INT;
        Opcode opc = getCastOpc(sourceType, castType);
        stmtV.addInsn(new Insn12x(opc, destinationReg, sourceReg), origStmt);
    } else if (isMoveCompatible(sourceType, castType)) {
        /*
			 * no actual cast needed, just move the reg content if regs differ
			 */
        if (destinationReg.getNumber() != sourceReg.getNumber()) {
            stmtV.addInsn(StmtVisitor.buildMoveInsn(destinationReg, sourceReg), origStmt);
        } else // one for jumps
        if (!origStmt.getBoxesPointingToThis().isEmpty())
            stmtV.addInsn(new Insn10x(Opcode.NOP), origStmt);
    } else if (needsCastThroughInt(sourceType, castType)) {
        /*
			 * an unsupported "dest = (cast) src" is broken down to
			 * "tmp = (int) src" and "dest = (cast) tmp", using a tmp reg to not
			 * mess with the original reg types
			 */
        Opcode castToIntOpc = getCastOpc(sourceType, PrimitiveType.INT);
        Opcode castFromIntOpc = getCastOpc(PrimitiveType.INT, castType);
        Register tmp = regAlloc.asTmpReg(IntType.v());
        stmtV.addInsn(new Insn12x(castToIntOpc, tmp, sourceReg), origStmt);
        stmtV.addInsn(new Insn12x(castFromIntOpc, destinationReg, tmp.clone()), origStmt);
    } else {
        // the leftover simple cases, where we just cast as stated
        Opcode opc = getCastOpc(sourceType, castType);
        stmtV.addInsn(new Insn12x(opc, destinationReg, sourceReg), origStmt);
    }
}
Also used : RefType(soot.RefType) RefType(soot.RefType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) LongType(soot.LongType) NullType(soot.NullType) ArrayType(soot.ArrayType) IntegerType(soot.IntegerType) PrimType(soot.PrimType) Insn12x(soot.toDex.instructions.Insn12x) Opcode(org.jf.dexlib2.Opcode) Insn10x(soot.toDex.instructions.Insn10x) NullType(soot.NullType)

Example 5 with Insn12x

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

the class ExprVisitor method caseXorExpr.

@Override
public void caseXorExpr(XorExpr xe) {
    Value firstOperand = xe.getOp1();
    Value secondOperand = xe.getOp2();
    constantV.setOrigStmt(origStmt);
    // conversion
    if (secondOperand.equals(IntConstant.v(-1)) || secondOperand.equals(LongConstant.v(-1))) {
        PrimitiveType destRegType = PrimitiveType.getByName(destinationReg.getType().toString());
        Register orgDestReg = destinationReg;
        // We may need a temporary register if we need a typecast
        if (isBiggerThan(PrimitiveType.getByName(secondOperand.getType().toString()), destRegType)) {
            destinationReg = regAlloc.asTmpReg(IntType.v());
        }
        if (secondOperand.equals(IntConstant.v(-1))) {
            Register sourceReg = regAlloc.asImmediate(firstOperand, constantV);
            stmtV.addInsn(new Insn12x(Opcode.NOT_INT, destinationReg, sourceReg), origStmt);
        } else if (secondOperand.equals(LongConstant.v(-1))) {
            Register sourceReg = regAlloc.asImmediate(firstOperand, constantV);
            stmtV.addInsn(new Insn12x(Opcode.NOT_LONG, destinationReg, sourceReg), origStmt);
        }
        // result
        if (orgDestReg != destinationReg) {
            Register tempReg = destinationReg.clone();
            destinationReg = orgDestReg.clone();
            castPrimitive(tempReg, secondOperand, destinationReg.getType());
        }
    } else {
        // No shortcut, create normal binary operation
        buildCalculatingBinaryInsn("XOR", firstOperand, secondOperand, xe);
    }
}
Also used : Insn12x(soot.toDex.instructions.Insn12x) Value(soot.Value)

Aggregations

Insn12x (soot.toDex.instructions.Insn12x)6 Opcode (org.jf.dexlib2.Opcode)4 Value (soot.Value)3 ArrayType (soot.ArrayType)2 DoubleType (soot.DoubleType)2 FloatType (soot.FloatType)2 IntType (soot.IntType)2 IntegerType (soot.IntegerType)2 LongType (soot.LongType)2 NullType (soot.NullType)2 PrimType (soot.PrimType)2 RefType (soot.RefType)2 Type (soot.Type)2 Insn10x (soot.toDex.instructions.Insn10x)1 Insn22x (soot.toDex.instructions.Insn22x)1 Insn32x (soot.toDex.instructions.Insn32x)1