FileDocCategorySizeDatePackage
DecodedInstruction.javaAPI DocAndroid 5.1 API13088Thu Mar 12 22:18:30 GMT 2015com.android.dx.io.instructions

DecodedInstruction

public abstract class DecodedInstruction extends Object
A decoded Dalvik instruction. This consists of a format codec, a numeric opcode, an optional index type, and any additional arguments of the instruction. The additional arguments (if any) are represented as uninterpreted data.

Note: The names of the arguments are not meant to match the names given in the Dalvik instruction format specification, specification which just names fields (somewhat) arbitrarily alphabetically from A. In this class, non-register fields are given descriptive names and register fields are consistently named alphabetically.

Fields Summary
private final InstructionCodec
format
non-null; instruction format / codec
private final int
opcode
opcode number
private final int
index
constant index argument
private final com.android.dx.io.IndexType
indexType
null-ok; index type
private final int
target
target address argument. This is an absolute address, not just a signed offset. Note: The address is unsigned, even though it is stored in an {@code int}.
private final long
literal
literal value argument; also used for special verification error constants (format 20bc) as well as should-be-zero values (formats 10x, 20t, 30t, and 32x)
Constructors Summary
public DecodedInstruction(InstructionCodec format, int opcode, int index, com.android.dx.io.IndexType indexType, int target, long literal)
Constructs an instance.

        if (format == null) {
            throw new NullPointerException("format == null");
        }

        if (!Opcodes.isValidShape(opcode)) {
            throw new IllegalArgumentException("invalid opcode");
        }

        this.format = format;
        this.opcode = opcode;
        this.index = index;
        this.indexType = indexType;
        this.target = target;
        this.literal = literal;
    
Methods Summary
public static com.android.dx.io.instructions.DecodedInstructiondecode(CodeInput in)
Decodes an instruction from the given input source.

        int opcodeUnit = in.read();
        int opcode = Opcodes.extractOpcodeFromUnit(opcodeUnit);
        InstructionCodec format = OpcodeInfo.getFormat(opcode);

        return format.decode(opcodeUnit, in);
    
public static com.android.dx.io.instructions.DecodedInstruction[]decodeAll(short[] encodedInstructions)
Decodes an array of instructions. The result has non-null elements at each offset that represents the start of an instruction.

        int size = encodedInstructions.length;
        DecodedInstruction[] decoded = new DecodedInstruction[size];
        ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);

        try {
            while (in.hasMore()) {
                decoded[in.cursor()] = DecodedInstruction.decode(in);
            }
        } catch (EOFException ex) {
            throw new DexException(ex);
        }

        return decoded;
    
public final voidencode(CodeOutput out)
Encodes this instance to the given output.

        format.encode(this, out);
    
public intgetA()

        return 0;
    
public final shortgetAByte()
Gets the A register number, as a byte. This will throw if the value is out of the range of an unsigned byte.

        int a = getA();

        if ((a & ~0xff) != 0) {
            throw new DexException("Register A out of range: " + Hex.u8(a));
        }

        return (short) a;
    
public final shortgetANibble()
Gets the A register number, as a nibble. This will throw if the value is out of the range of an unsigned nibble.

        int a = getA();

        if ((a & ~0xf) != 0) {
            throw new DexException("Register A out of range: " + Hex.u8(a));
        }

        return (short) a;
    
public final shortgetAUnit()
Gets the A register number, as a code unit. This will throw if the value is out of the range of an unsigned code unit.

        int a = getA();

        if ((a & ~0xffff) != 0) {
            throw new DexException("Register A out of range: " + Hex.u8(a));
        }

        return (short) a;
    
public intgetB()

        return 0;
    
public final shortgetBByte()
Gets the B register number, as a byte. This will throw if the value is out of the range of an unsigned byte.

        int b = getB();

        if ((b & ~0xff) != 0) {
            throw new DexException("Register B out of range: " + Hex.u8(b));
        }

        return (short) b;
    
public final shortgetBNibble()
Gets the B register number, as a nibble. This will throw if the value is out of the range of an unsigned nibble.

        int b = getB();

        if ((b & ~0xf) != 0) {
            throw new DexException("Register B out of range: " + Hex.u8(b));
        }

        return (short) b;
    
public final shortgetBUnit()
Gets the B register number, as a code unit. This will throw if the value is out of the range of an unsigned code unit.

        int b = getB();

        if ((b & ~0xffff) != 0) {
            throw new DexException("Register B out of range: " + Hex.u8(b));
        }

        return (short) b;
    
public intgetC()

        return 0;
    
public final shortgetCByte()
Gets the C register number, as a byte. This will throw if the value is out of the range of an unsigned byte.

        int c = getC();

        if ((c & ~0xff) != 0) {
            throw new DexException("Register C out of range: " + Hex.u8(c));
        }

        return (short) c;
    
