Disassembly

API for disassembly. More...

Enumerations

enum  opdis_error_t {
  opdis_error_unknown, opdis_error_bounds, opdis_error_invalid_insn, opdis_error_decode_insn,
  opdis_error_bfd, opdis_error_max_items
}
 

Error codes passed to OPDIS_ERROR.

More...

Functions

opdis_t LIBCALL opdis_init (void)
 Initialize an opdis disassembler.
void LIBCALL opdis_term (opdis_t o)
 Cleanup an opdis disassembler.
unsigned int LIBCALL opdis_disasm_insn_size (opdis_t o, opdis_buf_t buf, opdis_vma_t vma)
 Return the size of the instruction at an offset in the buffer.
unsigned int LIBCALL opdis_disasm_insn (opdis_t o, opdis_buf_t buf, opdis_vma_t vma, opdis_insn_t *insn)
 Disassemble a single instruction in the buffer.
int LIBCALL opdis_disasm_linear (opdis_t o, opdis_buf_t buf, opdis_vma_t vma, opdis_off_t length)
 Disassemble a sequence of instructions in order.
int LIBCALL opdis_disasm_cflow (opdis_t o, opdis_buf_t buf, opdis_vma_t vma)
 Disassemble a buffer following flow of control.
void LIBCALL opdis_error (opdis_t o, enum opdis_error_t error, const char *msg)
 Send an error message to the error reporter/.

Detailed Description

API for disassembly.

The general use of libopdis is to create an opdis_t, invoke a disassembly function on a buffer, and free the opdis_t:

        opdis_t o;
        opdis_buf_t buf;

        FILE * f = fopen( "a.out", "r" );
        if ( f ) {
                buf = opdis_buf_read( f, 0, 0 );
                o = opdis_init();
                opdis_disasm_linear( o, buf, 0, 0 );
                opdis_term( o );
                fclose(f);
        }

More control over the process is generally achieved through configuration of the opdis_t.


Enumeration Type Documentation

Error codes passed to OPDIS_ERROR.

Enumerator:
opdis_error_bounds 

Buffer bounds exceeded

opdis_error_invalid_insn 

Invalid instruction

opdis_error_decode_insn 

Decoding error

opdis_error_bfd 

BFD error

opdis_error_max_items 

Instruction > insn_buf


Function Documentation

opdis_disasm_cflow ( opdis_t  o,
opdis_buf_t  buf,
opdis_vma_t  vma 
)

Disassemble a buffer following flow of control.

Parameters:
o opdis disassembler
buf The buffer to disassemble
vma The address (VMA) of the entry point in the buffer
Note:
If the vma of buf is 0, then vma is the offset into the buffer.
opdis_disasm_insn ( opdis_t  o,
opdis_buf_t  buf,
opdis_vma_t  vma,
opdis_insn_t insn 
)

Disassemble a single instruction in the buffer.

Parameters:
o opdis disassembler
buf The buffer to disassemble
vma The address (VMA) in the buffer to disassemble.
insn The op_insn_t to fill with the disassembled instruction
Note:
If the vma of buf is 0, then vma is the offset into the buffer.
opdis_disasm_insn_size ( opdis_t  o,
opdis_buf_t  buf,
opdis_vma_t  vma 
)

Return the size of the instruction at an offset in the buffer.

Parameters:
o opdis disassembler
buf The buffer to disassemble
vma The address (VMA) in the buffer to disassemble.
Note:
If the vma of buf is 0, then vma is the offset into the buffer.
opdis_disasm_linear ( opdis_t  o,
opdis_buf_t  buf,
opdis_vma_t  vma,
opdis_off_t  length 
)

Disassemble a sequence of instructions in order.

Parameters:
o opdis disassembler
buf The buffer to disassemble
vma The address (VMA) in the buffer to start disassembly at.
length The number of bytes to disassemble.
Note:
If the vma of buf is 0, then vma is the offset into the buffer.
If length is zero, then all bytes from offset to the end of the buffer will be disassembled.
opdis_error ( opdis_t  o,
enum opdis_error_t  error,
const char *  msg 
)

Send an error message to the error reporter/.

This is used internally and by callbacks to report errors.

Parameters:
o opdis disassembler
error The error code
msg The detailed error message
opdis_init ( void   ) 

Initialize an opdis disassembler.

Allocates an opdis_t and configures it using opdis_set_defaults().

See also:
opdis_init_from_bfd opdis_term
Returns:
An opdis disassembler object
opdis_term ( opdis_t  o  ) 

Cleanup an opdis disassembler.

Frees an opdis_t and all its associated resources

Parameters:
o The opdis disassembler to free
See also:
opdis_init

Generated on Wed Mar 10 14:30:46 2010 for Opdis Disassembly Library by  doxygen 1.6.1