Search in sources :

Example 6 with ArrayEncodedValue

use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project smali by JesusFreke.

the class CallSiteUtil method getEncodedCallSite.

public static ArrayEncodedValue getEncodedCallSite(CallSiteReference callSiteReference) {
    return new BaseArrayEncodedValue() {

        @Nonnull
        @Override
        public List<? extends EncodedValue> getValue() {
            List<EncodedValue> encodedCallSite = Lists.newArrayList();
            encodedCallSite.add(new BaseMethodHandleEncodedValue() {

                @Nonnull
                @Override
                public MethodHandleReference getValue() {
                    return callSiteReference.getMethodHandle();
                }
            });
            encodedCallSite.add(new ImmutableStringEncodedValue(callSiteReference.getMethodName()));
            encodedCallSite.add(new BaseMethodTypeEncodedValue() {

                @Nonnull
                @Override
                public MethodProtoReference getValue() {
                    return callSiteReference.getMethodProto();
                }
            });
            encodedCallSite.addAll(callSiteReference.getExtraArguments());
            return encodedCallSite;
        }
    };
}
Also used : ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) BaseArrayEncodedValue(org.jf.dexlib2.base.value.BaseArrayEncodedValue) BaseMethodHandleEncodedValue(org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue) BaseMethodTypeEncodedValue(org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) BaseArrayEncodedValue(org.jf.dexlib2.base.value.BaseArrayEncodedValue) Nonnull(javax.annotation.Nonnull) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) MethodProtoReference(org.jf.dexlib2.iface.reference.MethodProtoReference) MethodHandleReference(org.jf.dexlib2.iface.reference.MethodHandleReference) BaseMethodHandleEncodedValue(org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue) BaseMethodTypeEncodedValue(org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue)

Example 7 with ArrayEncodedValue

use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project smali by JesusFreke.

the class ClassPool method intern.

public void intern(@Nonnull ClassDef classDef) {
    PoolClassDef poolClassDef = new PoolClassDef(classDef);
    PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
    if (prev != null) {
        throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
    }
    dexPool.typeSection.intern(poolClassDef.getType());
    dexPool.typeSection.internNullable(poolClassDef.getSuperclass());
    dexPool.typeListSection.intern(poolClassDef.getInterfaces());
    dexPool.stringSection.internNullable(poolClassDef.getSourceFile());
    HashSet<String> fields = new HashSet<String>();
    for (Field field : poolClassDef.getFields()) {
        String fieldDescriptor = DexFormatter.INSTANCE.getShortFieldDescriptor(field);
        if (!fields.add(fieldDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for field %s->%s", poolClassDef.getType(), fieldDescriptor);
        }
        dexPool.fieldSection.intern(field);
        EncodedValue initialValue = field.getInitialValue();
        if (initialValue != null) {
            dexPool.internEncodedValue(initialValue);
        }
        dexPool.annotationSetSection.intern(field.getAnnotations());
        ArrayEncodedValue staticInitializers = getStaticInitializers(poolClassDef);
        if (staticInitializers != null) {
            dexPool.encodedArraySection.intern(staticInitializers);
        }
    }
    HashSet<String> methods = new HashSet<String>();
    for (PoolMethod method : poolClassDef.getMethods()) {
        String methodDescriptor = DexFormatter.INSTANCE.getShortMethodDescriptor(method);
        if (!methods.add(methodDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for method %s->%s", poolClassDef.getType(), methodDescriptor);
        }
        dexPool.methodSection.intern(method);
        internCode(method);
        internDebug(method);
        dexPool.annotationSetSection.intern(method.getAnnotations());
        for (MethodParameter parameter : method.getParameters()) {
            dexPool.annotationSetSection.intern(parameter.getAnnotations());
        }
    }
    dexPool.annotationSetSection.intern(poolClassDef.getAnnotations());
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue)

Example 8 with ArrayEncodedValue

use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project smali by JesusFreke.

the class BuilderEncodedArrayPool method internArrayEncodedValue.

@Nonnull
public BuilderArrayEncodedValue internArrayEncodedValue(@Nonnull ArrayEncodedValue arrayEncodedValue) {
    BuilderArrayEncodedValue builderArrayEncodedValue = internedItems.get(arrayEncodedValue);
    if (builderArrayEncodedValue != null) {
        return builderArrayEncodedValue;
    }
    builderArrayEncodedValue = (BuilderArrayEncodedValue) dexBuilder.internEncodedValue(arrayEncodedValue);
    BuilderArrayEncodedValue previous = internedItems.putIfAbsent(builderArrayEncodedValue, builderArrayEncodedValue);
    return previous == null ? builderArrayEncodedValue : previous;
}
Also used : BuilderArrayEncodedValue(org.jf.dexlib2.writer.builder.BuilderEncodedValues.BuilderArrayEncodedValue) Nonnull(javax.annotation.Nonnull)

Example 9 with ArrayEncodedValue

use of org.jf.dexlib2.iface.value.ArrayEncodedValue 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/")) {
                            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) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) 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) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) 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) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) MethodEncodedValue(org.jf.dexlib2.iface.value.MethodEncodedValue) 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) MethodEncodedValue(org.jf.dexlib2.iface.value.MethodEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference)

Example 10 with ArrayEncodedValue

use of org.jf.dexlib2.iface.value.ArrayEncodedValue in project smali by JesusFreke.

the class ArrayEncodedValueAdaptor method writeTo.

public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull ArrayEncodedValue arrayEncodedValue, @Nullable String containingClass) throws IOException {
    writer.write('{');
    Collection<? extends EncodedValue> values = arrayEncodedValue.getValue();
    if (values.size() == 0) {
        writer.write('}');
        return;
    }
    writer.write('\n');
    writer.indent(4);
    boolean first = true;
    for (EncodedValue encodedValue : values) {
        if (!first) {
            writer.write(",\n");
        }
        first = false;
        EncodedValueAdaptor.writeTo(writer, encodedValue, containingClass);
    }
    writer.deindent(4);
    writer.write("\n}");
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue)

Aggregations

ArrayEncodedValue (org.jf.dexlib2.iface.value.ArrayEncodedValue)9 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)9 AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)6 ArrayList (java.util.ArrayList)4 MethodEncodedValue (org.jf.dexlib2.iface.value.MethodEncodedValue)4 StringEncodedValue (org.jf.dexlib2.iface.value.StringEncodedValue)4 TypeEncodedValue (org.jf.dexlib2.iface.value.TypeEncodedValue)4 Nonnull (javax.annotation.Nonnull)3 Annotation (org.jf.dexlib2.iface.Annotation)3 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)3 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)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 ImmutableArrayEncodedValue (org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue)2