public final shortgetCNibble()
Gets the C register number, as a nibble. This will throw if the value is out of the range of an unsigned nibble.

        int c = getC();

        if ((c & ~0xf) != 0) {
            throw new DexException("Register C out of range: " + Hex.u8(c));
        }

        return (short) c;
    
public final shortgetCUnit()
Gets the C register number, as a code unit. This will throw if the value is out of the range of an unsigned code unit.

        int c = getC();

        if ((c & ~0xffff) != 0) {
            throw new DexException("Register C out of range: " + Hex.u8(c));
        }

        return (short) c;
    
public intgetD()

        return 0;
    
public final shortgetDByte()
Gets the D register number, as a byte. This will throw if the value is out of the range of an unsigned byte.

        int d = getD();

        if ((d & ~0xff) != 0) {
            throw new DexException("Register D out of range: " + Hex.u8(d));
        }

        return (short) d;
    
public final shortgetDNibble()
Gets the D register number, as a nibble. This will throw if the value is out of the range of an unsigned nibble.

        int d = getD();

        if ((d & ~0xf) != 0) {
            throw new DexException("Register D out of range: " + Hex.u8(d));
        }

        return (short) d;
    
public final shortgetDUnit()
Gets the D register number, as a code unit. This will throw if the value is out of the range of an unsigned code unit.

        int d = getD();

        if ((d & ~0xffff) != 0) {
            throw new DexException("Register D out of range: " + Hex.u8(d));
        }

        return (short) d;
    
public intgetE()

        return 0;
    
public final shortgetENibble()
Gets the E register number, as a nibble. This will throw if the value is out of the range of an unsigned nibble.

        int e = getE();

        if ((e & ~0xf) != 0) {
            throw new DexException("Register E out of range: " + Hex.u8(e));
        }

        return (short) e;
    
public final InstructionCodecgetFormat()

        return format;
    
public final intgetIndex()

        return index;
    
public final com.android.dx.io.IndexTypegetIndexType()

        return indexType;
    
public final shortgetIndexUnit()
Gets the index, as a code unit.

        return (short) index;
    
public final longgetLiteral()

        return literal;
    
public final intgetLiteralByte()
Gets the literal value, masked to be a byte in size. This will throw if the value is out of the range of a signed byte.

        if (literal != (byte) literal) {
            throw new DexException("Literal out of range: " + Hex.u8(literal));
        }

        return (int) literal & 0xff;
    
public final intgetLiteralInt()
Gets the literal value, masked to be an int in size. This will throw if the value is out of the range of a signed int.

        if (literal != (int) literal) {
            throw new DexException("Literal out of range: " + Hex.u8(literal));
        }

        return (int) literal;
    
public final intgetLiteralNibble()
Gets the literal value, masked to be a nibble in size. This will throw if the value is out of the range of a signed nibble.

        if ((literal < -8) || (literal > 7)) {
            throw new DexException("Literal out of range: " + Hex.u8(literal));
        }

        return (int) literal & 0xf;
    
public final shortgetLiteralUnit()
Gets the literal value, as a code unit. This will throw if the value is out of the range of a signed code unit.

        if (literal != (short) literal) {
            throw new DexException("Literal out of range: " + Hex.u8(literal));
        }

        return (short) literal;
    
public final intgetOpcode()

        return opcode;
    
public final shortgetOpcodeUnit()
Gets the opcode, as a code unit.

        return (short) opcode;
    
public abstract intgetRegisterCount()

public final shortgetRegisterCountUnit()
Gets the register count, as a code unit. This will throw if the value is out of the range of an unsigned code unit.

        int registerCount = getRegisterCount();

        if ((registerCount & ~0xffff) != 0) {
            throw new DexException("Register count out of range: "
                    + Hex.u8(registerCount));
        }

        return (short) registerCount;
    
public final intgetTarget()
Gets the raw target.

        return target;
    
public final intgetTarget(int baseAddress)
Gets the target as a relative offset from the given address.

        return target - baseAddress;
    
public final intgetTargetByte(int baseAddress)
Gets the target as a relative offset from the given base address, masked to be a byte in size. This will throw if the value is out of the range of a signed byte.

        int relativeTarget = getTarget(baseAddress);

        if (relativeTarget != (byte) relativeTarget) {
            throw new DexException("Target out of range: "
                    + Hex.s4(relativeTarget));
        }

        return relativeTarget & 0xff;
    
public final shortgetTargetUnit(int baseAddress)
Gets the target as a relative offset from the given base address, as a code unit. This will throw if the value is out of the range of a signed code unit.

        int relativeTarget = getTarget(baseAddress);

        if (relativeTarget != (short) relativeTarget) {
            throw new DexException("Target out of range: "
                    + Hex.s4(relativeTarget));
        }

        return (short) relativeTarget;
    
public abstract com.android.dx.io.instructions.DecodedInstructionwithIndex(int newIndex)
Returns an instance just like this one, except with the index replaced with the given one.