Removed `ZydisDecodedInstruction.instrPointer`

The instruction-pointer was always pointing to the next instruction (which is inconsistent for branch instructions). We can't always tell IF an instruction is going to branch (for the conditional ones), so we decided to completely remove it.

You can always manually combine `instrAddress` and `length` to calculate this value.
This commit is contained in:
flobernd 2017-12-01 20:21:25 +01:00
parent 1cd788f751
commit 930c4df970
No known key found for this signature in database
GPG Key ID: 9C3AE0ED4A969F10
3 changed files with 8 additions and 17 deletions

View File

@ -829,17 +829,10 @@ typedef struct ZydisDecodedInstruction_
*/ */
ZydisInstructionAttributes attributes; ZydisInstructionAttributes attributes;
/** /**
* @brief The instruction address points at the current instruction (relative to the * @brief The instruction address points at the current instruction (based on the initial
* initial instruction pointer). * instruction pointer).
*/ */
ZydisU64 instrAddress; ZydisU64 instrAddress;
/**
* @brief The instruction pointer points at the address of the next instruction (relative
* to the initial instruction pointer).
*
* This field is used to properly format relative instructions.
*/
ZydisU64 instrPointer;
/** /**
* @brief Information about accessed CPU flags. * @brief Information about accessed CPU flags.
*/ */

View File

@ -4562,14 +4562,10 @@ ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, const void* bu
ZYDIS_CHECK(ZydisCollectOptionalPrefixes(&context, instruction)); ZYDIS_CHECK(ZydisCollectOptionalPrefixes(&context, instruction));
ZYDIS_CHECK(ZydisDecodeInstruction(&context, instruction)); ZYDIS_CHECK(ZydisDecodeInstruction(&context, instruction));
instruction->instrPointer = instruction->instrAddress + instruction->length;
// TODO: The index, dest and mask regs for AVX2 gathers must be different. // TODO: The index, dest and mask regs for AVX2 gathers must be different.
// TODO: More EVEX UD conditions (page 81) // TODO: More EVEX UD conditions (page 81)
// TODO: Set AVX-512 info
return ZYDIS_STATUS_SUCCESS; return ZYDIS_STATUS_SUCCESS;
} }

View File

@ -50,13 +50,14 @@ ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
} }
if (operand->mem.base == ZYDIS_REGISTER_EIP) if (operand->mem.base == ZYDIS_REGISTER_EIP)
{ {
*address = *address = (ZydisU64)((ZydisU32)instruction->instrAddress + instruction->length +
(ZydisU64)((ZydisU32)instruction->instrPointer + (ZydisU32)operand->mem.disp.value); (ZydisU32)operand->mem.disp.value);
return ZYDIS_STATUS_SUCCESS; return ZYDIS_STATUS_SUCCESS;
} }
if (operand->mem.base == ZYDIS_REGISTER_RIP) if (operand->mem.base == ZYDIS_REGISTER_RIP)
{ {
*address = (ZydisU64)(instruction->instrPointer + operand->mem.disp.value); *address = (ZydisU64)(instruction->instrAddress + instruction->length +
operand->mem.disp.value);
return ZYDIS_STATUS_SUCCESS; return ZYDIS_STATUS_SUCCESS;
} }
if ((operand->mem.base == ZYDIS_REGISTER_NONE) && if ((operand->mem.base == ZYDIS_REGISTER_NONE) &&
@ -81,7 +82,8 @@ ZydisStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
case ZYDIS_OPERAND_TYPE_IMMEDIATE: case ZYDIS_OPERAND_TYPE_IMMEDIATE:
if (operand->imm.isSigned && operand->imm.isRelative) if (operand->imm.isSigned && operand->imm.isRelative)
{ {
*address = (ZydisU64)((ZydisI64)instruction->instrPointer + operand->imm.value.s); *address = (ZydisU64)((ZydisI64)instruction->instrAddress + instruction->length +
operand->imm.value.s);
switch (instruction->machineMode) switch (instruction->machineMode)
{ {
case ZYDIS_MACHINE_MODE_LONG_COMPAT_16: case ZYDIS_MACHINE_MODE_LONG_COMPAT_16: