Skip to content

Formatter: keep disp_padding preset when set to PADDING_AUTO#617

Open
dxbjavid wants to merge 1 commit into
zyantific:masterfrom
dxbjavid:formatter-disp-padding-auto
Open

Formatter: keep disp_padding preset when set to PADDING_AUTO#617
dxbjavid wants to merge 1 commit into
zyantific:masterfrom
dxbjavid:formatter-disp-padding-auto

Conversation

@dxbjavid

Copy link
Copy Markdown
Contributor

A DISP_PADDING of ZYDIS_PADDING_AUTO is resolved to the style preset in ZydisFormatterSetProperty, then immediately overwritten by the unconditional disp_padding = value, so it stays at -1. The AT&T/Intel displacement printers pass disp_padding straight to the number formatter with no AUTO handling (unlike imm/addr), so SetProperty returns SUCCESS but every later format of a memory operand with a displacement fails with INSUFFICIENT_BUFFER_SIZE. Move the assignment into an else.

@mappzor

mappzor commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

It should be noted that ZYDIS_FORMATTER_PROP_IMM_PADDING is handled in the same manner. Putting value overwrite problem aside for a moment let's look at the documentation:

    /**
     * Controls the padding of displacement values.
     *
     * Pass `ZYDIS_PADDING_DISABLED` to disable padding, or any other integer value for custom
     * padding.
     */
    ZYDIS_FORMATTER_PROP_DISP_PADDING,
    /**
     * Controls the padding of immediate values.
     *
     * Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all
     * immediates to the operand-width (hexadecimal only), or any other integer value for custom
     * padding.
     */
    ZYDIS_FORMATTER_PROP_IMM_PADDING,

For ZYDIS_FORMATTER_PROP_DISP_PADDING there's no mention of ZYDIS_PADDING_AUTO at all, so ZYDIS_PADDING_AUTO processing inside ZydisFormatterSetProperty should not exist.
For ZYDIS_FORMATTER_PROP_IMM_PADDING passing ZYDIS_PADDING_AUTO will first use value taken from formatter style preset and overwrite it with ZYDIS_PADDING_AUTO. Actually this overwrite saves the day because ZYDIS_PADDING_AUTO value will eventually reach ZydisFormatterBasePrintIMM which handles ZYDIS_PADDING_AUTO as intended.

Unless I'm misunderstanding the intent here, both cases of "resolve using style preset" are unintended leftovers and should be removed.

@dxbjavid dxbjavid force-pushed the formatter-disp-padding-auto branch from 7113cfc to 952d405 Compare June 4, 2026 17:55
@dxbjavid

dxbjavid commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

You're right, the preset resolution was a leftover in both. Reworked it: DISP_PADDING no longer special-cases AUTO at all, so passing it now gets rejected like any other out-of-range value (matches the docs, and the disp printer doesn't understand AUTO anyway). IMM_PADDING keeps AUTO but just passes it straight through to the field the same way ADDR_PADDING_* already do, since ZydisFormatterBasePrintIMM resolves it. Regression suite still passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants