Search in sources :

Example 1 with Insn35c

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

the class ExprVisitor method buildInvokeInsn.

private Insn buildInvokeInsn(String invokeOpcode, MethodReference method, List<Register> argumentRegs) {
    Insn invokeInsn;
    int regCountForArguments = SootToDexUtils.getRealRegCount(argumentRegs);
    if (regCountForArguments <= 5) {
        Register[] paddedArray = pad35cRegs(argumentRegs);
        Opcode opc = Opcode.valueOf(invokeOpcode);
        invokeInsn = new Insn35c(opc, regCountForArguments, paddedArray[0], paddedArray[1], paddedArray[2], paddedArray[3], paddedArray[4], method);
    } else if (regCountForArguments <= 255) {
        Opcode opc = Opcode.valueOf(invokeOpcode + "_RANGE");
        invokeInsn = new Insn3rc(opc, argumentRegs, (short) regCountForArguments, method);
    } else {
        throw new Error("too many parameter registers for invoke-* (> 255): " + regCountForArguments + " or registers too big (> 4 bits)");
    }
    // save the return type for the move-result insn
    stmtV.setLastReturnTypeDescriptor(method.getReturnType());
    return invokeInsn;
}
Also used : Insn(soot.toDex.instructions.Insn) Insn35c(soot.toDex.instructions.Insn35c) Insn3rc(soot.toDex.instructions.Insn3rc) Opcode(org.jf.dexlib2.Opcode)

Example 2 with Insn35c

use of soot.toDex.instructions.Insn35c 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)

Aggregations

Insn35c (soot.toDex.instructions.Insn35c)2 Insn3rc (soot.toDex.instructions.Insn3rc)2 ArrayList (java.util.ArrayList)1 Opcode (org.jf.dexlib2.Opcode)1 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)1 ArrayType (soot.ArrayType)1 Value (soot.Value)1 Insn (soot.toDex.instructions.Insn)1 Insn11x (soot.toDex.instructions.Insn11x)1