examples/xed-disas-filter.c
/* Decode fields in lines of the form

   prefix hexbytes ...

   and replace it in the output with the decoded instruction. Each line
   is assumed to be a single instruction for now.

   Optionally we look for a another hex address before prefix that gives
   the IP. */
Decode fields in lines of the form
prefix hexbytes

and replace it in the output with the decoded instruction. Each line
is assumed to be a single instruction for now.

Optionally we look for a another hex address before prefix that gives
the IP.
Decode fields in lines of the form prefix hexbytes and replace it in the output with the decoded instruction . Each line is assumed to be a single instruction for now . Optionally we look for a another hex address before prefix that gives the IP .
xed_uint_t disas_filter(xed_decoded_inst_t *inst, char *prefix, xed_disas_info_t *di)
{
    char line[LINELEN];
    di->symfn = get_symbol;
    xed_register_disassembly_callback(xed_disassembly_callback_function);
    while (fgets(line, LINELEN, stdin)) {
	xed_error_enum_t err;
	char *insn = strstr(line, prefix), *ip;
	xed_uint_t ilen;
	char out[256];
	unsigned long val;
	char *endp;
	xed_uint8_t insnbuf[IMAX];
	if (!insn) {
	    fputs(line, stdout);
	    continue;
	}
	ip = insn + strlen(prefix);
	ilen = 0;
	do {
	    val = strtoul(ip, &endp, 16);
	    if (insn == endp)
		    break;
	    insnbuf[ilen++] = (xed_uint8_t)val;
	    ip = endp;
	} while (ilen < IMAX);
	xed_state_t state;
	xed_state_zero(&state);
	xed_state_set_machine_mode(&state, di->dstate.mmode);
	xed_decoded_inst_zero_set_mode(inst, &state);
	if ((err = xed_decode(inst, insnbuf, ilen)) != XED_ERROR_NONE) {
	    snprintf(out, sizeof out, "%s" , xed_error_enum_t2str(err));
	} else {
	    disassemble(di, out, sizeof out, inst, get_ip(line),
			    nm_symtab_init ? &nm_symtab : NULL);
	}
	printf("%.*s\t\t%s%s", (int)(insn - line), line, out, endp);
    }
    return 0;
}
xed_uint_t disas_filter ( xed_decoded_inst_t * inst , char * prefix , xed_disas_info_t * di ) { char line [ LINELEN ] ; di -> symfn = get_symbol ; xed_register_disassembly_callback ( xed_disassembly_callback_function ) ; while ( fgets ( line , LINELEN , stdin ) ) { xed_error_enum_t err ; char * insn = strstr ( line , prefix ) , * ip ; xed_uint_t ilen ; char out [ 256 ] ; unsigned long val ; char * endp ; xed_uint8_t insnbuf [ IMAX ] ; if ( ! insn ) { fputs ( line , stdout ) ; continue ; } ip = insn + strlen ( prefix ) ; ilen = 0 ; do { val = strtoul ( ip , & endp , 16 ) ; if ( insn == endp ) break ; insnbuf [ ilen ++ ] = ( xed_uint8_t ) val ; ip = endp ; } while ( ilen < IMAX ) ; xed_state_t state ; xed_state_zero ( & state ) ; xed_state_set_machine_mode ( & state , di -> dstate . mmode ) ; xed_decoded_inst_zero_set_mode ( inst , & state ) ; if ( ( err = xed_decode ( inst , insnbuf , ilen ) ) != XED_ERROR_NONE ) { snprintf ( out , sizeof out , " " , xed_error_enum_t2str ( err ) ) ; } else { disassemble ( di , out , sizeof out , inst , get_ip ( line ) , nm_symtab_init ? & nm_symtab : NULL ) ; } printf ( " \t \t " , ( int ) ( insn - line ) , line , out , endp ) ; } return 0 ; }
Decode fields in lines of the form
prefix hexbytes ...
Decode fields in lines of the form prefix hexbytes ...