Search in sources :

Example 6 with AnnotationArrayElem

use of soot.tagkit.AnnotationArrayElem in project robovm by robovm.

the class MarshalerLookup method getSupportedCallTypes.

private Set<Long> getSupportedCallTypes(AnnotationTag anno) {
    AnnotationArrayElem el = (AnnotationArrayElem) getElemByName(anno, "supportedCallTypes");
    if (el == null) {
        return new HashSet<Long>(Arrays.asList(Bro.MarshalerFlags.CALL_TYPE_BRIDGE, Bro.MarshalerFlags.CALL_TYPE_CALLBACK, Bro.MarshalerFlags.CALL_TYPE_STRUCT_MEMBER, Bro.MarshalerFlags.CALL_TYPE_GLOBAL_VALUE, Bro.MarshalerFlags.CALL_TYPE_PTR));
    }
    ArrayList<AnnotationElem> values = ((AnnotationArrayElem) el).getValues();
    Set<Long> callTypes = new HashSet<>();
    for (AnnotationElem value : values) {
        callTypes.add(((AnnotationLongElem) value).getValue());
    }
    return callTypes;
}
Also used : AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationElem(soot.tagkit.AnnotationElem) HashSet(java.util.HashSet)

Example 7 with AnnotationArrayElem

use of soot.tagkit.AnnotationArrayElem in project robovm by robovm.

the class AttributesEncoder method encodeAnnotationElementValue.

