Zydis  v2.0.3
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 #include <Zydis/String.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /* ============================================================================================== */
45 /* Enums and types */
46 /* ============================================================================================== */
47 
48 /* ---------------------------------------------------------------------------------------------- */
49 /* Formatter style */
50 /* ---------------------------------------------------------------------------------------------- */
51 
56 
61 {
66 
71 };
72 
73 /* ---------------------------------------------------------------------------------------------- */
74 /* Attributes */
75 /* ---------------------------------------------------------------------------------------------- */
76 
81 
86 {
113 
132 
171 
176 };
177 
178 /* ---------------------------------------------------------------------------------------------- */
179 /* Address format */
180 /* ---------------------------------------------------------------------------------------------- */
181 
186 {
216 
221 };
222 
223 /* ---------------------------------------------------------------------------------------------- */
224 /* Displacement format */
225 /* ---------------------------------------------------------------------------------------------- */
226 
231 {
248 
253 };
254 
255 /* ---------------------------------------------------------------------------------------------- */
256 /* Immediate format */
257 /* ---------------------------------------------------------------------------------------------- */
258 
263 {
285 
290 };
291 
292 /* ---------------------------------------------------------------------------------------------- */
293 /* Hooks */
294 /* ---------------------------------------------------------------------------------------------- */
295 
300 
305 {
322 
354 
375 
389 
394 };
395 
396 /* ---------------------------------------------------------------------------------------------- */
397 
402 
407 {
437 
442 };
443 
444 /* ---------------------------------------------------------------------------------------------- */
445 
446 typedef struct ZydisFormatter_ ZydisFormatter;
447 
468 typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter,
469  ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData);
470 
507  ZydisString* string, const ZydisDecodedInstruction* instruction,
508  const ZydisDecodedOperand* operand, void* userData);
509 
527  ZydisString* string, const ZydisDecodedInstruction* instruction,
528  const ZydisDecodedOperand* operand, ZydisRegister reg, void* userData);
529 
547  ZydisString* string, const ZydisDecodedInstruction* instruction,
548  const ZydisDecodedOperand* operand, ZydisU64 address, void* userData);
549 
567  ZydisString* string, const ZydisDecodedInstruction* instruction,
568  const ZydisDecodedOperand* operand, ZydisDecoratorType decorator, void* userData);
569 
570 /* ---------------------------------------------------------------------------------------------- */
571 /* Formatter struct */
572 /* ---------------------------------------------------------------------------------------------- */
573 
578 {
610 };
611 
612 /* ---------------------------------------------------------------------------------------------- */
613 
614 /* ============================================================================================== */
615 /* Exported functions */
616 /* ============================================================================================== */
617 
627 
638  ZydisFormatterProperty property, ZydisUPointer value);
639 
655  ZydisFormatterHookType hook, const void** callback);
656 
668  const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen);
669 
683  const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen, void* userData);
684 
700  const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen);
701 
719  const ZydisDecodedInstruction* instruction, ZydisU8 index, char* buffer, ZydisUSize bufferLen,
720  void* userData);
721 
722 /* ============================================================================================== */
723 
724 #ifdef __cplusplus
725 }
726 #endif
727 
728 #endif /* ZYDIS_FORMATTER_H */
uint64_t ZydisU64
Definition: CommonTypes.h:48
uint8_t ZydisU8
Definition: CommonTypes.h:45
uintptr_t ZydisUPointer
Definition: CommonTypes.h:55
ZydisU8 ZydisBool
@briefs Defines the ZydisBool datatype.
Definition: CommonTypes.h:133
size_t ZydisUSize
Definition: CommonTypes.h:53
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
General helper and platform detection macros.
ZydisU8 ZydisRegister
Defines the ZydisRegister datatype.
Definition: EnumRegister.h:4
ZydisU8 ZydisDecoratorType
Defines the ZydisDecoratorType datatype.
Definition: Formatter.h:401
ZydisDecoratorTypes
Values that represent decorator-types.
Definition: Formatter.h:407
@ ZYDIS_DECORATOR_TYPE_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:441
@ ZYDIS_DECORATOR_TYPE_SAE
The suppress-all-exceptions decorator.
Definition: Formatter.h:424
@ ZYDIS_DECORATOR_TYPE_INVALID
Definition: Formatter.h:408
@ ZYDIS_DECORATOR_TYPE_RC
The rounding-control decorator.
Definition: Formatter.h:420
@ ZYDIS_DECORATOR_TYPE_BC
The broadcast decorator.
Definition: Formatter.h:416
@ ZYDIS_DECORATOR_TYPE_MASK
The embedded-mask decorator.
Definition: Formatter.h:412
@ ZYDIS_DECORATOR_TYPE_CONVERSION
The conversion decorator.
Definition: Formatter.h:432
@ ZYDIS_DECORATOR_TYPE_SWIZZLE
The register-swizzle decorator.
Definition: Formatter.h:428
@ ZYDIS_DECORATOR_TYPE_EH
The eviction-hint decorator.
Definition: Formatter.h:436
ZydisStatus(* ZydisFormatterFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, void *userData)
Defines the ZydisFormatterFunc function pointer.
Definition: Formatter.h:468
ZydisStatus(* ZydisFormatterOperandFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, void *userData)
Defines the ZydisFormatterOperandFunc function pointer.
Definition: Formatter.h:506
ZydisU8 ZydisFormatterProperty
Defines the ZydisFormatterProperty datatype.
Definition: Formatter.h:80
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.
ZydisStatus(* ZydisFormatterRegisterFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZydisRegister reg, void *userData)
Defines the ZydisFormatterRegisterFunc function pointer.
Definition: Formatter.h:526
ZydisStatus(* ZydisFormatterDecoratorFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZydisDecoratorType decorator, void *userData)
Defines the ZydisFormatterDecoratorFunc function pointer.
Definition: Formatter.h:566
ZydisImmediateFormat
Values that represent formatter immediate-formats.
Definition: Formatter.h:263
@ ZYDIS_IMM_FORMAT_HEX_UNSIGNED
Formats immediates as unsigned hexadecimal values.
Definition: Formatter.h:284
@ ZYDIS_IMM_FORMAT_HEX_SIGNED
Formats immediates as signed hexadecimal values.
Definition: Formatter.h:276
@ ZYDIS_IMM_FORMAT_HEX_AUTO
Automatically chooses the most suitable formatting-mode based on the operands ZydisOperandInfo....
Definition: Formatter.h:268
@ ZYDIS_IMM_FORMAT_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:289
ZydisFormatterProperties
Values that represent formatter-properties.
Definition: Formatter.h:86
@ ZYDIS_FORMATTER_PROP_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:175
@ ZYDIS_FORMATTER_PROP_ADDR_FORMAT
Controls the format of addresses.
Definition: Formatter.h:119
@ ZYDIS_FORMATTER_PROP_HEX_SUFFIX
Sets the suffix for hexadecimal values.
Definition: Formatter.h:152
@ ZYDIS_FORMATTER_PROP_HEX_PADDING_ADDR
Controls the padding (minimum number of chars) of hexadecimal address values.
Definition: Formatter.h:158
@ ZYDIS_FORMATTER_PROP_FORCE_MEMSEG
Controls the printing of segment prefixes.
Definition: Formatter.h:103
@ ZYDIS_FORMATTER_PROP_IMM_FORMAT
Controls the format of immediate values.
Definition: Formatter.h:131
@ ZYDIS_FORMATTER_PROP_HEX_PREFIX
Sets the prefix for hexadecimal values.
Definition: Formatter.h:146
@ ZYDIS_FORMATTER_PROP_DISP_FORMAT
Controls the format of displacement values.
Definition: Formatter.h:125
@ ZYDIS_FORMATTER_PROP_HEX_PADDING_IMM
Controls the padding (minimum number of chars) of hexadecimal immediate values.
Definition: Formatter.h:170
@ ZYDIS_FORMATTER_PROP_HEX_PADDING_DISP
Controls the padding (minimum number of chars) of hexadecimal displacement values.
Definition: Formatter.h:164
@ ZYDIS_FORMATTER_PROP_FORCE_MEMSIZE
Controls the printing of memory-operand sizes.
Definition: Formatter.h:112
@ ZYDIS_FORMATTER_PROP_UPPERCASE
Controls the letter-case.
Definition: Formatter.h:94
@ ZYDIS_FORMATTER_PROP_HEX_UPPERCASE
Controls the letter-case of hexadecimal values.
Definition: Formatter.h:140
ZydisFormatterHookTypes
Values that represent formatter hook-types.
Definition: Formatter.h:305
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_REG
This function is invoked to format a register operand.
Definition: Formatter.h:334
@ ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS
This function is invoked to print an absolute address.
Definition: Formatter.h:366
@ ZYDIS_FORMATTER_HOOK_POST_OPERAND
This function is invoked after the formatter formatted an operand.
Definition: Formatter.h:321
@ ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION
This function refers to the main formatting function.
Definition: Formatter.h:330
@ ZYDIS_FORMATTER_HOOK_PRINT_DISP
This function is invoked to print a memory displacement value.
Definition: Formatter.h:370
@ ZYDIS_FORMATTER_HOOK_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:393
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM
This function is invoked to format a memory operand.
Definition: Formatter.h:342
@ ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR
This function is invoked after formatting an operand to print a EVEX/MVEX decorator.
Definition: Formatter.h:388
@ ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION
This function is invoked after the formatter formatted an instruction.
Definition: Formatter.h:313
@ ZYDIS_FORMATTER_HOOK_PRINT_IMM
This function is invoked to print an immediate value.
Definition: Formatter.h:374
@ ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION
This function is invoked before the formatter formats an instruction.
Definition: Formatter.h:309
@ ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE
This function is invoked to print the size of a memory operand.
Definition: Formatter.h:379
@ ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES
This function is invoked to print the instruction prefixes.
Definition: Formatter.h:383
@ ZYDIS_FORMATTER_HOOK_PRE_OPERAND
This function is invoked before the formatter formats an operand.
Definition: Formatter.h:317
@ ZYDIS_FORMATTER_HOOK_PRINT_REGISTER
This function is invoked to print a register.
Definition: Formatter.h:362
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM
This function is invoked to format an immediate operand.
Definition: Formatter.h:353
@ ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC
This function is invoked to print the instruction mnemonic.
Definition: Formatter.h:358
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR
This function is invoked to format a pointer operand.
Definition: Formatter.h:346
ZydisDisplacementFormat
Values that represent displacement-formats.
Definition: Formatter.h:231
@ ZYDIS_DISP_FORMAT_HEX_SIGNED
Formats displacements as signed hexadecimal values.
Definition: Formatter.h:239
@ ZYDIS_DISP_FORMAT_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:252
@ ZYDIS_DISP_FORMAT_HEX_UNSIGNED
Formats displacements as unsigned hexadecimal values.
Definition: Formatter.h:247
ZYDIS_EXPORT ZydisStatus ZydisFormatterSetProperty(ZydisFormatter *formatter, ZydisFormatterProperty property, ZydisUPointer value)
Sets the value of the specified formatter attribute.
ZYDIS_EXPORT ZydisStatus ZydisFormatterInit(ZydisFormatter *formatter, ZydisFormatterStyle style)
Initializes the given ZydisFormatter instance.
ZydisU8 ZydisFormatterStyle
Defines the ZydisFormatterStyle datatype.
Definition: Formatter.h:55
ZydisAddressFormat
Values that represent address-formats.
Definition: Formatter.h:186
@ ZYDIS_ADDR_FORMAT_ABSOLUTE
Displays absolute addresses instead of relative ones.
Definition: Formatter.h:193
@ ZYDIS_ADDR_FORMAT_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:220
@ ZYDIS_ADDR_FORMAT_RELATIVE_UNSIGNED
Uses unsigned hexadecimal values to display relative addresses.
Definition: Formatter.h:215
@ ZYDIS_ADDR_FORMAT_RELATIVE_SIGNED
Uses signed hexadecimal values to display relative addresses.
Definition: Formatter.h:204
ZydisFormatterStyles
Values that represent formatter-styles.
Definition: Formatter.h:61
@ ZYDIS_FORMATTER_STYLE_INTEL
Generates intel-style disassembly.
Definition: Formatter.h:65
@ ZYDIS_FORMATTER_STYLE_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:70
ZydisU8 ZydisFormatterHookType
Defines the ZydisFormatterHookType datatype.
Definition: Formatter.h:299
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, ZydisU8 index, char *buffer, ZydisUSize bufferLen, void *userData)
Formats the given operand and writes it into the output buffer.
ZydisStatus(* ZydisFormatterAddressFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZydisU64 address, void *userData)
Defines the ZydisFormatterAddressFunc function pointer.
Definition: Formatter.h:546
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstruction(const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, char *buffer, ZydisUSize bufferLen)
Formats the given instruction and writes it into the output buffer.
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatInstructionEx(const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, char *buffer, ZydisUSize bufferLen, void *userData)
Formats the given instruction and writes it into the output buffer.
ZYDIS_EXPORT ZydisStatus ZydisFormatterFormatOperand(const ZydisFormatter *formatter, const ZydisDecodedInstruction *instruction, ZydisU8 index, char *buffer, ZydisUSize bufferLen)
Formats the given operand and writes it into the output buffer.
Status code definitions and check macros.
ZydisU32 ZydisStatus
Defines the ZydisStatus datatype.
Definition: Status.h:48
ZydisU8 ZydisLetterCase
Defines the ZydisLetterCase datatype.
Definition: String.h:97
Defines the ZydisDecodedInstruction struct.
Definition: DecoderTypes.h:818
Defines the ZydisDecodedOperand struct.
Definition: DecoderTypes.h:93
Defines the ZydisFormatter struct.
Definition: Formatter.h:578
ZydisFormatterOperandFunc funcFormatOperandImm
Definition: Formatter.h:601
ZydisBool forceMemorySize
Definition: Formatter.h:581
ZydisU8 formatImm
Definition: Formatter.h:584
ZydisU8 formatAddress
Definition: Formatter.h:582
ZydisU8 hexPaddingImm
Definition: Formatter.h:592
ZydisFormatterRegisterFunc funcPrintRegister
Definition: Formatter.h:603
ZydisString * hexSuffix
Definition: Formatter.h:588
ZydisString hexPrefixData
Definition: Formatter.h:587
ZydisU8 hexPaddingDisp
Definition: Formatter.h:591
ZydisFormatterOperandFunc funcFormatOperandPtr
Definition: Formatter.h:600
ZydisFormatterOperandFunc funcFormatOperandMem
Definition: Formatter.h:599
ZydisFormatterAddressFunc funcPrintAddress
Definition: Formatter.h:604
ZydisBool hexUppercase
Definition: Formatter.h:585
ZydisFormatterOperandFunc funcPrintImm
Definition: Formatter.h:606
ZydisFormatterOperandFunc funcPrintMemSize
Definition: Formatter.h:607
ZydisFormatterOperandFunc funcPrintDisp
Definition: Formatter.h:605
ZydisFormatterFunc funcPreInstruction
Definition: Formatter.h:593
ZydisFormatterFunc funcFormatInstruction
Definition: Formatter.h:597
ZydisU8 formatDisp
Definition: Formatter.h:583
ZydisFormatterFunc funcPrintMnemonic
Definition: Formatter.h:602
ZydisFormatterOperandFunc funcFormatOperandReg
Definition: Formatter.h:598
ZydisFormatterFunc funcPrintPrefixes
Definition: Formatter.h:608
ZydisFormatterFunc funcPostInstruction
Definition: Formatter.h:594
ZydisFormatterDecoratorFunc funcPrintDecorator
Definition: Formatter.h:609
ZydisFormatterOperandFunc funcPostOperand
Definition: Formatter.h:596
ZydisString hexSuffixData
Definition: Formatter.h:589
ZydisLetterCase letterCase
Definition: Formatter.h:579
ZydisString * hexPrefix
Definition: Formatter.h:586
ZydisBool forceMemorySegment
Definition: Formatter.h:580
ZydisFormatterOperandFunc funcPreOperand
Definition: Formatter.h:595
ZydisU8 hexPaddingAddress
Definition: Formatter.h:590
Defines the ZydisString struct.
Definition: String.h:50