/src/zydis/include/Zydis/Internal/DecoderData.h
Line | Count | Source |
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_INTERNAL_DECODERDATA_H |
28 | | #define ZYDIS_INTERNAL_DECODERDATA_H |
29 | | |
30 | | #include <Zycore/Defines.h> |
31 | | #include <Zycore/Types.h> |
32 | | #include <Zydis/Defines.h> |
33 | | |
34 | | #ifdef __cplusplus |
35 | | extern "C" { |
36 | | #endif |
37 | | |
38 | | /* ============================================================================================== */ |
39 | | /* Enums and types */ |
40 | | /* ============================================================================================== */ |
41 | | |
42 | | // MSVC does not like types other than (un-)signed int for bit-fields |
43 | | #ifdef ZYAN_MSVC |
44 | | # pragma warning(push) |
45 | | # pragma warning(disable:4214) |
46 | | #endif |
47 | | |
48 | | #pragma pack(push, 1) |
49 | | |
50 | | /* ---------------------------------------------------------------------------------------------- */ |
51 | | /* Decoder tree */ |
52 | | /* ---------------------------------------------------------------------------------------------- */ |
53 | | |
54 | | /** |
55 | | * Defines the `ZydisDecoderTreeNodeType` data-type. |
56 | | */ |
57 | | typedef ZyanU8 ZydisDecoderTreeNodeType; |
58 | | |
59 | | /** |
60 | | * Values that represent zydis decoder tree node types. |
61 | | */ |
62 | | enum ZydisDecoderTreeNodeTypes |
63 | | { |
64 | | ZYDIS_NODETYPE_INVALID = 0x00, |
65 | | /** |
66 | | * Reference to an instruction-definition. |
67 | | */ |
68 | | ZYDIS_NODETYPE_DEFINITION_MASK = 0x80, |
69 | | /** |
70 | | * Reference to an XOP-map filter. |
71 | | */ |
72 | | ZYDIS_NODETYPE_FILTER_XOP = 0x01, |
73 | | /** |
74 | | * Reference to an VEX-map filter. |
75 | | */ |
76 | | ZYDIS_NODETYPE_FILTER_VEX = 0x02, |
77 | | /** |
78 | | * Reference to an EVEX/MVEX-map filter. |
79 | | */ |
80 | | ZYDIS_NODETYPE_FILTER_EMVEX = 0x03, |
81 | | /** |
82 | | * Reference to a REX2-map filter. |
83 | | */ |
84 | | ZYDIS_NODETYPE_FILTER_REX2 = 0x04, |
85 | | /** |
86 | | * Reference to an opcode filter. |
87 | | */ |
88 | | ZYDIS_NODETYPE_FILTER_OPCODE = 0x05, |
89 | | /** |
90 | | * Reference to an instruction-mode filter. |
91 | | */ |
92 | | ZYDIS_NODETYPE_FILTER_MODE = 0x06, |
93 | | /** |
94 | | * Reference to an compacted instruction-mode filter. |
95 | | */ |
96 | | ZYDIS_NODETYPE_FILTER_MODE_COMPACT = 0x07, |
97 | | /** |
98 | | * Reference to a ModRM.mod filter. |
99 | | */ |
100 | | ZYDIS_NODETYPE_FILTER_MODRM_MOD = 0x08, |
101 | | /** |
102 | | * Reference to a compacted ModRM.mod filter. |
103 | | */ |
104 | | ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x09, |
105 | | /** |
106 | | * Reference to a ModRM.reg filter. |
107 | | */ |
108 | | ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x0A, |
109 | | /** |
110 | | * Reference to a ModRM.rm filter. |
111 | | */ |
112 | | ZYDIS_NODETYPE_FILTER_MODRM_RM = 0x0B, |
113 | | /** |
114 | | * Reference to a PrefixGroup1 filter. |
115 | | */ |
116 | | ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1 = 0x0C, |
117 | | /** |
118 | | * Reference to a mandatory-prefix filter. |
119 | | */ |
120 | | ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX = 0x0D, |
121 | | /** |
122 | | * Reference to an operand-size filter. |
123 | | */ |
124 | | ZYDIS_NODETYPE_FILTER_OPERAND_SIZE = 0x0E, |
125 | | /** |
126 | | * Reference to an address-size filter. |
127 | | */ |
128 | | ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE = 0x0F, |
129 | | /** |
130 | | * Reference to a vector-length filter. |
131 | | */ |
132 | | ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH = 0x10, |
133 | | /** |
134 | | * Reference to an REX/VEX/EVEX.W filter. |
135 | | */ |
136 | | ZYDIS_NODETYPE_FILTER_REX_W = 0x11, |
137 | | /** |
138 | | * Reference to an REX/VEX/EVEX.B filter. |
139 | | */ |
140 | | ZYDIS_NODETYPE_FILTER_REX_B = 0x12, |
141 | | /** |
142 | | * Reference to an EVEX.b filter. |
143 | | */ |
144 | | ZYDIS_NODETYPE_FILTER_EVEX_B = 0x13, |
145 | | /** |
146 | | * Reference to an MVEX.E filter. |
147 | | */ |
148 | | ZYDIS_NODETYPE_FILTER_MVEX_E = 0x14, |
149 | | /** |
150 | | * Reference to a AMD-mode filter. |
151 | | */ |
152 | | ZYDIS_NODETYPE_FILTER_MODE_AMD = 0x15, |
153 | | /** |
154 | | * Reference to a KNC-mode filter. |
155 | | */ |
156 | | ZYDIS_NODETYPE_FILTER_MODE_KNC = 0x16, |
157 | | /** |
158 | | * Reference to a MPX-mode filter. |
159 | | */ |
160 | | ZYDIS_NODETYPE_FILTER_MODE_MPX = 0x17, |
161 | | /** |
162 | | * Reference to a CET-mode filter. |
163 | | */ |
164 | | ZYDIS_NODETYPE_FILTER_MODE_CET = 0x18, |
165 | | /** |
166 | | * Reference to a LZCNT-mode filter. |
167 | | */ |
168 | | ZYDIS_NODETYPE_FILTER_MODE_LZCNT = 0x19, |
169 | | /** |
170 | | * Reference to a TZCNT-mode filter. |
171 | | */ |
172 | | ZYDIS_NODETYPE_FILTER_MODE_TZCNT = 0x1A, |
173 | | /** |
174 | | * Reference to a WBNOINVD-mode filter. |
175 | | */ |
176 | | ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD = 0x1B, |
177 | | /** |
178 | | * Reference to a CLDEMOTE-mode filter. |
179 | | */ |
180 | | ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE = 0x1C, |
181 | | /** |
182 | | * Reference to a IPREFETCH-mode filter. |
183 | | */ |
184 | | ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH = 0x1D, |
185 | | /** |
186 | | * Reference to a UD0_COMPAT-mode filter. |
187 | | */ |
188 | | ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT = 0x1E, |
189 | | /** |
190 | | * Reference to an EVEX.nd filter. |
191 | | */ |
192 | | ZYDIS_NODETYPE_FILTER_EVEX_ND = 0x1F, |
193 | | /** |
194 | | * Reference to an EVEX.nf filter. |
195 | | */ |
196 | | ZYDIS_NODETYPE_FILTER_EVEX_NF = 0x20, |
197 | | /** |
198 | | * Reference to an EVEX.scc filter. |
199 | | */ |
200 | | ZYDIS_NODETYPE_FILTER_EVEX_SCC = 0x21, |
201 | | /** |
202 | | * Reference to a REX2-prefix filter. |
203 | | */ |
204 | | ZYDIS_NODETYPE_FILTER_REX2_PREFIX = 0x22, |
205 | | /** |
206 | | * Reference to a EVEX.U filter. |
207 | | */ |
208 | | ZYDIS_NODETYPE_FILTER_EVEX_U = 0x23 |
209 | | }; |
210 | | |
211 | | /* ---------------------------------------------------------------------------------------------- */ |
212 | | |
213 | | /** |
214 | | * Defines the `ZydisDecoderTreeNodeValue` data-type. |
215 | | */ |
216 | | typedef ZyanU16 ZydisDecoderTreeNodeValue; |
217 | | |
218 | | /* ---------------------------------------------------------------------------------------------- */ |
219 | | |
220 | | /** |
221 | | * Defines the `ZydisDecoderTreeNode` struct. |
222 | | */ |
223 | | typedef struct ZydisDecoderTreeNode_ |
224 | | { |
225 | | ZydisDecoderTreeNodeType type; |
226 | | ZydisDecoderTreeNodeValue value; |
227 | | } ZydisDecoderTreeNode; |
228 | | |
229 | | /* ---------------------------------------------------------------------------------------------- */ |
230 | | |
231 | | #pragma pack(pop) |
232 | | |
233 | | #ifdef ZYAN_MSVC |
234 | | # pragma warning(pop) |
235 | | #endif |
236 | | |
237 | | /* ---------------------------------------------------------------------------------------------- */ |
238 | | /* Physical instruction encoding info */ |
239 | | /* ---------------------------------------------------------------------------------------------- */ |
240 | | |
241 | | /** |
242 | | * Defines the `ZydisInstructionEncodingFlags` data-type. |
243 | | */ |
244 | | typedef ZyanU8 ZydisInstructionEncodingFlags; |
245 | | |
246 | | /** |
247 | | * The instruction has an optional modrm byte. |
248 | | */ |
249 | 5.88k | #define ZYDIS_INSTR_ENC_FLAG_HAS_MODRM 0x01 |
250 | | |
251 | | /** |
252 | | * The instruction has an optional displacement value. |
253 | | */ |
254 | 5.84k | #define ZYDIS_INSTR_ENC_FLAG_HAS_DISP 0x02 |
255 | | |
256 | | /** |
257 | | * The instruction has an optional immediate value. |
258 | | */ |
259 | 5.83k | #define ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 0x04 |
260 | | |
261 | | /** |
262 | | * The instruction has a second optional immediate value. |
263 | | */ |
264 | 5.79k | #define ZYDIS_INSTR_ENC_FLAG_HAS_IMM1 0x08 |
265 | | |
266 | | /** |
267 | | * The instruction ignores the value of `modrm.mod` and always assumes `modrm.mod == 3` |
268 | | * ("reg, reg" - form). |
269 | | * |
270 | | * Instructions with this flag can't have a SIB byte or a displacement value. |
271 | | */ |
272 | 6.03k | #define ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM 0x10 |
273 | | |
274 | | /** |
275 | | * Defines the `ZydisInstructionEncodingInfo` struct. |
276 | | */ |
277 | | typedef struct ZydisInstructionEncodingInfo_ |
278 | | { |
279 | | /** |
280 | | * Contains flags with information about the physical instruction-encoding. |
281 | | */ |
282 | | ZydisInstructionEncodingFlags flags; |
283 | | /** |
284 | | * Displacement info. |
285 | | */ |
286 | | struct |
287 | | { |
288 | | /** |
289 | | * The size of the displacement value. |
290 | | */ |
291 | | ZyanU8 size[3]; |
292 | | } disp; |
293 | | /** |
294 | | * Immediate info. |
295 | | */ |
296 | | struct |
297 | | { |
298 | | /** |
299 | | * The size of the immediate value. |
300 | | */ |
301 | | ZyanU8 size[3]; |
302 | | /** |
303 | | * Signals, if the value is signed. |
304 | | */ |
305 | | ZyanBool is_signed; |
306 | | /** |
307 | | * Signals, if the value is an address. |
308 | | */ |
309 | | ZyanBool is_address; |
310 | | /** |
311 | | * Signals, if the value is a relative offset. |
312 | | */ |
313 | | ZyanBool is_relative; |
314 | | } imm[2]; |
315 | | } ZydisInstructionEncodingInfo; |
316 | | |
317 | | /* ---------------------------------------------------------------------------------------------- */ |
318 | | |
319 | | /* ============================================================================================== */ |
320 | | /* Functions */ |
321 | | /* ============================================================================================== */ |
322 | | |
323 | | /* ---------------------------------------------------------------------------------------------- */ |
324 | | /* Decoder tree */ |
325 | | /* ---------------------------------------------------------------------------------------------- */ |
326 | | |
327 | | extern const ZydisDecoderTreeNode zydis_decoder_tree_root; |
328 | | |
329 | | /** |
330 | | * Returns the root node of the instruction tree. |
331 | | * |
332 | | * @return The root node of the instruction tree. |
333 | | */ |
334 | | ZYAN_INLINE const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void) |
335 | 6.06k | { |
336 | 6.06k | return &zydis_decoder_tree_root; |
337 | 6.06k | } Decoder.c:ZydisDecoderTreeGetRootNode Line | Count | Source | 335 | 6.06k | { | 336 | 6.06k | return &zydis_decoder_tree_root; | 337 | 6.06k | } |
Unexecuted instantiation: DecoderData.c:ZydisDecoderTreeGetRootNode |
338 | | |
339 | | /** |
340 | | * Returns the child node of `parent` specified by `index`. |
341 | | * |
342 | | * @param parent The parent node. |
343 | | * @param index The index of the child node to retrieve. |
344 | | * |
345 | | * @return The specified child node. |
346 | | */ |
347 | | ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode( |
348 | | const ZydisDecoderTreeNode* parent, ZyanU16 index); |
349 | | |
350 | | /** |
351 | | * Returns information about optional instruction parts (like modrm, displacement or |
352 | | * immediates) for the instruction that is linked to the given `node`. |
353 | | * |
354 | | * @param node The instruction definition node. |
355 | | * @param info A pointer to the `ZydisInstructionParts` struct. |
356 | | */ |
357 | | ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node, |
358 | | const ZydisInstructionEncodingInfo** info); |
359 | | |
360 | | /* ---------------------------------------------------------------------------------------------- */ |
361 | | |
362 | | /* ============================================================================================== */ |
363 | | |
364 | | #ifdef __cplusplus |
365 | | } |
366 | | #endif |
367 | | |
368 | | #endif /* ZYDIS_INTERNAL_DECODERDATA_H */ |