Search in sources :

Example 1 with ImmutableEncodedValue

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

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

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

the class DexPrinter method buildCommonAnnotations.

private Set<Annotation> buildCommonAnnotations(AbstractHost host, Set<String> skipList) {
    Set<Annotation> annotations = new HashSet<Annotation>();
    // handle deprecated tag
    if (host.hasTag("DeprecatedTag") && !skipList.contains("Ljava/lang/Deprecated;")) {
        ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Ljava/lang/Deprecated;", Collections.<AnnotationElement>emptySet());
        annotations.add(ann);
        skipList.add("Ljava/lang/Deprecated;");
    }
    // handle signature tag
    if (host.hasTag("SignatureTag") && !skipList.contains("Ldalvik/annotation/Signature;")) {
        SignatureTag tag = (SignatureTag) host.getTag("SignatureTag");
        List<String> splitSignature = SootToDexUtils.splitSignature(tag.getSignature());
        Set<ImmutableAnnotationElement> elements = null;
        if (splitSignature != null && splitSignature.size() > 0) {
            List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>();
            for (String s : splitSignature) {
                ImmutableStringEncodedValue val = new ImmutableStringEncodedValue(s);
                valueList.add(val);
            }
            ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList);
            ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue);
            elements = Collections.singleton(valueElement);
        } else
            LOGGER.info("Signature annotation without value detected");
        ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Signature;", elements);
        annotations.add(ann);
        skipList.add("Ldalvik/annotation/Signature;");
    }
    return annotations;
}
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) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) SignatureTag(soot.tagkit.SignatureTag) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)3 Annotation (org.jf.dexlib2.iface.Annotation)3 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)3 ImmutableAnnotationElement (org.jf.dexlib2.immutable.ImmutableAnnotationElement)3 ImmutableEncodedValue (org.jf.dexlib2.immutable.value.ImmutableEncodedValue)3 SignatureTag (soot.tagkit.SignatureTag)3 HashSet (java.util.HashSet)2 ImmutableArrayEncodedValue (org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue)2 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)2 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)2 AnnotationTag (soot.tagkit.AnnotationTag)2 ConstantValueTag (soot.tagkit.ConstantValueTag)2 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)2 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)2 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)2 InnerClassTag (soot.tagkit.InnerClassTag)2 IntegerConstantValueTag (soot.tagkit.IntegerConstantValueTag)2 LineNumberTag (soot.tagkit.LineNumberTag)2 LongConstantValueTag (soot.tagkit.LongConstantValueTag)2 ParamNamesTag (soot.tagkit.ParamNamesTag)2