Skip to content

Instructions

Decoded Dalvik bytecode. Method.instructions returns a list of these objects. See bytecode in the code guide.

opcode_name

opcode_name(opcode: int) -> str

The name of a Dalvik opcode byte, such as invoke-virtual for 0x6e.

An opcode the format does not use gives unused-XX, with the byte in hex.

to_string

to_string(instruction: Instruction) -> str

One instruction as text: the opcode name, then its operands.

Operands that point into a table of the DEX file are shown as raw indices, such as string@12 or method@4. An instruction alone cannot turn them into names. For names, use Method.calls(), Method.field_accesses(), Method.string_loads() and Method.type_uses().

InstructionView

Bases: Sequence[Instruction]

The decoded instructions of one method, as a read-only sequence.

It copies nothing up front: reading view[i] builds that one instruction. It supports len(), indexing, slicing (which returns a list) and iteration. The view keeps the analysis alive.

InstructionBase

The fields every instruction has.

offset property

offset: int

Position of the instruction in the method, in 16-bit code units from the start of the code.

opcode property

opcode: int

The raw opcode byte. opcode_name gives its name.

size property

size: int

Length of the instruction in code units, from 1 to 5.

OperandWidth

Bases: Enum

How many registers a value takes.

SINGLE class-attribute instance-attribute

SINGLE = 0

A 32-bit value or a reference. It takes one register.

PAIR class-attribute instance-attribute

PAIR = 1

A 64-bit value, long or double. It takes two registers, vN and vN+1.

NopInstruction

nop: does nothing.

base instance-attribute

The fields every instruction has: offset, opcode and size.

MoveInstruction

move, move-wide, move-object and their /from16 and /16 forms, the move-result instructions, and move-exception.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

src instance-attribute

src: Optional[int]

The register read. None for the move-result instructions and move-exception, which take their value from the last call or the caught exception and name no source register.

width instance-attribute

width: OperandWidth

The width of the value moved.

ConstInstruction

const/4, const/16, const, const/high16, const-wide/16, const-wide/32, const-wide, const-wide/high16: load a number into a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

value instance-attribute

value: int

The number, as a 64-bit integer for every form. The bytecode does not say whether a constant is an integer or a floating-point number, so a float or double constant appears here as its bit pattern.

width instance-attribute

width: OperandWidth

PAIR for the const-wide forms, SINGLE for the others.

ConstStringInstruction

const-string, const-string/jumbo: load a string into a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

string_index instance-attribute

string_index: int

Index of the string in the DEX file's string table. Method.string_loads() gives the string itself.

ConstClassInstruction

const-class: load a class object into a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

type_index instance-attribute

type_index: int

Index of the type in the DEX file's type table. Method.type_uses() gives the descriptor.

ConstMethodHandleInstruction

const-method-handle: load a java.lang.invoke.MethodHandle into a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

method_handle_index instance-attribute

method_handle_index: int

Index of the handle in the DEX file's method handle table.

ConstMethodTypeInstruction

const-method-type: load a java.lang.invoke.MethodType into a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

proto_index instance-attribute

proto_index: int

Index of the prototype in the DEX file's prototype table.

ReturnInstruction

return-void, return, return-wide, return-object.

base instance-attribute

The fields every instruction has: offset, opcode and size.

reg instance-attribute

reg: Optional[int]

The register that holds the returned value, or None for return-void.

width instance-attribute

width: OperandWidth

The width of the returned value.

ThrowInstruction

throw: throws the exception held in a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

reg instance-attribute

reg: int

The register that holds the exception.

GotoInstruction

goto, goto/16, goto/32: an unconditional jump.

base instance-attribute

The fields every instruction has: offset, opcode and size.

branch_offset instance-attribute

branch_offset: int

Where the branch goes, in code units, counted from this instruction's own offset. It is negative for a jump backwards.

IfInstruction

if-eq, if-ne, if-lt, if-ge, if-gt, if-le: compare two registers and jump when the condition holds.

base instance-attribute

The fields every instruction has: offset, opcode and size.

branch_offset instance-attribute

branch_offset: int

Where the branch goes, in code units, counted from this instruction's own offset. It is negative for a jump backwards.

reg_a instance-attribute

reg_a: int

The first register compared.

reg_b instance-attribute

reg_b: int

The second register compared.

IfZeroInstruction

if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez: compare one register with zero and jump when the condition holds.

base instance-attribute

The fields every instruction has: offset, opcode and size.

branch_offset instance-attribute

branch_offset: int

Where the branch goes, in code units, counted from this instruction's own offset. It is negative for a jump backwards.

reg instance-attribute

reg: int

The register compared with zero.

SwitchInstruction

packed-switch, sparse-switch: jump to the case that matches a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

payload_offset instance-attribute

payload_offset: int

Where the case table is stored, in code units, counted from this instruction's own offset.

reg instance-attribute

reg: int

The register that is tested.

is_packed instance-attribute

is_packed: bool

True for packed-switch, false for sparse-switch.

cases instance-attribute

cases: list[SwitchCase]

The decoded cases. The list is empty when the case table is damaged.

SwitchCase

One case of a switch instruction.

key instance-attribute

key: int

The value the case matches.

target instance-attribute

target: int

Where the case jumps, in code units, counted from the offset of the switch instruction.

CompareInstruction

cmpl-float, cmpg-float, cmpl-double, cmpg-double, cmp-long: compare two values and store -1, 0 or 1.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register that gets the result. The result is always an int.

src_a instance-attribute

src_a: int

The first register compared.

src_b instance-attribute

src_b: int

The second register compared.

src_width instance-attribute

src_width: OperandWidth

PAIR when the operands are long or double, SINGLE for float.

