xed_uint_t disas_decode_binary(const xed_state_t* dstate, const xed_uint8_t* hex_decode_text, const unsigned int bytes, xed_decoded_inst_t* xedd, xed_uint64_t runtime_address) { xed_uint64_t t1,t2; xed_error_enum_t xed_error; xed_bool_t okay; if (CLIENT_VERBOSE) { print_hex_line(hex_decode_text, bytes); } t1 = xed_get_time(); xed_error = xed_decode(xedd, hex_decode_text, bytes); t2 = xed_get_time(); okay = (xed_error == XED_ERROR_NONE); if (CLIENT_VERBOSE3) { xed_uint64_t delta = t2-t1; printf("Decode time = " XED_FMT_LU "\n", delta); } if (okay) { if (CLIENT_VERBOSE1) { char tbuf[XED_TMP_BUF_LEN]; xed_decoded_inst_dump(xedd,tbuf,XED_TMP_BUF_LEN); printf("%s\n",tbuf); } if (CLIENT_VERBOSE) { char buf[XED_TMP_BUF_LEN]; if (xed_decoded_inst_valid(xedd)) { printf( "ICLASS: %s CATEGORY: %s EXTENSION: %s IFORM: %s" " ISA_SET: %s\n", xed_iclass_enum_t2str(xed_decoded_inst_get_iclass(xedd)), xed_category_enum_t2str(xed_decoded_inst_get_category(xedd)), xed_extension_enum_t2str(xed_decoded_inst_get_extension(xedd)), xed_iform_enum_t2str(xed_decoded_inst_get_iform_enum(xedd)), xed_isa_set_enum_t2str(xed_decoded_inst_get_isa_set(xedd))); } memset(buf,0,XED_TMP_BUF_LEN); disassemble(buf,XED_TMP_BUF_LEN, xedd, runtime_address,0); printf("SHORT: %s\n", buf); } return 1; } else { xed_decode_error(0, 0, hex_decode_text, xed_error); return 0; } (void) dstate; // pacify compiler }
void dump_inst(const xed_inst_t* p) { unsigned int j; printf("%s ", xed_iclass_enum_t2str(xed_inst_iclass(p))); printf("%s ", xed_iform_enum_t2str(xed_inst_iform_enum(p))); printf("%s ", xed_category_enum_t2str(xed_inst_category(p))); printf("%s ", xed_extension_enum_t2str(xed_inst_extension(p))); printf("%s ", xed_isa_set_enum_t2str(xed_inst_isa_set(p))); print_attributes(p); printf("%2u ", xed_inst_noperands(p)); printf("\n"); for(j=0;j<xed_inst_noperands(p);j++) { printf("\t%u ", j); dump_operand(xed_inst_operand(p,j)); printf("\n"); } }
static int format_jcc(const xed_inst_t *xi) { uint32_t dest, next; char opcode[20], jmp_dst[20]; const xed_operand_t *op = xed_inst_operand(xi, 0); xed_operand_enum_t op_name = xed_operand_name(op); xed_reg_enum_t reg_id; strcpy(opcode, xed_iclass_enum_t2str(xed_decoded_inst_get_iclass(&xedd_g))); INST* inst = get_inst(g_pc); if(operand_is_relbr(op_name, &dest)){ next = g_pc + xed_decoded_inst_get_length(&xedd_g); dest += next;//TODO: handle two branch #ifdef DEBUG fprintf(stdout, "format:%x\t%s\n", g_pc, g_inst_str); #endif #ifdef STATISTICS g_symbol_nums++; g_jcc_num++; #endif if(get_inst(dest)) sprintf(inst_buffer, "%s L_0x%x", opcode, dest); else{ sprintf(inst_buffer, "%s L_ERROR_0x%x", opcode, g_current_func->begin()->first); #ifdef STATISTICS g_check_nums += 1; fprintf(stderr, "check at pc\t%x\n", g_pc); #endif } if(get_inst(next)) memset(safety_guard, 0, sizeof(safety_guard)); else{ sprintf(safety_guard, "jmp L_ERROR_0x%x", g_current_func->begin()->first); #ifdef STATISTICS fprintf(stderr, "check at pc\t%x\n", g_pc); g_check_nums += 1; #endif } }else{ fprintf(stderr, "error in format_jcc\n"); } }
void x86_dump_ins(void *ins) { xed_decoded_inst_t xedd; xed_decoded_inst_t *xptr = &xedd; xed_error_enum_t xed_error; char inst_buf[1024]; char errbuf[2048]; xed_decoded_inst_zero_set_mode(xptr, &x86_decoder_settings.xed_settings); xed_error = xed_decode(xptr, (uint8_t*) ins, 15); if (xed_error == XED_ERROR_NONE) { xed_format_xed(xptr, inst_buf, sizeof(inst_buf), (xed_uint64_t)(uintptr_t)ins); sprintf(errbuf, "(%p, %d bytes, %s) %s \n" , ins, xed_decoded_inst_get_length(xptr), xed_iclass_enum_t2str(iclass(xptr)), inst_buf); } else { #if defined(ENABLE_XOP) && defined (HOST_CPU_x86_64) amd_decode_t decode_res; adv_amd_decode(&decode_res, ins); if (decode_res.success) { if (decode_res.weak) sprintf(errbuf, "(%p, %d bytes) weak AMD XOP \n", ins, (int) decode_res.len); else sprintf(errbuf, "(%p, %d bytes) robust AMD XOP \n", ins, (int) decode_res.len); } else #endif // ENABLE_XOP and HOST_CPU_x86_64 sprintf(errbuf, "x86_dump_ins: xed decode error addr=%p, code = %d\n", ins, (int) xed_error); } EMSG(errbuf); fprintf(stderr, errbuf); fflush(stderr); }