x86_format_insn, x86_format_mnemonic, x86_format_operand, x86_format_header - generate a string
Contents
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><addressrva=offset=size=bytes=/><prefixtype=string=/><mnemonicgroup=type=string=cpu=isa=note=/><flagstype=set><flagname=></flags><stack_modval=><flagstype=tested><flagname=></flags><operandname=><registername=type=size=/><immediatetype=value=/><relative_offsetvalue=/><absolute_addressvalue=><segmentvalue=/></absolute_address><address_expression><segmentvalue=/><base><registername=type=size=/></base><index><registername=type=size=/></index><scale><immediatevalue=/></scale><displacement><immediatevalue=/><addressvalue=/></displacement></address_expression><segment_offset><addressvalue=/></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");
}
Name
x86_format_insn, x86_format_mnemonic, x86_format_operand, x86_format_header - generate a string
representation of a disassembled instruction.
See Also
libdisasm(7), x86_disasm(3), x86_init(3), x86dis(1) mammon_ 0.21 x86_format_insn(3)
Synopsis
#include<libdis.h>intx86_format_operand(x86_op_t*op,char*buf,int len,enumx86_asm_format format);intx86_format_mnemonic(x86_insn_t*insn,char*buf,int len,enumx86_asm_format format );intx86_format_insn(x86_insn_t*insn,char*buf,int len,enumx86_asm_format format );intx86_format_header(char*buf,int len,enumx86_asm_format format);
