use of jadx.plugins.input.java.data.DataReader 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);
}
}
use of jadx.plugins.input.java.data.DataReader 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);
}
use of jadx.plugins.input.java.data.DataReader in project jadx by skylot.
the class JavaInsnData method getByteCode.
@Override
public byte[] getByteCode() {
DataReader reader = state.reader();
int startOffset = reader.getOffset();
try {
reader.absPos(insnStart);
return reader.readBytes(1 + payloadSize);
} finally {
reader.absPos(startOffset);
}
}
use of jadx.plugins.input.java.data.DataReader 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);
}
}
use of jadx.plugins.input.java.data.DataReader 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);
}
Aggregations