From 8dd599555ffd388ca9fae9fdba644eb8e1cdc109 Mon Sep 17 00:00:00 2001 From: flobernd Date: Sun, 9 Apr 2017 23:11:16 +0200 Subject: [PATCH] Further improvements on #13 --- src/Decoder.c | 10 ---------- src/Utils.c | 8 +++++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Decoder.c b/src/Decoder.c index 726085f..f6c4243 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -2386,16 +2386,6 @@ ZydisStatus ZydisDecoderDecodeInstructionEx(ZydisInstructionDecoder* decoder, } } - // For relative operands, apply instruction length offset. - for (size_t i = 0; i < info->operandCount; ++i) - { - if (info->operands[i].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - info->operands[i].imm.isRelative) - { - info->operands[i].imm.value.sqword += info->length; - } - } - // Replace XCHG rAX, rAX with NOP alias if (info->mnemonic == ZYDIS_MNEMONIC_XCHG) { diff --git a/src/Utils.c b/src/Utils.c index 9975219..fd2fa15 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -51,19 +51,21 @@ ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisInstructionInfo* info } if (operand->mem.base == ZYDIS_REGISTER_EIP) { - *address = (uint64_t)((uint32_t)info->instrPointer + operand->mem.disp.value.sdword); + *address = (uint64_t)((uint32_t)info->instrPointer + operand->mem.disp.value.sdword); return ZYDIS_STATUS_SUCCESS; } if (operand->mem.base == ZYDIS_REGISTER_RIP) { - *address = (uint64_t)(info->instrPointer + operand->mem.disp.value.sqword); + *address = + (uint64_t)(info->instrPointer + operand->mem.disp.value.sqword); return ZYDIS_STATUS_SUCCESS; } break; case ZYDIS_OPERAND_TYPE_IMMEDIATE: if (operand->imm.isSigned && operand->imm.isRelative) { - *address = (uint64_t)((int64_t)info->instrPointer + operand->imm.value.sqword); + *address = + (uint64_t)((int64_t)info->instrPointer + info->length + operand->imm.value.sqword); switch (info->mode) { case ZYDIS_DISASSEMBLER_MODE_16BIT: