private DecodedInstruction decodeRawInsn(ShortArrayCodeInput in) throws EOFException { int opcodeUnit = in.read(); int opcode = Opcodes.extractOpcodeFromUnit(opcodeUnit); OpcodeInfo.Info opcodeInfo; try { opcodeInfo = OpcodeInfo.get(opcode); } catch (IllegalArgumentException e) { LOG.warn("Ignore decode error: '{}', replace with NOP instruction", e.getMessage()); opcodeInfo = OpcodeInfo.NOP; } return opcodeInfo.getFormat().decode(opcodeUnit, in); }
@NotNull private InsnNode decode(DecodedInstruction insn, int offset) throws DecodeException { switch (insn.getOpcode()) { case Opcodes.NOP: case Opcodes.PACKED_SWITCH_PAYLOAD: InsnNode constStrInsn = new ConstStringNode(dex.getString(insn.getIndex())); constStrInsn.setResult(InsnArg.reg(insn, 0, ArgType.STRING)); return constStrInsn; InsnNode constClsInsn = new ConstClassNode(dex.getType(insn.getIndex())); constClsInsn.setResult(InsnArg.reg(insn, 0, ArgType.CLASS)); return constClsInsn; case Opcodes.GOTO_16: case Opcodes.GOTO_32: return new GotoNode(insn.getTarget()); InsnNode instInsn = new IndexInsnNode(InsnType.INSTANCE_OF, dex.getType(insn.getIndex()), 1); instInsn.setResult(InsnArg.reg(insn, 0, ArgType.BOOLEAN)); instInsn.addArg(InsnArg.reg(insn, 1, ArgType.UNKNOWN_OBJECT)); ArgType castType = dex.getType(insn.getIndex()); InsnNode checkCastInsn = new IndexInsnNode(InsnType.CHECK_CAST, castType, 1); checkCastInsn.setResult(InsnArg.reg(insn, 0, castType)); case Opcodes.IGET_WIDE: case Opcodes.IGET_OBJECT: FieldInfo igetFld = FieldInfo.fromDex(dex, insn.getIndex()); InsnNode igetInsn = new IndexInsnNode(InsnType.IGET, igetFld, 1);
/** * Generates the signature and checksum of the dex file {@code out} and * writes them to the file. */ public void writeHashes(DexBuffer dex) throws IOException { byte[] signature = computeSignature(dex); dex.open(SIGNATURE_OFFSET).write(signature); int checksum = computeChecksum(dex); dex.open(CHECKSUM_OFFSET).writeInt(checksum); } }
/** * Gets the {@link IndexType} for the given opcode value. */ public static IndexType getIndexType(int opcode) { return get(opcode).getIndexType(); }
public void writeTo(DexBuffer.Section out) { out.writeByte(visibility); out.writeUleb128(typeIndex); out.writeUleb128(names.length); for (int i = 0; i < names.length; i++) { out.writeUleb128(names[i]); values[i].writeTo(out); } }
@Override public String get(int index) { checkBounds(index, tableOfContents.stringIds.size); return open(tableOfContents.stringIds.off + (index * SizeOf.STRING_ID_ITEM)) .readString(); } @Override public int size() {
@Override public FieldId get(int index) { checkBounds(index, tableOfContents.fieldIds.size); return open(tableOfContents.fieldIds.off + (SizeOf.MEMBER_ID_ITEM * index)) .readFieldId(); } @Override public int size() {
@Override public MethodId get(int index) { checkBounds(index, tableOfContents.methodIds.size); return open(tableOfContents.methodIds.off + (SizeOf.MEMBER_ID_ITEM * index)) .readMethodId(); } @Override public int size() {
private ClassData.Field[] readFields(int count) { ClassData.Field[] result = new ClassData.Field[count]; int fieldIndex = 0; for (int i = 0; i < count; i++) { fieldIndex += readUleb128(); // field index diff int accessFlags = readUleb128(); result[i] = new ClassData.Field(fieldIndex, accessFlags); } return result; }
/** * Gets the {@link IndexType} for the given opcode value. */ public static IndexType getIndexType(int opcode) { return get(opcode).getIndexType(); }
/** * Gets the {@link IndexType} for the given opcode value. */ public static IndexType getIndexType(int opcode) { return get(opcode).getIndexType(); }
/** * Gets the {@link IndexType} for the given opcode value. */ public static IndexType getIndexType(int opcode) { return get(opcode).getIndexType(); }
/** * Gets the {@link IndexType} for the given opcode value. */ public static IndexType getIndexType(int opcode) { return get(opcode).getIndexType(); }