Search in sources :

Example 6 with StringEncodedValue

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

the class DexField method addConstantTag.

/**
 * Add constant tag. Should only be called if field is final.
 *
 * @param df
 * @param sf
 */
private static void addConstantTag(SootField df, Field sf) {
    Tag tag = null;
    EncodedValue ev = sf.getInitialValue();
    if (ev instanceof BooleanEncodedValue) {
        tag = new IntegerConstantValueTag(((BooleanEncodedValue) ev).getValue() == true ? 1 : 0);
    } else if (ev instanceof ByteEncodedValue) {
        tag = new IntegerConstantValueTag(((ByteEncodedValue) ev).getValue());
    } else if (ev instanceof CharEncodedValue) {
        tag = new IntegerConstantValueTag(((CharEncodedValue) ev).getValue());
    } else if (ev instanceof DoubleEncodedValue) {
        tag = new DoubleConstantValueTag(((DoubleEncodedValue) ev).getValue());
    } else if (ev instanceof FloatEncodedValue) {
        tag = new FloatConstantValueTag(((FloatEncodedValue) ev).getValue());
    } else if (ev instanceof IntEncodedValue) {
        tag = new IntegerConstantValueTag(((IntEncodedValue) ev).getValue());
    } else if (ev instanceof LongEncodedValue) {
        tag = new LongConstantValueTag(((LongEncodedValue) ev).getValue());
    } else if (ev instanceof ShortEncodedValue) {
        tag = new IntegerConstantValueTag(((ShortEncodedValue) ev).getValue());
    } else if (ev instanceof StringEncodedValue) {
        tag = new StringConstantValueTag(((StringEncodedValue) ev).getValue());
    }
    if (tag != null)
        df.addTag(tag);
}
Also used : FloatEncodedValue(org.jf.dexlib2.iface.value.FloatEncodedValue) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) DoubleEncodedValue(org.jf.dexlib2.iface.value.DoubleEncodedValue) FloatEncodedValue(org.jf.dexlib2.iface.value.FloatEncodedValue) ShortEncodedValue(org.jf.dexlib2.iface.value.ShortEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) IntEncodedValue(org.jf.dexlib2.iface.value.IntEncodedValue) CharEncodedValue(org.jf.dexlib2.iface.value.CharEncodedValue) ByteEncodedValue(org.jf.dexlib2.iface.value.ByteEncodedValue) LongEncodedValue(org.jf.dexlib2.iface.value.LongEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) BooleanEncodedValue(org.jf.dexlib2.iface.value.BooleanEncodedValue) DoubleEncodedValue(org.jf.dexlib2.iface.value.DoubleEncodedValue) ShortEncodedValue(org.jf.dexlib2.iface.value.ShortEncodedValue) BooleanEncodedValue(org.jf.dexlib2.iface.value.BooleanEncodedValue) ByteEncodedValue(org.jf.dexlib2.iface.value.ByteEncodedValue) LongEncodedValue(org.jf.dexlib2.iface.value.LongEncodedValue) LongConstantValueTag(soot.tagkit.LongConstantValueTag) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) Tag(soot.tagkit.Tag) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) LongConstantValueTag(soot.tagkit.LongConstantValueTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) CharEncodedValue(org.jf.dexlib2.iface.value.CharEncodedValue) IntEncodedValue(org.jf.dexlib2.iface.value.IntEncodedValue) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag)

Example 7 with StringEncodedValue

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

Example 8 with StringEncodedValue

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

the class DexPool method internEncodedValue.

void internEncodedValue(@Nonnull EncodedValue encodedValue) {
    switch(encodedValue.getValueType()) {
        case ValueType.ANNOTATION:
            AnnotationEncodedValue annotationEncodedValue = (AnnotationEncodedValue) encodedValue;
            typeSection.intern(annotationEncodedValue.getType());
            for (AnnotationElement element : annotationEncodedValue.getElements()) {
                stringSection.intern(element.getName());
                internEncodedValue(element.getValue());
            }
            break;
        case ValueType.ARRAY:
            for (EncodedValue element : ((ArrayEncodedValue) encodedValue).getValue()) {
                internEncodedValue(element);
            }
            break;
        case ValueType.STRING:
            stringSection.intern(((StringEncodedValue) encodedValue).getValue());
            break;
        case ValueType.TYPE:
            typeSection.intern(((TypeEncodedValue) encodedValue).getValue());
            break;
        case ValueType.ENUM:
            fieldSection.intern(((EnumEncodedValue) encodedValue).getValue());
            break;
        case ValueType.FIELD:
            fieldSection.intern(((FieldEncodedValue) encodedValue).getValue());
            break;
        case ValueType.METHOD:
            methodSection.intern(((MethodEncodedValue) encodedValue).getValue());
            break;
        case ValueType.METHOD_HANDLE:
            methodHandleSection.intern(((MethodHandleEncodedValue) encodedValue).getValue());
            break;
        case ValueType.METHOD_TYPE:
            protoSection.intern(((MethodTypeEncodedValue) encodedValue).getValue());
            break;
    }
}
Also used : AnnotationElement(org.jf.dexlib2.iface.AnnotationElement)

Aggregations

AnnotationElement (org.jf.dexlib2.iface.AnnotationElement)5 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)4 StringEncodedValue (org.jf.dexlib2.iface.value.StringEncodedValue)4 ArrayList (java.util.ArrayList)3 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Annotation (org.jf.dexlib2.iface.Annotation)2 ArrayEncodedValue (org.jf.dexlib2.iface.value.ArrayEncodedValue)2 BooleanEncodedValue (org.jf.dexlib2.iface.value.BooleanEncodedValue)2 ByteEncodedValue (org.jf.dexlib2.iface.value.ByteEncodedValue)2 CharEncodedValue (org.jf.dexlib2.iface.value.CharEncodedValue)2 DoubleEncodedValue (org.jf.dexlib2.iface.value.DoubleEncodedValue)2 EnumEncodedValue (org.jf.dexlib2.iface.value.EnumEncodedValue)2 FieldEncodedValue (org.jf.dexlib2.iface.value.FieldEncodedValue)2 FloatEncodedValue (org.jf.dexlib2.iface.value.FloatEncodedValue)2 IntEncodedValue (org.jf.dexlib2.iface.value.IntEncodedValue)2 LongEncodedValue (org.jf.dexlib2.iface.value.LongEncodedValue)2 MethodEncodedValue (org.jf.dexlib2.iface.value.MethodEncodedValue)2 ShortEncodedValue (org.jf.dexlib2.iface.value.ShortEncodedValue)2