|
Zydis v4.1.1
|
Functions for formatting instructions to human-readable text. More...
#include <Zycore/Defines.h>#include <Zycore/String.h>#include <Zycore/Types.h>#include <Zydis/DecoderTypes.h>#include <Zydis/FormatterBuffer.h>Go to the source code of this file.
Data Structures | |
| struct | ZydisFormatterContext_ |
| Context structure that that is passed to all formatter. More... | |
| struct | ZydisFormatter_ |
| Context structure keeping track of internal state of the formatter. More... | |
Macros | |
| #define | ZYDIS_RUNTIME_ADDRESS_NONE (ZyanU64)(-1) |
| Use this constant as value for runtime_address in ZydisFormatterFormatInstruction(Ex) or ZydisFormatterFormatOperand(Ex) to print relative values for all addresses. | |
Typedefs | |
| typedef enum ZydisFormatterStyle_ | ZydisFormatterStyle |
| Enum selecting the syntax to format the disassembly in. | |
| typedef enum ZydisFormatterProperty_ | ZydisFormatterProperty |
| Enum selecting a property of the formatter. | |
| typedef enum ZydisNumericBase_ | ZydisNumericBase |
| Enum defining different mantissae to be used during formatting. | |
| typedef enum ZydisSignedness_ | ZydisSignedness |
| Enum defining the signeness of integers to be used during formatting. | |
| typedef enum ZydisPadding_ | ZydisPadding |
| Enum definining magic values that receive special treatment when used as padding properties of the formatter. | |
| typedef enum ZydisFormatterFunction_ | ZydisFormatterFunction |
| Enum selecting a formatter function to be replaced with hooks. | |
| typedef enum ZydisDecorator_ | ZydisDecorator |
| Enum of all decorator types. | |
| typedef struct ZydisFormatter_ | ZydisFormatter |
| typedef struct ZydisFormatterContext_ | ZydisFormatterContext |
| Context structure that that is passed to all formatter. | |
| typedef ZyanStatus(* | ZydisFormatterFunc) (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context) |
| Defines the ZydisFormatterFunc function prototype. | |
| typedef ZyanStatus(* | ZydisFormatterRegisterFunc) (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisRegister reg) |
| Defines the ZydisFormatterRegisterFunc function prototype. | |
| typedef ZyanStatus(* | ZydisFormatterDecoratorFunc) (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisDecorator decorator) |
| Defines the ZydisFormatterDecoratorFunc function prototype. | |
Functions | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterInit (ZydisFormatter *formatter, ZydisFormatterStyle style) |
| Initializes the given ZydisFormatter instance. | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterSetProperty (ZydisFormatter *formatter, ZydisFormatterProperty property, ZyanUPointer value) |
| Changes the value of the specified formatter property. | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterSetHook (ZydisFormatter *formatter, ZydisFormatterFunction type, const void **callback) |
| Replaces a formatter function with a custom callback and/or retrieves the currently used function. | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterFormatInstruction (const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operands, ZyanU8 operand_count, char *buffer, ZyanUSize length, ZyanU64 runtime_address, void *user_data) |
| Formats the given instruction and writes it into the output buffer. | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterFormatOperand (const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, char *buffer, ZyanUSize length, ZyanU64 runtime_address, void *user_data) |
| Formats the given operand and writes it into the output buffer. | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterTokenizeInstruction (const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operands, ZyanU8 operand_count, void *buffer, ZyanUSize length, ZyanU64 runtime_address, ZydisFormatterTokenConst **token, void *user_data) |
| Tokenizes the given instruction and writes it into the output buffer. | |
| ZYDIS_EXPORT ZyanStatus | ZydisFormatterTokenizeOperand (const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, void *buffer, ZyanUSize length, ZyanU64 runtime_address, ZydisFormatterTokenConst **token, void *user_data) |
| Tokenizes the given operand and writes it into the output buffer. | |
Functions for formatting instructions to human-readable text.
| #define ZYDIS_RUNTIME_ADDRESS_NONE (ZyanU64)(-1) |
Use this constant as value for runtime_address in ZydisFormatterFormatInstruction(Ex) or ZydisFormatterFormatOperand(Ex) to print relative values for all addresses.
| typedef enum ZydisDecorator_ ZydisDecorator |
Enum of all decorator types.
| typedef struct ZydisFormatter_ ZydisFormatter |
| typedef struct ZydisFormatterContext_ ZydisFormatterContext |
Context structure that that is passed to all formatter.
| typedef ZyanStatus(* ZydisFormatterDecoratorFunc) (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisDecorator decorator) |
Defines the ZydisFormatterDecoratorFunc function prototype.
| Formatter | A pointer to the ZydisFormatter instance. |
| buffer | A pointer to the ZydisFormatterBuffer struct. |
| context | A pointer to the ZydisFormatterContext struct. |
| decorator | The decorator type. |
This function type is used for:
| typedef ZyanStatus(* ZydisFormatterFunc) (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context) |
Defines the ZydisFormatterFunc function prototype.
| Formatter | A pointer to the ZydisFormatter instance. |
| buffer | A pointer to the ZydisFormatterBuffer struct. |
| context | A pointer to the ZydisFormatterContext struct. |
Returning a status code other than ZYAN_STATUS_SUCCESS will immediately cause the formatting process to fail (see exceptions below).
Returning ZYDIS_STATUS_SKIP_TOKEN is valid for functions of the following types and will instruct the formatter to omit the whole operand:
This function prototype is used by functions of the following types:
| typedef enum ZydisFormatterFunction_ ZydisFormatterFunction |
Enum selecting a formatter function to be replaced with hooks.
Do NOT change the order of the values this enum or the function fields inside the ZydisFormatter struct.
| typedef enum ZydisFormatterProperty_ ZydisFormatterProperty |
Enum selecting a property of the formatter.
| typedef ZyanStatus(* ZydisFormatterRegisterFunc) (const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisRegister reg) |
Defines the ZydisFormatterRegisterFunc function prototype.
| Formatter | A pointer to the ZydisFormatter instance. |
| buffer | A pointer to the ZydisFormatterBuffer struct. |
| context | A pointer to the ZydisFormatterContext struct. |
| reg | The register. |
This function prototype is used by functions of the following types:
| typedef enum ZydisFormatterStyle_ ZydisFormatterStyle |
Enum selecting the syntax to format the disassembly in.
| typedef enum ZydisNumericBase_ ZydisNumericBase |
Enum defining different mantissae to be used during formatting.
| typedef enum ZydisPadding_ ZydisPadding |
Enum definining magic values that receive special treatment when used as padding properties of the formatter.
| typedef enum ZydisSignedness_ ZydisSignedness |
Enum defining the signeness of integers to be used during formatting.
| enum ZydisDecorator_ |
Enum of all decorator types.
Enum selecting a formatter function to be replaced with hooks.
Do NOT change the order of the values this enum or the function fields inside the ZydisFormatter struct.
| Enumerator | |
|---|---|
| ZYDIS_FORMATTER_FUNC_PRE_INSTRUCTION | This function is invoked before the formatter formats an instruction. |
| ZYDIS_FORMATTER_FUNC_POST_INSTRUCTION | This function is invoked after the formatter formatted an instruction. |
| ZYDIS_FORMATTER_FUNC_FORMAT_INSTRUCTION | This function refers to the main formatting function. Replacing this function allows for complete custom formatting, but indirectly disables all other hooks except for ZYDIS_FORMATTER_FUNC_PRE_INSTRUCTION and ZYDIS_FORMATTER_FUNC_POST_INSTRUCTION. |
| ZYDIS_FORMATTER_FUNC_PRE_OPERAND | This function is invoked before the formatter formats an operand. |
| ZYDIS_FORMATTER_FUNC_POST_OPERAND | This function is invoked after the formatter formatted an operand. |
| ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_REG | This function is invoked to format a register operand. |
| ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_MEM | This function is invoked to format a memory operand. Replacing this function might indirectly disable some specific calls to the ZYDIS_FORMATTER_FUNC_PRINT_TYPECAST, ZYDIS_FORMATTER_FUNC_PRINT_SEGMENT, ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS and ZYDIS_FORMATTER_FUNC_PRINT_DISP functions. |
| ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_PTR | This function is invoked to format a pointer operand. |
| ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_IMM | This function is invoked to format an immediate operand. Replacing this function might indirectly disable some specific calls to the ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS, ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_REL and ZYDIS_FORMATTER_FUNC_PRINT_IMM functions. |
| ZYDIS_FORMATTER_FUNC_PRINT_MNEMONIC | This function is invoked to print the instruction mnemonic. |
| ZYDIS_FORMATTER_FUNC_PRINT_REGISTER | This function is invoked to print a register. |
| ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS | This function is invoked to print absolute addresses. Conditionally invoked, if a runtime-address different to ZYDIS_RUNTIME_ADDRESS_NONE was passed:
Always invoked for:
|
| ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_REL | This function is invoked to print relative addresses. Conditionally invoked, if ZYDIS_RUNTIME_ADDRESS_NONE was passed as runtime-address:
|
| ZYDIS_FORMATTER_FUNC_PRINT_DISP | This function is invoked to print a memory displacement value. If the memory displacement contains an address and a runtime-address different to ZYDIS_RUNTIME_ADDRESS_NONE was passed, ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS is called instead. |
| ZYDIS_FORMATTER_FUNC_PRINT_IMM | This function is invoked to print an immediate value. If the immediate contains an address and a runtime-address different to ZYDIS_RUNTIME_ADDRESS_NONE was passed, ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS is called instead. If the immediate contains an address and ZYDIS_RUNTIME_ADDRESS_NONE was passed as runtime-address, ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_REL is called instead. |
| ZYDIS_FORMATTER_FUNC_PRINT_TYPECAST | This function is invoked to print the size of a memory operand (INTEL only). |
| ZYDIS_FORMATTER_FUNC_PRINT_SEGMENT | This function is invoked to print the segment-register of a memory operand. |
| ZYDIS_FORMATTER_FUNC_PRINT_PREFIXES | This function is invoked to print the instruction prefixes. |
| ZYDIS_FORMATTER_FUNC_PRINT_DECORATOR | This function is invoked after formatting an operand to print a EVEX/MVEX decorator. |
| ZYDIS_FORMATTER_FUNC_MAX_VALUE | Maximum value of this enum. |
| ZYDIS_FORMATTER_FUNC_REQUIRED_BITS | The minimum number of bits required to represent all values of this enum. |
Enum selecting a property of the formatter.
| Enumerator | |
|---|---|
| ZYDIS_FORMATTER_PROP_FORCE_SIZE | Controls the printing of effective operand-size suffixes (AT&T) or operand-sizes of memory operands (INTEL). Pass ZYAN_TRUE as value to force the formatter to always print the size, or ZYAN_FALSE to only print it if needed. |
| ZYDIS_FORMATTER_PROP_FORCE_SEGMENT | Controls the printing of segment prefixes. Pass ZYAN_TRUE as value to force the formatter to always print the segment register of memory-operands or ZYAN_FALSE to omit implicit DS/SS segments. |
| ZYDIS_FORMATTER_PROP_FORCE_SCALE_ONE | Controls the printing of the scale-factor component for memory operands. Pass ZYAN_TRUE as value to force the formatter to always print the scale-factor component of memory operands or ZYAN_FALSE to omit the scale factor for values of 1. |
| ZYDIS_FORMATTER_PROP_FORCE_RELATIVE_BRANCHES | Controls the printing of branch addresses. Pass ZYAN_TRUE as value to force the formatter to always print relative branch addresses or ZYAN_FALSE to use absolute addresses, if a runtime-address different to ZYDIS_RUNTIME_ADDRESS_NONE was passed. |
| ZYDIS_FORMATTER_PROP_FORCE_RELATIVE_RIPREL | Controls the printing of EIP/RIP-relative addresses. Pass ZYAN_TRUE as value to force the formatter to always print relative addresses for EIP/RIP-relative operands or ZYAN_FALSE to use absolute addresses, if a runtime- address different to ZYDIS_RUNTIME_ADDRESS_NONE was passed. |
| ZYDIS_FORMATTER_PROP_PRINT_BRANCH_SIZE | Controls the printing of branch-instructions sizes. Pass ZYAN_TRUE as value to print the size (short, near) of branch instructions or ZYAN_FALSE to hide it. Note that the far/l modifier is always printed. |
| ZYDIS_FORMATTER_PROP_DETAILED_PREFIXES | Controls the printing of instruction prefixes. Pass ZYAN_TRUE as value to print all instruction-prefixes (even ignored or duplicate ones) or ZYAN_FALSE to only print prefixes that are effectively used by the instruction. |
| ZYDIS_FORMATTER_PROP_ADDR_BASE | Controls the base of address values. |
| ZYDIS_FORMATTER_PROP_ADDR_SIGNEDNESS | Controls the signedness of relative addresses. Absolute addresses are always unsigned. |
| ZYDIS_FORMATTER_PROP_ADDR_PADDING_ABSOLUTE | Controls the padding of absolute address values. 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 | Controls the padding of relative address values. 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_DISP_BASE | Controls the base of displacement values. |
| ZYDIS_FORMATTER_PROP_DISP_SIGNEDNESS | Controls the signedness of displacement values. |
| ZYDIS_FORMATTER_PROP_DISP_PADDING | Controls the padding of displacement values. Pass ZYDIS_PADDING_DISABLED to disable padding, or any other integer value for custom padding. |
| ZYDIS_FORMATTER_PROP_IMM_BASE | Controls the base of immediate values. |
| ZYDIS_FORMATTER_PROP_IMM_SIGNEDNESS | Controls the signedness of immediate values. Pass ZYDIS_SIGNEDNESS_AUTO to automatically choose the most suitable mode based on the operands ZydisDecodedOperand.imm.is_signed attribute. |
| ZYDIS_FORMATTER_PROP_IMM_PADDING | Controls the padding of immediate values. Pass ZYDIS_PADDING_DISABLED to disable padding, ZYDIS_PADDING_AUTO to padd all immediates to the operand-width (hexadecimal only), or any other integer value for custom padding. |
| ZYDIS_FORMATTER_PROP_UPPERCASE_PREFIXES | Controls the letter-case for prefixes. Pass ZYAN_TRUE as value to format in uppercase or ZYAN_FALSE to format in lowercase. |
| ZYDIS_FORMATTER_PROP_UPPERCASE_MNEMONIC | Controls the letter-case for the mnemonic. Pass ZYAN_TRUE as value to format in uppercase or ZYAN_FALSE to format in lowercase. |
| ZYDIS_FORMATTER_PROP_UPPERCASE_REGISTERS | Controls the letter-case for registers. Pass ZYAN_TRUE as value to format in uppercase or ZYAN_FALSE to format in lowercase. |
| ZYDIS_FORMATTER_PROP_UPPERCASE_TYPECASTS | Controls the letter-case for typecasts. Pass ZYAN_TRUE as value to format in uppercase or ZYAN_FALSE to format in lowercase. |
| ZYDIS_FORMATTER_PROP_UPPERCASE_DECORATORS | Controls the letter-case for decorators. Pass ZYAN_TRUE as value to format in uppercase or ZYAN_FALSE to format in lowercase. WARNING: this is currently not implemented (ignored). |
| ZYDIS_FORMATTER_PROP_DEC_PREFIX | Controls the prefix for decimal values. Pass a pointer to a null-terminated C-style string with a maximum length of 10 characters to set a custom prefix, or ZYAN_NULL to disable it. The string is deep-copied into an internal buffer. |
| ZYDIS_FORMATTER_PROP_DEC_SUFFIX | Controls the suffix for decimal values. Pass a pointer to a null-terminated C-style string with a maximum length of 10 characters to set a custom suffix, or ZYAN_NULL to disable it. The string is deep-copied into an internal buffer. |
| ZYDIS_FORMATTER_PROP_HEX_UPPERCASE | Controls the letter-case of hexadecimal values. Pass ZYAN_TRUE as value to format in uppercase and ZYAN_FALSE to format in lowercase. The default value is ZYAN_TRUE. |
| ZYDIS_FORMATTER_PROP_HEX_FORCE_LEADING_NUMBER | Controls whether to prepend hexadecimal values with a leading zero if the first character is non-numeric. Pass ZYAN_TRUE to prepend a leading zero if the first character is non-numeric or ZYAN_FALSE to disable this functionality. The default value is ZYAN_FALSE. |
| ZYDIS_FORMATTER_PROP_HEX_PREFIX | Controls the prefix for hexadecimal values. Pass a pointer to a null-terminated C-style string with a maximum length of 10 characters to set a custom prefix, or ZYAN_NULL to disable it. The string is deep-copied into an internal buffer. |
| ZYDIS_FORMATTER_PROP_HEX_SUFFIX | Controls the suffix for hexadecimal values. Pass a pointer to a null-terminated C-style string with a maximum length of 10 characters to set a custom suffix, or ZYAN_NULL to disable it. The string is deep-copied into an internal buffer. |
| ZYDIS_FORMATTER_PROP_MAX_VALUE | Maximum value of this enum. |
| ZYDIS_FORMATTER_PROP_REQUIRED_BITS | The minimum number of bits required to represent all values of this enum. |
| enum ZydisFormatterStyle_ |
Enum selecting the syntax to format the disassembly in.
| enum ZydisNumericBase_ |
Enum defining different mantissae to be used during formatting.
| enum ZydisPadding_ |
Enum definining magic values that receive special treatment when used as padding properties of the formatter.
| enum ZydisSignedness_ |
Enum defining the signeness of integers to be used during formatting.