static int gen_hex( struct ud *u ) { unsigned int i; unsigned char *src_ptr = inp_sess( u ); char* src_hex; /* bail out if in error stat. */ if ( u->error ) return -1; /* output buffer pointe */ src_hex = ( char* ) u->insn_hexcode; /* for each byte used to decode instruction */ for ( i = 0; i < u->inp_ctr; ++i, ++src_ptr) { sprintf( src_hex, "%02x", *src_ptr & 0xFF ); src_hex += 2; } return 0; }
/* ============================================================================= * ud_insn_hex() - Returns hex form of disassembled instruction. * ============================================================================= */ const char* ud_insn_hex(struct ud* u) { u->insn_hexcode[0] = 0; if (!u->error) { unsigned int i; unsigned char *src_ptr = inp_sess(u); char* src_hex; src_hex = (char*) u->insn_hexcode; /* for each byte used to decode instruction */ for (i = 0; i < u->inp_ctr && i < sizeof(u->insn_hexcode) / 2; ++i, ++src_ptr) { sprintf(src_hex, "%02x", *src_ptr & 0xFF); src_hex += 2; } } return u->insn_hexcode; }