Zydis 3.2.1.0
FormatterIntel.h
Go to the documentation of this file.
1/***************************************************************************************************
2
3 Zyan Disassembler Library (Zydis)
4
5 Original Author : Florian Bernd, Joel Hoener
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_INTEL_H
33#define ZYDIS_FORMATTER_INTEL_H
34
35#include <Zydis/Formatter.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* ============================================================================================== */
44/* Formatter functions */
45/* ============================================================================================== */
46
47/* ---------------------------------------------------------------------------------------------- */
48/* Intel */
49/* ---------------------------------------------------------------------------------------------- */
50
51ZyanStatus ZydisFormatterIntelFormatInstruction(const ZydisFormatter* formatter,
53
54ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,
56
57ZyanStatus ZydisFormatterIntelPrintMnemonic(const ZydisFormatter* formatter,
59
60ZyanStatus ZydisFormatterIntelPrintRegister(const ZydisFormatter* formatter,
61 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg);
62
63ZyanStatus ZydisFormatterIntelPrintDISP(const ZydisFormatter* formatter,
65
66ZyanStatus ZydisFormatterIntelPrintTypecast(const ZydisFormatter* formatter,
68
69/* ---------------------------------------------------------------------------------------------- */
70/* MASM */
71/* ---------------------------------------------------------------------------------------------- */
72
73ZyanStatus ZydisFormatterIntelFormatInstructionMASM(const ZydisFormatter* formatter,
75
76ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter,
78
79/* ---------------------------------------------------------------------------------------------- */
80
81/* ============================================================================================== */
82/* Fomatter presets */
83/* ============================================================================================== */
84
85/* ---------------------------------------------------------------------------------------------- */
86/* INTEL */
87/* ---------------------------------------------------------------------------------------------- */
88
92static const ZydisFormatter FORMATTER_INTEL =
93{
95 /* force_memory_size */ ZYAN_FALSE,
96 /* force_memory_seg */ ZYAN_FALSE,
97 /* force_memory_scale */ ZYAN_TRUE,
98 /* force_relative_branches */ ZYAN_FALSE,
99 /* force_relative_riprel */ ZYAN_FALSE,
100 /* print_branch_size */ ZYAN_FALSE,
101 /* detailed_prefixes */ ZYAN_FALSE,
102 /* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
103 /* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
104 /* addr_padding_absolute */ ZYDIS_PADDING_AUTO,
105 /* addr_padding_relative */ 2,
106 /* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
107 /* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
108 /* disp_padding */ 2,
109 /* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
110 /* imm_signedness */ ZYDIS_SIGNEDNESS_UNSIGNED,
111 /* imm_padding */ 2,
112 /* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
113 /* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
114 /* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
115 /* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
116 /* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
117 /* hex_uppercase */ ZYAN_TRUE,
118 /* number_format */
119 {
120 // ZYDIS_NUMERIC_BASE_DEC
121 {
122 // Prefix
123 {
124 /* string */ ZYAN_NULL,
125 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
126 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
127 },
128 // Suffix
129 {
130 /* string */ ZYAN_NULL,
131 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
132 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
133 }
134 },
135 // ZYDIS_NUMERIC_BASE_HEX
136 {
137 // Prefix
138 {
139 /* string */ &FORMATTER_INTEL.number_format[
141 /* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"),
142 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
143 },
144 // Suffix
145 {
146 /* string */ ZYAN_NULL,
147 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
148 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
149 }
150 }
151 },
152 /* func_pre_instruction */ ZYAN_NULL,
153 /* func_post_instruction */ ZYAN_NULL,
154 /* func_format_instruction */ &ZydisFormatterIntelFormatInstruction,
155 /* func_pre_operand */ ZYAN_NULL,
156 /* func_post_operand */ ZYAN_NULL,
157 /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
158 /* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,
159 /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
160 /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
161 /* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,
162 /* func_print_register */ &ZydisFormatterIntelPrintRegister,
163 /* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS,
164 /* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL,
165 /* func_print_disp */ &ZydisFormatterIntelPrintDISP,
166 /* func_print_imm */ &ZydisFormatterBasePrintIMM,
167 /* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,
168 /* func_print_segment */ &ZydisFormatterBasePrintSegment,
169 /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
170 /* func_print_decorator */ &ZydisFormatterBasePrintDecorator
171};
172
173/* ---------------------------------------------------------------------------------------------- */
174/* MASM */
175/* ---------------------------------------------------------------------------------------------- */
176
180static const ZydisFormatter FORMATTER_INTEL_MASM =
181{
183 /* force_memory_size */ ZYAN_TRUE,
184 /* force_memory_seg */ ZYAN_FALSE,
185 /* force_memory_scale */ ZYAN_TRUE,
186 /* force_relative_branches */ ZYAN_FALSE,
187 /* force_relative_riprel */ ZYAN_FALSE,
188 /* print_branch_size */ ZYAN_FALSE,
189 /* detailed_prefixes */ ZYAN_FALSE,
190 /* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
191 /* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
192 /* addr_padding_absolute */ ZYDIS_PADDING_DISABLED,
193 /* addr_padding_relative */ ZYDIS_PADDING_DISABLED,
194 /* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
195 /* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
196 /* disp_padding */ ZYDIS_PADDING_DISABLED,
197 /* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
198 /* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO,
199 /* imm_padding */ ZYDIS_PADDING_DISABLED,
200 /* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
201 /* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
202 /* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
203 /* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
204 /* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
205 /* hex_uppercase */ ZYAN_TRUE,
206 /* number_format */
207 {
208 // ZYDIS_NUMERIC_BASE_DEC
209 {
210 // Prefix
211 {
212 /* string */ ZYAN_NULL,
213 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
214 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
215 },
216 // Suffix
217 {
218 /* string */ ZYAN_NULL,
219 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
220 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
221 }
222 },
223 // ZYDIS_NUMERIC_BASE_HEX
224 {
225 // Prefix
226 {
227 /* string */ ZYAN_NULL,
228 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
229 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
230 },
231 // Suffix
232 {
233 /* string */ &FORMATTER_INTEL_MASM.number_format[
235 /* string_data */ ZYAN_DEFINE_STRING_VIEW("h"),
236 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
237 }
238 }
239 },
240 /* func_pre_instruction */ ZYAN_NULL,
241 /* func_post_instruction */ ZYAN_NULL,
242 /* func_format_instruction */ &ZydisFormatterIntelFormatInstructionMASM,
243 /* func_pre_operand */ ZYAN_NULL,
244 /* func_post_operand */ ZYAN_NULL,
245 /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
246 /* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,
247 /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
248 /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
249 /* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,
250 /* func_print_register */ &ZydisFormatterIntelPrintRegister,
251 /* func_print_address_abs */ &ZydisFormatterIntelPrintAddressMASM,
252 /* func_print_address_rel */ &ZydisFormatterIntelPrintAddressMASM,
253 /* func_print_disp */ &ZydisFormatterIntelPrintDISP,
254 /* func_print_imm */ &ZydisFormatterBasePrintIMM,
255 /* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,
256 /* func_print_segment */ &ZydisFormatterBasePrintSegment,
257 /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
258 /* func_print_decorator */ &ZydisFormatterBasePrintDecorator
259};
260
261/* ---------------------------------------------------------------------------------------------- */
262
263/* ============================================================================================== */
264
265#ifdef __cplusplus
266}
267#endif
268
269#endif // ZYDIS_FORMATTER_INTEL_H
Provides formatter functions that are shared between the different formatters.
Functions for formatting instructions to human-readable text.
@ ZYDIS_FORMATTER_STYLE_INTEL_MASM
Generates MASM-style disassembly that is directly accepted as input for the MASM assembler.
Definition: Formatter.h:82
@ ZYDIS_FORMATTER_STYLE_INTEL
Generates Intel-style disassembly.
Definition: Formatter.h:75
@ ZYDIS_SIGNEDNESS_AUTO
Automatically choose the most suitable mode based on the operands ZydisDecodedOperand....
Definition: Formatter.h:369
@ ZYDIS_SIGNEDNESS_UNSIGNED
Force unsigned values.
Definition: Formatter.h:377
@ ZYDIS_SIGNEDNESS_SIGNED
Force signed values.
Definition: Formatter.h:373
@ ZYDIS_PADDING_AUTO
Padds the value to the current stack-width for addresses, or to the operand-width for immediate value...
Definition: Formatter.h:404
@ ZYDIS_PADDING_DISABLED
Disables padding.
Definition: Formatter.h:399
@ ZYDIS_NUMERIC_BASE_HEX
Hexadecimal system.
Definition: Formatter.h:346
Provides some internal, more performant, but unsafe helper functions for the ZyanString data-type.
@ ZYDIS_LETTER_CASE_DEFAULT
Uses the given text "as is".
Definition: String.h:70
Defines the ZydisFormatterBuffer struct.
Definition: FormatterBuffer.h:168
Defines the ZydisFormatterContext struct.
Definition: Formatter.h:639
Defines the ZydisFormatter struct.
Definition: Formatter.h:753
ZyanStringView string_data
The ZyanStringView to use as prefix/suffix.
Definition: Formatter.h:865
struct ZydisFormatter_::@0 number_format[ZYDIS_NUMERIC_BASE_MAX_VALUE+1][2]
The number formats for all numeric bases.