Data Model for disassembled objects. More...
Data Structures | |
struct | opdis_reg_t |
CPU Register operand. More... | |
struct | opdis_abs_addr_t |
An absolute address operand. More... | |
struct | opdis_addr_expr_t |
An address expression operand. More... | |
struct | opdis_op_t |
Operand object. More... | |
struct | opdis_insn_t |
Instruction object. More... | |
Enumerations | |
enum | opdis_op_cat_t { opdis_op_cat_unknown, opdis_op_cat_register, opdis_op_cat_immediate, opdis_op_cat_absolute, opdis_op_cat_expr } |
The category of an operand. More... | |
enum | opdis_op_flag_t { opdis_op_flag_none = 0, opdis_op_flag_r = 1, opdis_op_flag_w = 2, opdis_op_flag_x = 4, opdis_op_flag_signed = 8, opdis_op_flag_address = 16, opdis_op_flag_indirect = 32 } |
Flags applied to an operand. More... | |
enum | opdis_insn_subset_t { opdis_insn_subset_gen, opdis_insn_subset_fpu, opdis_insn_subset_gpu, opdis_insn_subset_simd, opdis_insn_subset_vm } |
The subset of an ISA that the instruction belongs to. More... | |
enum | opdis_insn_cat_t { opdis_insn_cat_unknown, opdis_insn_cat_cflow, opdis_insn_cat_stack, opdis_insn_cat_lost, opdis_insn_cat_test, opdis_insn_cat_math, opdis_insn_cat_bit, opdis_insn_cat_io, opdis_insn_cat_trap, opdis_insn_cat_priv, opdis_insn_cat_nop } |
The category of an instruction. More... | |
enum | opdis_cflow_flag_t { opdis_cflow_flag_none = 0, opdis_cflow_flag_call = 1, opdis_cflow_flag_callcc = 2, opdis_cflow_flag_jmp = 4, opdis_cflow_flag_jmpcc = 8, opdis_cflow_flag_ret = 16 } |
Details of the control flow instruction. More... | |
enum | opdis_stack_flag_t { opdis_stack_flag_none = 0, opdis_stack_flag_push = 1, opdis_stack_flag_pop = 2, opdis_stack_flag_frame = 4, opdis_stack_flag_unframe = 8 } |
Details of the instruction. More... | |
enum | opdis_bit_flag_t { opdis_bit_flag_none = 0, opdis_bit_flag_and = 1, opdis_bit_flag_or = 2, opdis_bit_flag_xor = 4, opdis_bit_flag_not = 8, opdis_bit_flag_lsl = 16, opdis_bit_flag_lsr = 32, opdis_bit_flag_asl = 64, opdis_bit_flag_asr = 128, opdis_bit_flag_rol = 256, opdis_bit_flag_ror = 512, opdis_bit_flag_rcl = 1024, opdis_bit_flag_rcr = 2048 } |
Details of the instruction. More... | |
enum | opdis_io_flag_t { opdis_io_flag_none = 0, opdis_io_flag_in = 1, opdis_io_flag_out = 2 } |
Details of the instruction. More... | |
enum | opdis_addr_expr_elem_t { opdis_addr_expr_base = 1, opdis_addr_expr_index = 2, opdis_addr_expr_disp = 4, opdis_addr_expr_disp_u = 8, opdis_addr_expr_disp_s = 16, opdis_addr_expr_disp_abs = 32 } |
Elements present in an address expression. More... | |
enum | opdis_addr_expr_shift_t { opdis_addr_expr_lsl, opdis_addr_expr_lsr, opdis_addr_expr_asl, opdis_addr_expr_ror, opdis_addr_expr_rrx } |
Type of shift operation used in address expression. More... | |
Functions | |
opdis_insn_t *LIBCALL | opdis_insn_alloc (opdis_off_t num_operands) |
Allocate an instruction object and initialize its contents to zero. | |
opdis_insn_t *LIBCALL | opdis_insn_alloc_fixed (size_t ascii_sz, size_t mnemonic_sz, size_t num_operands, size_t op_ascii_sz) |
Allocate a fixed-size instruction object for use as a buffer. | |
opdis_insn_t *LIBCALL | opdis_insn_dupe (const opdis_insn_t *insn) |
Duplicate an instruction object. | |
void LIBCALL | opdis_insn_clear (opdis_insn_t *insn) |
Clear the contents of an instruction object. | |
void LIBCALL | opdis_insn_free (opdis_insn_t *insn) |
Free an allocated instruction object. | |
void LIBCALL | opdis_insn_set_ascii (opdis_insn_t *i, const char *ascii) |
Set the ascii field of an instruction. | |
void LIBCALL | opdis_insn_set_mnemonic (opdis_insn_t *i, const char *mnemonic) |
Set the mnemonic field of an instruction. | |
void LIBCALL | opdis_insn_add_prefix (opdis_insn_t *i, const char *prefix) |
Append a string to the prefix field. | |
void LIBCALL | opdis_insn_add_comment (opdis_insn_t *i, const char *cmt) |
Append a string to the comment field. | |
int LIBCALL | opdis_insn_add_operand (opdis_insn_t *i, opdis_op_t *op) |
Add an operand to an instruction. | |
opdis_op_t *LIBCALL | opdis_insn_next_avail_op (opdis_insn_t *i) |
Return next available allocated operand. | |
int LIBCALL | opdis_insn_is_branch (opdis_insn_t *i) |
Determine if the instruction has a branch target operand. | |
int LIBCALL | opdis_insn_fallthrough (opdis_insn_t *i) |
Determine if the execution falls through to the next instruction. | |
int LIBCALL | opdis_insn_isa_str (const opdis_insn_t *insn, char *buf, int buf_len) |
Generate a string representation of instruction isa field. | |
int LIBCALL | opdis_insn_cat_str (const opdis_insn_t *insn, char *buf, int buf_len) |
Generate a string representation of instruction category field. | |
int LIBCALL | opdis_insn_flags_str (const opdis_insn_t *insn, char *buf, int buf_len, const char *delim) |
Generate a string representation of instruction flags field. | |
opdis_op_t *LIBCALL | opdis_op_alloc (void) |
Allocate an operand object. | |
opdis_op_t *LIBCALL | opdis_op_alloc_fixed (size_t ascii_sz) |
Allocate a fixed-size operand object for use as a buffer. | |
opdis_op_t *LIBCALL | opdis_op_dupe (opdis_op_t *op) |
Duplicate an operand object. | |
void LIBCALL | opdis_op_clear (opdis_op_t *op) |
Clear the contents of an operand object. | |
void LIBCALL | opdis_op_free (opdis_op_t *op) |
Free an allocated operand object. | |
void LIBCALL | opdis_op_set_ascii (opdis_op_t *op, const char *ascii) |
Set the ascii field of an operand. | |
int LIBCALL | opdis_op_cat_str (const opdis_op_t *op, char *buf, int buf_len) |
Generate a string representation of operand category field. | |
int LIBCALL | opdis_op_flags_str (const opdis_op_t *op, char *buf, int buf_len, const char *delim) |
Generate a string representation of operand flags field. | |
int LIBCALL | opdis_reg_flags_str (const opdis_reg_t *reg, char *buf, int buf_len, const char *delim) |
Generate a string representation of register flags field. | |
int LIBCALL | opdis_addr_expr_shift_str (const opdis_addr_expr_t *exp, char *buf, int buf_len) |
Generate a string representation of addr expression shift field. |
Data Model for disassembled objects.
The libopdis data model consist of objects for instructions, operands, and operand values.
Each instruction consists of address details (vma, offset, size, bytes), zero or more prefixes, a
mnemonic for the machine opcode, and zero or more operands. Each operand consists of a value which may be a register , absolute address , address expression , or immediate value.
Instruction, operand, and register objects all have an ascii attribute that contains the raw output from libopcodes for this object. Note that libopcodes attempts to format its output for objdump, so there may be trailing whitespace in the ascii fields.
Instruction and operand objects have a category attribute that determines the broad type or category of the instruction (e.g. is it a control flow or stack operation) or operand (e.g. is it a register or immediate value).
Insructions, operands, and registers also have a flags attribute that contains additional information. For instructions, this will consist of a more detailed operation type (e.g. jump vs call). For operands, this will contain usage info (e.g. is the operand an address, is the operand read or written, etc). For registers, this will contain general usage info about the register (e.g. is it general-purpose, it is a stack pointer, etc).
Elements present in an address expression.
Type of shift operation used in address expression.
enum opdis_bit_flag_t |
Details of the instruction.
These flags encode specific information about the instructions: is it a shift or rotate (and is the carry flag significant), is it an AND/OR/XOR/NOT operation, etc.
enum opdis_cflow_flag_t |
Details of the control flow instruction.
These flags encode specific information about the control flow instructions: is it a call, does it branch, is it a return, etc.
enum opdis_insn_cat_t |
The category of an instruction.
The type or category of an instruction. This is used to distinguish between instructions at a high level : control flow instructions (jmp, call, ret), stack instructions (push, pop), floating point instructions, etc.
enum opdis_insn_subset_t |
The subset of an ISA that the instruction belongs to.
enum opdis_io_flag_t |
Details of the instruction.
These flags encode specific information about the instructions: does it read input from a port, does it write output to a port, etc.
enum opdis_op_cat_t |
The category of an operand.
The type or category of an instruction operand. This is used to distinguish between operands that are registers, memory locations, immediate values, or relative offsets.
enum opdis_op_flag_t |
Flags applied to an operand.
Operand flags are used to encode additional information about the operand.
enum opdis_stack_flag_t |
Details of the instruction.
These flags encode specific information about the instructions: is it a push or a pop, does it enter or leave a stack frame, etc.
int opdis_addr_expr_shift_str | ( | const opdis_addr_expr_t * | exp, | |
char * | buf, | |||
int | buf_len | |||
) |
Generate a string representation of addr expression shift field.
exp | The address expression. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. |
void opdis_insn_add_comment | ( | opdis_insn_t * | i, | |
const char * | cmt | |||
) |
Append a string to the comment field.
i | The instruction to modify. | |
cmt | The value to append to the comment field. |
int opdis_insn_add_operand | ( | opdis_insn_t * | i, | |
opdis_op_t * | op | |||
) |
Add an operand to an instruction.
Append an operand to the list of operands in the instruction. This does not duplicate the operand; it performs a realloc on the operands array, appends the pointer op to it, and increases the instruction count.
i | The instruction to modify. | |
op | The operand to append to the instruction. |
void opdis_insn_add_prefix | ( | opdis_insn_t * | i, | |
const char * | prefix | |||
) |
Append a string to the prefix field.
a a
i | The instruction to modify. | |
prefix | The value to append to the prefix field. |
opdis_insn_t * opdis_insn_alloc | ( | opdis_off_t | num_operands | ) |
Allocate an instruction object and initialize its contents to zero.
num_operands | The number of operands to allocate, or 0. |
opdis_insn_t * opdis_insn_alloc_fixed | ( | size_t | ascii_sz, | |
size_t | mnemonic_sz, | |||
size_t | num_operands, | |||
size_t | op_ascii_sz | |||
) |
Allocate a fixed-size instruction object for use as a buffer.
This allocates an instruction object with the specified number of operands, and with ascii and mnemonic allocated to the specified sizes. Each operand is allocated by opdis_op_alloc_fixed.
ascii_sz | ||
mnemonic_sz | ||
num_operands | ||
op_ascii_sz |
int opdis_insn_cat_str | ( | const opdis_insn_t * | insn, | |
char * | buf, | |||
int | buf_len | |||
) |
Generate a string representation of instruction category field.
i | The instruction. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. |
void opdis_insn_clear | ( | opdis_insn_t * | insn | ) |
Clear the contents of an instruction object.
i | The instruction to clear. |
opdis_insn_t * opdis_insn_dupe | ( | const opdis_insn_t * | insn | ) |
Duplicate an instruction object.
Allocate an instruction object and initialize it with the contents of i. This is primarily used to create an instruction object from a fixed-size opdis_insn_t. The ascii, mnemonic, and operands fields are only as large as they need to be (i.e. the length of the string and the number of valid operands).
i | The instruction to duplicate. |
int opdis_insn_fallthrough | ( | opdis_insn_t * | i | ) |
Determine if the execution falls through to the next instruction.
Returns true (1) if execution falls through to the subsequent instruction in memory. This is true for all instructions except unconditional jumps (JMP) and procedure returns (RET).
i | The instruction to examine. |
int opdis_insn_flags_str | ( | const opdis_insn_t * | insn, | |
char * | buf, | |||
int | buf_len, | |||
const char * | delim | |||
) |
Generate a string representation of instruction flags field.
i | The instruction. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. | |
delim | The delimiter to use between flags. |
void opdis_insn_free | ( | opdis_insn_t * | insn | ) |
Free an allocated instruction object.
i | The instruction to free. |
int opdis_insn_is_branch | ( | opdis_insn_t * | i | ) |
Determine if the instruction has a branch target operand.
Returns true (1) if the instruction has a branch target operand. The branch target operand is accessible via i->target.
i | The instruction to examine. |
int opdis_insn_isa_str | ( | const opdis_insn_t * | insn, | |
char * | buf, | |||
int | buf_len | |||
) |
Generate a string representation of instruction isa field.
i | The instruction. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. |
opdis_op_t * opdis_insn_next_avail_op | ( | opdis_insn_t * | i | ) |
Return next available allocated operand.
i | The instruction to containing the operand. |
void opdis_insn_set_ascii | ( | opdis_insn_t * | i, | |
const char * | ascii | |||
) |
Set the ascii field of an instruction.
This duplicates the string ascii and sets the ascii field of i to the new string. If the ascii field is non-NULL, it is freed before the assignment.
i | The instruction to modify. | |
ascii | The new value for the ascii field. |
void opdis_insn_set_mnemonic | ( | opdis_insn_t * | i, | |
const char * | mnemonic | |||
) |
Set the mnemonic field of an instruction.
This duplicates the string mnemonic and sets the mnemonic field of i to the new string. If the mnemonic field is non-NULL, it is freed before the assignment.
i | The instruction to modify. | |
mnemonic | The new value for the mnemonic field. |
opdis_op_t * opdis_op_alloc | ( | void | ) |
opdis_op_t * opdis_op_alloc_fixed | ( | size_t | ascii_sz | ) |
Allocate a fixed-size operand object for use as a buffer.
This allocates an operand object with ascii allocated to the specified size.
ascii_sz |
int opdis_op_cat_str | ( | const opdis_op_t * | op, | |
char * | buf, | |||
int | buf_len | |||
) |
Generate a string representation of operand category field.
op | The operand. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. |
void opdis_op_clear | ( | opdis_op_t * | op | ) |
Clear the contents of an operand object.
o | The operand to clear. |
opdis_op_t * opdis_op_dupe | ( | opdis_op_t * | op | ) |
Duplicate an operand object.
Allocate an operand object and initialize it with the contents of op. This is primarily used to create an operand object from a fixed-size opdis_op_t.
op | The operand to duplicate. |
int opdis_op_flags_str | ( | const opdis_op_t * | op, | |
char * | buf, | |||
int | buf_len, | |||
const char * | delim | |||
) |
Generate a string representation of operand flags field.
op | The operand. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. | |
delim | The delimiter to use between flags. |
void opdis_op_free | ( | opdis_op_t * | op | ) |
void opdis_op_set_ascii | ( | opdis_op_t * | op, | |
const char * | ascii | |||
) |
Set the ascii field of an operand.
This duplicates the string ascii and sets the ascii field of op to the new string. If the ascii field is non-NULL, it is freed before the assignment.
op | The operand to modify | |
ascii | The new value for the ascii field. |
int opdis_reg_flags_str | ( | const opdis_reg_t * | reg, | |
char * | buf, | |||
int | buf_len, | |||
const char * | delim | |||
) |
Generate a string representation of register flags field.
reg | The register. | |
buf | The buffer to append the string to. | |
buf_len | The length of the buffer. | |
delim | The delimiter to use between flags. |