Const fixes and name updates for libdis.h

This commit is contained in:
nemerle 2014-02-28 11:24:09 +01:00
parent 0209b7ceb2
commit 5c7799b778
5 changed files with 43 additions and 42 deletions

View File

@ -288,20 +288,21 @@ struct x86_op_t{
} data; } data;
/* this is needed to make formatting operands more sane */ /* this is needed to make formatting operands more sane */
void * insn; /* pointer to x86_insn_t owning operand */ void * insn; /* pointer to x86_insn_t owning operand */
size_t size() size_t size() const
{ {
return operand_size(); return operand_size();
} }
/* get size of operand data in bytes */ /* get size of operand data in bytes */
size_t operand_size(); size_t operand_size() const;
/* format (sprintf) an operand into 'buf' using specified syntax */ /* format (sprintf) an operand into 'buf' using specified syntax */
int x86_format_operand(char *buf, int len, enum x86_asm_format format ); int x86_format_operand(char *buf, int len, enum x86_asm_format format );
bool is_address( ) { bool is_address( ) const {
return ( type == op_absolute || type == op_offset ); return ( type == op_absolute || type == op_offset );
} }
bool is_relative( ) { bool is_relative( ) const {
return ( type == op_relative_near || type == op_relative_far ); return ( type == op_relative_near || type == op_relative_far );
} }
bool is_immediate( ) const { return ( type == op_immediate ); }
int32_t getAddress() int32_t getAddress()
{ {
assert(is_address()||is_relative()); assert(is_address()||is_relative());
@ -634,10 +635,10 @@ public:
/* convenience routine: returns count of operands matching 'type' */ /* convenience routine: returns count of operands matching 'type' */
size_t x86_operand_count( enum x86_op_foreach_type type ); size_t x86_operand_count( enum x86_op_foreach_type type );
/* accessor functions for the operands */ /* accessor functions for the operands */
x86_op_t * x86_operand_1st( ); x86_op_t * operand_1st( );
x86_op_t * x86_operand_2nd( ); x86_op_t * operand_2nd( );
x86_op_t * x86_operand_3rd( ); x86_op_t * operand_3rd( );
x86_op_t * get_dest(); const x86_op_t * get_dest() const;
int32_t x86_get_rel_offset( ); int32_t x86_get_rel_offset( );
x86_op_t * x86_get_branch_target( ); x86_op_t * x86_get_branch_target( );
x86_op_t * x86_get_imm( ); x86_op_t * x86_get_imm( );

View File

@ -161,7 +161,7 @@ unsigned int X86_Disasm::x86_disasm_forward( unsigned char *buf, unsigned int bu
} }
if ( follow_insn_dest(&insn) ) { if ( follow_insn_dest(&insn) ) {
op = insn.x86_operand_1st();//x86_get_dest_operand op = insn.operand_1st();//x86_get_dest_operand
next_addr = -1; next_addr = -1;
/* if caller supplied a resolver, use it to determine /* if caller supplied a resolver, use it to determine

View File

@ -1052,8 +1052,8 @@ static int format_att_mnemonic( x86_insn_t *insn, char *buf, int len) {
/* do long jump/call prefix */ /* do long jump/call prefix */
if ( insn->type == insn_jmp || insn->type == insn_call ) { if ( insn->type == insn_jmp || insn->type == insn_call ) {
if (! is_imm_jmp( insn->x86_operand_1st() ) || if (! is_imm_jmp( insn->operand_1st() ) ||
(insn->x86_operand_1st())->datatype != op_byte ) { (insn->operand_1st())->datatype != op_byte ) {
/* far jump/call, use "l" prefix */ /* far jump/call, use "l" prefix */
STRNCAT( buf, "l", len ); STRNCAT( buf, "l", len );
} }
@ -1077,11 +1077,11 @@ static int format_att_mnemonic( x86_insn_t *insn, char *buf, int len) {
insn->type == insn_out insn->type == insn_out
)) { )) {
if ( insn->x86_operand_count( op_explicit ) > 0 && if ( insn->x86_operand_count( op_explicit ) > 0 &&
is_memory_op( insn->x86_operand_1st() ) ){ is_memory_op( insn->operand_1st() ) ){
size = insn->x86_operand_1st()->operand_size(); size = insn->operand_1st()->operand_size();
} else if ( insn->x86_operand_count( op_explicit ) > 1 && } else if ( insn->x86_operand_count( op_explicit ) > 1 &&
is_memory_op( insn->x86_operand_2nd() ) ){ is_memory_op( insn->operand_2nd() ) ){
size = insn->x86_operand_2nd()->operand_size(); size = insn->operand_2nd()->operand_size();
} }
} }
@ -1223,24 +1223,24 @@ static int format_xml_insn( x86_insn_t *insn, char *buf, int len ) {
len -= format_insn_eflags_str( insn->flags_tested, buf, len ); len -= format_insn_eflags_str( insn->flags_tested, buf, len );
STRNCAT( buf, "\"/>\n\t</flags>\n", len ); STRNCAT( buf, "\"/>\n\t</flags>\n", len );
if ( insn->x86_operand_1st() ) { if ( insn->operand_1st() ) {
insn->x86_operand_1st()->x86_format_operand(str, insn->operand_1st()->x86_format_operand(str,
sizeof str, xml_syntax); sizeof str, xml_syntax);
STRNCAT( buf, "\t<operand name=dest>\n", len ); STRNCAT( buf, "\t<operand name=dest>\n", len );
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
STRNCAT( buf, "\t</operand>\n", len ); STRNCAT( buf, "\t</operand>\n", len );
} }
if ( insn->x86_operand_2nd() ) { if ( insn->operand_2nd() ) {
insn->x86_operand_2nd()->x86_format_operand(str,sizeof str, insn->operand_2nd()->x86_format_operand(str,sizeof str,
xml_syntax); xml_syntax);
STRNCAT( buf, "\t<operand name=src>\n", len ); STRNCAT( buf, "\t<operand name=src>\n", len );
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
STRNCAT( buf, "\t</operand>\n", len ); STRNCAT( buf, "\t</operand>\n", len );
} }
if ( insn->x86_operand_3rd() ) { if ( insn->operand_3rd() ) {
insn->x86_operand_3rd()->x86_format_operand(str,sizeof str, insn->operand_3rd()->x86_format_operand(str,sizeof str,
xml_syntax); xml_syntax);
STRNCAT( buf, "\t<operand name=imm>\n", len ); STRNCAT( buf, "\t<operand name=imm>\n", len );
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
@ -1342,13 +1342,13 @@ int x86_insn_t::x86_format_insn( char *buf, int len,
STRNCAT( buf, "\t", len ); STRNCAT( buf, "\t", len );
/* dest */ /* dest */
if ( (dst = x86_operand_1st()) && !(dst->flags.op_implied) ) { if ( (dst = operand_1st()) && !(dst->flags.op_implied) ) {
dst->x86_format_operand(str, MAX_OP_STRING, format); dst->x86_format_operand(str, MAX_OP_STRING, format);
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
} }
/* src */ /* src */
if ( (src = x86_operand_2nd()) ) { if ( (src = operand_2nd()) ) {
if ( !(dst->flags.op_implied) ) { if ( !(dst->flags.op_implied) ) {
STRNCAT( buf, ", ", len ); STRNCAT( buf, ", ", len );
} }
@ -1357,9 +1357,9 @@ int x86_insn_t::x86_format_insn( char *buf, int len,
} }
/* imm */ /* imm */
if ( x86_operand_3rd()) { if ( operand_3rd()) {
STRNCAT( buf, ", ", len ); STRNCAT( buf, ", ", len );
x86_operand_3rd()->x86_format_operand(str, MAX_OP_STRING,format); operand_3rd()->x86_format_operand(str, MAX_OP_STRING,format);
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
} }
@ -1373,8 +1373,8 @@ int x86_insn_t::x86_format_insn( char *buf, int len,
/* not sure which is correct? sometimes GNU as requires /* not sure which is correct? sometimes GNU as requires
* an imm as the first operand, sometimes as the third... */ * an imm as the first operand, sometimes as the third... */
/* imm */ /* imm */
if ( x86_operand_3rd() ) { if ( operand_3rd() ) {
x86_operand_3rd()->x86_format_operand(str, MAX_OP_STRING,format); operand_3rd()->x86_format_operand(str, MAX_OP_STRING,format);
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
/* there is always 'dest' operand if there is 'src' */ /* there is always 'dest' operand if there is 'src' */
STRNCAT( buf, ", ", len ); STRNCAT( buf, ", ", len );
@ -1382,13 +1382,13 @@ int x86_insn_t::x86_format_insn( char *buf, int len,
if ( (note & insn_note_nonswap ) == 0 ) { if ( (note & insn_note_nonswap ) == 0 ) {
/* regular AT&T style swap */ /* regular AT&T style swap */
src = x86_operand_2nd(); src = operand_2nd();
dst = x86_operand_1st(); dst = operand_1st();
} }
else { else {
/* special-case instructions */ /* special-case instructions */
src = x86_operand_1st(); src = operand_1st();
dst = x86_operand_2nd(); dst = operand_2nd();
} }
/* src */ /* src */
@ -1431,20 +1431,20 @@ int x86_insn_t::x86_format_insn( char *buf, int len,
/* print operands */ /* print operands */
/* dest */ /* dest */
if ( x86_operand_1st() ) { if ( operand_1st() ) {
x86_operand_1st()->x86_format_operand(str, MAX_OP_STRING,format); operand_1st()->x86_format_operand(str, MAX_OP_STRING,format);
STRNCATF( buf, "%s\t", str, len ); STRNCATF( buf, "%s\t", str, len );
} }
/* src */ /* src */
if ( x86_operand_2nd() ) { if ( operand_2nd() ) {
x86_operand_2nd()->x86_format_operand(str, MAX_OP_STRING,format); operand_2nd()->x86_format_operand(str, MAX_OP_STRING,format);
STRNCATF( buf, "%s\t", str, len ); STRNCATF( buf, "%s\t", str, len );
} }
/* imm */ /* imm */
if ( x86_operand_3rd()) { if ( operand_3rd()) {
x86_operand_3rd()->x86_format_operand(str, MAX_OP_STRING,format); operand_3rd()->x86_format_operand(str, MAX_OP_STRING,format);
STRNCAT( buf, str, len ); STRNCAT( buf, str, len );
} }
} }

View File

@ -93,7 +93,7 @@ x86_op_t * x86_insn_t::x86_get_branch_target() {
return NULL; return NULL;
} }
x86_op_t * x86_insn_t::get_dest() { const x86_op_t * x86_insn_t::get_dest() const {
x86_oplist_t *op_lst; x86_oplist_t *op_lst;
assert(this); assert(this);
if ( ! operands ) { if ( ! operands ) {
@ -169,7 +169,7 @@ uint8_t *x86_insn_t::x86_get_raw_imm() {
} }
size_t x86_op_t::operand_size() { size_t x86_op_t::operand_size() const {
switch (datatype ) { switch (datatype ) {
case op_byte: return 1; case op_byte: return 1;
case op_word: return 2; case op_word: return 2;

View File

@ -184,7 +184,7 @@ size_t x86_insn_t::x86_operand_count( enum x86_op_foreach_type type ) {
} }
/* accessor functions */ /* accessor functions */
x86_op_t * x86_insn_t::x86_operand_1st() { x86_op_t * x86_insn_t::operand_1st() {
if (! explicit_count ) { if (! explicit_count ) {
return NULL; return NULL;
} }
@ -192,7 +192,7 @@ x86_op_t * x86_insn_t::x86_operand_1st() {
return &(operands->op); return &(operands->op);
} }
x86_op_t * x86_insn_t::x86_operand_2nd( ) { x86_op_t * x86_insn_t::operand_2nd( ) {
if ( explicit_count < 2 ) { if ( explicit_count < 2 ) {
return NULL; return NULL;
} }
@ -200,7 +200,7 @@ x86_op_t * x86_insn_t::x86_operand_2nd( ) {
return &(operands->next->op); return &(operands->next->op);
} }
x86_op_t * x86_insn_t::x86_operand_3rd( ) { x86_op_t * x86_insn_t::operand_3rd( ) {
if ( explicit_count < 3 ) { if ( explicit_count < 3 ) {
return NULL; return NULL;
} }