diff --git a/src/Decoder.c b/src/Decoder.c index d1d43a7..08fe326 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -4279,16 +4279,20 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context, ZYDIS_UNREACHABLE; } - // Check gather/scatter registers + // Check gather registers if (isGather) { ZYDIS_ASSERT(hasVSIB); ZYDIS_ASSERT(instruction->raw.modrm.mod != 3); ZYDIS_ASSERT(instruction->raw.modrm.rm == 4); - const ZydisU8 dest = instruction->raw.modrm.reg | (context->cache.R << 3) | - (context->cache.R2 << 4); - const ZydisU8 index = instruction->raw.sib.index | (context->cache.X << 3) | - (context->cache.V2 << 4); + + ZydisU8 dest = instruction->raw.modrm.reg; + ZydisU8 index = instruction->raw.sib.index; + if (context->decoder->machineMode == ZYDIS_MACHINE_MODE_LONG_64) + { + dest = dest | (context->cache.R << 3) | (context->cache.R2 << 4); + index = index | (context->cache.X << 3) | (context->cache.V2 << 4); + } ZydisU8 mask = 0xFF; switch (instruction->encoding)