x86_format_insn(3)
β¨ x86_format_insn(3) β¨ β the libdisasm girlies' guide to pretty-printing instructions
okay so bestie, we're in libdisasm territory today and honestly? it's giving disassembler glamour π
this is the page for x86_format_insn, x86_format_mnemonic, x86_format_operand and x86_format_header β aka the four functions that take your disassembled instruction and turn it into a cute little string you can actually print. π
πΈ NAME πΈ
x86_format_insn, x86_format_mnemonic, x86_format_operand, x86_format_header β generate a string representation of a disassembled instruction.
β¨ 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 builds an assembly-language representation of the disassembled instruction, in whatever format you asked for. x86_format_mnemonic and x86_format_operand are the ones x86_format_insn calls to format the instruction mnemonic and the operands respectively β but you're a main character, so you can absolutely call them directly yourself. π«Ά
Every one of these routines fills the 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. yes, a whole function just to describe a format. it's iconic of it honestly. π
π¦ The formats available π¦
native_syntaxβ Intel syntax with address and hexintel_syntaxβ Intel x86 syntaxatt_syntaxβ AT&T Syntaxraw_syntaxβ Pipe-delimited internal formatxml_syntaxβ XML representation
π native_syntax
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
Intel syntax uses dest, src ordering and displays the instruction in tab-and-comma delimited format:
"MNEMONIC\tDEST, SRC, IMM"
π att_syntax
AT&T syntax uses src, dest ordering (yes, the ordering flips, keep up bestie π) and displays the instruction in tab-and-comma delimited format:
"MNEMONIC\tSRC, DEST, IMM"
π raw_syntax
Raw syntax spills all the details of the instruction in pipe-delimited format:
"ADDRESS|OFFSET|SIZE|BYTES|PREFIX|PREFIX_STRING|
π xml_syntax
XML syntax also spills all the details of the instruction, but make it XML:
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 π₯
okay this first one will print insn in Intel syntax. no cap, that's literally what the comment says:
void att_print( x86_insn_t *insn ) {
char line[256];
x86_format_insn(insn, line, 256, intel_syntax);
printf( "%s\n", line);
}
and this next 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");
}
bestie, copy these exactly as written β that's what the page gives you, character for character. π
π SEE ALSO π
libdisasm(7), x86_disasm(3), x86_init(3), x86dis(1)
and that's the whole vibe check, bestie. this page came to you courtesy of mammon_, version 0.21, dated back in the day, and it's filed under x86_format_insn(3). go format some instructions, you absolute icon. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libdisasm-dev 0.23-6+b1
- debian trixie: libdisasm-dev 0.23-7 Β· Artistic-1.0-clarified
- ubuntu jammy: libdisasm-dev 0.23-6build1
- ubuntu noble: libdisasm-dev 0.23-6.1
- ubuntu questing: libdisasm-dev 0.23-7
- ubuntu resolute: libdisasm-dev 0.23-7build1 Β· Artistic-1.0-clarified
- ubuntu stonking: libdisasm-dev 0.23-7build1 Β· Artistic-1.0-clarified
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms