Zydis  v3.2.0
FormatterBase.h File Reference

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

Include dependency graph for FormatterBase.h:
This graph shows which files directly or indirectly include this file:

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

Typedefs

typedef struct ZydisPredefinedToken_ ZydisPredefinedToken
 

Functions

ZYAN_INLINE ZyanStatus ZydisFormatterBufferAppendPredefined (ZydisFormatterBuffer *buffer, const ZydisPredefinedToken *data)
 Appends a predefined token-list to the buffer. More...
 
ZyanU32 ZydisFormatterHelperGetExplicitSize (const ZydisFormatter *formatter, ZydisFormatterContext *context, ZyanU8 memop_id)
 Returns the size to be used as explicit size suffix (AT&T) or explicit typecast (INTEL), if required. More...
 
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)); \
}
ZYAN_INLINE ZyanStatus ZydisFormatterBufferAppendPredefined(ZydisFormatterBuffer *buffer, const ZydisPredefinedToken *data)
Appends a predefined token-list to the buffer.
Definition: FormatterBase.h:218
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:229

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

Parameters
bufferA pointer to the ZydisFormatterBuffer struct.
nameThe 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)); \
}
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:260

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

Parameters
bufferA pointer to the ZydisFormatterBuffer struct.
nameThe base name (without prefix) of the string- or token.
letter-caseThe 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)); \
}
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
bufferA pointer to the ZydisFormatterBuffer struct.
typeThe 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
bufferA pointer to the ZydisFormatterBuffer struct.
stateReceives 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_sign 
)
Value:
switch (base) \
{ \
ZYAN_CHECK(ZydisStringAppendDecS(str, value, padding_length, force_sign, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
ZYAN_CHECK(ZydisStringAppendHexS(str, value, padding_length, \
(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
Hexadecimal system.
Definition: Formatter.h:346
@ ZYDIS_NUMERIC_BASE_DEC
Decimal system.
Definition: Formatter.h:342
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:361
ZYAN_INLINE ZyanStatus ZydisStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, 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:430

Appends a signed numeric value to the given string.

Parameters
formatterA pointer to the ZydisFormatter instance.
baseThe numeric base.
strThe destination string.
valueThe value.
padding_lengthThe padding length.
force_signForces printing of the '+' sign for positive numbers.

◆ ZYDIS_STRING_APPEND_NUM_U

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

Appends an unsigned numeric value to the given string.

Parameters
formatterA pointer to the ZydisFormatter instance.
baseThe numeric base.
strThe destination string.
valueThe value.
padding_lengthThe padding length.

Typedef Documentation

◆ 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
bufferA pointer to the ZydisFormatterBuffer struct.
dataA 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,
ZyanU8  memop_id 
)

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

Parameters
formatterA pointer to the ZydisFormatter instance.
contextA pointer to the ZydisFormatterContext struct.
memop_idThe operand-id of 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.