Zydis: include/Zydis/Internal/FormatterBase.h File Reference

Zydis v4.1.0

Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
FormatterBase.h File Reference

Provides formatter functions that are shared between the different formatters. More...

`#include <Zydis/Formatter.h>`
`#include <Zydis/Internal/String.h>`

Go to the source code of this file.

## Data Structures
struct | ZydisPredefinedToken_

## Macros
#define | ZYDIS_STRING_APPEND_NUM_U(formatter, base, str, value, padding_length, force_leading_number)
| Appends an unsigned numeric value to the given string.
#define | ZYDIS_STRING_APPEND_NUM_S(formatter, base, str, value, padding_length, force_leading_number, force_sign)
| Appends a signed numeric value to the given string.
#define | ZYDIS_BUFFER_APPEND_TOKEN(buffer, type)
| Invokes the `ZydisFormatterBufferAppend` routine, if tokenization is enabled for the current pass.
#define | ZYDIS_BUFFER_REMEMBER(buffer, state)
| Returns a snapshot of the buffer-state.
#define | ZYDIS_BUFFER_APPEND(buffer, name)
| Appends a string (`STR_`-prefix) or a predefined token-list (`TOK_`-prefix).
#define | ZYDIS_BUFFER_APPEND_CASE(buffer, name, letter_case)
| Appends a string (`STR_`-prefix) or a predefined token-list (`TOK_`-prefix).

## Typedefs
typedef struct ZydisPredefinedToken_ | ZydisPredefinedToken

