Search in sources :

Example 1 with ImmutableIntEncodedValue

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

the class DexPrinter method buildInnerClassAttribute.

private List<Annotation> buildInnerClassAttribute(SootClass parentClass, InnerClassAttribute t, Set<String> skipList) {
    if (t.getSpecs() == null)
        return null;
    List<Annotation> anns = null;
    for (Tag t2 : t.getSpecs()) {
        InnerClassTag icTag = (InnerClassTag) t2;
        // In Dalvik, both the EnclosingMethod/EnclosingClass tag and the
        // InnerClass tag are written to the inner class which is different
        // to Java. We thus check whether this tag actually points to our
        // outer class.
        String outerClass = DexInnerClassParser.getOuterClassNameFromTag(icTag);
        String innerClass = icTag.getInnerClass().replaceAll("/", ".");
        // next tag.
        if (!parentClass.hasOuterClass() || !innerClass.equals(parentClass.getName()))
            continue;
        // If the outer class points to the very same class, we null it
        if (parentClass.getName().equals(outerClass) && icTag.getOuterClass() == null)
            outerClass = null;
        // Do not write garbage. Never.
        if (parentClass.getName().equals(outerClass))
            continue;
        // This is an actual inner class. Write the annotation
        if (skipList.add("Ldalvik/annotation/InnerClass;")) {
            // InnerClass annotation
            List<AnnotationElement> elements = new ArrayList<AnnotationElement>();
            ImmutableAnnotationElement flagsElement = new ImmutableAnnotationElement("accessFlags", new ImmutableIntEncodedValue(icTag.getAccessFlags()));
            elements.add(flagsElement);
            ImmutableEncodedValue nameValue;
            if (icTag.getShortName() != null && !icTag.getShortName().isEmpty())
                nameValue = new ImmutableStringEncodedValue(icTag.getShortName());
            else
                nameValue = ImmutableNullEncodedValue.INSTANCE;
            ImmutableAnnotationElement nameElement = new ImmutableAnnotationElement("name", nameValue);
            elements.add(nameElement);
            if (anns == null)
                anns = new ArrayList<Annotation>();
            anns.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/InnerClass;", elements));
        }
    }
    return anns;
}
Also used : ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ArrayList(java.util.ArrayList) ImmutableEncodedValue(org.jf.dexlib2.immutable.value.ImmutableEncodedValue) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) InnerClassTag(soot.tagkit.InnerClassTag) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableIntEncodedValue(org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue) ConstantValueTag(soot.tagkit.ConstantValueTag) SourceFileTag(soot.tagkit.SourceFileTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) AnnotationTag(soot.tagkit.AnnotationTag) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) Tag(soot.tagkit.Tag) LineNumberTag(soot.tagkit.LineNumberTag) ParamNamesTag(soot.tagkit.ParamNamesTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) LongConstantValueTag(soot.tagkit.LongConstantValueTag) SignatureTag(soot.tagkit.SignatureTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag)

Example 2 with ImmutableIntEncodedValue

use of org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue 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

ImmutableIntEncodedValue (org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue)2 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)2 ConstantValueTag (soot.tagkit.ConstantValueTag)2 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)2 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)2 IntegerConstantValueTag (soot.tagkit.IntegerConstantValueTag)2 LongConstantValueTag (soot.tagkit.LongConstantValueTag)2 StringConstantValueTag (soot.tagkit.StringConstantValueTag)2 ArrayList (java.util.ArrayList)1 Annotation (org.jf.dexlib2.iface.Annotation)1 AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)1 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)1 ImmutableAnnotationElement (org.jf.dexlib2.immutable.ImmutableAnnotationElement)1 ImmutableByteEncodedValue (org.jf.dexlib2.immutable.value.ImmutableByteEncodedValue)1 ImmutableCharEncodedValue (org.jf.dexlib2.immutable.value.ImmutableCharEncodedValue)1 ImmutableDoubleEncodedValue (org.jf.dexlib2.immutable.value.ImmutableDoubleEncodedValue)1 ImmutableEncodedValue (org.jf.dexlib2.immutable.value.ImmutableEncodedValue)1 ImmutableFloatEncodedValue (org.jf.dexlib2.immutable.value.ImmutableFloatEncodedValue)1 ImmutableLongEncodedValue (org.jf.dexlib2.immutable.value.ImmutableLongEncodedValue)1 ImmutableShortEncodedValue (org.jf.dexlib2.immutable.value.ImmutableShortEncodedValue)1