Skip to content

Commit

Permalink
replacing has_displacement with size
Browse files Browse the repository at this point in the history
  • Loading branch information
NaC-L committed Mar 2, 2024
1 parent e6f6116 commit 1b7619e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions examples/Disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int main(void)

offset += instruction.length;
runtime_address += instruction.length;

}

return 0;
Expand Down
9 changes: 3 additions & 6 deletions include/Zydis/DecoderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,16 @@ typedef struct ZydisDecodedOperandMem_
*/
struct ZydisDecodedOperandMemDisp_
{
/**
* Signals, if the displacement value is used.
*/
ZyanBool has_displacement;

/**
* The displacement value
*/
ZyanI64 value;

/**
* size of the displacement value
* The size of the displacement value
*/
ZyanU16 size;
ZyanU8 size;
} disp;
} ZydisDecodedOperandMem;

Expand Down
2 changes: 0 additions & 2 deletions src/Decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,6 @@ static ZyanStatus ZydisDecodeOperandMemory(const ZydisDecoderContext* context,
if (displacement_size)
{
ZYAN_ASSERT(instruction->raw.disp.size == displacement_size);
operand->mem.disp.has_displacement = ZYAN_TRUE;
operand->mem.disp.value = instruction->raw.disp.value;
operand->mem.disp.size = displacement_size;
}
Expand Down Expand Up @@ -1830,7 +1829,6 @@ static ZyanStatus ZydisDecodeOperands(const ZydisDecoder* decoder, const ZydisDe
ZYAN_ASSERT(instruction->raw.disp.size);
operands[i].type = ZYDIS_OPERAND_TYPE_MEMORY;
operands[i].mem.type = ZYDIS_MEMOP_TYPE_MEM;
operands[i].mem.disp.has_displacement = ZYAN_TRUE;
operands[i].mem.disp.size = instruction->raw.disp.size;
operands[i].mem.disp.value = instruction->raw.disp.value;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4705,7 +4705,7 @@ ZYDIS_EXPORT ZyanStatus ZydisEncoderDecodedInstructionToEncoderRequest(
enc_op->mem.base = dec_op->mem.base;
enc_op->mem.index = dec_op->mem.index;
enc_op->mem.scale = dec_op->mem.type != ZYDIS_MEMOP_TYPE_MIB ? dec_op->mem.scale : 0;
if (dec_op->mem.disp.has_displacement)
if (dec_op->mem.disp.size)
{
enc_op->mem.displacement = dec_op->mem.disp.value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/FormatterATT.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter,

const ZyanBool absolute = !formatter->force_relative_riprel &&
(context->runtime_address != ZYDIS_RUNTIME_ADDRESS_NONE);
if (absolute && context->operand->mem.disp.has_displacement &&
if (absolute && context->operand->mem.disp.size &&
(context->operand->mem.index == ZYDIS_REGISTER_NONE) &&
((context->operand->mem.base == ZYDIS_REGISTER_NONE) ||
(context->operand->mem.base == ZYDIS_REGISTER_EIP ) ||
Expand All @@ -226,7 +226,7 @@ ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter,
if (neither_reg_nor_idx)
{
ZYAN_CHECK(formatter->func_print_address_abs(formatter, buffer, context));
} else if (context->operand->mem.disp.has_displacement && context->operand->mem.disp.value)
} else if (context->operand->mem.disp.size && context->operand->mem.disp.value)
{
ZYAN_CHECK(formatter->func_print_disp(formatter, buffer, context));
}
Expand Down
4 changes: 2 additions & 2 deletions src/FormatterIntel.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,

const ZyanBool absolute = !formatter->force_relative_riprel &&
(context->runtime_address != ZYDIS_RUNTIME_ADDRESS_NONE);
if (absolute && context->operand->mem.disp.has_displacement &&
if (absolute && context->operand->mem.disp.size &&
(context->operand->mem.index == ZYDIS_REGISTER_NONE) &&
((context->operand->mem.base == ZYDIS_REGISTER_NONE) ||
(context->operand->mem.base == ZYDIS_REGISTER_EIP ) ||
Expand Down Expand Up @@ -253,7 +253,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,
if (neither_reg_nor_idx)
{
ZYAN_CHECK(formatter->func_print_address_abs(formatter, buffer, context));
} else if (context->operand->mem.disp.has_displacement && context->operand->mem.disp.value)
} else if (context->operand->mem.disp.size && context->operand->mem.disp.value)
{
ZYAN_CHECK(formatter->func_print_disp(formatter, buffer, context));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
switch (operand->type)
{
case ZYDIS_OPERAND_TYPE_MEMORY:
if (!operand->mem.disp.has_displacement)
if (!operand->mem.disp.size)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
Expand Down

0 comments on commit 1b7619e

Please sign in to comment.