Search in sources :

Example 1 with TypeEncodedValue

use of org.jf.dexlib2.iface.value.TypeEncodedValue in project soot by Sable.

the class DexMethod method getThrownExceptions.

protected List<SootClass> getThrownExceptions(final Method method) {
    // the following snippet retrieves all exceptions that this method
    // throws by analyzing its annotations
    List<SootClass> thrownExceptions = new ArrayList<SootClass>();
    for (Annotation a : method.getAnnotations()) {
        Type atype = DexType.toSoot(a.getType());
        String atypes = atype.toString();
        if (!(atypes.equals("dalvik.annotation.Throws")))
            continue;
        for (AnnotationElement ae : a.getElements()) {
            EncodedValue ev = ae.getValue();
            if (ev instanceof ArrayEncodedValue) {
                for (EncodedValue evSub : ((ArrayEncodedValue) ev).getValue()) {
                    if (evSub instanceof TypeEncodedValue) {
                        TypeEncodedValue valueType = (TypeEncodedValue) evSub;
                        String exceptionName = valueType.getValue();
                        String dottedName = Util.dottedClassName(exceptionName);
                        thrownExceptions.add(SootResolver.v().makeClassRef(dottedName));
                    }
                }
            }
        }
    }
    return thrownExceptions;
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) Type(soot.Type) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) ArrayList(java.util.ArrayList) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) SootClass(soot.SootClass) Annotation(org.jf.dexlib2.iface.Annotation)

Example 2 with TypeEncodedValue

use of org.jf.dexlib2.iface.value.TypeEncodedValue in project soot by Sable.

the class DexAnnotation method handleAnnotation.

/**
 * @param annotations
 * @return
 */
