/* * decode_modrm_reg * * Decodes reg field of mod/rm byte * */ void decode_modrm_reg(ref ud u, ref ud_operand operand, reg_class type, ud_operand_size size) { byte reg = (byte)((BitOps.REX_R(u._rex) << 3) | BitOps.MODRM_REG(modrm(ref u))); decode_reg(ref u, ref operand, type, reg, size); }
/* * decode_ext() * * Decode opcode extensions (if any) */ int decode_ext(ref ud u, ushort ptr) { byte idx = 0; if ((ptr & 0x8000) == 0) { return(decode_insn(ref u, ptr)); } u.le = InstructionTables.ud_lookup_table_list[(~0x8000 & ptr)]; if (u.le.Type == ud_table_type.UD_TAB__OPC_3DNOW) { return(decode_3dnow(ref u)); } switch (u.le.Type) { case ud_table_type.UD_TAB__OPC_MOD: /* !11 = 0, 11 = 1 */ idx = (byte)((BitOps.MODRM_MOD(modrm(ref u)) + 1) / 4); break; /* disassembly mode/operand size/address size based tables. * 16 = 0,, 32 = 1, 64 = 2 */ case ud_table_type.UD_TAB__OPC_MODE: idx = (byte)(u.dis_mode != 64 ? 0 : 1); break; case ud_table_type.UD_TAB__OPC_OSIZE: idx = (byte)(eff_opr_mode(u.dis_mode, BitOps.REX_W(u.pfx_rex), u.pfx_opr) / 32); break; case ud_table_type.UD_TAB__OPC_ASIZE: idx = (byte)(eff_adr_mode(u.dis_mode, u.pfx_adr) / 32); break; case ud_table_type.UD_TAB__OPC_X87: idx = (byte)(modrm(ref u) - 0xC0); break; case ud_table_type.UD_TAB__OPC_VENDOR: if (u.vendor == UD_VENDOR_ANY) { /* choose a valid entry */ idx = (byte)((u.le.Table[idx] != 0) ? 0 : 1); } else if (u.vendor == UD_VENDOR_AMD) { idx = 0; } else { idx = 1; } break; case ud_table_type.UD_TAB__OPC_RM: idx = BitOps.MODRM_RM(modrm(ref u)); break; case ud_table_type.UD_TAB__OPC_REG: idx = BitOps.MODRM_REG(modrm(ref u)); break; case ud_table_type.UD_TAB__OPC_SSE: return(decode_ssepfx(ref u)); case ud_table_type.UD_TAB__OPC_VEX: return(decode_vex(ref u)); case ud_table_type.UD_TAB__OPC_VEX_W: idx = vex_w(ref u); break; case ud_table_type.UD_TAB__OPC_VEX_L: idx = vex_l(ref u); break; case ud_table_type.UD_TAB__OPC_TABLE: inp_next(ref u); return(decode_opcode(ref u)); default: Debug.Assert(false, "not reached"); break; } return(decode_ext(ref u, u.le.Table[idx])); }