Search in sources :

Example 1 with ImmutableArrayEncodedValue

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

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

Example 3 with ImmutableArrayEncodedValue

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

the class DexPrinter method buildMemberClassesAttribute.

private List<Annotation> buildMemberClassesAttribute(SootClass parentClass, InnerClassAttribute t, Set<String> skipList) {
    List<Annotation> anns = null;
    Set<String> memberClasses = null;
    // Collect the inner classes
    for (Tag t2 : t.getSpecs()) {
        InnerClassTag icTag = (InnerClassTag) t2;
        String outerClass = DexInnerClassParser.getOuterClassNameFromTag(icTag);
        // Only classes with names are member classes
        if (icTag.getOuterClass() != null && parentClass.getName().equals(outerClass)) {
            if (memberClasses == null)
                memberClasses = new HashSet<String>();
            memberClasses.add(SootToDexUtils.getDexClassName(icTag.getInnerClass()));
        }
    }
    // Write the member classes
    if (memberClasses != null && !memberClasses.isEmpty() && skipList.add("Ldalvik/annotation/MemberClasses;")) {
        List<EncodedValue> classes = new ArrayList<EncodedValue>();
        for (String memberClass : memberClasses) {
            ImmutableTypeEncodedValue classValue = new ImmutableTypeEncodedValue(memberClass);
            classes.add(classValue);
        }
        ImmutableArrayEncodedValue classesValue = new ImmutableArrayEncodedValue(classes);
        ImmutableAnnotationElement element = new ImmutableAnnotationElement("value", classesValue);
        ImmutableAnnotation memberAnnotation = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/MemberClasses;", Collections.singletonList(element));
        if (anns == null)
            anns = new ArrayList<Annotation>();
        anns.add(memberAnnotation);
    }
    return anns;
}
Also used : ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ArrayList(java.util.ArrayList) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) Annotation(org.jf.dexlib2.iface.Annotation) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) InnerClassTag(soot.tagkit.InnerClassTag) 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) 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 ImmutableArrayEncodedValue

use of org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue in project atlas by alibaba.

the class ClassReIClassDef method reAnnotation.