private List<Tag> handleAnnotation(Set<? extends org.jf.dexlib2.iface.Annotation> annotations, String classType) {
    if (annotations == null || annotations.size() == 0)
        return null;
    List<Tag> tags = new ArrayList<Tag>();
    // RUNTIME_VISIBLE,
    VisibilityAnnotationTag[] vatg = new VisibilityAnnotationTag[3];
    for (Annotation a : annotations) {
        int v = getVisibility(a.getVisibility());
        Tag t = null;
        Type atype = DexType.toSoot(a.getType());
        String atypes = atype.toString();
        int eSize = a.getElements().size();
        if (atypes.equals("dalvik.annotation.AnnotationDefault")) {
            if (eSize != 1)
                throw new RuntimeException("error: expected 1 element for annotation Default. Got " + eSize + " instead.");
            // get element
            AnnotationElem e = getElements(a.getElements()).get(0);
            AnnotationTag adt = new AnnotationTag(a.getType());
            adt.addElem(e);
            if (vatg[v] == null)
                vatg[v] = new VisibilityAnnotationTag(v);
            vatg[v].addAnnotation(adt);
        } else if (atypes.equals("dalvik.annotation.EnclosingClass")) {
            if (eSize != 1)
                throw new RuntimeException("error: expected 1 element for annotation EnclosingClass. Got " + eSize + " instead.");
            for (AnnotationElement elem : a.getElements()) {
                String outerClass = ((TypeEncodedValue) elem.getValue()).getValue();
                outerClass = Util.dottedClassName(outerClass);
                // repair it
                if (outerClass.equals(clazz.getName())) {
                    if (outerClass.contains("$-")) {
                        /*
							 * This is a special case for generated lambda
							 * classes of jack and jill compiler. Generated
							 * lambda classes may contain '$' which do not
							 * indicate an inner/outer class separator if the
							 * '$' occurs after a inner class with a name
							 * starting with '-'. Thus we search for '$-' and
							 * anything after it including '-' is the inner
							 * classes name and anything before it is the outer
							 * classes name.
							 */
                        outerClass = outerClass.substring(0, outerClass.indexOf("$-"));
                    } else if (outerClass.contains("$")) {
                        // remove everything after the last '$' including
                        // the last '$'
                        outerClass = outerClass.substring(0, outerClass.lastIndexOf("$"));
                    }
                }
                deps.typesToSignature.add(RefType.v(outerClass));
                clazz.setOuterClass(SootResolver.v().makeClassRef(outerClass));
                assert clazz.getOuterClass() != clazz;
            }
            // annotation.
            continue;
        } else if (atypes.equals("dalvik.annotation.EnclosingMethod")) {
            // ignore the annotation
            if (eSize == 0)
                continue;
            // If the pointer is ambiguous, we are in trouble
            if (eSize != 1)
                throw new RuntimeException("error: expected 1 element for annotation EnclosingMethod. Got " + eSize + " instead.");
            AnnotationStringElem e = (AnnotationStringElem) getElements(a.getElements()).get(0);
            String[] split1 = e.getValue().split("\\ \\|");
            String classString = split1[0];
            String methodString = split1[1];
            String parameters = split1[2];
            String returnType = split1[3];
            String methodSigString = "(" + parameters + ")" + returnType;
            t = new EnclosingMethodTag(classString, methodString, methodSigString);
            String outerClass = classString.replace("/", ".");
            deps.typesToSignature.add(RefType.v(outerClass));
            clazz.setOuterClass(SootResolver.v().makeClassRef(outerClass));
            assert clazz.getOuterClass() != clazz;
        } else if (atypes.equals("dalvik.annotation.InnerClass")) {
            // access flags of the inner class
            int accessFlags = -1;
            // name of the inner class
            String name = null;
            for (AnnotationElem ele : getElements(a.getElements())) {
                if (ele instanceof AnnotationIntElem && ele.getName().equals("accessFlags"))
                    accessFlags = ((AnnotationIntElem) ele).getValue();
                else if (ele instanceof AnnotationStringElem && ele.getName().equals("name"))
                    name = ((AnnotationStringElem) ele).getValue();
                else
                    throw new RuntimeException("Unexpected inner class annotation element");
            }
            // outer class name
            String outerClass;
            if (clazz.hasOuterClass()) {
                // If we have already set an outer class from some other
                // annotation, we use that
                // one.
                outerClass = clazz.getOuterClass().getName();
            } else if (classType.contains("$-")) {
                /*
					 * This is a special case for generated lambda classes of
					 * jack and jill compiler. Generated lambda classes may
					 * contain '$' which do not indicate an inner/outer class
					 * separator if the '$' occurs after a inner class with a
					 * name starting with '-'. Thus we search for '$-' and
					 * anything after it including '-' is the inner classes name
					 * and anything before it is the outer classes name.
					 */
                outerClass = classType.substring(0, classType.indexOf("$-"));
                if (Util.isByteCodeClassName(classType))
                    outerClass += ";";
            } else if (classType.contains("$")) {
                // remove everything after the last '$' including the last
                // '$'
                outerClass = classType.substring(0, classType.lastIndexOf("$")) + ";";
                if (Util.isByteCodeClassName(classType))
                    outerClass += ";";
            } else {
                // Make sure that no funny business is going on if the
                // annotation is broken and does not end in $nn.
                outerClass = null;
            }
            Tag innerTag = new InnerClassTag(DexType.toSootICAT(classType), outerClass == null ? null : DexType.toSootICAT(outerClass), name, accessFlags);
            tags.add(innerTag);
            if (outerClass != null && !clazz.hasOuterClass()) {
                String sootOuterClass = Util.dottedClassName(outerClass);
                deps.typesToSignature.add(RefType.v(sootOuterClass));
                clazz.setOuterClass(SootResolver.v().makeClassRef(sootOuterClass));
                assert clazz.getOuterClass() != clazz;
            }
            continue;
        } else if (atypes.equals("dalvik.annotation.MemberClasses")) {
            AnnotationArrayElem e = (AnnotationArrayElem) getElements(a.getElements()).get(0);
            for (AnnotationElem ae : e.getValues()) {
                AnnotationClassElem c = (AnnotationClassElem) ae;
                String innerClass = c.getDesc();
                String outerClass;
                String name;
                if (innerClass.contains("$-")) {
                    /*
						 * This is a special case for generated lambda classes
						 * of jack and jill compiler. Generated lambda classes
						 * may contain '$' which do not indicate an inner/outer
						 * class separator if the '$' occurs after a inner class
						 * with a name starting with '-'. Thus we search for
						 * '$-' and anything after it including '-' is the inner
						 * classes name and anything before it is the outer
						 * classes name.
						 */
                    int i = innerClass.indexOf("$-");
                    outerClass = innerClass.substring(0, i);
                    name = innerClass.substring(i + 2).replaceAll(";$", "");
                } else if (innerClass.contains("$")) {
                    // remove everything after the last '$' including the
                    // last '$'
                    int i = innerClass.lastIndexOf("$");
                    outerClass = innerClass.substring(0, i);
                    name = innerClass.substring(i + 1).replaceAll(";$", "");
                } else {
                    // Make sure that no funny business is going on if the
                    // annotation is broken and does not end in $nn.
                    outerClass = null;
                    name = null;
                }
                if (// anonymous or
                name != null && name.matches("^\\d*$"))
                    // local inner
                    // classes
                    name = null;
                // seems like this information is lost
                int accessFlags = 0;
                // during the .class -- dx --> .dex
                // process.
                Tag innerTag = new InnerClassTag(DexType.toSootICAT(innerClass), outerClass == null ? null : DexType.toSootICAT(outerClass), name, accessFlags);
                tags.add(innerTag);
            }
            continue;
        } else if (atypes.equals("dalvik.annotation.Signature")) {
            if (eSize != 1)
                throw new RuntimeException("error: expected 1 element for annotation Signature. Got " + eSize + " instead.");
            AnnotationArrayElem e = (AnnotationArrayElem) getElements(a.getElements()).get(0);
            String sig = "";
            for (AnnotationElem ae : e.getValues()) {
                AnnotationStringElem s = (AnnotationStringElem) ae;
                sig += s.getValue();
            }
            t = new SignatureTag(sig);
        } else if (atypes.equals("dalvik.annotation.Throws")) {
            // this is handled in soot.dexpler.DexMethod
            continue;
        } else if (atypes.equals("java.lang.Deprecated")) {
            if (eSize != 0)
                throw new RuntimeException("error: expected 1 element for annotation Deprecated. Got " + eSize + " instead.");
            t = new DeprecatedTag();
            AnnotationTag adt = new AnnotationTag("Ljava/lang/Deprecated;");
            if (vatg[v] == null)
                vatg[v] = new VisibilityAnnotationTag(v);
            vatg[v].addAnnotation(adt);
        } else {
            if (vatg[v] == null)
                vatg[v] = new VisibilityAnnotationTag(v);
            AnnotationTag tag = new AnnotationTag(a.getType());
            for (AnnotationElem e : getElements(a.getElements())) tag.addElem(e);
            vatg[v].addAnnotation(tag);
        }
        tags.add(t);
    }
    for (VisibilityAnnotationTag vat : vatg) if (vat != null)
        tags.add(vat);
    return tags;
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) DeprecatedTag(soot.tagkit.DeprecatedTag) ArrayList(java.util.ArrayList) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) Annotation(org.jf.dexlib2.iface.Annotation) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) RefType(soot.RefType) Type(soot.Type) ArrayType(soot.ArrayType) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) AnnotationClassElem(soot.tagkit.AnnotationClassElem) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) SignatureTag(soot.tagkit.SignatureTag) Tag(soot.tagkit.Tag) ParamNamesTag(soot.tagkit.ParamNamesTag) DeprecatedTag(soot.tagkit.DeprecatedTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) SignatureTag(soot.tagkit.SignatureTag) AnnotationTag(soot.tagkit.AnnotationTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem)

