Zydis  v2.0.0-beta1
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 
353 
374 
388 
393 };
394 
395 /* ---------------------------------------------------------------------------------------------- */
396 
401 
406 {
436 
441 };
442 
443 /* ---------------------------------------------------------------------------------------------- */
444 
445 typedef struct ZydisFormatter_ ZydisFormatter;
446 
470 typedef ZydisStatus (*ZydisFormatterFunc)(const ZydisFormatter* formatter,
471  ZydisString* string, const ZydisDecodedInstruction* instruction, void* userData);
472 
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 
570  ZydisString* string, const ZydisDecodedInstruction* instruction,
571  const ZydisDecodedOperand* operand, ZydisDecoratorType type, void* userData);
572 
573 /* ---------------------------------------------------------------------------------------------- */
574 /* Formatter struct */
575 /* ---------------------------------------------------------------------------------------------- */
576 
581 {
613 };
614 
615 /* ---------------------------------------------------------------------------------------------- */
616 
617 /* ============================================================================================== */
618 /* Exported functions */
619 /* ============================================================================================== */
620 
630 
641  ZydisFormatterProperty property, ZydisUPointer value);
642 
658  ZydisFormatterHookType hook, const void** callback);
659 
671  const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen);
672 
686  const ZydisDecodedInstruction* instruction, char* buffer, ZydisUSize bufferLen, void* userData);
687 
688 /* ============================================================================================== */
689 
690 #ifdef __cplusplus
691 }
692 #endif
693 
694 #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 ZydisDecoratorType
Defines the ZydisDecoratorType datatype.
Definition: Formatter.h:400
ZydisDecoratorTypes
Values that represent decorator-types.
Definition: Formatter.h:406
@ ZYDIS_DECORATOR_TYPE_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:440
@ ZYDIS_DECORATOR_TYPE_SAE
The suppress-all-exceptions decorator.
Definition: Formatter.h:423
@ ZYDIS_DECORATOR_TYPE_INVALID
Definition: Formatter.h:407
@ ZYDIS_DECORATOR_TYPE_RC
The rounding-control decorator.
Definition: Formatter.h:419
@ ZYDIS_DECORATOR_TYPE_BC
The broadcast decorator.
Definition: Formatter.h:415
@ ZYDIS_DECORATOR_TYPE_MASK
The embedded-mask decorator.
Definition: Formatter.h:411
@ ZYDIS_DECORATOR_TYPE_CONVERSION
The conversion decorator.
Definition: Formatter.h:431
@ ZYDIS_DECORATOR_TYPE_SWIZZLE
The register-swizzle decorator.
Definition: Formatter.h:427
@ ZYDIS_DECORATOR_TYPE_EH
The eviction-hint decorator.
Definition: Formatter.h:435
ZydisStatus(* ZydisFormatterFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, void *userData)
Defines the ZydisFormatterFunc function pointer.
Definition: Formatter.h:470
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
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:365
@ ZYDIS_FORMATTER_HOOK_POST_OPERAND
This function is invoked before 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:369
@ ZYDIS_FORMATTER_HOOK_MAX_VALUE
Maximum value of this enum.
Definition: Formatter.h:392
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM
This function is invoked to format a memory operand.
Definition: Formatter.h:341
@ ZYDIS_FORMATTER_HOOK_PRINT_DECORATOR
This function is invoked after formatting an operand to print a EVEX/MVEX decorator.
Definition: Formatter.h:387
@ ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION
This function is invoked before 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:373
@ 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:378
@ ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES
This function is invoked to print the instruction prefixes.
Definition: Formatter.h:382
@ 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:361
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM
This function is invoked to format an immediate operand.
Definition: Formatter.h:352
@ ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC
This function is invoked to print the instruction mnemonic.
Definition: Formatter.h:357
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR
This function is invoked to format a pointer operand.
Definition: Formatter.h:345
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.
ZydisStatus(* ZydisFormatterDecoratorFunc)(const ZydisFormatter *formatter, ZydisString *string, const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZydisDecoratorType type, void *userData)
Defines the ZydisFormatterDecoratorFunc function pointer.
Definition: Formatter.h:569
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
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.
ZydisU8 ZydisRegister
Defines the ZydisRegister datatype.
Definition: Register.h:54
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:93
Defines the ZydisDecodedInstruction struct.
Definition: DecoderTypes.h:778
Defines the ZydisDecodedOperand struct.
Definition: DecoderTypes.h:89
Defines the ZydisFormatter struct.
Definition: Formatter.h:581
ZydisFormatterOperandFunc funcFormatOperandImm
Definition: Formatter.h:604
ZydisBool forceMemorySize
Definition: Formatter.h:584
ZydisU8 formatImm
Definition: Formatter.h:587
ZydisU8 formatAddress
Definition: Formatter.h:585
ZydisU8 hexPaddingImm
Definition: Formatter.h:595
ZydisFormatterRegisterFunc funcPrintRegister
Definition: Formatter.h:606
ZydisString * hexSuffix
Definition: Formatter.h:591
ZydisString hexPrefixData
Definition: Formatter.h:590
ZydisU8 hexPaddingDisp
Definition: Formatter.h:594
ZydisFormatterOperandFunc funcFormatOperandPtr
Definition: Formatter.h:603
ZydisFormatterOperandFunc funcFormatOperandMem
Definition: Formatter.h:602
ZydisFormatterAddressFunc funcPrintAddress
Definition: Formatter.h:607
ZydisBool hexUppercase
Definition: Formatter.h:588
ZydisFormatterOperandFunc funcPrintImm
Definition: Formatter.h:609
ZydisFormatterOperandFunc funcPrintMemSize
Definition: Formatter.h:610
ZydisFormatterOperandFunc funcPrintDisp
Definition: Formatter.h:608
ZydisFormatterFunc funcPreInstruction
Definition: Formatter.h:596
ZydisFormatterFunc funcFormatInstruction
Definition: Formatter.h:600
ZydisU8 formatDisp
Definition: Formatter.h:586
ZydisFormatterFunc funcPrintMnemonic
Definition: Formatter.h:605
ZydisFormatterOperandFunc funcFormatOperandReg
Definition: Formatter.h:601
ZydisFormatterFunc funcPrintPrefixes
Definition: Formatter.h:611
ZydisFormatterFunc funcPostInstruction
Definition: Formatter.h:597
ZydisFormatterDecoratorFunc funcPrintDecorator
Definition: Formatter.h:612
ZydisFormatterOperandFunc funcPostOperand
Definition: Formatter.h:599
ZydisString hexSuffixData
Definition: Formatter.h:592
ZydisLetterCase letterCase
Definition: Formatter.h:582
ZydisString * hexPrefix
Definition: Formatter.h:589
ZydisBool forceMemorySegment
Definition: Formatter.h:583
ZydisFormatterOperandFunc funcPreOperand
Definition: Formatter.h:598
ZydisU8 hexPaddingAddress
Definition: Formatter.h:593
Defines the ZydisString struct.
Definition: String.h:46