Skip to content

Commit

Permalink
Utils: Handle OPERAND_TYPE_REGISTER in ZydisCalcAbsoluteAddressEx (
Browse files Browse the repository at this point in the history
  • Loading branch information
waddlesplash authored Aug 6, 2024
1 parent 16c6a36 commit af792c4
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,36 @@ ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction* instruction
return ZYAN_STATUS_INVALID_ARGUMENT;
}

if ((operand->type != ZYDIS_OPERAND_TYPE_MEMORY) ||
if ((operand->type != ZYDIS_OPERAND_TYPE_REGISTER) &&
((operand->type != ZYDIS_OPERAND_TYPE_MEMORY) ||
((operand->mem.base == ZYDIS_REGISTER_NONE) &&
(operand->mem.index == ZYDIS_REGISTER_NONE)) ||
(operand->mem.base == ZYDIS_REGISTER_EIP) ||
(operand->mem.base == ZYDIS_REGISTER_RIP))
(operand->mem.base == ZYDIS_REGISTER_RIP)))
{
return ZydisCalcAbsoluteAddress(instruction, operand, runtime_address, result_address);
}

ZyanU64 value = operand->mem.disp.value;
if (operand->mem.base)
ZyanU64 value;
if (operand->type == ZYDIS_OPERAND_TYPE_REGISTER)
{
value += register_context->values[operand->mem.base];
value = register_context->values[operand->reg.value];
}
if (operand->mem.index)
else if (operand->type == ZYDIS_OPERAND_TYPE_MEMORY)
{
value += register_context->values[operand->mem.index] * operand->mem.scale;
value = operand->mem.disp.value;
if (operand->mem.base)
{
value += register_context->values[operand->mem.base];
}
if (operand->mem.index)
{
value += register_context->values[operand->mem.index] * operand->mem.scale;
}
}
else
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}

switch (instruction->address_width)
Expand Down

0 comments on commit af792c4

Please sign in to comment.