00001
00011 #ifndef OPDIS_MODEL_H
00012 #define OPDIS_MODEL_H
00013
00014 #include <opdis/metadata.h>
00015 #include <opdis/types.h>
00016
00017 #ifdef WIN32
00018 #define LIBCALL _stdcall
00019 #else
00020 #define LIBCALL
00021 #endif
00022
00028 enum opdis_insn_decode_t {
00029 opdis_decode_invalid = 0,
00030 opdis_decode_basic = 1,
00031 opdis_decode_mnem = 2,
00032 opdis_decode_ops = 4,
00033 opdis_decode_mnem_flags = 8,
00034 opdis_decode_op_flags = 16
00035 };
00036
00037
00038
00039
00044 #define OPDIS_REG_NAME_SZ 16
00045
00053 typedef struct {
00054 char ascii[OPDIS_REG_NAME_SZ];
00055 enum opdis_reg_flag_t flags;
00056 unsigned char id;
00057 unsigned char size;
00058 } opdis_reg_t;
00059
00067 typedef struct {
00068 opdis_reg_t segment;
00069 uint64_t offset;
00070 } opdis_abs_addr_t;
00071
00079 enum opdis_addr_expr_elem_t {
00080 opdis_addr_expr_base = 1,
00081 opdis_addr_expr_index = 2,
00082 opdis_addr_expr_disp = 4,
00083 opdis_addr_expr_disp_u = 8,
00084 opdis_addr_expr_disp_s = 16,
00085 opdis_addr_expr_disp_abs = 32
00086 };
00087
00095 enum opdis_addr_expr_shift_t {
00096 opdis_addr_expr_lsl,
00097 opdis_addr_expr_lsr,
00098 opdis_addr_expr_asl,
00099 opdis_addr_expr_ror,
00100 opdis_addr_expr_rrx
00101 };
00102
00123 typedef struct {
00124 enum opdis_addr_expr_elem_t elements;
00125 enum opdis_addr_expr_shift_t shift;
00126 char scale;
00127 opdis_reg_t index;
00128 opdis_reg_t base;
00129 union {
00130 uint64_t u;
00131 int32_t s;
00132 opdis_abs_addr_t a;
00133 } displacement;
00134 } opdis_addr_expr_t;
00135
00144 typedef struct {
00145 char * ascii;
00146 enum opdis_op_cat_t category;
00147 enum opdis_op_flag_t flags;
00148 union {
00149 opdis_reg_t reg;
00150 opdis_addr_expr_t expr;
00151 opdis_abs_addr_t abs;
00152 union {
00153 opdis_vma_t vma;
00154 uint64_t u;
00155 int64_t s;
00156 } immediate;
00157 } value;
00158 unsigned char data_size;
00160
00161 unsigned char fixed_size;
00162 unsigned char ascii_sz;
00163 } opdis_op_t;
00164
00165
00166
00167
00188 typedef struct {
00189 enum opdis_insn_decode_t status;
00190 char * ascii;
00192 opdis_off_t offset;
00193 opdis_vma_t vma;
00195 opdis_off_t size;
00196 opdis_byte_t * bytes;
00198
00199 opdis_off_t num_prefixes;
00200 char * prefixes;
00202 char * mnemonic;
00203 enum opdis_insn_cat_t category;
00204 enum opdis_insn_subset_t isa;
00205 union {
00206 enum opdis_cflow_flag_t cflow;
00207 enum opdis_stack_flag_t stack;
00208 enum opdis_io_flag_t io;
00209 enum opdis_bit_flag_t bit;
00210 } flags;
00211 char * comment;
00214
00215 opdis_off_t num_operands;
00216 opdis_off_t alloc_operands;
00217 opdis_op_t ** operands;
00219
00220 opdis_op_t * target;
00221 opdis_op_t * dest;
00222 opdis_op_t * src;
00224
00225 unsigned char fixed_size;
00226 unsigned char ascii_sz;
00227 unsigned char mnemonic_sz;
00229 } opdis_insn_t;
00230
00231
00232 #ifdef __cplusplus
00233 extern "C"
00234 {
00235 #endif
00236
00237
00250 opdis_insn_t * LIBCALL opdis_insn_alloc( opdis_off_t num_operands );
00251
00270 opdis_insn_t * LIBCALL opdis_insn_alloc_fixed( size_t ascii_sz,
00271 size_t mnemonic_sz, size_t num_operands,
00272 size_t op_ascii_sz );
00273
00287 opdis_insn_t * LIBCALL opdis_insn_dupe( const opdis_insn_t * i );
00288
00295 void LIBCALL opdis_insn_clear( opdis_insn_t * i );
00296
00305 void LIBCALL opdis_insn_free( opdis_insn_t * i );
00306
00318 void LIBCALL opdis_insn_set_ascii( opdis_insn_t * i, const char * ascii );
00319
00331 void LIBCALL opdis_insn_set_mnemonic( opdis_insn_t * i, const char * mnemonic );
00332
00342 void LIBCALL opdis_insn_add_prefix( opdis_insn_t * i, const char * prefix );
00343
00351 void LIBCALL opdis_insn_add_comment( opdis_insn_t * i, const char * cmt );
00352
00367 int LIBCALL opdis_insn_add_operand( opdis_insn_t * i, opdis_op_t * op );
00368
00376 opdis_op_t * LIBCALL opdis_insn_next_avail_op( opdis_insn_t * i );
00377
00391 int LIBCALL opdis_insn_is_branch( opdis_insn_t * insn );
00392
00406 int LIBCALL opdis_insn_fallthrough( opdis_insn_t * insn );
00407
00419 int LIBCALL opdis_insn_isa_str( const opdis_insn_t * i, char * buf,
00420 int buf_len );
00421
00435 int LIBCALL opdis_insn_cat_str( const opdis_insn_t * i, char * buf,
00436 int buf_len );
00437
00450 int LIBCALL opdis_insn_flags_str( const opdis_insn_t * i, char * buf,
00451 int buf_len, const char * delim );
00452
00460 opdis_op_t * LIBCALL opdis_op_alloc( void );
00461
00473 opdis_op_t * LIBCALL opdis_op_alloc_fixed( size_t ascii_sz );
00474
00487 opdis_op_t * LIBCALL opdis_op_dupe( opdis_op_t * op );
00488
00495 void LIBCALL opdis_op_clear( opdis_op_t * o );
00496
00504 void LIBCALL opdis_op_free( opdis_op_t * op );
00505
00516 void LIBCALL opdis_op_set_ascii( opdis_op_t * op, const char * ascii );
00517
00529 int LIBCALL opdis_op_cat_str( const opdis_op_t * op, char * buf, int buf_len );
00530
00543 int LIBCALL opdis_op_flags_str( const opdis_op_t * op, char * buf, int buf_len,
00544 const char * delim );
00545
00558 int LIBCALL opdis_reg_flags_str( const opdis_reg_t * reg, char * buf,
00559 int buf_len, const char * delim );
00571 int LIBCALL opdis_addr_expr_shift_str( const opdis_addr_expr_t * exp,
00572 char * buf, int buf_len );
00573
00574 #ifdef __cplusplus
00575 }
00576 #endif
00577
00578 #endif