From 16c60185a6a6a3808758416dc7a035bd66cd63c7 Mon Sep 17 00:00:00 2001 From: flobernd Date: Tue, 13 Mar 2018 13:24:20 +0100 Subject: [PATCH] Fixed check for invalid gather registers in non 64-bit mode --- src/Decoder.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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)