@Override
protected Annotation reAnnotation(Annotation annotation) {
    String type = annotation.getType();
    boolean isArray = false;
    if (type.startsWith("[")) {
        isArray = true;
    }
    String newType = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className, isArray);
    Set<? extends AnnotationElement> sets = annotation.getElements();
    Set<ImmutableAnnotationElement> newAnnotationElement = new HashSet<ImmutableAnnotationElement>();
    for (AnnotationElement annotationElement : sets) {
        String name = annotationElement.getName();
        EncodedValue encodedValue = annotationElement.getValue();
        if (encodedValue instanceof ArrayEncodedValue) {
            List<EncodedValue> lists = new ArrayList<EncodedValue>();
            for (EncodedValue encodedValueSub : ((ArrayEncodedValue) encodedValue).getValue()) {
                if (encodedValueSub instanceof StringEncodedValue) {
                    String newValue = null;
                    boolean isArray1 = false;
                    String value = ((StringEncodedValue) encodedValueSub).getValue();
                    if (value.startsWith("[")) {
                        isArray1 = true;
                    }
                    if (basicValue.contains(value)) {
                        newValue = value;
                    } else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.startsWith("L")) {
                        newValue = value;
                    } else {
                        if (value.endsWith(";")) {
                            newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray1);
                        } else {
                            newValue = DefineUtils.getDotDefineClassName(classProcessor.classProcess(DefineUtils.getDotDalvikClassName(value)).className, isArray1);
                        }
                    }
                    ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
                    lists.add(immutableStringEncodedValue);
                } else if (encodedValueSub instanceof TypeEncodedValue) {
                    String newValueSub = null;
                    String value = ((TypeEncodedValue) encodedValueSub).getValue();
                    boolean isArray2 = false;
                    if (value.startsWith("[")) {
                        isArray2 = true;
                    }
                    if (basicValue.contains(value)) {
                        newValueSub = value;
                    } else if (value.startsWith("Ljava/util/") || !value.endsWith(";")) {
                        newValueSub = value;
                    } else {
                        newValueSub = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
                    }
                    ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValueSub);
                    lists.add(immutableTypeEncodedValue);
                } else {
                    lists.add(encodedValue);
                }
            }
            ImmutableArrayEncodedValue immutableArrayEncodedValue = new ImmutableArrayEncodedValue(lists);
            ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableArrayEncodedValue);
            newAnnotationElement.add(immutableAnnotationElement);
        } else if (encodedValue instanceof StringEncodedValue) {
            String value = ((StringEncodedValue) encodedValue).getValue();
            String newValue = null;
            isArray = false;
            if (value.startsWith("[")) {
                isArray = true;
            }
            if (basicValue.contains(value)) {
                newValue = value;
            } else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.startsWith("L")) {
                newValue = value;
            } else {
                if (value.endsWith(";")) {
                    newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray);
                } else {
                    newValue = DefineUtils.getDotDefineClassName(classProcessor.classProcess(DefineUtils.getDotDalvikClassName(value)).className, isArray);
                }
            }
            ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
            ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableStringEncodedValue);
            newAnnotationElement.add(immutableAnnotationElement);
        } else if (encodedValue instanceof TypeEncodedValue) {
            String newValue = null;
            String value = ((TypeEncodedValue) encodedValue).getValue();
            boolean isArray2 = false;
            if (value.startsWith("[")) {
                isArray2 = true;
            }
            if (basicValue.contains(value)) {
                newValue = value;
            } else if (value.startsWith("Ljava/util/") || !value.endsWith(";")) {
                newValue = value;
            } else {
                newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
            }
            ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValue);
            ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableTypeEncodedValue);
            newAnnotationElement.add(immutableAnnotationElement);
        } else if (encodedValue instanceof MethodEncodedValue) {
            MethodReference methodReference = ((MethodEncodedValue) encodedValue).getValue();
            String returnType = methodReference.getReturnType();
            boolean isArray3 = false;
            if (returnType.startsWith("[")) {
                isArray3 = true;
            }
            boolean isBasic = basicType.containsKey(returnType);
            List<? extends CharSequence> paramTypes = methodReference.getParameterTypes();
            List<CharSequence> dalvikParamTypes = new ArrayList<CharSequence>();
            List<CharSequence> newParamTypes = new ArrayList<CharSequence>();
            for (CharSequence charSequence : paramTypes) {
                boolean isArray1 = false;
                if (charSequence.toString().startsWith("[")) {
                    isArray1 = true;
                }
                if (basicType.containsKey(charSequence.toString())) {
                    newParamTypes.add(charSequence);
                    dalvikParamTypes.add(basicType.get(charSequence.toString()));
                    continue;
                }
                dalvikParamTypes.add(DefineUtils.getDalvikClassName(charSequence.toString()) + (isArray1 ? "[]" : ""));
                newParamTypes.add(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(charSequence.toString())).className, isArray1));
            }
            final ImmutableMethodReference immutableReference = new ImmutableMethodReference(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass())).className, false), classProcessor.methodProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass()), methodReference.getName(), isBasic ? basicType.get(methodReference.getReturnType()) : DefineUtils.getDalvikClassName(methodReference.getReturnType()) + (isArray3 ? "[]" : ""), StringUtils.join(dalvikParamTypes.toArray(), ",")).methodName, newParamTypes, isBasic ? returnType : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getReturnType())).className, methodReference.getReturnType().startsWith("[")));
            ImmutableMethodEncodedValue immutableMethodEncodedValue = new ImmutableMethodEncodedValue(immutableReference);
            ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableMethodEncodedValue);
            newAnnotationElement.add(immutableAnnotationElement);
        } else {
            newAnnotationElement.add(ImmutableAnnotationElement.of(annotationElement));
        }
    }
    return new ImmutableAnnotation(annotation.getVisibility(), newType, newAnnotationElement);
}
Also used : ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) ArrayList(java.util.ArrayList) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) MethodReference(org.jf.dexlib2.iface.reference.MethodReference) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) HashSet(java.util.HashSet)

Example 5 with ImmutableArrayEncodedValue

use of org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue in project atlas by alibaba.

the class ClassReIClassDef method getAnnotation.

