Zydis  v2.0.0-alpha2
Formatter.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 
3  Zyan Disassembler Library (Zydis)
4 
5  Original Author : Florian Bernd
6 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24 
25 ***************************************************************************************************/
26 
32 #ifndef ZYDIS_FORMATTER_H
33 #define ZYDIS_FORMATTER_H
34 
35 #include <Zydis/DecoderTypes.h>
36 #include <Zydis/Defines.h>
37 #include <Zydis/Status.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /* ============================================================================================== */
44 /* Enums and types */
45 /* ============================================================================================== */
46 
50 typedef uint8_t ZydisFormatterStyle;
51 
56 {
65 };
66 
67 /* ---------------------------------------------------------------------------------------------- */
68 
72 typedef uint32_t ZydisFormatterFlags;
73 
77 #define ZYDIS_FMTFLAG_UPPERCASE 0x00000001 // (1 << 0)
82 #define ZYDIS_FMTFLAG_FORCE_SEGMENTS 0x00000002 // (1 << 1)
86 #define ZYDIS_FMTFLAG_FORCE_OPERANDSIZE 0x00000004 // (1 << 2)
87 
88 /* ---------------------------------------------------------------------------------------------- */
89 
94 
99 {
128 };
129 
130 /* ---------------------------------------------------------------------------------------------- */
131 
136 
141 {
166 };
167 
168 /* ---------------------------------------------------------------------------------------------- */
169 
174 
179 {
209 };
210 
211 /* ---------------------------------------------------------------------------------------------- */
212 
216 typedef uint8_t ZydisFormatterHookType;
217 
222 {
301 };
302 
303 /* ---------------------------------------------------------------------------------------------- */
304 
308 typedef uint8_t ZydisDecoratorType;
309 
314 {
327 };
328 
329 typedef struct ZydisFormatter_ ZydisFormatter;
330 
345  const ZydisDecodedInstruction* instruction, void* userData);
346 
366  char** buffer, size_t bufferLen, const ZydisDecodedInstruction* instruction, void* userData);
367 
403  char** buffer, size_t bufferLen, const ZydisDecodedInstruction* instruction,
404  const ZydisDecodedOperand* operand, void* userData);
405 
426  char** buffer, size_t bufferLen, const ZydisDecodedInstruction* instruction,
427  const ZydisDecodedOperand* operand, uint64_t address, void* userData);
428 
452  char** buffer, size_t bufferLen, const ZydisDecodedInstruction* instruction,
453  const ZydisDecodedOperand* operand, ZydisDecoratorType type, void* userData);
454 
459 {
479 };
480 
481 /* ============================================================================================== */
482 /* Exported functions */
483 /* ============================================================================================== */
484 
494 
507  ZydisFormatterFlags flags, ZydisFormatterAddressFormat addressFormat,
508  ZydisFormatterDisplacementFormat displacementFormat,
509  ZydisFormatterImmediateFormat immmediateFormat);
510 
526  ZydisFormatterHookType hook, const void** callback);
527 
539  ZydisDecodedInstruction* instruction, char* buffer, size_t bufferLen);
540 
554  ZydisDecodedInstruction* instruction, char* buffer, size_t bufferLen, void* userData);
555 
556 /* ============================================================================================== */
557 
558 #ifdef __cplusplus
559 }
560 #endif
561 
562 #endif /* ZYDIS_FORMATTER_H */
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
General helper and platform detection macros.
ZydisDecoratorTypes
Values that represent decorator-types.
Definition: Formatter.h:314
@ ZYDIS_DECORATOR_TYPE_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:326
@ ZYDIS_DECORATOR_TYPE_SAE
Definition: Formatter.h:319
@ ZYDIS_DECORATOR_TYPE_EVICTION_HINT
Definition: Formatter.h:322
@ ZYDIS_DECORATOR_TYPE_INVALID
Definition: Formatter.h:315
@ ZYDIS_DECORATOR_TYPE_BROADCAST
Definition: Formatter.h:317
@ ZYDIS_DECORATOR_TYPE_MASK
Definition: Formatter.h:316
@ ZYDIS_DECORATOR_TYPE_CONVERSION
Definition: Formatter.h:321
@ ZYDIS_DECORATOR_TYPE_SWIZZLE
Definition: Formatter.h:320
@ ZYDIS_DECORATOR_TYPE_ROUNDING_CONTROL
Definition: Formatter.h:318
ZydisStatus(* ZydisFormatterFormatOperandFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, void *userData)
Defines the ZydisFormatterFormatOperandFunc function pointer.
Definition: Formatter.h:402
ZydisStatus(* ZydisFormatterFormatFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, const ZydisDecodedInstruction *instruction, void *userData)
Defines the ZydisFormatterFormatFunc function pointer.
Definition: Formatter.h:365
ZydisFormatterAddressFormats
Values that represent address-formats.
Definition: Formatter.h:99
@ ZYDIS_FORMATTER_ADDR_RELATIVE_SIGNED
Uses signed hexadecimal values to display relative addresses.
Definition: Formatter.h:115
@ ZYDIS_FORMATTER_ADDR_RELATIVE_UNSIGNED
Uses unsigned hexadecimal values to display relative addresses.
Definition: Formatter.h:123
@ ZYDIS_FORMATTER_ADDR_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:127
@ ZYDIS_FORMATTER_ADDR_ABSOLUTE
Displays absolute addresses instead of relative ones.
Definition: Formatter.h:107
@ ZYDIS_FORMATTER_ADDR_DEFAULT
Currently defaults to ZYDIS_FORMATTER_ADDR_ABSOLUTE.
Definition: Formatter.h:103
ZydisFormatterImmediateFormats
Values that represent formatter immediate-formats.
Definition: Formatter.h:179
@ ZYDIS_FORMATTER_IMM_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:208
@ ZYDIS_FORMATTER_IMM_HEX_SIGNED
Formats immediates as signed hexadecimal values.
Definition: Formatter.h:196
@ ZYDIS_FORMATTER_IMM_DEFAULT
Currently defaults to ZYDIS_FORMATTER_IMM_HEX_UNSIGNED.
Definition: Formatter.h:183
@ ZYDIS_FORMATTER_IMM_HEX_AUTO
Automatically chooses the most suitable formatting-mode based on the operands ZydisOperandInfo....
Definition: Formatter.h:188
@ ZYDIS_FORMATTER_IMM_HEX_UNSIGNED
Formats immediates as unsigned hexadecimal values.
Definition: Formatter.h:204
uint8_t ZydisDecoratorType
Defines the ZydisDecoratorType datatype.
Definition: Formatter.h:308
ZYDIS_EXPORT ZydisStatus ZydisFormatterSetHook(ZydisFormatter *formatter, ZydisFormatterHookType hook, const void **callback)
Replaces a formatter function with a custom callback and/or retrieves the currently used function.
uint8_t ZydisFormatterAddressFormat
Defines the ZydisFormatterAddressFormat datatype.
Definition: Formatter.h:93
ZydisFormatterDisplacementFormats
Values that represent displacement-formats.
Definition: Formatter.h:141
@ ZYDIS_FORMATTER_DISP_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:165
@ ZYDIS_FORMATTER_DISP_HEX_UNSIGNED
Formats displacements as unsigned hexadecimal values.
Definition: Formatter.h:161
@ ZYDIS_FORMATTER_DISP_HEX_SIGNED
Formats displacements as signed hexadecimal values.
Definition: Formatter.h:153
@ ZYDIS_FORMATTER_DISP_DEFAULT
Currently defaults to ZYDIS_FORMATTER_DISP_HEX_SIGNED.
Definition: Formatter.h:145
uint32_t ZydisFormatterFlags
Defines the ZydisFormatFlags datatype.
Definition: Formatter.h:72
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter *formatter, ZydisDecodedInstruction *instruction, char *buffer, size_t bufferLen, void *userData)
Formats the given instruction and writes it into the output buffer.
ZydisStatus(* ZydisFormatterNotifyFunc)(const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, void *userData)
Defines the ZydisFormatterNotifyFunc function pointer.
Definition: Formatter.h:344
uint8_t ZydisFormatterImmediateFormat
Defines the ZydisFormatterImmediateFormat datatype.
Definition: Formatter.h:173
uint8_t ZydisFormatterDisplacementFormat
Defines the ZydisFormatterDisplacementFormat datatype.
Definition: Formatter.h:135
ZYDIS_EXPORT ZydisStatus ZydisFormatterInitEx(ZydisFormatter *formatter, ZydisFormatterStyle style, ZydisFormatterFlags flags, ZydisFormatterAddressFormat addressFormat, ZydisFormatterDisplacementFormat displacementFormat, ZydisFormatterImmediateFormat immmediateFormat)
Initializes the given ZydisFormatter instance.
ZydisFormatterHookTypes
Values that represent formatter hook-types.
Definition: Formatter.h:222
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_REG
This function is called to format an register operand.
Definition: Formatter.h:251
@ ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS
This function is called to print an absolute address.
Definition: Formatter.h:288
@ ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION
This function refers to the main formatting function, that internally calls all other function exce...
Definition: Formatter.h:239
@ ZYDIS_FORMATTER_HOOK_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:300
@ ZYDIS_FORMATTER_HOOK_PRINT_DISPLACEMENT
This function is called to print a memory displacement value.
Definition: Formatter.h:292
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM
This function is called to format an memory operand.
Definition: Formatter.h:258
@ ZYDIS_FORMATTER_HOOK_PRINT_IMMEDIATE
This function is called to print an immediate value.
Definition: Formatter.h:296
@ ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR
This function is called right after formatting an operand to print the optional EVEX/MVEX operand-dec...
Definition: Formatter.h:284
@ ZYDIS_FORMATTER_HOOK_PRE
This function is called before the formatter starts formatting an instruction.
Definition: Formatter.h:226
@ ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES
This function is called to print the instruction prefixes.
Definition: Formatter.h:243
@ ZYDIS_FORMATTER_HOOK_PRINT_OPERANDSIZE
This function is called right before formatting an memory operand to print the optional size-specifie...
Definition: Formatter.h:274
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM
This function is called to format an immediate operand.
Definition: Formatter.h:269
@ ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC
This function is called to print the instruction mnemonic.
Definition: Formatter.h:247
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR
This function is called to format an pointer operand.
Definition: Formatter.h:262
@ ZYDIS_FORMATTER_HOOK_PRINT_SEGMENT
This function is called right before formatting an memory operand to print the optional segment-regis...
Definition: Formatter.h:279
@ ZYDIS_FORMATTER_HOOK_POST
This function is called before the formatter finished formatting an instruction.
Definition: Formatter.h:230
uint8_t ZydisFormatterHookType
Defines the ZydisFormatterHookType datatype.
Definition: Formatter.h:216
ZYDIS_EXPORT ZydisStatus ZydisFormatterInit(ZydisFormatter *formatter, ZydisFormatterStyle style)
Initializes the given ZydisFormatter instance.
ZydisStatus(* ZydisFormatterFormatAddressFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, uint64_t address, void *userData)
Defines the ZydisFormatterFormatAddressFunc function pointer.
Definition: Formatter.h:425
ZydisStatus(* ZydisFormatterFormatDecoratorFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZydisDecoratorType type, void *userData)
Defines the ZydisFormatterFormatDecoratorFunc function pointer.
Definition: Formatter.h:451
ZydisFormatterStyles
Values that represent formatter-styles.
Definition: Formatter.h:56
@ ZYDIS_FORMATTER_STYLE_INTEL
Generates intel-style disassembly.
Definition: Formatter.h:60
@ ZYDIS_FORMATTER_STYLE_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:64
uint8_t ZydisFormatterStyle
Defines the ZydisFormatterStyle datatype.
Definition: Formatter.h:50
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter *formatter, ZydisDecodedInstruction *instruction, char *buffer, size_t bufferLen)
Formats the given instruction and writes it into the output buffer.
Status code definitions and check macros.
uint32_t ZydisStatus
Defines the ZydisStatus datatype.
Definition: Status.h:48
Defines the ZydisDecodedInstruction struct.
Definition: DecoderTypes.h:740
Defines the ZydisDecodedOperand struct.
Definition: DecoderTypes.h:53
Defines the ZydisFormatter struct.
Definition: Formatter.h:459
ZydisFormatterFormatFunc funcPrintPrefixes
Definition: Formatter.h:467
ZydisFormatterNotifyFunc funcPre
Definition: Formatter.h:464
ZydisFormatterFormatOperandFunc funcPrintImmediate
Definition: Formatter.h:478
ZydisFormatterFormatOperandFunc funcFormatOperandMem
Definition: Formatter.h:470
ZydisFormatterFormatOperandFunc funcFormatOperandPtr
Definition: Formatter.h:471
ZydisFormatterFormatOperandFunc funcPrintSegment
Definition: Formatter.h:474
ZydisFormatterFormatOperandFunc funcPrintDisplacement
Definition: Formatter.h:477
ZydisFormatterAddressFormat addressFormat
Definition: Formatter.h:461
ZydisFormatterFormatOperandFunc funcPrintOperandSize
Definition: Formatter.h:473
ZydisFormatterFormatAddressFunc funcPrintAddress
Definition: Formatter.h:476
ZydisFormatterImmediateFormat immediateFormat
Definition: Formatter.h:463
ZydisFormatterFormatOperandFunc funcFormatOperandReg
Definition: Formatter.h:469
ZydisFormatterDisplacementFormat displacementFormat
Definition: Formatter.h:462
ZydisFormatterFormatFunc funcFormatInstruction
Definition: Formatter.h:466
ZydisFormatterNotifyFunc funcPost
Definition: Formatter.h:465
ZydisFormatterFlags flags
Definition: Formatter.h:460
ZydisFormatterFormatOperandFunc funcFormatOperandImm
Definition: Formatter.h:472
ZydisFormatterFormatFunc funcPrintMnemonic
Definition: Formatter.h:468
ZydisFormatterFormatDecoratorFunc funcPrintDecorator
Definition: Formatter.h:475