Search in sources :

Example 1 with ImmutableShortEncodedValue

use of org.jf.dexlib2.immutable.value.ImmutableShortEncodedValue in project soot by Sable.

the class DexPrinter method makeConstantItem.

private EncodedValue makeConstantItem(SootField sf, Tag t) {
    if (!(t instanceof ConstantValueTag))
        throw new RuntimeException("error: t not ConstantValueTag.");
    if (t instanceof IntegerConstantValueTag) {
        Type sft = sf.getType();
        IntegerConstantValueTag i = (IntegerConstantValueTag) t;
        if (sft instanceof BooleanType) {
            int v = i.getIntValue();
            if (v == 0) {
                return ImmutableBooleanEncodedValue.FALSE_VALUE;
            } else if (v == 1) {
                return ImmutableBooleanEncodedValue.TRUE_VALUE;
            } else {
                throw new RuntimeException("error: boolean value from int with value != 0 or 1.");
            }
        } else if (sft instanceof CharType) {
            return new ImmutableCharEncodedValue((char) i.getIntValue());
        } else if (sft instanceof ByteType) {
            return new ImmutableByteEncodedValue((byte) i.getIntValue());
        } else if (sft instanceof IntType) {
            return new ImmutableIntEncodedValue(i.getIntValue());
        } else if (sft instanceof ShortType) {
            return new ImmutableShortEncodedValue((short) i.getIntValue());
        } else {
            throw new RuntimeException("error: unexpected constant tag type: " + t + " for field " + sf);
        }
    } else if (t instanceof LongConstantValueTag) {
        LongConstantValueTag l = (LongConstantValueTag) t;
        return new ImmutableLongEncodedValue(l.getLongValue());
    } else if (t instanceof DoubleConstantValueTag) {
        DoubleConstantValueTag d = (DoubleConstantValueTag) t;
        return new ImmutableDoubleEncodedValue(d.getDoubleValue());
    } else if (t instanceof FloatConstantValueTag) {
        FloatConstantValueTag f = (FloatConstantValueTag) t;
        return new ImmutableFloatEncodedValue(f.getFloatValue());
    } else if (t instanceof StringConstantValueTag) {
        StringConstantValueTag s = (StringConstantValueTag) t;
        if (sf.getType().equals(RefType.v("java.lang.String")))
            return new ImmutableStringEncodedValue(s.getStringValue());
        else
            // Results in "Bogus static initialization"
            return null;
    } else
        throw new RuntimeException("Unexpected constant type");
}
Also used : ImmutableShortEncodedValue(org.jf.dexlib2.immutable.value.ImmutableShortEncodedValue) ImmutableCharEncodedValue(org.jf.dexlib2.immutable.value.ImmutableCharEncodedValue) ImmutableByteEncodedValue(org.jf.dexlib2.immutable.value.ImmutableByteEncodedValue) ShortType(soot.ShortType) BooleanType(soot.BooleanType) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) ByteType(soot.ByteType) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) IntType(soot.IntType) ConstantValueTag(soot.tagkit.ConstantValueTag) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) LongConstantValueTag(soot.tagkit.LongConstantValueTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) BooleanType(soot.BooleanType) Type(soot.Type) DexType(soot.dexpler.DexType) RefType(soot.RefType) ShortType(soot.ShortType) ByteType(soot.ByteType) IntType(soot.IntType) CharType(soot.CharType) ImmutableDoubleEncodedValue(org.jf.dexlib2.immutable.value.ImmutableDoubleEncodedValue) ImmutableFloatEncodedValue(org.jf.dexlib2.immutable.value.ImmutableFloatEncodedValue) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) LongConstantValueTag(soot.tagkit.LongConstantValueTag) ImmutableIntEncodedValue(org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue) CharType(soot.CharType) StringConstantValueTag(soot.tagkit.StringConstantValueTag) ImmutableLongEncodedValue(org.jf.dexlib2.immutable.value.ImmutableLongEncodedValue) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag)

Aggregations

ImmutableByteEncodedValue (org.jf.dexlib2.immutable.value.ImmutableByteEncodedValue)1 ImmutableCharEncodedValue (org.jf.dexlib2.immutable.value.ImmutableCharEncodedValue)1 ImmutableDoubleEncodedValue (org.jf.dexlib2.immutable.value.ImmutableDoubleEncodedValue)1 ImmutableFloatEncodedValue (org.jf.dexlib2.immutable.value.ImmutableFloatEncodedValue)1 ImmutableIntEncodedValue (org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue)1 ImmutableLongEncodedValue (org.jf.dexlib2.immutable.value.ImmutableLongEncodedValue)1 ImmutableShortEncodedValue (org.jf.dexlib2.immutable.value.ImmutableShortEncodedValue)1 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)1 BooleanType (soot.BooleanType)1 ByteType (soot.ByteType)1 CharType (soot.CharType)1 IntType (soot.IntType)1 RefType (soot.RefType)1 ShortType (soot.ShortType)1 Type (soot.Type)1 DexType (soot.dexpler.DexType)1 ConstantValueTag (soot.tagkit.ConstantValueTag)1 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)1 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)1 IntegerConstantValueTag (soot.tagkit.IntegerConstantValueTag)1