Search in sources :

Example 16 with DoubleType

use of soot.DoubleType in project soot by Sable.

the class FillArrayDataInstruction method getArrayElement.

private NumericConstant getArrayElement(Number element, DexBody body, int arrayRegister) {
    List<DexlibAbstractInstruction> instructions = body.instructionsBefore(this);
    Set<Integer> usedRegisters = new HashSet<Integer>();
    usedRegisters.add(arrayRegister);
    Type elementType = null;
    Outer: for (DexlibAbstractInstruction i : instructions) {
        if (usedRegisters.isEmpty())
            break;
        for (int reg : usedRegisters) if (i instanceof NewArrayInstruction) {
            NewArrayInstruction newArrayInstruction = (NewArrayInstruction) i;
            Instruction22c instruction22c = (Instruction22c) newArrayInstruction.instruction;
            if (instruction22c.getRegisterA() == reg) {
                ArrayType arrayType = (ArrayType) DexType.toSoot((TypeReference) instruction22c.getReference());
                elementType = arrayType.getElementType();
                break Outer;
            }
        }
        // look for new registers
        for (int reg : usedRegisters) {
            int newRegister = i.movesToRegister(reg);
            if (newRegister != -1) {
                usedRegisters.add(newRegister);
                usedRegisters.remove(reg);
                // there can't be more than one new
                break;
            }
        }
    }
    if (elementType == null) {
        // throw new InternalError("Unable to find array type to type array elements!");
        logger.warn("Unable to find array type to type array elements! Array was not defined! (obfuscated bytecode?)");
        return null;
    }
    NumericConstant value;
    if (elementType instanceof BooleanType) {
        value = IntConstant.v(element.intValue());
        IntConstant ic = (IntConstant) value;
        if (ic.value != 0) {
            value = IntConstant.v(1);
        }
    } else if (elementType instanceof ByteType) {
        value = IntConstant.v(element.byteValue());
    } else if (elementType instanceof CharType || elementType instanceof ShortType) {
        value = IntConstant.v(element.shortValue());
    } else if (elementType instanceof DoubleType) {
        value = DoubleConstant.v(Double.longBitsToDouble(element.longValue()));
    } else if (elementType instanceof FloatType) {
        value = FloatConstant.v(Float.intBitsToFloat(element.intValue()));
    } else if (elementType instanceof IntType) {
        value = IntConstant.v(element.intValue());
    } else if (elementType instanceof LongType) {
        value = LongConstant.v(element.longValue());
    } else {
        throw new RuntimeException("Invalid Array Type occured in FillArrayDataInstruction: " + elementType);
    }
    return value;
}
Also used : Instruction22c(org.jf.dexlib2.iface.instruction.formats.Instruction22c) LongType(soot.LongType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) FloatType(soot.FloatType) IntType(soot.IntType) ArrayType(soot.ArrayType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) CharType(soot.CharType) LongType(soot.LongType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) ArrayType(soot.ArrayType) Type(soot.Type) DexType(soot.dexpler.DexType) NumericConstant(soot.jimple.NumericConstant) DoubleType(soot.DoubleType) IntConstant(soot.jimple.IntConstant) TypeReference(org.jf.dexlib2.iface.reference.TypeReference) CharType(soot.CharType) HashSet(java.util.HashSet)

Aggregations

DoubleType (soot.DoubleType)16 FloatType (soot.FloatType)15 LongType (soot.LongType)15 IntType (soot.IntType)14 Type (soot.Type)13 ByteType (soot.ByteType)12 ShortType (soot.ShortType)12 BooleanType (soot.BooleanType)11 CharType (soot.CharType)11 Value (soot.Value)9 ArrayList (java.util.ArrayList)8 Local (soot.Local)8 RefType (soot.RefType)8 ArrayType (soot.ArrayType)7 List (java.util.List)6 NullType (soot.NullType)5 PrimType (soot.PrimType)5 IntConstant (soot.jimple.IntConstant)5 Iterator (java.util.Iterator)4 Unit (soot.Unit)4