Search in sources :

Example 1 with ConstPoolReader

use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.

the class JavaAnnotationsAttr method readAnnotation.

public static JadxAnnotation readAnnotation(AnnotationVisibility visibility, JavaClassData clsData, DataReader reader) {
    ConstPoolReader constPool = clsData.getConstPoolReader();
    String type = constPool.getUtf8(reader.readU2());
    int pairsCount = reader.readU2();
    Map<String, EncodedValue> pairs = new LinkedHashMap<>(pairsCount);
    for (int j = 0; j < pairsCount; j++) {
        String name = constPool.getUtf8(reader.readU2());
        EncodedValue value = EncodedValueReader.read(clsData, reader);
        pairs.put(name, value);
    }
    return new JadxAnnotation(visibility, type, pairs);
}
Also used : EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) JadxAnnotation(jadx.api.plugins.input.data.annotations.JadxAnnotation) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ConstPoolReader

use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.

the class JavaCodeReader method getTries.

@Override
public List<ITry> getTries() {
    skipToTries();
    int excTableLen = reader.readU2();
    if (excTableLen == 0) {
        return Collections.emptyList();
    }
    ConstPoolReader constPool = clsData.getConstPoolReader();
    Map<JavaTryData, List<JavaSingleCatch>> tries = new HashMap<>(excTableLen);
    for (int i = 0; i < excTableLen; i++) {
        int start = reader.readU2();
        int end = reader.readU2();
        int handler = reader.readU2();
        int type = reader.readU2();
        JavaTryData tryData = new JavaTryData(start, end);
        List<JavaSingleCatch> catches = tries.computeIfAbsent(tryData, k -> new ArrayList<>());
        if (type == 0) {
            catches.add(new JavaSingleCatch(handler, null));
        } else {
            catches.add(new JavaSingleCatch(handler, constPool.getClass(type)));
        }
    }
    return tries.entrySet().stream().map(e -> {
        JavaTryData tryData = e.getKey();
        tryData.setCatch(convertSingleCatches(e.getValue()));
        return tryData;
    }).collect(Collectors.toList());
}
Also used : DebugInfo(jadx.api.plugins.input.data.impl.DebugInfo) JavaAttrType(jadx.plugins.input.java.data.attributes.JavaAttrType) JavaTryData(jadx.plugins.input.java.data.code.trycatch.JavaTryData) HashMap(java.util.HashMap) JavaSingleCatch(jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LocalVarsAttr(jadx.plugins.input.java.data.attributes.debuginfo.LocalVarsAttr) JavaAttrStorage(jadx.plugins.input.java.data.attributes.JavaAttrStorage) Map(java.util.Map) ICodeReader(jadx.api.plugins.input.data.ICodeReader) JavaClassParseException(jadx.plugins.input.java.utils.JavaClassParseException) IDebugInfo(jadx.api.plugins.input.data.IDebugInfo) JavaClassData(jadx.plugins.input.java.data.JavaClassData) Set(java.util.Set) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) LocalVarTypesAttr(jadx.plugins.input.java.data.attributes.debuginfo.LocalVarTypesAttr) List(java.util.List) ILocalVar(jadx.api.plugins.input.data.ILocalVar) InsnData(jadx.api.plugins.input.insns.InsnData) DataReader(jadx.plugins.input.java.data.DataReader) CatchData(jadx.api.plugins.input.data.impl.CatchData) Collections(java.util.Collections) JavaLocalVar(jadx.plugins.input.java.data.attributes.debuginfo.JavaLocalVar) LineNumberTableAttr(jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr) ITry(jadx.api.plugins.input.data.ITry) HashMap(java.util.HashMap) JavaSingleCatch(jadx.plugins.input.java.data.code.trycatch.JavaSingleCatch) JavaTryData(jadx.plugins.input.java.data.code.trycatch.JavaTryData) ArrayList(java.util.ArrayList) List(java.util.List) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader)

Example 3 with ConstPoolReader

use of jadx.plugins.input.java.data.ConstPoolReader in project jadx by skylot.

the class LoadConstDecoder method decode.

@Override
public void decode(CodeDecodeState state) {
    DataReader reader = state.reader();
    JavaInsnData insn = state.insn();
    int index;
    if (wide) {
        index = reader.readU2();
    } else {
        index = reader.readU1();
    }
    ConstPoolReader constPoolReader = insn.constPoolReader();
    ConstantType constType = constPoolReader.jumpToConst(index);
    switch(constType) {
        case INTEGER:
        case FLOAT:
            insn.setLiteral(constPoolReader.readU4());
            insn.setOpcode(Opcode.CONST);
            state.push(0, SVType.NARROW);
            break;
        case LONG:
        case DOUBLE:
            insn.setLiteral(constPoolReader.readU8());
            insn.setOpcode(Opcode.CONST_WIDE);
            state.push(0, SVType.WIDE);
            break;
        case STRING:
            insn.setIndex(constPoolReader.readU2());
            insn.setOpcode(Opcode.CONST_STRING);
            state.push(0, SVType.NARROW);
            break;
        case UTF8:
            insn.setIndex(index);
            insn.setOpcode(Opcode.CONST_STRING);
            state.push(0, SVType.NARROW);
            break;
        case CLASS:
            insn.setIndex(index);
            insn.setOpcode(Opcode.CONST_CLASS);
            state.push(0, SVType.NARROW);
            break;
        default:
            throw new JavaClassParseException("Unsupported constant type: " + constType);
    }
}
Also used : DataReader(jadx.plugins.input.java.data.DataReader) JavaInsnData(jadx.plugins.input.java.data.code.JavaInsnData) ConstantType(jadx.plugins.input.java.data.ConstantType) JavaClassParseException(jadx.plugins.input.java.utils.JavaClassParseException) ConstPoolReader(jadx.plugins.input.java.data.ConstPoolReader)

Example 4 with ConstPoolReader

use of jadx.plugins.input.java.data.ConstPoolReader 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

ConstPoolReader (jadx.plugins.input.java.data.ConstPoolReader)4 JavaClassParseException (jadx.plugins.input.java.utils.JavaClassParseException)3 EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)2 DataReader (jadx.plugins.input.java.data.DataReader)2 ArrayList (java.util.ArrayList)2 ICodeReader (jadx.api.plugins.input.data.ICodeReader)1 IDebugInfo (jadx.api.plugins.input.data.IDebugInfo)1 ILocalVar (jadx.api.plugins.input.data.ILocalVar)1 ITry (jadx.api.plugins.input.data.ITry)1 JadxAnnotation (jadx.api.plugins.input.data.annotations.JadxAnnotation)1 CatchData (jadx.api.plugins.input.data.impl.CatchData)1 DebugInfo (jadx.api.plugins.input.data.impl.DebugInfo)1 JadxFieldRef (jadx.api.plugins.input.data.impl.JadxFieldRef)1 InsnData (jadx.api.plugins.input.insns.InsnData)1 ConstantType (jadx.plugins.input.java.data.ConstantType)1 JavaClassData (jadx.plugins.input.java.data.JavaClassData)1 JavaAttrStorage (jadx.plugins.input.java.data.attributes.JavaAttrStorage)1 JavaAttrType (jadx.plugins.input.java.data.attributes.JavaAttrType)1 JavaLocalVar (jadx.plugins.input.java.data.attributes.debuginfo.JavaLocalVar)1 LineNumberTableAttr (jadx.plugins.input.java.data.attributes.debuginfo.LineNumberTableAttr)1