## Functions
ZYAN_INLINE ZyanStatus | ZydisFormatterBufferAppendPredefined (ZydisFormatterBuffer *buffer, const ZydisPredefinedToken *data)
| Appends a predefined token-list to the `buffer`.
ZyanU32 | ZydisFormatterHelperGetExplicitSize (const ZydisFormatter *formatter, ZydisFormatterContext *context, const ZydisDecodedOperand *operand)
| Returns the size to be used as explicit size suffix (`AT&T`) or explicit typecast (`INTEL`), if required.
ZyanStatus | ZydisFormatterBaseFormatOperandREG (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBaseFormatOperandPTR (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBaseFormatOperandIMM (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBasePrintAddressABS (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBasePrintAddressREL (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBasePrintIMM (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBasePrintSegment (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBasePrintPrefixes (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZyanStatus | ZydisFormatterBasePrintDecorator (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisDecorator decorator)

## Detailed Description

Provides formatter functions that are shared between the different formatters.

## Macro Definition Documentation

## ◆ ZYDIS_BUFFER_APPEND

#define ZYDIS_BUFFER_APPEND | ( |  | buffer,
|  |  | name )

Value:
if ((buffer)->is_token_list) \
{ \
ZYAN_CHECK(ZydisFormatterBufferAppendPredefined(buffer, TOK_ ## name)); \
} else \
{ \
ZYAN_CHECK(ZydisStringAppendShort(&buffer->string, &STR_ ## name)); \
}
ZydisFormatterBufferAppendPredefined
ZYAN_INLINE ZyanStatus ZydisFormatterBufferAppendPredefined(ZydisFormatterBuffer *buffer, const ZydisPredefinedToken *data)
Appends a predefined token-list to the buffer.
Definition FormatterBase.h:224
ZydisStringAppendShort
ZYAN_INLINE ZyanStatus ZydisStringAppendShort(ZyanString *destination, const ZydisShortString *source)
Appends the content of the source short-string to the end of the destination string.
Definition String.h:231

Appends a string (`STR_`-prefix) or a predefined token-list (`TOK_`-prefix).

Parameters

  buffer | A pointer to the `ZydisFormatterBuffer` struct.
  name | The base name (without prefix) of the string- or token.

## ◆ ZYDIS_BUFFER_APPEND_CASE

#define ZYDIS_BUFFER_APPEND_CASE | ( |  | buffer,
|  |  | name,
|  |  | letter_case )

Value:
if ((buffer)->is_token_list) \
{ \
ZYAN_CHECK(ZydisFormatterBufferAppendPredefined(buffer, TOK_ ## name)); \
} else \
{ \
ZYAN_CHECK(ZydisStringAppendShortCase(&buffer->string, &STR_ ## name, letter_case)); \
}
ZydisStringAppendShortCase
ZYAN_INLINE ZyanStatus ZydisStringAppendShortCase(ZyanString *destination, const ZydisShortString *source, ZydisLetterCase letter_case)
Appends the content of the source short-string to the end of the destination string,...
Definition String.h:262

Appends a string (`STR_`-prefix) or a predefined token-list (`TOK_`-prefix).

Parameters

  buffer | A pointer to the `ZydisFormatterBuffer` struct.
  name | The base name (without prefix) of the string- or token.
  letter_case | The desired letter-case.

## ◆ ZYDIS_BUFFER_APPEND_TOKEN

#define ZYDIS_BUFFER_APPEND_TOKEN | ( |  | buffer,
|  |  | type )

Value:
if ((buffer)->is_token_list) \
{ \
ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, type)); \
}
ZydisFormatterBufferAppend
ZYDIS_EXPORT ZyanStatus ZydisFormatterBufferAppend(ZydisFormatterBuffer *buffer, ZydisTokenType type)
Appends a new token to the buffer.

Invokes the `ZydisFormatterBufferAppend` routine, if tokenization is enabled for the current pass.

Parameters

  buffer | A pointer to the `ZydisFormatterBuffer` struct.
  type | The token type.

Using this macro instead of direct calls to `ZydisFormatterBufferAppend` greatly improves the performance for non-tokenizing passes.

## ◆ ZYDIS_BUFFER_REMEMBER

#define ZYDIS_BUFFER_REMEMBER | ( |  | buffer,
|  |  | state )

Value:
if ((buffer)->is_token_list) \
{ \
(state) = (ZyanUPointer)(buffer)->string.vector.data; \
} else \
{ \
(state) = (ZyanUPointer)(buffer)->string.vector.size; \
}

Returns a snapshot of the buffer-state.

Parameters

  buffer | A pointer to the `ZydisFormatterBuffer` struct.
  state | Receives a snapshot of the buffer-state.

Using this macro instead of direct calls to `ZydisFormatterBufferRemember` improves the performance for non-tokenizing passes.

## ◆ ZYDIS_STRING_APPEND_NUM_S

#define ZYDIS_STRING_APPEND_NUM_S | ( |  | formatter,
|  |  | base,
|  |  | str,
|  |  | value,
|  |  | padding_length,
|  |  | force_leading_number,
|  |  | force_sign )

Value:
switch (base) \
{ \
case ZYDIS_NUMERIC_BASE_DEC: \
ZYAN_CHECK(ZydisStringAppendDecS(str, value, padding_length, force_sign, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
case ZYDIS_NUMERIC_BASE_HEX: \
ZYAN_CHECK(ZydisStringAppendHexS(str, value, padding_length, force_leading_number, \
(formatter)->hex_uppercase, force_sign, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
default: \
return ZYAN_STATUS_INVALID_ARGUMENT; \
}
ZYDIS_NUMERIC_BASE_HEX
@ ZYDIS_NUMERIC_BASE_HEX
Hexadecimal system.
Definition Formatter.h:358
ZYDIS_NUMERIC_BASE_DEC
@ ZYDIS_NUMERIC_BASE_DEC
Decimal system.
Definition Formatter.h:354
ZydisStringAppendHexS
ZYAN_INLINE ZyanStatus ZydisStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_leading_number, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given signed ordinal value to its hexadecimal text-representation and appends it to the s...
Definition String.h:435
ZydisStringAppendDecS
ZYAN_INLINE ZyanStatus ZydisStringAppendDecS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given signed ordinal value to its decimal text-representation and appends it to the strin...
Definition String.h:363

Appends a signed numeric value to the given string.

Parameters

  formatter | A pointer to the `ZydisFormatter` instance.
  base | The numeric base.
  str | The destination string.
  value | The value to append.
  padding_length | The padding length.
  force_leading_number | Enable this option to prepend a leading `0`, if the first character is non-numeric.
  force_sign | Enable to print the '+' sign for positive numbers.

## ◆ ZYDIS_STRING_APPEND_NUM_U

#define ZYDIS_STRING_APPEND_NUM_U | ( |  | formatter,
|  |  | base,
|  |  | str,
|  |  | value,
|  |  | padding_length,
|  |  | force_leading_number )

Value:
switch (base) \
{ \
case ZYDIS_NUMERIC_BASE_DEC: \
ZYAN_CHECK(ZydisStringAppendDecU(str, value, padding_length, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
case ZYDIS_NUMERIC_BASE_HEX: \
ZYAN_CHECK(ZydisStringAppendHexU(str, value, padding_length, force_leading_number, \
(formatter)->hex_uppercase, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
default: \
return ZYAN_STATUS_INVALID_ARGUMENT; \
}
ZydisStringAppendDecU
ZyanStatus ZydisStringAppendDecU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given unsigned ordinal value to its decimal text-representation and appends it to the str...
ZydisStringAppendHexU
ZyanStatus ZydisStringAppendHexU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, ZyanBool force_leading_number, ZyanBool uppercase, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given unsigned ordinal value to its hexadecimal text-representation and appends it to the...

Appends an unsigned numeric value to the given string.

Parameters

  formatter | A pointer to the `ZydisFormatter` instance.
  base | The numeric base.
  str | The destination string.
  value | The value to append.
  padding_length | The padding length.
  force_leading_number | Enable this option to prepend a leading `0` if the first character is non-numeric.

## Typedef Documentation

## ◆ ZydisPredefinedToken

typedef struct ZydisPredefinedToken_ ZydisPredefinedToken

## Function Documentation

## ◆ ZydisFormatterBaseFormatOperandIMM()

ZyanStatus ZydisFormatterBaseFormatOperandIMM | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBaseFormatOperandPTR()

ZyanStatus ZydisFormatterBaseFormatOperandPTR | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBaseFormatOperandREG()

ZyanStatus ZydisFormatterBaseFormatOperandREG | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBasePrintAddressABS()

ZyanStatus ZydisFormatterBasePrintAddressABS | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBasePrintAddressREL()

ZyanStatus ZydisFormatterBasePrintAddressREL | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBasePrintDecorator()

ZyanStatus ZydisFormatterBasePrintDecorator | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context,
|  | ZydisDecorator | decorator )

## ◆ ZydisFormatterBasePrintIMM()

ZyanStatus ZydisFormatterBasePrintIMM | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBasePrintPrefixes()

ZyanStatus ZydisFormatterBasePrintPrefixes | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBasePrintSegment()

ZyanStatus ZydisFormatterBasePrintSegment | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterBuffer * | buffer,
|  | ZydisFormatterContext * | context )

## ◆ ZydisFormatterBufferAppendPredefined()

ZYAN_INLINE ZyanStatus ZydisFormatterBufferAppendPredefined | ( | ZydisFormatterBuffer * | buffer,
|  | const ZydisPredefinedToken * | data )

Appends a predefined token-list to the `buffer`.

Parameters

  buffer | A pointer to the `ZydisFormatterBuffer` struct.
  data | A pointer to the `ZydisPredefinedToken` struct.

Returns
  A zycore status code.

This function is internally used to improve performance while adding static strings or multiple tokens at once.

## ◆ ZydisFormatterHelperGetExplicitSize()

ZyanU32 ZydisFormatterHelperGetExplicitSize | ( | const ZydisFormatter * | formatter,
|  | ZydisFormatterContext * | context,
|  | const ZydisDecodedOperand * | operand )

Returns the size to be used as explicit size suffix (`AT&T`) or explicit typecast (`INTEL`), if required.

Parameters

  formatter | A pointer to the `ZydisFormatter` instance.
  context | A pointer to the `ZydisFormatterContext` struct.
  operand | The instructions first memory operand.

Returns
  Returns the explicit size, if required, or `0`, if not needed.

This function always returns a size different to `0`, if the `ZYDIS_FORMATTER_PROP_FORCE_SIZE` is set to `ZYAN_TRUE`.