Example 3 with TypeEncodedValue

use of org.jf.dexlib2.iface.value.TypeEncodedValue 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 4 with TypeEncodedValue

use of org.jf.dexlib2.iface.value.TypeEncodedValue in project atlas by alibaba.

the class ApkPatch method getMethodAnnotaionPrepareClasses.

public static void getMethodAnnotaionPrepareClasses(DexDiffInfo dexDiffInfo, Set<String> prepareclasses) {
    for (DexBackedMethod method : dexDiffInfo.getModifiedMethods()) {
        Set<? extends Annotation> annotations = method.getAnnotations();
        if (annotations == null) {
            continue;
        }
        for (Annotation annotation : annotations) {
            String type = annotation.getType();
            if (type != null && type.startsWith("L") && type.endsWith(";")) {
                prepareclasses.add(type.substring(1, type.length() - 1).replace('/', '.'));
                System.out.println("prepare class: " + type);
            }
            Set<? extends AnnotationElement> elements = annotation.getElements();
            for (AnnotationElement dexBackedAnnotationElement : elements) {
                if (dexBackedAnnotationElement.getValue() instanceof DexBackedArrayEncodedValue) {
                    List<? extends EncodedValue> values = ((DexBackedArrayEncodedValue) dexBackedAnnotationElement.getValue()).getValue();
                    for (EncodedValue encodedValue : values) {
                        if (encodedValue instanceof TypeEncodedValue) {
                            prepareclasses.add(((TypeEncodedValue) encodedValue).getValue().substring(1, ((TypeEncodedValue) encodedValue).getValue().length() - 1).replace('/', '.'));
                            System.out.println("prepare class: " + ((TypeEncodedValue) encodedValue).getValue());
                        }
                    }
                } else if (dexBackedAnnotationElement.getValue() instanceof DexBackedTypeEncodedValue) {
                    String value = ((DexBackedTypeEncodedValue) dexBackedAnnotationElement.getValue()).getValue();
                    prepareclasses.add(value.substring(1, value.length() - 1).replace('/', '.'));
                    System.out.println("prepare class: " + value);
                }
            }
        }
    }
}
Also used : DexBackedArrayEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedArrayEncodedValue) DexBackedTypeEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue) DexBackedArrayEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedArrayEncodedValue) DexBackedAnnotationEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedAnnotationEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) DexBackedTypeEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) DexBackedAnnotationElement(org.jf.dexlib2.dexbacked.DexBackedAnnotationElement) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) DexBackedMethod(org.jf.dexlib2.dexbacked.DexBackedMethod) Annotation(org.jf.dexlib2.iface.Annotation) DexBackedAnnotation(org.jf.dexlib2.dexbacked.DexBackedAnnotation) DexBackedTypeEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue)

