Search in sources :

Example 1 with ConstantType

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

Aggregations

ConstPoolReader (jadx.plugins.input.java.data.ConstPoolReader)1 ConstantType (jadx.plugins.input.java.data.ConstantType)1 DataReader (jadx.plugins.input.java.data.DataReader)1 JavaInsnData (jadx.plugins.input.java.data.code.JavaInsnData)1 JavaClassParseException (jadx.plugins.input.java.utils.JavaClassParseException)1