/* ----------------------------------------------------------------------------- * gen_operand() - Generates assembly output for each operand. * ----------------------------------------------------------------------------- */ static void gen_operand(struct ud* u, struct ud_operand* op, int syn_cast) { switch(op->type) { case UD_OP_REG: ud_asmprintf(u, "%s", ud_reg_tab[op->base - UD_R_AL]); break; case UD_OP_MEM: if (syn_cast) { opr_cast(u, op); } ud_asmprintf(u, "["); if (u->pfx_seg) { ud_asmprintf(u, "%s:", ud_reg_tab[u->pfx_seg - UD_R_AL]); } if (op->base) { ud_asmprintf(u, "%s", ud_reg_tab[op->base - UD_R_AL]); } if (op->index) { ud_asmprintf(u, "%s%s", op->base != UD_NONE? "+" : "", ud_reg_tab[op->index - UD_R_AL]); if (op->scale) { ud_asmprintf(u, "*%d", op->scale); } } if (op->offset != 0) { ud_syn_print_mem_disp(u, op, (op->base != UD_NONE || op->index != UD_NONE) ? 1 : 0); } ud_asmprintf(u, "]"); break; case UD_OP_IMM: ud_syn_print_imm(u, op); break; case UD_OP_JIMM: ud_syn_print_addr(u, ud_syn_rel_target(u, op)); break; case UD_OP_PTR: switch (op->size) { case 32: ud_asmprintf(u, "word 0x%x:0x%x", (unsigned int) op->lval.ptr.seg, (unsigned int) (op->lval.ptr.off & 0xFFFF)); break; case 48: ud_asmprintf(u, "dword 0x%x:0x%x", op->lval.ptr.seg, (unsigned int) op->lval.ptr.off); break; } break; case UD_OP_CONST: if (syn_cast) opr_cast(u, op); ud_asmprintf(u, "%d", (int) op->lval.udword); break; default: return; } }
/* ----------------------------------------------------------------------------- * gen_operand() - Generates assembly output for each operand. * ----------------------------------------------------------------------------- */ static void gen_operand(struct ud* u, struct ud_operand* op) { switch(op->type) { case UD_OP_CONST: ud_asmprintf(u, "$0x%x", op->lval.udword); break; case UD_OP_REG: ud_asmprintf(u, "%%%s", ud_reg_tab[op->base - UD_R_AL]); break; case UD_OP_MEM: if (u->br_far) { opr_cast(u, op); } if (u->pfx_seg) { ud_asmprintf(u, "%%%s:", ud_reg_tab[u->pfx_seg - UD_R_AL]); } if (op->offset != 0) { ud_syn_print_mem_disp(u, op, 0); } if (op->base) { ud_asmprintf(u, "(%%%s", ud_reg_tab[op->base - UD_R_AL]); } if (op->index) { if (op->base) { ud_asmprintf(u, ","); } else { ud_asmprintf(u, "("); } ud_asmprintf(u, "%%%s", ud_reg_tab[op->index - UD_R_AL]); } if (op->scale) { ud_asmprintf(u, ",%d", op->scale); } if (op->base || op->index) { ud_asmprintf(u, ")"); } break; case UD_OP_IMM: ud_syn_print_imm(u, op); break; case UD_OP_JIMM: ud_syn_print_addr(u, ud_syn_rel_target(u, op)); break; case UD_OP_PTR: switch (op->size) { case 32: ud_asmprintf(u, "$0x%x, $0x%x", op->lval.ptr.seg, op->lval.ptr.off & 0xFFFF); break; case 48: ud_asmprintf(u, "$0x%x, $0x%x", op->lval.ptr.seg, op->lval.ptr.off); break; } break; default: return; } }
/* ----------------------------------------------------------------------------- * gen_operand() - 为每个操作数生成汇编输出. * ----------------------------------------------------------------------------- */ static void gen_operand(struct ud *u,struct ud_operand *op,int syn_cast,wchar_t *wtmp,size_t wcount) { switch(op->type) { case UD_OP_REG: wprintfcat(wtmp,wcount,L"%s",ud_reg_tab[op->base - UD_R_AL]); ud_casmprint(u,UDCA_GPRs,3,wtmp); break; case UD_OP_MEM: if (syn_cast) opr_cast(u, op,wtmp,wcount); //操作数类型 dword ptr if (u->pfx_seg) wprintfcat(wtmp,wcount,L"%s:", ud_reg_tab[u->pfx_seg - UD_R_AL]); //段寄存器 wprintfcat(wtmp,wcount,L"["); if (op->base) wprintfcat(wtmp,wcount,L"%s", ud_reg_tab[op->base - UD_R_AL]); if (op->index) { wprintfcat(wtmp,wcount,L"%s%s", op->base != UD_NONE? L"+" : L"",ud_reg_tab[op->index - UD_R_AL]); if (op->scale) wprintfcat(wtmp,wcount,L"*%d", op->scale); } if (op->offset != 0) { ud_syn_print_mem_disp(u, op, (op->base != UD_NONE || op->index != UD_NONE) ? 1 : 0,wtmp,wcount); } wprintfcat(wtmp,wcount,L"]"); ud_casmprint(u,UDCA_MOther,3,wtmp); break; case UD_OP_IMM: ud_syn_print_imm(u, op,wtmp,wcount); ud_casmprint(u,UDCA_IMM,3,wtmp); break; case UD_OP_JIMM: ud_syn_print_addr(u, ud_syn_rel_target(u, op),wtmp,wcount); ud_casmprint(u,UDCA_IMMAddr,3,wtmp); break; case UD_OP_PTR: switch (op->size) { case 32: wprintfcat(wtmp,wcount,L"word ptr 0x%X:0x%X", op->lval.ptr.seg,op->lval.ptr.off & 0xFFFF); break; case 48: wprintfcat(wtmp,wcount,L"dword ptr 0x%X:0x%X", op->lval.ptr.seg,op->lval.ptr.off); break; } ud_casmprint(u,UDCA_IMM,3,wtmp); break; case UD_OP_CONST: if (syn_cast) opr_cast(u, op,wtmp,wcount); wprintfcat(wtmp,wcount,L"%d", op->lval.udword); ud_casmprint(u,UDCA_IMM,3,wtmp); break; default: return; } }