Zydis: include/Zydis/Internal/FormatterIntel.h Source File

Zydis v4.1.1

Loading...
Searching...
No Matches
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
31
32#ifndef ZYDIS_FORMATTER_INTEL_H
33#define ZYDIS_FORMATTER_INTEL_H
34
35#include <Zydis/Formatter.h>
36#include <Zydis/Internal/FormatterBase.h>
37#include <Zydis/Internal/String.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,
52 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
53
54ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,
55 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
56
57ZyanStatus ZydisFormatterIntelPrintMnemonic(const ZydisFormatter* formatter,
58 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
59
60ZyanStatus ZydisFormatterIntelPrintRegister(const ZydisFormatter* formatter,
61 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg);
62
63ZyanStatus ZydisFormatterIntelPrintDISP(const ZydisFormatter* formatter,
64 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
65
66ZyanStatus ZydisFormatterIntelPrintTypecast(const ZydisFormatter* formatter,
67 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
68
69/* ---------------------------------------------------------------------------------------------- */
70/* MASM */
71/* ---------------------------------------------------------------------------------------------- */
72
73ZyanStatus ZydisFormatterIntelFormatInstructionMASM(const ZydisFormatter* formatter,
74 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
75
76ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter,
77 ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
78
79/* ---------------------------------------------------------------------------------------------- */
80
81/* ============================================================================================== */
82/* Fomatter presets */
83/* ============================================================================================== */
84
85/* ---------------------------------------------------------------------------------------------- */
86/* INTEL */
87/* ---------------------------------------------------------------------------------------------- */
88
92static const ZydisFormatter FORMATTER_INTEL =
93{
94 /* style */ ZYDIS_FORMATTER_STYLE_INTEL,
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 /* hex_force_leading_number */ ZYAN_FALSE,
119 /* number_format */
120 {
121 // ZYDIS_NUMERIC_BASE_DEC
122 {
123 // Prefix
124 {
125 /* string */ ZYAN_NULL,
126 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
127 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
128 },
129 // Suffix
130 {
131 /* string */ ZYAN_NULL,
132 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
133 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
134 }
135 },
136 // ZYDIS_NUMERIC_BASE_HEX
137 {
138 // Prefix
139 {
140 /* string */ &FORMATTER_INTEL.number_format[
141 ZYDIS_NUMERIC_BASE_HEX][0].string_data,
142 /* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"),
143 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
144 },
145 // Suffix
146 {
147 /* string */ ZYAN_NULL,
148 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
149 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
150 }
151 }
152 },
153 /* func_pre_instruction */ ZYAN_NULL,
154 /* func_post_instruction */ ZYAN_NULL,
155 /* func_format_instruction */ &ZydisFormatterIntelFormatInstruction,
156 /* func_pre_operand */ ZYAN_NULL,
157 /* func_post_operand */ ZYAN_NULL,
158 /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
159 /* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,
160 /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
161 /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
162 /* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,
163 /* func_print_register */ &ZydisFormatterIntelPrintRegister,
164 /* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS,
165 /* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL,
166 /* func_print_disp */ &ZydisFormatterIntelPrintDISP,
167 /* func_print_imm */ &ZydisFormatterBasePrintIMM,
168 /* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,
169 /* func_print_segment */ &ZydisFormatterBasePrintSegment,
170 /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
171 /* func_print_decorator */ &ZydisFormatterBasePrintDecorator
172};
173
174/* ---------------------------------------------------------------------------------------------- */
175/* MASM */
176/* ---------------------------------------------------------------------------------------------- */
177
181static const ZydisFormatter FORMATTER_INTEL_MASM =
182{
183 /* style */ ZYDIS_FORMATTER_STYLE_INTEL_MASM,
184 /* force_memory_size */ ZYAN_TRUE,
185 /* force_memory_seg */ ZYAN_FALSE,
186 /* force_memory_scale */ ZYAN_TRUE,
187 /* force_relative_branches */ ZYAN_FALSE,
188 /* force_relative_riprel */ ZYAN_FALSE,
189 /* print_branch_size */ ZYAN_FALSE,
190 /* detailed_prefixes */ ZYAN_FALSE,
191 /* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
192 /* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
193 /* addr_padding_absolute */ ZYDIS_PADDING_DISABLED,
194 /* addr_padding_relative */ ZYDIS_PADDING_DISABLED,
195 /* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
196 /* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
197 /* disp_padding */ ZYDIS_PADDING_DISABLED,
198 /* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
199 /* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO,
200 /* imm_padding */ ZYDIS_PADDING_DISABLED,
201 /* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
202 /* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
203 /* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
204 /* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
205 /* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
206 /* hex_uppercase */ ZYAN_TRUE,
207 /* hex_force_leading_number */ ZYAN_TRUE,
208 /* number_format */
209 {
210 // ZYDIS_NUMERIC_BASE_DEC
211 {
212 // Prefix
213 {
214 /* string */ ZYAN_NULL,
215 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
216 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
217 },
218 // Suffix
219 {
220 /* string */ ZYAN_NULL,
221 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
222 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
223 }
224 },
225 // ZYDIS_NUMERIC_BASE_HEX
226 {
227 // Prefix
228 {
229 /* string */ ZYAN_NULL,
230 /* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
231 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
232 },
233 // Suffix
234 {
235 /* string */ &FORMATTER_INTEL_MASM.number_format[
236 ZYDIS_NUMERIC_BASE_HEX][1].string_data,
237 /* string_data */ ZYAN_DEFINE_STRING_VIEW("h"),
238 /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
239 }
240 }
241 },
242 /* func_pre_instruction */ ZYAN_NULL,
243 /* func_post_instruction */ ZYAN_NULL,
244 /* func_format_instruction */ &ZydisFormatterIntelFormatInstructionMASM,
245 /* func_pre_operand */ ZYAN_NULL,
246 /* func_post_operand */ ZYAN_NULL,
247 /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
248 /* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,
249 /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
250 /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
251 /* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,
252 /* func_print_register */ &ZydisFormatterIntelPrintRegister,
253 /* func_print_address_abs */ &ZydisFormatterIntelPrintAddressMASM,
254 /* func_print_address_rel */ &ZydisFormatterIntelPrintAddressMASM,
255 /* func_print_disp */ &ZydisFormatterIntelPrintDISP,
256 /* func_print_imm */ &ZydisFormatterBasePrintIMM,
257 /* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,
258 /* func_print_segment */ &ZydisFormatterBasePrintSegment,
259 /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
260 /* func_print_decorator */ &ZydisFormatterBasePrintDecorator
261};
262
263/* ---------------------------------------------------------------------------------------------- */
264
265/* ============================================================================================== */
266
267#ifdef __cplusplus
268}
269#endif
270
271#endif // ZYDIS_FORMATTER_INTEL_H
ZydisRegister
enum ZydisRegister_ ZydisRegister
Defines the ZydisRegister enum.
FormatterBase.h
Provides formatter functions that are shared between the different formatters.
ZydisFormatterBasePrintIMM
ZyanStatus ZydisFormatterBasePrintIMM(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBasePrintAddressABS
ZyanStatus ZydisFormatterBasePrintAddressABS(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBasePrintPrefixes
ZyanStatus ZydisFormatterBasePrintPrefixes(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBasePrintSegment
ZyanStatus ZydisFormatterBasePrintSegment(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBasePrintAddressREL
ZyanStatus ZydisFormatterBasePrintAddressREL(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBaseFormatOperandREG
ZyanStatus ZydisFormatterBaseFormatOperandREG(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBaseFormatOperandPTR
ZyanStatus ZydisFormatterBaseFormatOperandPTR(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBasePrintDecorator
ZyanStatus ZydisFormatterBasePrintDecorator(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisDecorator decorator)
ZydisFormatterBaseFormatOperandIMM
ZyanStatus ZydisFormatterBaseFormatOperandIMM(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterBuffer
struct ZydisFormatterBuffer_ ZydisFormatterBuffer
Defines the ZydisFormatterBuffer struct.
ZydisFormatterIntelPrintTypecast
ZyanStatus ZydisFormatterIntelPrintTypecast(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterIntelPrintDISP
ZyanStatus ZydisFormatterIntelPrintDISP(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterIntelPrintRegister
ZyanStatus ZydisFormatterIntelPrintRegister(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context, ZydisRegister reg)
ZydisFormatterIntelPrintMnemonic
ZyanStatus ZydisFormatterIntelPrintMnemonic(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterIntelPrintAddressMASM
ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterIntelFormatOperandMEM
ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterIntelFormatInstruction
ZyanStatus ZydisFormatterIntelFormatInstruction(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
ZydisFormatterIntelFormatInstructionMASM
ZyanStatus ZydisFormatterIntelFormatInstructionMASM(const ZydisFormatter *formatter, ZydisFormatterBuffer *buffer, ZydisFormatterContext *context)
Formatter.h
Functions for formatting instructions to human-readable text.
ZYDIS_FORMATTER_STYLE_INTEL_MASM
@ 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
@ ZYDIS_FORMATTER_STYLE_INTEL
Generates Intel-style disassembly.
Definition Formatter.h:75
ZYDIS_SIGNEDNESS_AUTO
@ ZYDIS_SIGNEDNESS_AUTO
Automatically choose the most suitable mode based on the operands ZydisDecodedOperand....
Definition Formatter.h:381
ZYDIS_SIGNEDNESS_UNSIGNED
@ ZYDIS_SIGNEDNESS_UNSIGNED
Force unsigned values.
Definition Formatter.h:389
ZYDIS_SIGNEDNESS_SIGNED
@ ZYDIS_SIGNEDNESS_SIGNED
Force signed values.
Definition Formatter.h:385
ZydisFormatter
struct ZydisFormatter_ ZydisFormatter
Definition Formatter.h:646
ZYDIS_PADDING_AUTO
@ ZYDIS_PADDING_AUTO
Padds the value to the current stack-width for addresses, or to the operand-width for immediate value...
Definition Formatter.h:417
ZYDIS_PADDING_DISABLED
@ ZYDIS_PADDING_DISABLED
Disables padding.
Definition Formatter.h:412
ZydisFormatterContext
struct ZydisFormatterContext_ ZydisFormatterContext
Context structure that that is passed to all formatter.
ZYDIS_NUMERIC_BASE_HEX
@ ZYDIS_NUMERIC_BASE_HEX
Hexadecimal system.
Definition Formatter.h:358
String.h
Provides some internal, more performant, but unsafe helper functions for the ZyanString data-type.
ZYDIS_LETTER_CASE_DEFAULT
@ ZYDIS_LETTER_CASE_DEFAULT
Uses the given text "as is".
Definition String.h:72