Example 5 with TypeEncodedValue

use of org.jf.dexlib2.iface.value.TypeEncodedValue in project atlas by alibaba.

the class ApkPatch method getClassAnnotaionPrepareClasses.

public static void getClassAnnotaionPrepareClasses(DexBackedClassDef classDef, Set<String> prepareclasses, DexDiffInfo dexDiffInfo) {
    for (DexBackedClassDef modifyClasses : dexDiffInfo.getModifiedClasses()) {
        if (classDef.getType().equals(modifyClasses.getType())) {
            if (classDef.getAnnotations() != null) {
                Set<? extends DexBackedAnnotation> annotations = classDef.getAnnotations();
                for (DexBackedAnnotation annotation : annotations) {
                    String type = annotation.getType();
                    if (type != null && type.startsWith("L") && type.endsWith(";")) {
                        prepareclasses.add(type.substring(1, type.length() - 1).replace('/', '.'));
                        System.out.println("prepare class: " + type);
                    }
                    Set<? extends DexBackedAnnotationElement> elements = annotation.getElements();
                    for (DexBackedAnnotationElement dexBackedAnnotationElement : elements) {
                        if (dexBackedAnnotationElement.getValue() instanceof DexBackedArrayEncodedValue) {
                            List<? extends EncodedValue> values = ((DexBackedArrayEncodedValue) dexBackedAnnotationElement.getValue()).getValue();
                            for (EncodedValue encodedValue : values) {
                                if (encodedValue instanceof TypeEncodedValue) {
                                    prepareclasses.add(((TypeEncodedValue) encodedValue).getValue().substring(1, ((TypeEncodedValue) encodedValue).getValue().length() - 1).replace('/', '.'));
                                    System.out.println("prepare class: " + ((TypeEncodedValue) encodedValue).getValue());
                                }
                            }
                        } else if (dexBackedAnnotationElement.getValue() instanceof DexBackedTypeEncodedValue) {
                            String value = ((DexBackedTypeEncodedValue) dexBackedAnnotationElement.getValue()).getValue();
                            prepareclasses.add(value.substring(1, value.length() - 1).replace('/', '.'));
                            System.out.println("prepare class: " + value);
                        } else if (dexBackedAnnotationElement.getValue() instanceof DexBackedAnnotationEncodedValue) {
                            String value = ((DexBackedAnnotationEncodedValue) dexBackedAnnotationElement.getValue()).getType();
                        }
                    }
                }
            }
        }
    }
}
Also used : DexBackedAnnotationElement(org.jf.dexlib2.dexbacked.DexBackedAnnotationElement) DexBackedArrayEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedArrayEncodedValue) DexBackedTypeEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue) DexBackedArrayEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedArrayEncodedValue) DexBackedAnnotationEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedAnnotationEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) DexBackedTypeEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) DexBackedAnnotationEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedAnnotationEncodedValue) DexBackedAnnotation(org.jf.dexlib2.dexbacked.DexBackedAnnotation) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) DexBackedTypeEncodedValue(org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue)

Aggregations

AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)7 ArrayList (java.util.ArrayList)5 TypeEncodedValue (org.jf.dexlib2.iface.value.TypeEncodedValue)5 Annotation (org.jf.dexlib2.iface.Annotation)4 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)4 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)3 MethodEncodedValue (org.jf.dexlib2.iface.value.MethodEncodedValue)3 HashSet (java.util.HashSet)2 List (java.util.List)2 DexBackedAnnotation (org.jf.dexlib2.dexbacked.DexBackedAnnotation)2 DexBackedAnnotationElement (org.jf.dexlib2.dexbacked.DexBackedAnnotationElement)2 DexBackedAnnotationEncodedValue (org.jf.dexlib2.dexbacked.value.DexBackedAnnotationEncodedValue)2 DexBackedArrayEncodedValue (org.jf.dexlib2.dexbacked.value.DexBackedArrayEncodedValue)2 DexBackedTypeEncodedValue (org.jf.dexlib2.dexbacked.value.DexBackedTypeEncodedValue)2 ArrayEncodedValue (org.jf.dexlib2.iface.value.ArrayEncodedValue)2 EnumEncodedValue (org.jf.dexlib2.iface.value.EnumEncodedValue)2 FieldEncodedValue (org.jf.dexlib2.iface.value.FieldEncodedValue)2 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)2 ImmutableAnnotationElement (org.jf.dexlib2.immutable.ImmutableAnnotationElement)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)2