mirror of https://github.com/x64dbg/zydis
Fixed register decoding for XOP and VEX instructions
This commit is contained in:
parent
b118637dae
commit
808ccac372
|
@ -149,19 +149,19 @@ enum ZydisRegisterEncodings
|
||||||
/**
|
/**
|
||||||
* @brief The register-id is encoded in `modrm.reg`.
|
* @brief The register-id is encoded in `modrm.reg`.
|
||||||
*
|
*
|
||||||
* Possible extension by `REX/XOP/VEX/EVEX/MVEX.R'` (vector only) and `REX/XOP/VEX/EVEX/MVEX.R`.
|
* Possible extension by `EVEX/MVEX.R'` (vector only) and `REX/XOP/VEX/EVEX/MVEX.R`.
|
||||||
*/
|
*/
|
||||||
ZYDIS_REG_ENCODING_REG,
|
ZYDIS_REG_ENCODING_REG,
|
||||||
/**
|
/**
|
||||||
* @brief The register-id is encoded in `XOP/VEX/EVEX/MVEX.vvvv`.
|
* @brief The register-id is encoded in `XOP/VEX/EVEX/MVEX.vvvv`.
|
||||||
*
|
*
|
||||||
* Possible extension by `EVEX/MVEX.V'` (vector only).
|
* Possible extension by `EVEX/MVEX.v'` (vector only).
|
||||||
*/
|
*/
|
||||||
ZYDIS_REG_ENCODING_NDSNDD,
|
ZYDIS_REG_ENCODING_NDSNDD,
|
||||||
/**
|
/**
|
||||||
* @brief The register-id is encoded in `modrm.rm`.
|
* @brief The register-id is encoded in `modrm.rm`.
|
||||||
*
|
*
|
||||||
* Possible extension by `REX/XOP/VEX/EVEX/MVEX.X` (vector only) and `REX/XOP/VEX/EVEX/MVEX.B`.
|
* Possible extension by `EVEX/MVEX.X` (vector only) and `REX/XOP/VEX/EVEX/MVEX.B`.
|
||||||
*/
|
*/
|
||||||
ZYDIS_REG_ENCODING_RM,
|
ZYDIS_REG_ENCODING_RM,
|
||||||
/**
|
/**
|
||||||
|
@ -179,7 +179,7 @@ enum ZydisRegisterEncodings
|
||||||
/**
|
/**
|
||||||
* @brief The register-id is encoded in `sib.index`.
|
* @brief The register-id is encoded in `sib.index`.
|
||||||
*
|
*
|
||||||
* Possible extension by `REX/XOP/VEX/EVEX/MVEX.V'` (vector only) and `REX/XOP/VEX/EVEX/MVEX.X`.
|
* Possible extension by `EVEX/MVEX.V'` (vector only) and `REX/XOP/VEX/EVEX/MVEX.X`.
|
||||||
*/
|
*/
|
||||||
ZYDIS_REG_ENCODING_VIDX,
|
ZYDIS_REG_ENCODING_VIDX,
|
||||||
/**
|
/**
|
||||||
|
@ -906,11 +906,12 @@ static uint8_t ZydisCalcRegisterId(ZydisDecoderContext* context, ZydisInstructio
|
||||||
{
|
{
|
||||||
ZYDIS_ASSERT(info->details.modrm.isDecoded);
|
ZYDIS_ASSERT(info->details.modrm.isDecoded);
|
||||||
uint8_t value = info->details.modrm.reg | (context->cache.R << 3);
|
uint8_t value = info->details.modrm.reg | (context->cache.R << 3);
|
||||||
|
// R' only exists for EVEX and MVEX. No encoding check needed
|
||||||
switch (registerClass)
|
switch (registerClass)
|
||||||
{
|
{
|
||||||
case ZYDIS_REGCLASS_XMM:
|
case ZYDIS_REGCLASS_XMM:
|
||||||
case ZYDIS_REGCLASS_YMM:
|
case ZYDIS_REGCLASS_YMM:
|
||||||
case ZYDIS_REGCLASS_ZMM:
|
case ZYDIS_REGCLASS_ZMM:
|
||||||
value |= (context->cache.R2 << 4);
|
value |= (context->cache.R2 << 4);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -919,6 +920,7 @@ static uint8_t ZydisCalcRegisterId(ZydisDecoderContext* context, ZydisInstructio
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
case ZYDIS_REG_ENCODING_NDSNDD:
|
case ZYDIS_REG_ENCODING_NDSNDD:
|
||||||
|
// v' only exists for EVEX and MVEX. No encoding check needed
|
||||||
switch (registerClass)
|
switch (registerClass)
|
||||||
{
|
{
|
||||||
case ZYDIS_REGCLASS_XMM:
|
case ZYDIS_REGCLASS_XMM:
|
||||||
|
@ -934,15 +936,21 @@ static uint8_t ZydisCalcRegisterId(ZydisDecoderContext* context, ZydisInstructio
|
||||||
{
|
{
|
||||||
ZYDIS_ASSERT(info->details.modrm.isDecoded);
|
ZYDIS_ASSERT(info->details.modrm.isDecoded);
|
||||||
uint8_t value = info->details.modrm.rm | (context->cache.B << 3);
|
uint8_t value = info->details.modrm.rm | (context->cache.B << 3);
|
||||||
switch (registerClass)
|
// We have to check the instruction-encoding, because the extension by X is only valid
|
||||||
|
// for EVEX and MVEX instructions
|
||||||
|
if ((info->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) ||
|
||||||
|
(info->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX))
|
||||||
{
|
{
|
||||||
case ZYDIS_REGCLASS_XMM:
|
switch (registerClass)
|
||||||
case ZYDIS_REGCLASS_YMM:
|
{
|
||||||
case ZYDIS_REGCLASS_ZMM:
|
case ZYDIS_REGCLASS_XMM:
|
||||||
value |= (context->cache.X << 4);
|
case ZYDIS_REGCLASS_YMM:
|
||||||
break;
|
case ZYDIS_REGCLASS_ZMM:
|
||||||
default:
|
value |= (context->cache.X << 4);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -967,6 +975,7 @@ static uint8_t ZydisCalcRegisterId(ZydisDecoderContext* context, ZydisInstructio
|
||||||
ZYDIS_ASSERT((registerClass == ZYDIS_REGCLASS_XMM) ||
|
ZYDIS_ASSERT((registerClass == ZYDIS_REGCLASS_XMM) ||
|
||||||
(registerClass == ZYDIS_REGCLASS_YMM) ||
|
(registerClass == ZYDIS_REGCLASS_YMM) ||
|
||||||
(registerClass == ZYDIS_REGCLASS_ZMM));
|
(registerClass == ZYDIS_REGCLASS_ZMM));
|
||||||
|
// v' only exists for EVEX and MVEX. No encoding check needed
|
||||||
return info->details.sib.index | (context->cache.X << 3) | (context->cache.V2 << 4);
|
return info->details.sib.index | (context->cache.X << 3) | (context->cache.V2 << 4);
|
||||||
case ZYDIS_REG_ENCODING_IS4:
|
case ZYDIS_REG_ENCODING_IS4:
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue