Search in sources :

Example 1 with ImmutableAnnotation

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

the class DexPrinter method buildMethodParameterAnnotations.

/**
 * Returns all method parameter annotations (or null) for a specific parameter
 *
 * @param m
 *            the method
 * @param paramIdx
 *            the parameter index
 * @return the annotations (or null)
 */
private Set<Annotation> buildMethodParameterAnnotations(SootMethod m, final int paramIdx) {
    Set<String> skipList = null;
    Set<Annotation> annotations = null;
    for (Tag t : m.getTags()) {
        if (t.getName().equals("VisibilityParameterAnnotationTag")) {
            VisibilityParameterAnnotationTag vat = (VisibilityParameterAnnotationTag) t;
            if (skipList == null) {
                skipList = new HashSet<String>();
                annotations = new HashSet<Annotation>();
            }
            List<ImmutableAnnotation> visibilityItems = buildVisibilityParameterAnnotationTag(vat, skipList, paramIdx);
            annotations.addAll(visibilityItems);
        }
    }
    return annotations;
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) 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) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation)

Example 2 with ImmutableAnnotation

use of org.jf.dexlib2.immutable.ImmutableAnnotation 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 3 with ImmutableAnnotation

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

the class DexPrinter method buildMethodAnnotations.

private Set<Annotation> buildMethodAnnotations(SootMethod m) {
    Set<String> skipList = new HashSet<String>();
    Set<Annotation> annotations = buildCommonAnnotations(m, skipList);
    for (Tag t : m.getTags()) {
        if (t.getName().equals("VisibilityAnnotationTag")) {
            List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag((VisibilityAnnotationTag) t, skipList);
            annotations.addAll(visibilityItems);
        }
    }
    List<SootClass> exceptionList = m.getExceptionsUnsafe();
    if (exceptionList != null && !exceptionList.isEmpty()) {
        List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>(exceptionList.size());
        for (SootClass exceptionClass : exceptionList) {
            valueList.add(new ImmutableTypeEncodedValue(DexType.toDalvikICAT(exceptionClass.getName()).replace(".", "/")));
        }
        ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList);
        ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue);
        Set<ImmutableAnnotationElement> elements = Collections.singleton(valueElement);
        ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Throws;", elements);
        annotations.add(ann);
    }
    return annotations;
}
Also used : ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ArrayList(java.util.ArrayList) ImmutableEncodedValue(org.jf.dexlib2.immutable.value.ImmutableEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) SootClass(soot.SootClass) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) 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) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) HashSet(java.util.HashSet)

Example 4 with ImmutableAnnotation

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

the class DexPrinter method buildFieldAnnotations.

private Set<Annotation> buildFieldAnnotations(SootField f) {
    Set<String> skipList = new HashSet<String>();
    Set<Annotation> annotations = buildCommonAnnotations(f, skipList);
    for (Tag t : f.getTags()) {
        if (t.getName().equals("VisibilityAnnotationTag")) {
            List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag((VisibilityAnnotationTag) t, skipList);
            annotations.addAll(visibilityItems);
        }
    }
    return annotations;
}
Also used : 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) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) HashSet(java.util.HashSet)

Example 5 with ImmutableAnnotation

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

the class DexPrinter method buildVisibilityAnnotationTag.

private List<ImmutableAnnotation> buildVisibilityAnnotationTag(VisibilityAnnotationTag t, Set<String> skipList) {
    if (t.getAnnotations() == null)
        return Collections.emptyList();
    List<ImmutableAnnotation> annotations = new ArrayList<ImmutableAnnotation>();
    for (AnnotationTag at : t.getAnnotations()) {
        String type = at.getType();
        if (!skipList.add(type))
            continue;
        Set<String> alreadyWritten = new HashSet<String>();
        List<AnnotationElement> elements = null;
        if (!at.getElems().isEmpty()) {
            elements = new ArrayList<AnnotationElement>();
            for (AnnotationElem ae : at.getElems()) {
                if (ae.getName() == null || ae.getName().isEmpty())
                    throw new RuntimeException("Null or empty annotation name encountered");
                if (!alreadyWritten.add(ae.getName()))
                    throw new RuntimeException("Duplicate annotation attribute: " + ae.getName());
                EncodedValue value = buildEncodedValueForAnnotation(ae);
                ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value);
                elements.add(element);
            }
        }
        String typeName = SootToDexUtils.getDexClassName(at.getType());
        ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(t.getVisibility()), typeName, elements);
        annotations.add(ann);
    }
    return annotations;
}
Also used : ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ArrayList(java.util.ArrayList) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ImmutableNullEncodedValue(org.jf.dexlib2.immutable.value.ImmutableNullEncodedValue) ImmutableFieldEncodedValue(org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue) ImmutableByteEncodedValue(org.jf.dexlib2.immutable.value.ImmutableByteEncodedValue) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableEncodedValue(org.jf.dexlib2.immutable.value.ImmutableEncodedValue) ImmutableAnnotationEncodedValue(org.jf.dexlib2.immutable.value.ImmutableAnnotationEncodedValue) ImmutableCharEncodedValue(org.jf.dexlib2.immutable.value.ImmutableCharEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ImmutableFloatEncodedValue(org.jf.dexlib2.immutable.value.ImmutableFloatEncodedValue) ImmutableLongEncodedValue(org.jf.dexlib2.immutable.value.ImmutableLongEncodedValue) ImmutableShortEncodedValue(org.jf.dexlib2.immutable.value.ImmutableShortEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableDoubleEncodedValue(org.jf.dexlib2.immutable.value.ImmutableDoubleEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableEnumEncodedValue(org.jf.dexlib2.immutable.value.ImmutableEnumEncodedValue) ImmutableIntEncodedValue(org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue) ImmutableBooleanEncodedValue(org.jf.dexlib2.immutable.value.ImmutableBooleanEncodedValue) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) HashSet(java.util.HashSet)

Aggregations

ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)14 ImmutableAnnotationElement (org.jf.dexlib2.immutable.ImmutableAnnotationElement)12 ArrayList (java.util.ArrayList)10 Annotation (org.jf.dexlib2.iface.Annotation)10 HashSet (java.util.HashSet)9 AnnotationTag (soot.tagkit.AnnotationTag)8 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)8 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)8 AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)7 ImmutableArrayEncodedValue (org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue)7 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)7 ImmutableTypeEncodedValue (org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue)7 ImmutableEncodedValue (org.jf.dexlib2.immutable.value.ImmutableEncodedValue)6 ImmutableMethodEncodedValue (org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue)6 SignatureTag (soot.tagkit.SignatureTag)6 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)5 ConstantValueTag (soot.tagkit.ConstantValueTag)5 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)5 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)5 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)5