Zydis  v2.0.0-alpha1
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 
27 #ifndef ZYDIS_FORMATTER_H
28 #define ZYDIS_FORMATTER_H
29 
30 #include <Zydis/DecoderTypes.h>
31 #include <Zydis/Defines.h>
32 #include <Zydis/Status.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* ============================================================================================== */
39 /* Enums and types */
40 /* ============================================================================================== */
41 
45 typedef uint8_t ZydisFormatterStyle;
46 
51 {
56 };
57 
58 /* ---------------------------------------------------------------------------------------------- */
59 
63 typedef uint32_t ZydisFormatterFlags;
64 
68 #define ZYDIS_FMTFLAG_UPPERCASE 0x00000001
73 #define ZYDIS_FMTFLAG_FORCE_SEGMENTS 0x00000002
77 #define ZYDIS_FMTFLAG_FORCE_OPERANDSIZE 0x00000004
78 
79 /* ---------------------------------------------------------------------------------------------- */
80 
85 
90 {
115 };
116 
117 /* ---------------------------------------------------------------------------------------------- */
118 
123 
128 {
149 };
150 
151 /* ---------------------------------------------------------------------------------------------- */
152 
157 
162 {
188 };
189 
190 /* ---------------------------------------------------------------------------------------------- */
191 
195 typedef uint8_t ZydisFormatterHookType;
196 
201 {
276 };
277 
278 /* ---------------------------------------------------------------------------------------------- */
279 
283 typedef uint8_t ZydisDecoratorType;
284 
289 {
298 };
299 
300 typedef struct ZydisFormatter_ ZydisFormatter;
301 
315  ZydisDecodedInstruction* instruction);
316 
335  char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction);
336 
371  char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
372  ZydisDecodedOperand* operand);
373 
393  char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
394  ZydisDecodedOperand* operand, uint64_t address);
395 
418  char** buffer, size_t bufferLen, ZydisDecodedInstruction* instruction,
419  ZydisDecodedOperand* operand, ZydisDecoratorType type);
420 
425 {
445 };
446 
447 /* ============================================================================================== */
448 /* Exported functions */
449 /* ============================================================================================== */
450 
460 
473  ZydisFormatterFlags flags, ZydisFormatterAddressFormat addressFormat,
474  ZydisFormatterDisplacementFormat displacementFormat,
475  ZydisFormatterImmediateFormat immmediateFormat);
476 
492  ZydisFormatterHookType hook, const void** callback);
493 
505  ZydisDecodedInstruction* instruction, char* buffer, size_t bufferLen);
506 
507 /* ============================================================================================== */
508 
509 #ifdef __cplusplus
510 }
511 #endif
512 
513 #endif /* ZYDIS_FORMATTER_H */
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
ZydisDecoratorTypes
Values that represent decorator-types.
Definition: Formatter.h:289
@ ZYDIS_DECORATOR_TYPE_SAE
Definition: Formatter.h:294
@ ZYDIS_DECORATOR_TYPE_EVICTION_HINT
Definition: Formatter.h:297
@ ZYDIS_DECORATOR_TYPE_INVALID
Definition: Formatter.h:290
@ ZYDIS_DECORATOR_TYPE_BROADCAST
Definition: Formatter.h:292
@ ZYDIS_DECORATOR_TYPE_MASK
Definition: Formatter.h:291
@ ZYDIS_DECORATOR_TYPE_CONVERSION
Definition: Formatter.h:296
@ ZYDIS_DECORATOR_TYPE_SWIZZLE
Definition: Formatter.h:295
@ ZYDIS_DECORATOR_TYPE_ROUNDING_CONTROL
Definition: Formatter.h:293
ZydisFormatterAddressFormats
Values that represent address-formats.
Definition: Formatter.h:90
@ ZYDIS_FORMATTER_ADDR_RELATIVE_SIGNED
Uses signed hexadecimal values to display relative addresses.
Definition: Formatter.h:106
@ ZYDIS_FORMATTER_ADDR_RELATIVE_UNSIGNED
Uses unsigned hexadecimal values to display relative addresses.
Definition: Formatter.h:114
@ ZYDIS_FORMATTER_ADDR_ABSOLUTE
Displays absolute addresses instead of relative ones.
Definition: Formatter.h:98
@ ZYDIS_FORMATTER_ADDR_DEFAULT
Currently defaults to ZYDIS_FORMATTER_ADDR_ABSOLUTE.
Definition: Formatter.h:94
ZydisFormatterImmediateFormats
Values that represent formatter immediate-formats.
Definition: Formatter.h:162
@ ZYDIS_FORMATTER_IMM_HEX_SIGNED
Formats immediates as signed hexadecimal values.
Definition: Formatter.h:179
@ ZYDIS_FORMATTER_IMM_DEFAULT
Currently defaults to ZYDIS_FORMATTER_IMM_HEX_UNSIGNED.
Definition: Formatter.h:166
@ ZYDIS_FORMATTER_IMM_HEX_AUTO
Automatically chooses the most suitable formatting-mode based on the operands ZydisOperandInfo....
Definition: Formatter.h:171
@ ZYDIS_FORMATTER_IMM_HEX_UNSIGNED
Formats immediates as unsigned hexadecimal values.
Definition: Formatter.h:187
uint8_t ZydisDecoratorType
Defines the ZydisDecoratorType datatype.
Definition: Formatter.h:283
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(* ZydisFormatterNotifyFunc)(const ZydisFormatter *formatter, ZydisDecodedInstruction *instruction)
Defines the ZydisFormatterNotifyFunc function pointer.
Definition: Formatter.h:314
uint8_t ZydisFormatterAddressFormat
Defines the ZydisFormatterAddressFormat datatype.
Definition: Formatter.h:84
ZydisFormatterDisplacementFormats
Values that represent displacement-formats.
Definition: Formatter.h:128
@ ZYDIS_FORMATTER_DISP_HEX_UNSIGNED
Formats displacements as unsigned hexadecimal values.
Definition: Formatter.h:148
@ ZYDIS_FORMATTER_DISP_HEX_SIGNED
Formats displacements as signed hexadecimal values.
Definition: Formatter.h:140
@ ZYDIS_FORMATTER_DISP_DEFAULT
Currently defaults to ZYDIS_FORMATTER_DISP_HEX_SIGNED.
Definition: Formatter.h:132
uint32_t ZydisFormatterFlags
Defines the ZydisFormatFlags datatype.
Definition: Formatter.h:63
ZydisStatus(* ZydisFormatterFormatFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, ZydisDecodedInstruction *instruction)
Defines the ZydisFormatterFormatFunc function pointer.
Definition: Formatter.h:334
uint8_t ZydisFormatterImmediateFormat
Defines the ZydisFormatterImmediateFormat datatype.
Definition: Formatter.h:156
uint8_t ZydisFormatterDisplacementFormat
Defines the ZydisFormatterDisplacementFormat datatype.
Definition: Formatter.h:122
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:201
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_REG
This function is called to format an register operand.
Definition: Formatter.h:230
@ ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS
This function is called to print an absolute address.
Definition: Formatter.h:267
@ ZYDIS_FORMATTER_HOOK_FORMAT_INSTRUCTION
This function refers to the main formatting function, that internally calls all other function exce...
Definition: Formatter.h:218
@ ZYDIS_FORMATTER_HOOK_PRINT_DISPLACEMENT
This function is called to print a memory displacement value.
Definition: Formatter.h:271
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM
This function is called to format an memory operand.
Definition: Formatter.h:237
@ ZYDIS_FORMATTER_HOOK_PRINT_IMMEDIATE
This function is called to print an immediate value.
Definition: Formatter.h:275
@ 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:263
@ ZYDIS_FORMATTER_HOOK_PRE
This function is called before the formatter starts formatting an instruction.
Definition: Formatter.h:205
@ ZYDIS_FORMATTER_HOOK_PRINT_PREFIXES
This function is called to print the instruction prefixes.
Definition: Formatter.h:222
@ ZYDIS_FORMATTER_HOOK_PRINT_OPERANDSIZE
This function is called right before formatting an memory operand to print the optional size-specifie...
Definition: Formatter.h:253
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_IMM
This function is called to format an immediate operand.
Definition: Formatter.h:248
@ ZYDIS_FORMATTER_HOOK_PRINT_MNEMONIC
This function is called to print the instruction mnemonic.
Definition: Formatter.h:226
@ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_PTR
This function is called to format an pointer operand.
Definition: Formatter.h:241
@ ZYDIS_FORMATTER_HOOK_PRINT_SEGMENT
This function is called right before formatting an memory operand to print the optional segment-regis...
Definition: Formatter.h:258
@ ZYDIS_FORMATTER_HOOK_POST
This function is called before the formatter finished formatting an instruction.
Definition: Formatter.h:209
uint8_t ZydisFormatterHookType
Defines the ZydisFormatterHookType datatype.
Definition: Formatter.h:195
ZYDIS_EXPORT ZydisStatus ZydisFormatterInit(ZydisFormatter *formatter, ZydisFormatterStyle style)
Initializes the given ZydisFormatter instance.
ZydisFormatterStyles
Values that represent formatter-styles.
Definition: Formatter.h:51
@ ZYDIS_FORMATTER_STYLE_INTEL
Generates intel-style disassembly.
Definition: Formatter.h:55
uint8_t ZydisFormatterStyle
Defines the ZydisFormatterStyle datatype.
Definition: Formatter.h:45
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.
ZydisStatus(* ZydisFormatterFormatAddressFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, ZydisDecodedInstruction *instruction, ZydisDecodedOperand *operand, uint64_t address)
Defines the ZydisFormatterFormatAddressFunc function pointer.
Definition: Formatter.h:392
ZydisStatus(* ZydisFormatterFormatOperandFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, ZydisDecodedInstruction *instruction, ZydisDecodedOperand *operand)
Defines the ZydisFormatterFormatOperandFunc function pointer.
Definition: Formatter.h:370
ZydisStatus(* ZydisFormatterFormatDecoratorFunc)(const ZydisFormatter *formatter, char **buffer, size_t bufferLen, ZydisDecodedInstruction *instruction, ZydisDecodedOperand *operand, ZydisDecoratorType type)
Defines the ZydisFormatterFormatDecoratorFunc function pointer.
Definition: Formatter.h:417
uint32_t ZydisStatus
Defines the ZydisStatus datatype.
Definition: Status.h:43
Defines the ZydisDecodedInstruction struct.
Definition: DecoderTypes.h:676
Defines the ZydisDecodedOperand struct.
Definition: DecoderTypes.h:52
Defines the ZydisFormatter struct.
Definition: Formatter.h:425
ZydisFormatterFormatFunc funcPrintPrefixes
Definition: Formatter.h:433
ZydisFormatterNotifyFunc funcPre
Definition: Formatter.h:430
ZydisFormatterFormatOperandFunc funcPrintImmediate
Definition: Formatter.h:444
ZydisFormatterFormatOperandFunc funcFormatOperandMem
Definition: Formatter.h:436
ZydisFormatterFormatOperandFunc funcFormatOperandPtr
Definition: Formatter.h:437
ZydisFormatterFormatOperandFunc funcPrintSegment
Definition: Formatter.h:440
ZydisFormatterFormatOperandFunc funcPrintDisplacement
Definition: Formatter.h:443
ZydisFormatterAddressFormat addressFormat
Definition: Formatter.h:427
ZydisFormatterFormatOperandFunc funcPrintOperandSize
Definition: Formatter.h:439
ZydisFormatterFormatAddressFunc funcPrintAddress
Definition: Formatter.h:442
ZydisFormatterImmediateFormat immediateFormat
Definition: Formatter.h:429
ZydisFormatterFormatOperandFunc funcFormatOperandReg
Definition: Formatter.h:435
ZydisFormatterDisplacementFormat displacementFormat
Definition: Formatter.h:428
ZydisFormatterFormatFunc funcFormatInstruction
Definition: Formatter.h:432
ZydisFormatterNotifyFunc funcPost
Definition: Formatter.h:431
ZydisFormatterFlags flags
Definition: Formatter.h:426
ZydisFormatterFormatOperandFunc funcFormatOperandImm
Definition: Formatter.h:438
ZydisFormatterFormatFunc funcPrintMnemonic
Definition: Formatter.h:434
ZydisFormatterFormatDecoratorFunc funcPrintDecorator
Definition: Formatter.h:441