Zydis 3.2.1.0
Utils.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_UTILS_H
33#define ZYDIS_UTILS_H
34
35#include <Zycore/Defines.h>
36#include <Zydis/DecoderTypes.h>
37#include <Zydis/Status.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* ============================================================================================== */
44/* Macros */
45/* ============================================================================================== */
46
47/* ---------------------------------------------------------------------------------------------- */
48/* Constants */
49/* ---------------------------------------------------------------------------------------------- */
50
51#define ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT 9
52
53/* ---------------------------------------------------------------------------------------------- */
54
55/* ============================================================================================== */
56/* Enums and types */
57/* ============================================================================================== */
58
63{
64 ZYDIS_INSTR_SEGMENT_NONE,
109
119
124{
128 ZyanU8 count;
129 struct
130 {
138 ZyanU8 offset;
142 ZyanU8 size;
143 } segments[ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT];
145
146/* ============================================================================================== */
147/* Exported functions */
148/* ============================================================================================== */
149
156/* ---------------------------------------------------------------------------------------------- */
157/* Address calculation */
158/* ---------------------------------------------------------------------------------------------- */
159
160// TODO: Provide a function that works in minimal-mode and does not require a operand parameter
161
178ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
179 const ZydisDecodedOperand* operand, ZyanU64 runtime_address, ZyanU64* result_address);
180
198ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction* instruction,
199 const ZydisDecodedOperand* operand, ZyanU64 runtime_address,
200 const ZydisRegisterContext* register_context, ZyanU64* result_address);
201
202/* ---------------------------------------------------------------------------------------------- */
203/* Accessed CPU flags */
204/* ---------------------------------------------------------------------------------------------- */
205
215ZYDIS_EXPORT ZyanStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction,
216 ZydisCPUFlagAction action, ZydisCPUFlags* flags);
217
229ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsRead(
230 const ZydisDecodedInstruction* instruction, ZydisCPUFlags* flags);
231
244ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsWritten(
245 const ZydisDecodedInstruction* instruction, ZydisCPUFlags* flags);
246
247/* ---------------------------------------------------------------------------------------------- */
248/* Instruction segments */
249/* ---------------------------------------------------------------------------------------------- */
250
260ZYDIS_EXPORT ZyanStatus ZydisGetInstructionSegments(const ZydisDecodedInstruction* instruction,
261 ZydisInstructionSegments* segments);
262
263/* ---------------------------------------------------------------------------------------------- */
264
269/* ============================================================================================== */
270
271#ifdef __cplusplus
272}
273#endif
274
275#endif /* ZYDIS_UTILS_H */
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
ZyanU32 ZydisCPUFlags
Defines the ZydisCPUFlags data-type.
Definition: DecoderTypes.h:466
enum ZydisCPUFlagAction_ ZydisCPUFlagAction
Defines the ZydisCPUFlagAction enum.
Status code definitions and check macros.
enum ZydisInstructionSegment_ ZydisInstructionSegment
Defines the ZydisInstructionSegment struct.
struct ZydisInstructionSegments_ ZydisInstructionSegments
Defines the ZydisInstructionSegments struct.
ZydisInstructionSegment_
Defines the ZydisInstructionSegment struct.
Definition: Utils.h:63
@ ZYDIS_INSTR_SEGMENT_XOP
The XOP prefix bytes.
Definition: Utils.h:76
@ ZYDIS_INSTR_SEGMENT_IMMEDIATE
The immediate bytes.
Definition: Utils.h:108
@ ZYDIS_INSTR_SEGMENT_OPCODE
The opcode bytes.
Definition: Utils.h:92
@ ZYDIS_INSTR_SEGMENT_MODRM
The ModRM byte.
Definition: Utils.h:96
@ ZYDIS_INSTR_SEGMENT_MVEX
The MVEX prefix bytes.
Definition: Utils.h:88
@ ZYDIS_INSTR_SEGMENT_REX
The effective REX prefix byte.
Definition: Utils.h:72
@ ZYDIS_INSTR_SEGMENT_SIB
The SIB byte.
Definition: Utils.h:100
@ ZYDIS_INSTR_SEGMENT_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: Utils.h:117
@ ZYDIS_INSTR_SEGMENT_EVEX
The EVEX prefix bytes.
Definition: Utils.h:84
@ ZYDIS_INSTR_SEGMENT_VEX
The VEX prefix bytes.
Definition: Utils.h:80
@ ZYDIS_INSTR_SEGMENT_DISPLACEMENT
The displacement bytes.
Definition: Utils.h:104
@ ZYDIS_INSTR_SEGMENT_PREFIXES
The legacy prefixes (including ignored REX prefixes).
Definition: Utils.h:68
@ ZYDIS_INSTR_SEGMENT_MAX_VALUE
Maximum value of this enum.
Definition: Utils.h:113
ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZyanU64 runtime_address, ZyanU64 *result_address)
Calculates the absolute address value for the given instruction operand.
ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operand, ZyanU64 runtime_address, const ZydisRegisterContext *register_context, ZyanU64 *result_address)
Calculates the absolute address value for the given instruction operand.
ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsWritten(const ZydisDecodedInstruction *instruction, ZydisCPUFlags *flags)
Returns a mask of accessed CPU-flags that are written (modified, undefined) by the current instructio...
ZYDIS_EXPORT ZyanStatus ZydisGetInstructionSegments(const ZydisDecodedInstruction *instruction, ZydisInstructionSegments *segments)
Returns offsets and sizes of all logical instruction segments (e.g.
ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsRead(const ZydisDecodedInstruction *instruction, ZydisCPUFlags *flags)
Returns a mask of accessed CPU-flags that are read (tested) by the current instruction.
ZYDIS_EXPORT ZyanStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction *instruction, ZydisCPUFlagAction action, ZydisCPUFlags *flags)
Returns a mask of accessed CPU-flags matching the given action.
Information about a decoded instruction.
Definition: DecoderTypes.h:969
Defines the ZydisDecodedOperand struct.
Definition: DecoderTypes.h:111
Defines the ZydisInstructionSegments struct.
Definition: Utils.h:124
ZyanU8 count
The number of logical instruction segments.
Definition: Utils.h:128
ZyanU8 size
The size of the segment, in bytes.
Definition: Utils.h:142
ZydisInstructionSegment type
The type of the segment.
Definition: Utils.h:134
ZyanU8 offset
The offset of the segment relative to the start of the instruction (in bytes).
Definition: Utils.h:138
Defines the ZydisRegisterContext struct.
Definition: Register.h:171