00001
00011 #ifndef OPDIS_H
00012 #define OPDIS_H
00013
00014 #include <dis-asm.h>
00015
00016 #include <opdis/types.h>
00017 #include <opdis/insn_buf.h>
00018 #include <opdis/model.h>
00019 #include <opdis/tree.h>
00020
00021 #ifdef WIN32
00022 #define LIBCALL _stdcall
00023 #else
00024 #define LIBCALL
00025 #endif
00026
00027
00028 #ifdef __cplusplus
00029 extern "C"
00030 {
00031 #endif
00032
00033
00034
00048 typedef int (*OPDIS_HANDLER) ( const opdis_insn_t * i, void * arg );
00049
00061 int opdis_default_handler( const opdis_insn_t * i, void * arg );
00062
00080 typedef void (*OPDIS_DISPLAY) ( const opdis_insn_t * i, void * arg );
00081
00089 void opdis_default_display ( const opdis_insn_t * i, void * arg );
00090
00119 typedef int (*OPDIS_DECODER) ( const opdis_insn_buf_t in,
00120 opdis_insn_t * out,
00121 const opdis_byte_t * buf,
00122 opdis_off_t offset,
00123 opdis_vma_t vma,
00124 opdis_off_t length,
00125 void * arg );
00126
00138 int opdis_default_decoder( const opdis_insn_buf_t in, opdis_insn_t * out,
00139 const opdis_byte_t * buf, opdis_off_t,
00140 opdis_vma_t vma, opdis_off_t length,
00141 void * arg );
00142
00161 typedef opdis_vma_t (*OPDIS_RESOLVER) ( const opdis_insn_t * i, void * arg );
00162
00171 opdis_vma_t opdis_default_resolver( const opdis_insn_t * i, void * arg );
00172
00178 enum opdis_error_t { opdis_error_unknown,
00179 opdis_error_bounds,
00180 opdis_error_invalid_insn,
00181 opdis_error_decode_insn,
00182 opdis_error_bfd,
00183 opdis_error_max_items
00184 };
00185
00197 typedef void (*OPDIS_ERROR) ( enum opdis_error_t error, const char * msg,
00198 void * arg );
00199
00207 void opdis_default_error_reporter( enum opdis_error_t error, const char * msg,
00208 void * arg );
00209
00210
00211
00222 typedef struct {
00227 disassemble_info config;
00228
00233 disassembler_ftype disassembler;
00234
00238 OPDIS_ERROR error_reporter;
00239 void * error_reporter_arg;
00240
00244 OPDIS_DISPLAY display;
00245 void * display_arg;
00246
00250 OPDIS_HANDLER handler;
00251 void * handler_arg;
00252
00256 OPDIS_RESOLVER resolver;
00257 void * resolver_arg;
00258
00262 OPDIS_DECODER decoder;
00263 void * decoder_arg;
00264
00268 opdis_insn_buf_t buf;
00269
00270
00283 opdis_vma_tree_t visited_addr;
00284
00288 int debug;
00289 } opdis_info_t;
00290
00297 typedef opdis_info_t * opdis_t;
00298
00299
00300
00310 opdis_t LIBCALL opdis_init( void );
00311
00312
00326 opdis_t LIBCALL opdis_init_from_bfd( bfd * target );
00327
00337 void LIBCALL opdis_term( opdis_t o );
00338
00339
00351 void LIBCALL opdis_set_defaults( opdis_t o );
00352
00360 enum opdis_x86_syntax_t {
00361 opdis_x86_syntax_intel,
00362 opdis_x86_syntax_att
00363 };
00364
00375 void LIBCALL opdis_set_x86_syntax( opdis_t o, enum opdis_x86_syntax_t syntax );
00376
00409 void LIBCALL opdis_set_arch( opdis_t o, enum bfd_architecture arch,
00410 unsigned long mach, disassembler_ftype fn );
00411
00425 void LIBCALL opdis_set_disassembler_options( opdis_t o, const char * options );
00426
00442 void LIBCALL opdis_set_display( opdis_t o, OPDIS_DISPLAY fn, void * arg );
00443
00458 void LIBCALL opdis_set_handler( opdis_t o, OPDIS_HANDLER fn, void * arg );
00459
00475 void LIBCALL opdis_set_decoder( opdis_t o, OPDIS_DECODER fn, void * arg );
00476
00493 void LIBCALL opdis_set_resolver( opdis_t o, OPDIS_RESOLVER fn, void * arg );
00494
00505 void LIBCALL opdis_set_error_reporter( opdis_t o, OPDIS_ERROR fn, void * arg );
00506
00516 unsigned int LIBCALL opdis_disasm_insn_size( opdis_t o, opdis_buf_t buf,
00517 opdis_vma_t vma );
00518
00519
00520
00521
00522
00533 unsigned int LIBCALL opdis_disasm_insn( opdis_t o, opdis_buf_t buf,
00534 opdis_vma_t vma,
00535 opdis_insn_t * insn );
00536
00549 int LIBCALL opdis_disasm_linear( opdis_t o, opdis_buf_t buf, opdis_vma_t vma,
00550 opdis_off_t length );
00560 int LIBCALL opdis_disasm_cflow( opdis_t o, opdis_buf_t buf,
00561 opdis_vma_t vma );
00573 int LIBCALL opdis_disasm_bfd_linear( opdis_t o, bfd * abfd, opdis_vma_t vma,
00574 opdis_off_t length );
00583 int LIBCALL opdis_disasm_bfd_cflow( opdis_t o, bfd * abfd, opdis_vma_t vma );
00584
00592 int LIBCALL opdis_disasm_bfd_section( opdis_t o, asection * sec );
00593
00601 int LIBCALL opdis_disasm_bfd_symbol( opdis_t o, asymbol * sym );
00602
00610 int LIBCALL opdis_disasm_bfd_entry( opdis_t o, bfd * abfd );
00611
00621 void LIBCALL opdis_error( opdis_t o, enum opdis_error_t error,
00622 const char * msg );
00623
00629 void LIBCALL opdis_debug( opdis_t o, int min_level, const char * format, ... );
00630
00631 #ifdef __cplusplus
00632 }
00633 #endif
00634
00635 #endif