Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter improvements (sizes and addresses) #472

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/Zydis/Formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ typedef enum ZydisFormatterProperty_
/**
* Controls the padding of absolute address values.
*
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to padd all
* addresses to the current stack width (hexadecimal only), or any other integer value for
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all
* addresses to the current address width (hexadecimal only), or any other integer value for
* custom padding.
*/
ZYDIS_FORMATTER_PROP_ADDR_PADDING_ABSOLUTE,
/**
* Controls the padding of relative address values.
*
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to padd all
* addresses to the current stack width (hexadecimal only), or any other integer value for
* Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all
* addresses to the current address width (hexadecimal only), or any other integer value for
* custom padding.
*/
ZYDIS_FORMATTER_PROP_ADDR_PADDING_RELATIVE,
Expand Down
9 changes: 7 additions & 2 deletions src/FormatterBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ ZyanU32 ZydisFormatterHelperGetExplicitSize(const ZydisFormatter* formatter,

ZYAN_ASSERT(operand->type == ZYDIS_OPERAND_TYPE_MEMORY);
ZYAN_ASSERT((operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) ||
(operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) ||
(operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB));

if (formatter->force_memory_size)
{
return operand->size;
}
else if (operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN)
{
return 0;
}

if (!context->operands)
{
Expand Down Expand Up @@ -230,7 +235,7 @@ ZyanStatus ZydisFormatterBasePrintAddressABS(const ZydisFormatter* formatter,
if ((formatter->addr_padding_absolute == ZYDIS_PADDING_AUTO) &&
(formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX))
{
switch (context->instruction->stack_width)
switch (context->instruction->address_width)
{
case 16:
padding = 4;
Expand Down Expand Up @@ -270,7 +275,7 @@ ZyanStatus ZydisFormatterBasePrintAddressREL(const ZydisFormatter* formatter,
if ((formatter->addr_padding_relative == ZYDIS_PADDING_AUTO) &&
(formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX))
{
switch (context->instruction->stack_width)
switch (context->instruction->address_width)
{
case 16:
padding = 4;
Expand Down
3 changes: 2 additions & 1 deletion src/FormatterIntel.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,
ZYAN_ASSERT(context);

if ((context->operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) ||
(context->operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) ||
(context->operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB))
{
ZYAN_CHECK(formatter->func_print_typecast(formatter, buffer, context));
Expand Down Expand Up @@ -425,7 +426,7 @@ ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter,
if ((formatter->addr_padding_relative == ZYDIS_PADDING_AUTO) &&
(formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX))
{
switch (context->instruction->stack_width)
switch (context->instruction->address_width)
{
case 16:
padding = 4;
Expand Down
Loading