x86_format_operand(3) generate

Other Alias

x86_format_insn, x86_format_mnemonic, x86_format_header

SYNOPSIS

#include <libdis.h>

int x86_format_operand(x86_op_t *op, char *buf, int len,
       enum x86_asm_format
format);

int x86_format_mnemonic(x86_insn_t *insn, char *buf, int len,
       enum x86_asm_format
format );

int x86_format_insn(x86_insn_t *insn, char *buf, int len,
       enum x86_asm_format
format );

int x86_format_header( char *buf, int len,
       enum x86_asm_format
format);

DESCRIPTION

x86_format_insn generates an assembly-langauge representation of the disassembled instruction in the specified format. x86_format_mnemonic and are called by x86_format_operand to format the instruction mnemonic and operands, respectively, but they may be invoked directly by the user. Each of these routines fills buffer buf of len bytes with an ASCII string representing the instruction, mnemonic, or operand.
x86_format_header fills buffer buf of len bytes with a description of the specified format.

The following formats are available:

       native_syntax : Intel syntax with address and hex

       intel_syntax : Intel x86 syntax

       att_syntax : AT&T Syntax

       raw_syntax : Pipe-delimited internal format

       xml_syntax : XML representation

Native syntax uses dest, src ordering and displays
the address, opcode bytes, and instruction in tab-delimited
format:

       "ADDRESS\tBYTES\tMNEMONIC\tDEST\tSRC\tIMM"

Intel syntax uses dest, src ordering and displays the instruction in tab-and-comma delimited format:

       "MNEMONIC\tDEST, SRC, IMM"

AT&T syntax uses src, destordering and displays the instruction in tab-and-comma delimited format:

       "MNEMONIC\tSRC, DEST, IMM"

Raw syntax displays all details of the instruction in pipe-delimited format:

       "ADDRESS|OFFSET|SIZE|BYTES|PREFIX|PREFIX_STRING|

XML syntax displays all details of the instruction in XML format:

        GROUP|TYPE|NOTES|MNEMONIC|CPU|ISA|FLAGS_SET|

        FLAGS_TESTED|STACK_MOD|STACK_MOD_VAL"

        [|OP_TYPE|OP_DATATYPE|OP_ACCESS|OP_FLAGS|OP]*"

        "<x86_insn>

               <address rva= offset= size= bytes=/>

               <prefix type= string=/>

               <mnemonic group= type= string= cpu= isa= note= />

               <flags type=set>

                  <flag name=>

               </flags>

               <stack_mod val= >

               <flags type=tested>

                  <flag name=>

               </flags>

               <operand name=>

                  <register name= type= size=/>

                  <immediate type= value=/>

                  <relative_offset value=/>

                  <absolute_address value=>

                     <segment value=/>

                  </absolute_address>

                  <address_expression>

                     <segment value=/>

                     <base>

                        <register name= type= size=/>

                     </base>

                     <index>

                        <register name= type= size=/>

                     </index>

                     <scale>

                        <immediate value=/>

                     </scale>

                     <displacement>

                        <immediate value=/>

                        <address value=/>

                     </displacement>

                  </address_expression>

                  <segment_offset>

                     <address value=/>

                  </segment_offset>

               </operand>

            </x86_insn>"
 

EXAMPLES

The following will print insn in Intel syntax:

void att_print( x86_insn_t *insn ) {

        char line[256];

        x86_format_insn(insn, line, 256, intel_syntax);

        printf( "%s\n", line);
}

The following routine formats an instruction manually using AT&T syntax:

void manual_print( x86_insn_t *insn, void *arg ) {

        char buf[128];

        int i;

        printf("%08lX", insn->addr );

        for ( i = 0; i < 10; i++ ) {

                if ( i < insn->size ) {

                        printf(" %02X", insn->bytes[i]);

                } else {

                        printf("   ");

                }

        }

        x86_format_mnemonic( insn, buf, 128, att_syntax );

        printf( "\t%s\t", buf );

        if ( insn->operands[op_src].type != op_unused ) {

                x86_format_operand( &insn->operands[op_src],

                               insn, buf, 128, att_syntax );

                /* if src is present, so is dest */

                printf("%s, ", buf);

        }

        if ( insn->operands[op_dest].type != op_unused ) {

                x86_format_operand( &insn->operands[op_dest],

                               insn, buf, 128, att_syntax );

                printf("%s", buf);

        }

        if ( insn->operands[op_imm].type != op_unused ) {

                x86_format_operand( &insn->operands[op_imm],

                               insn, buf, 128, att_syntax );

                /* if src is present, so is dest */

                printf(", %s", buf);

        }

        printf("\n");
}