public Set<? extends Annotation> getAnnotation(Set<? extends Annotation> annotations) {
    Set<ImmutableAnnotation> newAnnotations = new HashSet<ImmutableAnnotation>();
    for (Annotation annotation : annotations) {
        String type = annotation.getType();
        boolean isArray = false;
        if (type.startsWith("[")) {
            isArray = true;
        }
        String newType = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className, isArray);
        Set<? extends AnnotationElement> sets = annotation.getElements();
        Set<ImmutableAnnotationElement> newAnnotationElement = new HashSet<ImmutableAnnotationElement>();
        for (AnnotationElement annotationElement : sets) {
            String name = annotationElement.getName();
            EncodedValue encodedValue = annotationElement.getValue();
            if (encodedValue instanceof ArrayEncodedValue) {
                List<EncodedValue> lists = new ArrayList<EncodedValue>();
                for (EncodedValue encodedValueSub : ((ArrayEncodedValue) encodedValue).getValue()) {
                    if (encodedValueSub instanceof StringEncodedValue) {
                        String newValue = null;
                        boolean isArray1 = false;
                        String value = ((StringEncodedValue) encodedValueSub).getValue();
                        if (value.startsWith("[")) {
                            isArray1 = true;
                        }
                        if (basicValue.contains(value)) {
                            newValue = value;
                        } else if (value.startsWith("Ljava/util/") || !value.endsWith(";") || value.startsWith("Ljava/lang/") || !value.startsWith("L")) {
                            newValue = value;
                        } else {
                            newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray1);
                        }
                        ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
                        lists.add(immutableStringEncodedValue);
                    } else if (encodedValueSub instanceof TypeEncodedValue) {
                        String newValueSub = null;
                        String value = ((TypeEncodedValue) encodedValueSub).getValue();
                        boolean isArray2 = false;
                        if (value.startsWith("[")) {
                            isArray2 = true;
                        }
                        if (basicValue.contains(value)) {
                            newValueSub = value;
                        } else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.endsWith(";")) {
                            newValueSub = value;
                        } else {
                            newValueSub = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
                        }
                        ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValueSub);
                        lists.add(immutableTypeEncodedValue);
                    } else {
                        lists.add(encodedValue);
                    }
                }
                ImmutableArrayEncodedValue immutableArrayEncodedValue = new ImmutableArrayEncodedValue(lists);
                ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableArrayEncodedValue);
                newAnnotationElement.add(immutableAnnotationElement);
            } else if (encodedValue instanceof StringEncodedValue) {
                String value = ((StringEncodedValue) encodedValue).getValue();
                boolean isArray3 = false;
                if (value.startsWith("[")) {
                    isArray3 = true;
                }
                String newValue = null;
                if (basicValue.contains(value)) {
                    newValue = value;
                } else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.endsWith(";")) {
                    newValue = value;
                } else {
                    newValue = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray3);
                }
                ImmutableStringEncodedValue immutableStringEncodedValue = new ImmutableStringEncodedValue(newValue);
                ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableStringEncodedValue);
                newAnnotationElement.add(immutableAnnotationElement);
            } else if (encodedValue instanceof MethodEncodedValue) {
                MethodReference methodReference = ((MethodEncodedValue) encodedValue).getValue();
                String returnType = methodReference.getReturnType();
                boolean isBasic = false;
                List<? extends CharSequence> paramTypes = methodReference.getParameterTypes();
                List<CharSequence> dalvikParamTypes = new ArrayList<CharSequence>();
                List<CharSequence> newParamTypes = new ArrayList<CharSequence>();
                for (CharSequence charSequence : paramTypes) {
                    if (basicType.containsKey(charSequence.toString())) {
                        newParamTypes.add(charSequence);
                        dalvikParamTypes.add(basicType.get(charSequence.toString()));
                        continue;
                    }
                    dalvikParamTypes.add(DefineUtils.getDalvikClassName(charSequence.toString()) + (isArray ? "[]" : ""));
                    newParamTypes.add(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(charSequence.toString())).className, isArray));
                }
                final ImmutableMethodReference immutableReference = new ImmutableMethodReference(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass())).className, false), classProcessor.methodProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass()), methodReference.getName(), isBasic ? basicType.get(methodReference.getReturnType()) : DefineUtils.getDalvikClassName(methodReference.getReturnType()) + (isArray ? "[]" : ""), StringUtils.join(dalvikParamTypes.toArray(), ",")).methodName, newParamTypes, isBasic ? returnType : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getReturnType())).className, methodReference.getReturnType().startsWith("[")));
                ImmutableMethodEncodedValue immutableMethodEncodedValue = new ImmutableMethodEncodedValue(immutableReference);
                ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableMethodEncodedValue);
                newAnnotationElement.add(immutableAnnotationElement);
            } else if (encodedValue instanceof TypeEncodedValue) {
                String newValueSub = null;
                String value = ((TypeEncodedValue) encodedValue).getValue();
                boolean isArray2 = false;
                if (value.startsWith("[")) {
                    isArray2 = true;
                }
                if (basicValue.contains(value)) {
                    newValueSub = value;
                } else if (value.startsWith("Ljava/util/") || value.startsWith("Ljava/lang/") || !value.endsWith(";")) {
                    newValueSub = value;
                } else {
                    newValueSub = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(value)).className, isArray2);
                }
                ImmutableTypeEncodedValue immutableTypeEncodedValue = new ImmutableTypeEncodedValue(newValueSub);
                ImmutableAnnotationElement immutableAnnotationElement = new ImmutableAnnotationElement(name, immutableTypeEncodedValue);
                newAnnotationElement.add(immutableAnnotationElement);
            } else {
                newAnnotationElement.add(ImmutableAnnotationElement.of(annotationElement));
            }
        }
        ImmutableAnnotation immutableAnnotation = new ImmutableAnnotation(annotation.getVisibility(), newType, newAnnotationElement);
        newAnnotations.add(immutableAnnotation);
    }
    return newAnnotations;
}
Also used : ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ArrayList(java.util.ArrayList) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) HashSet(java.util.HashSet) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) 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) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) MethodReference(org.jf.dexlib2.iface.reference.MethodReference) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference)

Aggregations

ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)5 ImmutableAnnotationElement (org.jf.dexlib2.immutable.ImmutableAnnotationElement)5 ImmutableArrayEncodedValue (org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue)5 Annotation (org.jf.dexlib2.iface.Annotation)4 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)4 ImmutableTypeEncodedValue (org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue)4 ImmutableEncodedValue (org.jf.dexlib2.immutable.value.ImmutableEncodedValue)3 ImmutableMethodEncodedValue (org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue)3 SignatureTag (soot.tagkit.SignatureTag)3 AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)2 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)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