TypeInstruction

check-cast, instance-of, new-instance, new-array.

base instance-attribute

The fields every instruction has: offset, opcode and size.

type_index instance-attribute

type_index: int

Index of the type in the DEX file's type table. Method.type_uses() gives the descriptor.

dest instance-attribute

dest: int

The register the instruction works on: the register that is cast for check-cast, the result for instance-of and new-array, the new object for new-instance.

src instance-attribute

src: Optional[int]

The object register for instance-of, the size register for new-array. None for check-cast and new-instance, which use one register.

FilledNewArrayInstruction

filled-new-array, filled-new-array/range: create an array and fill it from registers.

base instance-attribute

The fields every instruction has: offset, opcode and size.

type_index instance-attribute

type_index: int

Index of the array type in the DEX file's type table.

arg_regs instance-attribute

arg_regs: list[int]

The registers that hold the elements, in order.

FillArrayInstruction

fill-array-data: fill an array from a table of constants stored in the code.

base instance-attribute

The fields every instruction has: offset, opcode and size.

reg instance-attribute

reg: int

The register that holds the array.

payload_offset instance-attribute

payload_offset: int

Where the table of constants is stored, in code units, counted from this instruction's own offset.

MonitorInstruction

monitor-enter, monitor-exit: take and release the lock of an object. They are the start and end of a synchronized block.

base instance-attribute

The fields every instruction has: offset, opcode and size.

reg instance-attribute

reg: int

The register that holds the object.

is_enter instance-attribute

is_enter: bool

True for monitor-enter, false for monitor-exit.

ArrayOpInstruction

The aget and aput instructions: read or write one element of an array.

base instance-attribute

The fields every instruction has: offset, opcode and size.

value_reg instance-attribute

value_reg: int

The register the element is read into, or written from.

array_reg instance-attribute

array_reg: int

The register that holds the array.

index_reg instance-attribute

index_reg: int

The register that holds the index.

is_write instance-attribute

is_write: bool

True for the aput instructions.

width instance-attribute

width: OperandWidth

The width of the element.

ArrayLengthInstruction

array-length: store the length of an array in a register.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register that gets the length.

array_reg instance-attribute

array_reg: int

The register that holds the array.

FieldInstruction

The iget, iput, sget and sput instructions: read or write a field.

base instance-attribute

The fields every instruction has: offset, opcode and size.

field_index instance-attribute

field_index: int

Index of the field in the DEX file's field table. Method.field_accesses() gives the FieldId.

value_reg instance-attribute

value_reg: int

The register the field is read into, or written from.

object_reg instance-attribute

object_reg: Optional[int]

The register that holds the object. None for a static field.

is_static instance-attribute

is_static: bool

True for the sget and sput instructions.

is_write instance-attribute

is_write: bool

True for the iput and sput instructions.

width instance-attribute

width: OperandWidth

The width of the field's value.

InvokeInstruction

invoke-virtual, invoke-super, invoke-direct, invoke-static, invoke-interface and their /range forms: call a method.

base instance-attribute

The fields every instruction has: offset, opcode and size.

method_index instance-attribute

method_index: int

Index of the method in the DEX file's method table. Method.calls() gives the MethodId and the kind of invoke.

arg_regs instance-attribute

arg_regs: list[int]

The argument registers, in order. For a call on an object the first one holds the object. A long or double argument takes two entries.

InvokePolymorphicInstruction

invoke-polymorphic, invoke-polymorphic/range: call a signature-polymorphic method, such as MethodHandle.invokeExact, with the prototype of this call.

base instance-attribute

The fields every instruction has: offset, opcode and size.

method_index instance-attribute

method_index: int

Index of the method in the DEX file's method table, such as MethodHandle.invokeExact. Method.calls() gives the MethodId.

proto_index instance-attribute

proto_index: int

Index in the DEX file's prototype table of the prototype of this call: the types the call site passes and expects back.

arg_regs instance-attribute

arg_regs: list[int]

The argument registers, in order. The first one holds the method handle.

InvokeCustomInstruction

invoke-custom, invoke-custom/range: call through a call site bound at runtime.

base instance-attribute

The fields every instruction has: offset, opcode and size.

call_site_index instance-attribute

call_site_index: int

Index of the call site in the DEX file's call site table.

arg_regs instance-attribute

arg_regs: list[int]

The argument registers, in order.

UnaryOpInstruction

One-operand arithmetic and conversions: neg-int, not-long, int-to-long, double-to-float and the like.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

src instance-attribute

src: int

The register read.

dest_width instance-attribute

dest_width: OperandWidth

The width of the result.

src_width instance-attribute

src_width: OperandWidth

The width of the operand.

BinaryOpInstruction

Two-operand arithmetic on registers: add-int, sub-long, mul-double, shl-int and the like, and their /2addr forms.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

src_a instance-attribute

src_a: int

The first operand. For a /2addr form it is the same register as dest.

src_b instance-attribute

src_b: int

The second operand.

width instance-attribute

width: OperandWidth

The width of the operation.

BinaryLitInstruction

Arithmetic on a register and a constant: add-int/lit16, rsub-int, mul-int/lit8, ushr-int/lit8 and the like.

base instance-attribute

The fields every instruction has: offset, opcode and size.

dest instance-attribute

dest: int

The register written.

src instance-attribute

src: int

The register read.

literal instance-attribute

literal: int

The constant operand.

InvalidInstruction

An opcode the Dalvik format does not use, as found in a damaged or deliberately broken method. base.opcode is the raw byte and base.size is 1. Android rejects such a method, so it never runs; the control-flow graph treats the instruction like a nop.

base instance-attribute

The fields every instruction has: offset, opcode and size.