Search in sources :

Example 1 with JavaInsnData

use of jadx.plugins.input.java.data.code.JavaInsnData 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 2 with JavaInsnData

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

the class TableSwitchDecoder method read.

private static void read(CodeDecodeState state, boolean skip) {
    DataReader reader = state.reader();
    JavaInsnData insn = state.insn();
    int dataOffset = reader.getOffset();
    int insnOffset = insn.getOffset();
    reader.skip(3 - insnOffset % 4);
    int defTarget = insnOffset + reader.readS4();
    int low = reader.readS4();
    int high = reader.readS4();
    int count = high - low + 1;
    if (skip) {
        reader.skip(count * 4);
    } else {
        state.pop(0);
        int[] keys = new int[count];
        int[] targets = new int[count];
        for (int i = 0; i < count; i++) {
            int target = insnOffset + reader.readS4();
            keys[i] = low + i;
            targets[i] = target;
            state.registerJump(target);
        }
        insn.setTarget(defTarget);
        state.registerJump(defTarget);
        insn.setPayload(new SwitchPayload(count, keys, targets));
    }
    insn.setPayloadSize(reader.getOffset() - dataOffset);
}
Also used : DataReader(jadx.plugins.input.java.data.DataReader) SwitchPayload(jadx.api.plugins.input.insns.custom.impl.SwitchPayload) JavaInsnData(jadx.plugins.input.java.data.code.JavaInsnData)

Example 3 with JavaInsnData

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

the class InvokeDecoder method decode.

@Override
public void decode(CodeDecodeState state) {
    DataReader reader = state.reader();
    int mthIdx = reader.readS2();
    if (payloadSize == 4) {
        reader.skip(2);
    }
    JavaInsnData insn = state.insn();
    insn.setIndex(mthIdx);
    boolean instanceCall;
    IMethodProto mthProto;
    if (apiOpcode == Opcode.INVOKE_CUSTOM) {
        ICallSite callSite = insn.getIndexAsCallSite();
        insn.setPayload(callSite);
        mthProto = (IMethodProto) callSite.getValues().get(2).getValue();
        // 'this' arg already included in proto args
        instanceCall = false;
    } else {
        IMethodRef mthRef = insn.getIndexAsMethod();
        mthRef.load();
        insn.setPayload(mthRef);
        mthProto = mthRef;
        instanceCall = apiOpcode != Opcode.INVOKE_STATIC;
    }
    int argsCount = mthProto.getArgTypes().size();
    if (instanceCall) {
        argsCount++;
    }
    // allocate twice of the size for worst case
    insn.setRegsCount(argsCount * 2);
    int[] regs = insn.getRegsArray();
    // calculate actual count of registers
    // set '1' in regs to be filled with stack values later, '0' for skip
    int regsCount = 0;
    if (instanceCall) {
        regs[regsCount++] = 1;
    }
    for (String type : mthProto.getArgTypes()) {
        int size = getRegsCountForType(type);
        regs[regsCount++] = 1;
        if (size == 2) {
            regs[regsCount++] = 0;
        }
    }
    insn.setRegsCount(regsCount);
    for (int i = regsCount - 1; i >= 0; i--) {
        if (regs[i] == 1) {
            state.pop(i);
        }
    }
    String returnType = mthProto.getReturnType();
    if (!returnType.equals("V")) {
        insn.setResultReg(state.push(returnType));
    } else {
        insn.setResultReg(-1);
    }
}
Also used : DataReader(jadx.plugins.input.java.data.DataReader) IMethodProto(jadx.api.plugins.input.data.IMethodProto) JavaInsnData(jadx.plugins.input.java.data.code.JavaInsnData) IMethodRef(jadx.api.plugins.input.data.IMethodRef) ICallSite(jadx.api.plugins.input.data.ICallSite)

Example 4 with JavaInsnData

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

the class WideDecoder method decode.

@Override
public void decode(CodeDecodeState state) {
    DataReader reader = state.reader();
    JavaInsnData insn = state.insn();
    int opcode = reader.readU1();
    if (opcode == IINC) {
        int varNum = reader.readU2();
        int constValue = reader.readS2();
        state.local(0, varNum).local(1, varNum).lit(constValue);
        insn.setPayloadSize(5);
        insn.setRegsCount(2);
        insn.setOpcode(Opcode.ADD_INT_LIT);
        return;
    }
    int index = reader.readU2();
    switch(opcode) {
        // iload,
        case 0x15:
        // fload
        case 0x17:
        case // aload
        0x19:
            state.local(1, index).push(0);
            break;
        // lload
        case 0x16:
        case // dload
        0x18:
            state.local(1, index).pushWide(0);
            break;
        case 0x36:
        case 0x37:
        case 0x38:
        case 0x39:
        case 0x3a:
            // *store
            state.pop(1).local(0, index);
            break;
        default:
            throw new JavaClassParseException("Unexpected opcode in 'wide': 0x" + Integer.toHexString(opcode));
    }
    insn.setPayloadSize(3);
    insn.setRegsCount(2);
    insn.setOpcode(Opcode.MOVE);
}
Also used : DataReader(jadx.plugins.input.java.data.DataReader) JavaInsnData(jadx.plugins.input.java.data.code.JavaInsnData) JavaClassParseException(jadx.plugins.input.java.utils.JavaClassParseException)

Example 5 with JavaInsnData

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

the class LookupSwitchDecoder method read.

private static void read(CodeDecodeState state, boolean skip) {
    DataReader reader = state.reader();
    JavaInsnData insn = state.insn();
    int dataOffset = reader.getOffset();
    int insnOffset = insn.getOffset();
    reader.skip(3 - insnOffset % 4);
    int defTarget = insnOffset + reader.readS4();
    int pairs = reader.readS4();
    if (skip) {
        reader.skip(pairs * 8);
    } else {
        state.pop(0);
        int[] keys = new int[pairs];
        int[] targets = new int[pairs];
        for (int i = 0; i < pairs; i++) {
            keys[i] = reader.readS4();
            int target = insnOffset + reader.readS4();
            targets[i] = target;
            state.registerJump(target);
        }
        insn.setTarget(defTarget);
        state.registerJump(defTarget);
        insn.setPayload(new SwitchPayload(pairs, keys, targets));
    }
    insn.setPayloadSize(reader.getOffset() - dataOffset);
}
Also used : DataReader(jadx.plugins.input.java.data.DataReader) SwitchPayload(jadx.api.plugins.input.insns.custom.impl.SwitchPayload) JavaInsnData(jadx.plugins.input.java.data.code.JavaInsnData)

Aggregations

DataReader (jadx.plugins.input.java.data.DataReader)6 JavaInsnData (jadx.plugins.input.java.data.code.JavaInsnData)6 SwitchPayload (jadx.api.plugins.input.insns.custom.impl.SwitchPayload)2 JavaClassParseException (jadx.plugins.input.java.utils.JavaClassParseException)2 ICallSite (jadx.api.plugins.input.data.ICallSite)1 IMethodProto (jadx.api.plugins.input.data.IMethodProto)1 IMethodRef (jadx.api.plugins.input.data.IMethodRef)1 ConstPoolReader (jadx.plugins.input.java.data.ConstPoolReader)1 ConstantType (jadx.plugins.input.java.data.ConstantType)1