Search in sources :

Example 1 with Insn23x

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

the class ExprVisitor method buildCmpInsn.

private Insn buildCmpInsn(String opcodePrefix, Value firstOperand, Value secondOperand) {
    constantV.setOrigStmt(origStmt);
    Register firstReg = regAlloc.asImmediate(firstOperand, constantV);
    Register secondReg = regAlloc.asImmediate(secondOperand, constantV);
    // select fitting opcode according to the prefix and the type of the
    // operands
    Opcode opc = null;
    // first one
    if (opcodePrefix.equals("CMP_LONG")) {
        opc = Opcode.CMP_LONG;
    } else if (firstReg.isFloat()) {
        opc = Opcode.valueOf(opcodePrefix + "_FLOAT");
    } else if (firstReg.isDouble()) {
        opc = Opcode.valueOf(opcodePrefix + "_DOUBLE");
    } else {
        throw new RuntimeException("unsupported type of operands for cmp* opcode: " + firstOperand.getType());
    }
    return new Insn23x(opc, destinationReg, firstReg, secondReg);
}
Also used : Insn23x(soot.toDex.instructions.Insn23x) Opcode(org.jf.dexlib2.Opcode)

Example 2 with Insn23x

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

the class StmtVisitor method buildArrayPutInsn.

private Insn buildArrayPutInsn(ArrayRef destRef, Value source) {
    Local array = (Local) destRef.getBase();
    Register arrayReg = regAlloc.asLocal(array);
    Value index = destRef.getIndex();
    Register indexReg = regAlloc.asImmediate(index, constantV);
    Register sourceReg = regAlloc.asImmediate(source, constantV);
    String arrayTypeDescriptor = SootToDexUtils.getArrayTypeDescriptor((ArrayType) array.getType());
    Opcode opc = getPutGetOpcodeWithTypeSuffix(APUT_OPCODE, arrayTypeDescriptor);
    return new Insn23x(opc, sourceReg, arrayReg, indexReg);
}
Also used : Insn23x(soot.toDex.instructions.Insn23x) Value(soot.Value) Local(soot.Local) Opcode(org.jf.dexlib2.Opcode)

Example 3 with Insn23x

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

the class StmtVisitor method buildArrayGetInsn.

private Insn buildArrayGetInsn(Register destinationReg, ArrayRef sourceRef) {
    Value index = sourceRef.getIndex();
    Register indexReg = regAlloc.asImmediate(index, constantV);
    Local array = (Local) sourceRef.getBase();
    Register arrayReg = regAlloc.asLocal(array);
    String arrayTypeDescriptor = SootToDexUtils.getArrayTypeDescriptor((ArrayType) array.getType());
    Opcode opc = getPutGetOpcodeWithTypeSuffix(AGET_OPCODE, arrayTypeDescriptor);
    return new Insn23x(opc, destinationReg, arrayReg, indexReg);
}
Also used : Insn23x(soot.toDex.instructions.Insn23x) Value(soot.Value) Local(soot.Local) Opcode(org.jf.dexlib2.Opcode)

Example 4 with Insn23x

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

the class ExprVisitor method buildNormalBinaryInsn.

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

Example 5 with Insn23x

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

the class RegisterAssigner method findFittingInsn.

private Insn findFittingInsn(Insn insn) {
    if (!insn.hasIncompatibleRegs()) {
        // no incompatible regs -> no fitting needed
        return null;
    }
    // we expect the dex specification to rarely change, so we hard-code the
    // mapping "unfitting -> fitting"
    Opcode opc = insn.getOpcode();
    if (insn instanceof Insn11n && opc.equals(Opcode.CONST_4)) {
        // const-4 (11n, byteReg) -> const-16 (21s, shortReg)
        Insn11n unfittingInsn = (Insn11n) insn;
        if (unfittingInsn.getRegA().fitsShort()) {
            return new Insn21s(Opcode.CONST_16, unfittingInsn.getRegA(), unfittingInsn.getLitB());
        }
    } else if (insn instanceof TwoRegInsn && opc.name.endsWith("_2ADDR")) {
        // */2addr (12x, byteReg,byteReg) -> * (23x,
        // shortReg,shortReg,shortReg)
        Register regA = ((TwoRegInsn) insn).getRegA();
        Register regB = ((TwoRegInsn) insn).getRegB();
        if (regA.fitsShort() && regB.fitsShort()) {
            // use new opcode without the "/2addr"
            int oldOpcLength = opc.name.length();
            String newOpcName = opc.name.substring(0, oldOpcLength - 6);
            Opcode newOpc = Opcode.valueOf(newOpcName);
            Register regAClone = regA.clone();
            return new Insn23x(newOpc, regA, regAClone, regB);
        }
    } else if (insn instanceof TwoRegInsn && SootToDexUtils.isNormalMove(opc)) {
        /*
			 * move+ (12x, byteReg,byteReg) -> move+/from16 (22x,
			 * shortReg,unconstReg) -> move+/16 (32x, unconstReg,unconstReg)
			 * where "+" is "", "-object" or "-wide"
			 */
        Register regA = ((TwoRegInsn) insn).getRegA();
        Register regB = ((TwoRegInsn) insn).getRegB();
        if (regA.getNumber() != regB.getNumber()) {
            return StmtVisitor.buildMoveInsn(regA, regB);
        }
    }
    // no fitting insn found
    return null;
}
Also used : Insn23x(soot.toDex.instructions.Insn23x) Insn21s(soot.toDex.instructions.Insn21s) Opcode(org.jf.dexlib2.Opcode) TwoRegInsn(soot.toDex.instructions.TwoRegInsn) Insn11n(soot.toDex.instructions.Insn11n)

Aggregations

Opcode (org.jf.dexlib2.Opcode)5 Insn23x (soot.toDex.instructions.Insn23x)5 Local (soot.Local)2 Value (soot.Value)2 Insn11n (soot.toDex.instructions.Insn11n)1 Insn21s (soot.toDex.instructions.Insn21s)1 TwoRegInsn (soot.toDex.instructions.TwoRegInsn)1