Search in sources :

Example 16 with EncodedValue

use of jadx.api.plugins.input.data.annotations.EncodedValue in project jadx by skylot.

the class PrepareForCodeGen method checkEncodedValue.

@SuppressWarnings("unchecked")
private void checkEncodedValue(MethodNode mth, EncodedValue encodedValue) {
    switch(encodedValue.getType()) {
        case ENCODED_FIELD:
            Object fieldData = encodedValue.getValue();
            FieldInfo fieldInfo;
            if (fieldData instanceof IFieldRef) {
                fieldInfo = FieldInfo.fromRef(mth.root(), (IFieldRef) fieldData);
            } else {
                fieldInfo = (FieldInfo) fieldData;
            }
            FieldNode fieldNode = mth.root().resolveField(fieldInfo);
            if (fieldNode != null) {
                fieldNode.addUseIn(mth);
            }
            break;
        case ENCODED_ANNOTATION:
            IAnnotation annotation = (IAnnotation) encodedValue.getValue();
            annotation.getValues().forEach((k, v) -> checkEncodedValue(mth, v));
            break;
        case ENCODED_ARRAY:
            List<EncodedValue> valueList = (List<EncodedValue>) encodedValue.getValue();
            valueList.forEach(v -> checkEncodedValue(mth, v));
            break;
    }
}
Also used : IAnnotation(jadx.api.plugins.input.data.annotations.IAnnotation) EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) FieldNode(jadx.core.dex.nodes.FieldNode) InsnList(jadx.core.utils.InsnList) List(java.util.List) IFieldRef(jadx.api.plugins.input.data.IFieldRef) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 17 with EncodedValue

use of jadx.api.plugins.input.data.annotations.EncodedValue in project jadx by skylot.

the class EncodedValueReader method read.

public static EncodedValue read(JavaClassData clsData, DataReader reader) {
    ConstPoolReader constPool = clsData.getConstPoolReader();
    char tag = (char) reader.readU1();
    switch(tag) {
        case 'B':
            return new EncodedValue(EncodedType.ENCODED_BYTE, (byte) constPool.getInt(reader.readU2()));
        case 'C':
            return new EncodedValue(EncodedType.ENCODED_CHAR, (char) constPool.getInt(reader.readU2()));
        case 'D':
            return new EncodedValue(EncodedType.ENCODED_DOUBLE, constPool.getDouble(reader.readU2()));
        case 'F':
            return new EncodedValue(EncodedType.ENCODED_FLOAT, constPool.getFloat(reader.readU2()));
        case 'I':
            return new EncodedValue(EncodedType.ENCODED_INT, constPool.getInt(reader.readU2()));
        case 'J':
            return new EncodedValue(EncodedType.ENCODED_LONG, constPool.getLong(reader.readU2()));
        case 'S':
            return new EncodedValue(EncodedType.ENCODED_SHORT, (short) constPool.getInt(reader.readU2()));
        case 'Z':
            return new EncodedValue(EncodedType.ENCODED_BOOLEAN, 1 == constPool.getInt(reader.readU2()));
        case 's':
            return new EncodedValue(EncodedType.ENCODED_STRING, constPool.getUtf8(reader.readU2()));
        case 'e':
            String cls = constPool.getUtf8(reader.readU2());
            String name = constPool.getUtf8(reader.readU2());
            return new EncodedValue(EncodedType.ENCODED_ENUM, new JadxFieldRef(cls, name, cls));
        case 'c':
            return new EncodedValue(EncodedType.ENCODED_TYPE, constPool.getUtf8(reader.readU2()));
        case '@':
            return new EncodedValue(EncodedType.ENCODED_ANNOTATION, JavaAnnotationsAttr.readAnnotation(AnnotationVisibility.RUNTIME, clsData, reader));
        case '[':
            int len = reader.readU2();
            List<EncodedValue> values = new ArrayList<>(len);
            for (int i = 0; i < len; i++) {
                values.add(read(clsData, reader));
            }
            return new EncodedValue(EncodedType.ENCODED_ARRAY, values);
        default:
            throw new JavaClassParseException("Unknown element value tag: " + tag);
    }
}
Also used : EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) JadxFieldRef(jadx.api.plugins.input.data.impl.JadxFieldRef) JavaClassParseException(jadx.plugins.input.java.utils.JavaClassParseException) ArrayList(java.util.ArrayList) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader)

Aggregations

EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)17 FieldInfo (jadx.core.dex.info.FieldInfo)4 FieldNode (jadx.core.dex.nodes.FieldNode)4 ArrayList (java.util.ArrayList)4 IAnnotation (jadx.api.plugins.input.data.annotations.IAnnotation)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 ICallSite (jadx.api.plugins.input.data.ICallSite)2 IFieldRef (jadx.api.plugins.input.data.IFieldRef)2 AnnotationVisibility (jadx.api.plugins.input.data.annotations.AnnotationVisibility)2 JadxAnnotation (jadx.api.plugins.input.data.annotations.JadxAnnotation)2 AnnotationsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationsAttr)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 ConstPoolReader (jadx.plugins.input.java.data.ConstPoolReader)2 JavaClassParseException (jadx.plugins.input.java.utils.JavaClassParseException)2 LinkedHashMap (java.util.LinkedHashMap)2 EncodedType (jadx.api.plugins.input.data.annotations.EncodedType)1 IJadxAttribute (jadx.api.plugins.input.data.attributes.IJadxAttribute)1 AnnotationDefaultClassAttr (jadx.api.plugins.input.data.attributes.types.AnnotationDefaultClassAttr)1