private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
    PackedStructureType type = getAnnotationElementType(ae);
    Value kind = new IntegerConstant((byte) ae.getKind());
    if (ae instanceof AnnotationIntElem) {
        AnnotationIntElem aie = (AnnotationIntElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
    } else if (ae instanceof AnnotationLongElem) {
        AnnotationLongElem ale = (AnnotationLongElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
    } else if (ae instanceof AnnotationFloatElem) {
        AnnotationFloatElem afe = (AnnotationFloatElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
    } else if (ae instanceof AnnotationDoubleElem) {
        AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
    } else if (ae instanceof AnnotationStringElem) {
        AnnotationStringElem ase = (AnnotationStringElem) ae;
        return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
    } else if (ae instanceof AnnotationClassElem) {
        AnnotationClassElem ace = (AnnotationClassElem) ae;
        addDependencyIfNeeded(ace.getDesc());
        return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
    } else if (ae instanceof AnnotationEnumElem) {
        AnnotationEnumElem aee = (AnnotationEnumElem) ae;
        addDependencyIfNeeded(aee.getTypeName());
        return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
    } else if (ae instanceof AnnotationArrayElem) {
        AnnotationArrayElem aae = (AnnotationArrayElem) ae;
        Value[] values = new Value[aae.getNumValues() + 2];
        values[0] = kind;
        values[1] = new IntegerConstant((char) aae.getNumValues());
        for (int i = 0; i < aae.getNumValues(); i++) {
            values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
        }
        return new PackedStructureConstant(type, values);
    } else if (ae instanceof AnnotationAnnotationElem) {
        AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
        return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
    }
    throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem) Value(org.robovm.compiler.llvm.Value)

Example 8 with AnnotationArrayElem

use of soot.tagkit.AnnotationArrayElem in project soot by Sable.

the class AnnotationElemBuilder method visitArray.

@Override
public AnnotationVisitor visitArray(final String name) {
    return new AnnotationElemBuilder() {

        @Override
        public void visitEnd() {
            String ename = name;
            if (ename == null)
                ename = "default";
            AnnotationElemBuilder.this.elems.add(new AnnotationArrayElem(this.elems, '[', ename));
        }
    };
}
Also used : AnnotationArrayElem(soot.tagkit.AnnotationArrayElem)

Example 9 with AnnotationArrayElem

use of soot.tagkit.AnnotationArrayElem in project soot by Sable.

the class AnnotationElemBuilder method getAnnotationElement.

public AnnotationElem getAnnotationElement(String name, Object value) {
    AnnotationElem elem;
    if (value instanceof Byte) {
        elem = new AnnotationIntElem((Byte) value, 'B', name);
    } else if (value instanceof Boolean) {
        elem = new AnnotationIntElem(((Boolean) value) ? 1 : 0, 'Z', name);
    } else if (value instanceof Character) {
        elem = new AnnotationIntElem((Character) value, 'C', name);
    } else if (value instanceof Short) {
        elem = new AnnotationIntElem((Short) value, 'S', name);
    } else if (value instanceof Integer) {
        elem = new AnnotationIntElem((Integer) value, 'I', name);
    } else if (value instanceof Long) {
        elem = new AnnotationLongElem((Long) value, 'J', name);
    } else if (value instanceof Float) {
        elem = new AnnotationFloatElem((Float) value, 'F', name);
    } else if (value instanceof Double) {
        elem = new AnnotationDoubleElem((Double) value, 'D', name);
    } else if (value instanceof String) {
        elem = new AnnotationStringElem(value.toString(), 's', name);
    } else if (value instanceof Type) {
        Type t = (Type) value;
        elem = new AnnotationClassElem(t.getDescriptor(), 'c', name);
    } else if (value.getClass().isArray()) {
        ArrayList<AnnotationElem> annotationArray = new ArrayList<AnnotationElem>();
        if (value instanceof byte[]) {
            for (Object element : (byte[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof boolean[]) {
            for (Object element : (boolean[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof char[]) {
            for (Object element : (char[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof short[]) {
            for (Object element : (short[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof int[]) {
            for (Object element : (int[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof long[]) {
            for (Object element : (long[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof float[]) {
            for (Object element : (float[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof double[]) {
            for (Object element : (double[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof String[]) {
            for (Object element : (String[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else if (value instanceof Type[]) {
            for (Object element : (Type[]) value) annotationArray.add(getAnnotationElement(name, element));
        } else
            throw new UnsupportedOperationException("Unsupported array value type: " + value.getClass());
        elem = new AnnotationArrayElem(annotationArray, '[', name);
    } else
        throw new UnsupportedOperationException("Unsupported value type: " + value.getClass());
    return (elem);
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) ArrayList(java.util.ArrayList) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) Type(org.objectweb.asm.Type) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem)

Example 10 with AnnotationArrayElem

use of soot.tagkit.AnnotationArrayElem in project soot by Sable.

the class DexAnnotation method handleAnnotationElement.

private ArrayList<AnnotationElem> handleAnnotationElement(AnnotationElement ae, List<? extends EncodedValue> evList) {
    ArrayList<AnnotationElem> aelemList = new ArrayList<AnnotationElem>();
    for (EncodedValue ev : evList) {
        int type = ev.getValueType();
        AnnotationElem elem = null;
        switch(type) {
            case // BYTE
            0x00:
                {
                    ByteEncodedValue v = (ByteEncodedValue) ev;
                    elem = new AnnotationIntElem(v.getValue(), 'B', ae.getName());
                    break;
                }
            case // SHORT
            0x02:
                {
                    ShortEncodedValue v = (ShortEncodedValue) ev;
                    elem = new AnnotationIntElem(v.getValue(), 'S', ae.getName());
                    break;
                }
            case // CHAR
            0x03:
                {
                    CharEncodedValue v = (CharEncodedValue) ev;
                    elem = new AnnotationIntElem(v.getValue(), 'C', ae.getName());
                    break;
                }
            case // INT
            0x04:
                {
                    IntEncodedValue v = (IntEncodedValue) ev;
                    elem = new AnnotationIntElem(v.getValue(), 'I', ae.getName());
                    break;
                }
            case // LONG
            0x06:
                {
                    LongEncodedValue v = (LongEncodedValue) ev;
                    elem = new AnnotationLongElem(v.getValue(), 'J', ae.getName());
                    break;
                }
            case // FLOAT
            0x10:
                {
                    FloatEncodedValue v = (FloatEncodedValue) ev;
                    elem = new AnnotationFloatElem(v.getValue(), 'F', ae.getName());
                    break;
                }
            case // DOUBLE
            0x11:
                {
                    DoubleEncodedValue v = (DoubleEncodedValue) ev;
                    elem = new AnnotationDoubleElem(v.getValue(), 'D', ae.getName());
                    break;
                }
            case // STRING
            0x17:
                {
                    StringEncodedValue v = (StringEncodedValue) ev;
                    elem = new AnnotationStringElem(v.getValue(), 's', ae.getName());
                    break;
                }
            case // TYPE
            0x18:
                {
                    TypeEncodedValue v = (TypeEncodedValue) ev;
                    elem = new AnnotationClassElem(v.getValue(), 'c', ae.getName());
                    break;
                }
            case // FIELD (Dalvik specific?)
            0x19:
                {
                    FieldEncodedValue v = (FieldEncodedValue) ev;
                    FieldReference fr = v.getValue();
                    String fieldSig = "";
                    fieldSig += DexType.toSootAT(fr.getDefiningClass()) + ": ";
                    fieldSig += DexType.toSootAT(fr.getType()) + " ";
                    fieldSig += fr.getName();
                    elem = new AnnotationStringElem(fieldSig, 'f', ae.getName());
                    break;
                }
            case // METHOD (Dalvik specific?)
            0x1a:
                {
                    MethodEncodedValue v = (MethodEncodedValue) ev;
                    MethodReference mr = v.getValue();
                    String className = DexType.toSootICAT(mr.getDefiningClass());
                    String returnType = DexType.toSootAT(mr.getReturnType());
                    String methodName = mr.getName();
                    String parameters = "";
                    for (CharSequence p : mr.getParameterTypes()) {
                        parameters += DexType.toSootAT(p.toString());
                    }
                    String mSig = className + " |" + methodName + " |" + parameters + " |" + returnType;
                    elem = new AnnotationStringElem(mSig, 'M', ae.getName());
                    break;
                }
            case // ENUM : Warning -> encoding Dalvik specific!
            0x1b:
                {
                    EnumEncodedValue v = (EnumEncodedValue) ev;
                    FieldReference fr = v.getValue();
                    elem = new AnnotationEnumElem(DexType.toSootAT(fr.getType()).toString(), fr.getName(), 'e', ae.getName());
                    break;
                }
            case // ARRAY
            0x1c:
                {
                    ArrayEncodedValue v = (ArrayEncodedValue) ev;
                    ArrayList<AnnotationElem> l = handleAnnotationElement(ae, v.getValue());
                    if (l != null)
                        elem = new AnnotationArrayElem(l, '[', ae.getName());
                    break;
                }
            case // ANNOTATION
            0x1d:
                {
                    AnnotationEncodedValue v = (AnnotationEncodedValue) ev;
                    AnnotationTag t = new AnnotationTag(DexType.toSootAT(v.getType()).toString());
                    for (AnnotationElement newElem : v.getElements()) {
                        List<EncodedValue> l = new ArrayList<EncodedValue>();
                        l.add(newElem.getValue());
                        List<AnnotationElem> aList = handleAnnotationElement(newElem, l);
                        if (aList != null)
                            for (AnnotationElem e : aList) t.addElem(e);
                    }
                    elem = new AnnotationAnnotationElem(t, '@', ae.getName());
                    break;
                }
            case // NULL (Dalvik specific?)
            0x1e:
                {
                    elem = new AnnotationStringElem(null, 'N', ae.getName());
                    break;
                }
            case // BOOLEAN
            0x1f:
                {
                    BooleanEncodedValue v = (BooleanEncodedValue) ev;
                    elem = new AnnotationBooleanElem(v.getValue(), 'Z', ae.getName());
                    break;
                }
            default:
                {
                    throw new RuntimeException("Unknown annotation element 0x" + Integer.toHexString(type));
                }
        }
        if (elem != null)
            aelemList.add(elem);
    }
    return aelemList;
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationEncodedValue(org.jf.dexlib2.iface.value.AnnotationEncodedValue) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) FloatEncodedValue(org.jf.dexlib2.iface.value.FloatEncodedValue) ArrayList(java.util.ArrayList) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ShortEncodedValue(org.jf.dexlib2.iface.value.ShortEncodedValue) FieldEncodedValue(org.jf.dexlib2.iface.value.FieldEncodedValue) EnumEncodedValue(org.jf.dexlib2.iface.value.EnumEncodedValue) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) ByteEncodedValue(org.jf.dexlib2.iface.value.ByteEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) List(java.util.List) ArrayList(java.util.ArrayList) CharEncodedValue(org.jf.dexlib2.iface.value.CharEncodedValue) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) MethodEncodedValue(org.jf.dexlib2.iface.value.MethodEncodedValue) AnnotationBooleanElem(soot.tagkit.AnnotationBooleanElem) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationEncodedValue(org.jf.dexlib2.iface.value.AnnotationEncodedValue) DoubleEncodedValue(org.jf.dexlib2.iface.value.DoubleEncodedValue) ShortEncodedValue(org.jf.dexlib2.iface.value.ShortEncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) LongEncodedValue(org.jf.dexlib2.iface.value.LongEncodedValue) BooleanEncodedValue(org.jf.dexlib2.iface.value.BooleanEncodedValue) MethodEncodedValue(org.jf.dexlib2.iface.value.MethodEncodedValue) IntEncodedValue(org.jf.dexlib2.iface.value.IntEncodedValue) CharEncodedValue(org.jf.dexlib2.iface.value.CharEncodedValue) ByteEncodedValue(org.jf.dexlib2.iface.value.ByteEncodedValue) FieldEncodedValue(org.jf.dexlib2.iface.value.FieldEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) FloatEncodedValue(org.jf.dexlib2.iface.value.FloatEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) EnumEncodedValue(org.jf.dexlib2.iface.value.EnumEncodedValue) DoubleEncodedValue(org.jf.dexlib2.iface.value.DoubleEncodedValue) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) BooleanEncodedValue(org.jf.dexlib2.iface.value.BooleanEncodedValue) AnnotationClassElem(soot.tagkit.AnnotationClassElem) LongEncodedValue(org.jf.dexlib2.iface.value.LongEncodedValue) MethodReference(org.jf.dexlib2.iface.reference.MethodReference) IntEncodedValue(org.jf.dexlib2.iface.value.IntEncodedValue)

Aggregations

AnnotationArrayElem (soot.tagkit.AnnotationArrayElem)12 AnnotationElem (soot.tagkit.AnnotationElem)10 AnnotationAnnotationElem (soot.tagkit.AnnotationAnnotationElem)9 AnnotationStringElem (soot.tagkit.AnnotationStringElem)7 ArrayList (java.util.ArrayList)6 AnnotationClassElem (soot.tagkit.AnnotationClassElem)6 AnnotationIntElem (soot.tagkit.AnnotationIntElem)6 AnnotationTag (soot.tagkit.AnnotationTag)6 AnnotationDoubleElem (soot.tagkit.AnnotationDoubleElem)5 AnnotationEnumElem (soot.tagkit.AnnotationEnumElem)5 AnnotationFloatElem (soot.tagkit.AnnotationFloatElem)5 AnnotationLongElem (soot.tagkit.AnnotationLongElem)5 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)5 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)5 AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Annotation (org.jf.dexlib2.iface.Annotation)1 MethodParameter (org.jf.dexlib2.iface.MethodParameter)1 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)1