//当不存在REX时,REG域数组,[具体的选项][REG]
const char *ModRM_REG0[0xA][0x8] =
{
{"AL", "CL", "DL", "BL", "AH", "CH", "DH", "BH" },//reg8
{"AX", "CX", "DX", "BX", "SP", "BP", "SI", "DI" },//reg16
{"EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI"},//reg32
{"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI"},//reg64
{"MMX0","MMX1","MMX2","MMX3","MMX4","MMX5","MMX6","MMX7"},//mmx
{"XMM0","XMM1","XMM2","XMM3","XMM4","XMM5","XMM6","XMM7"},//xmm
{"YMM0","YMM1","YMM2","YMM3","YMM4","YMM5","YMM6","YMM7"},//ymm
{"ES", "CS", "SS", "DS", "FS", "GS", "invalid","invalid"},//sReg
{"CR0", "CR1", "CR2", "CR3", "CR4", "CR5", "CR6", "CR7" },//cReg
{"DR0", "DR1", "DR2", "DR3", "DR4", "DR5", "DR6", "DR7" } //dReg
};
//当存在REX且REX.R为0时,REG域数组,[具体的选项][REG]
const char *ModRM_REG10[0xA][0x8] =
{
{"AL", "CL", "DL", "BL", "SPL", "BPL", "SIL", "DIL"},//reg8
{"AX", "CX", "DX", "BX", "SP", "BP", "SI", "DI" },//reg16
{"EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI"},//reg32
{"RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI"},//reg64
{"MMX0","MMX1","MMX2","MMX3","MMX4","MMX5","MMX6","MMX7"},//mmx
{"XMM0","XMM1","XMM2","XMM3","XMM4","XMM5","XMM6","XMM7"},//xmm
{"YMM0","YMM1","YMM2","YMM3","YMM4","YMM5","YMM6","YMM7"},//ymm
{"ES", "CS", "SS", "DS", "FS", "GS","invalid","invalid"},//sReg
{"CR0", "CR1", "CR2", "CR3", "CR4", "CR5", "CR6", "CR7"},//cReg
{"DR0", "DR1", "DR2", "DR3", "DR4", "DR5", "DR6", "DR7"} //dReg
};
//当存在REX且REX.R为1时,REG域数组,[具体的选项][REG]
const char *ModRM_REG11[0xA][0x8] =
{
{"R8B", "R9B", "R10B", "R11B", "R12B", "R13B", "R14B", "R15B"},//reg8
{"R8W", "R9W", "R10W", "R11W", "R12W", "R13W", "R14W", "R15W"},//reg16
{"R8D", "R9D", "R10D", "R11D", "R12D", "R13D", "R14D", "R15D"},//reg32
{"R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15"},//reg64
{"MMX0","MMX1","MMX2", "MMX3", "MMX4", "MMX5", "MMX6", "MMX7"},//mmx
{"XMM8","XMM9","XMM10","XMM11","XMM12","XMM13","XMM14","XMM15"},//xmm
{"YMM8","YMM9","YMM10","YMM11","YMM12","YMM13","YMM14","YMM15"},//ymm
{"ES", "CS", "SS", "DS", "FS", "GS", "invalid","invalid"}, //sReg
{"CR8", "CR9", "CR10", "CR11", "CR12", "CR13", "CR14", "CR15" },//cReg
{"DR8", "DR9", "DR10", "DR11", "DR12", "DR13", "DR14", "DR15" } //dReg
};
//解码Mod.REG域函数
static void DecodeREG(BYTE* PModRM, CString &Result, bool REX_Flag, bool REX_W_Flag, bool REX_R_Flag, int Mode, bool OPSizeFlag, int DecodeType)
{
if (MODE32 == Mode)
{
if (GPRS != DecodeType)
Result = Result + " " + ModRM_REG0[DecodeType][REG(*PModRM)] + " ";
else
{
if (OPSizeFlag)
Result = Result + " " + ModRM_REG0[REG16][REG(*PModRM)] + " ";
else
Result = Result + " " + ModRM_REG0[REG32][REG(*PModRM)] + " ";
}
}
else
{
if (REX_Flag)
{
if (REX_R_Flag)
{
if (GPRS != DecodeType)
Result = Result + " " + ModRM_REG11[DecodeType][REG(*PModRM)] + " ";
else
{
if (REX_W_Flag)
Result = Result + " " + ModRM_REG11[REG64][REG(*PModRM)] + " ";
else
{
if (OPSizeFlag)
Result = Result + " " + ModRM_REG11[REG16][REG(*PModRM)] + " ";
else
Result = Result + " " + ModRM_REG11[REG32][REG(*PModRM)] + " ";
}
}
}
else
{
if (GPRS != DecodeType)
Result = Result + " " + ModRM_REG10[DecodeType][REG(*PModRM)] + " ";
else
{
if (REX_W_Flag)
Result = Result + " " + ModRM_REG10[REG64][REG(*PModRM)] + " ";
else
{
if (OPSizeFlag)
Result = Result + " " + ModRM_REG10[REG16][REG(*PModRM)] + " ";
else
Result = Result + " " + ModRM_REG10[REG32][REG(*PModRM)] + " ";
}
}
}
}
else
{
if (GPRS != DecodeType)
Result = Result + " " + ModRM_REG0[DecodeType][REG(*PModRM)] + " ";
else
{
if (REX_W_Flag)
Result = Result + " " + ModRM_REG0[REG64][REG(*PModRM)] + " ";
else
{
if (OPSizeFlag)
Result = Result + " " + ModRM_REG0[REG16][REG(*PModRM)] + " ";
else
Result = Result + " " + ModRM_REG0[REG32][REG(*PModRM)] + " ";
}
}
}
}
}