Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/zydis/include/Zydis/Segment.h
4216 views
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
/**
28
* @file
29
* Functions and types providing encoding information about individual instruction bytes.
30
*/
31
32
#ifndef ZYDIS_SEGMENT_H
33
#define ZYDIS_SEGMENT_H
34
35
#include <Zycore/Defines.h>
36
#include <Zydis/DecoderTypes.h>
37
#include <Zydis/Status.h>
38
39
#ifdef __cplusplus
40
extern "C" {
41
#endif
42
43
/**
44
* @addtogroup segment Segment
45
* Functions and types providing encoding information about individual instruction bytes.
46
* @{
47
*/
48
49
/* ============================================================================================== */
50
/* Macros */
51
/* ============================================================================================== */
52
53
/* ---------------------------------------------------------------------------------------------- */
54
/* Constants */
55
/* ---------------------------------------------------------------------------------------------- */
56
57
#define ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT 9
58
59
/* ---------------------------------------------------------------------------------------------- */
60
61
/* ============================================================================================== */
62
/* Enums and types */
63
/* ============================================================================================== */
64
65
/**
66
* Defines the `ZydisInstructionSegment` struct.
67
*/
68
typedef enum ZydisInstructionSegment_
69
{
70
ZYDIS_INSTR_SEGMENT_NONE,
71
/**
72
* The legacy prefixes (including ignored `REX` prefixes).
73
*/
74
ZYDIS_INSTR_SEGMENT_PREFIXES,
75
/**
76
* The effective `REX` prefix byte.
77
*/
78
ZYDIS_INSTR_SEGMENT_REX,
79
/**
80
* The `XOP` prefix bytes.
81
*/
82
ZYDIS_INSTR_SEGMENT_XOP,
83
/**
84
* The `VEX` prefix bytes.
85
*/
86
ZYDIS_INSTR_SEGMENT_VEX,
87
/**
88
* The `EVEX` prefix bytes.
89
*/
90
ZYDIS_INSTR_SEGMENT_EVEX,
91
/**
92
* The `MVEX` prefix bytes.
93
*/
94
ZYDIS_INSTR_SEGMENT_MVEX,
95
/**
96
* The opcode bytes.
97
*/
98
ZYDIS_INSTR_SEGMENT_OPCODE,
99
/**
100
* The `ModRM` byte.
101
*/
102
ZYDIS_INSTR_SEGMENT_MODRM,
103
/**
104
* The `SIB` byte.
105
*/
106
ZYDIS_INSTR_SEGMENT_SIB,
107
/**
108
* The displacement bytes.
109
*/
110
ZYDIS_INSTR_SEGMENT_DISPLACEMENT,
111
/**
112
* The immediate bytes.
113
*/
114
ZYDIS_INSTR_SEGMENT_IMMEDIATE,
115
116
/**
117
* Maximum value of this enum.
118
*/
119
ZYDIS_INSTR_SEGMENT_MAX_VALUE = ZYDIS_INSTR_SEGMENT_IMMEDIATE,
120
/**
121
* The minimum number of bits required to represent all values of this enum.
122
*/
123
ZYDIS_INSTR_SEGMENT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_INSTR_SEGMENT_MAX_VALUE)
124
} ZydisInstructionSegment;
125
126
/**
127
* Defines the `ZydisInstructionSegments` struct.
128
*/
129
typedef struct ZydisInstructionSegments_
130
{
131
/**
132
* The number of logical instruction segments.
133
*/
134
ZyanU8 count;
135
struct
136
{
137
/**
138
* The type of the segment.
139
*/
140
ZydisInstructionSegment type;
141
/**
142
* The offset of the segment relative to the start of the instruction (in bytes).
143
*/
144
ZyanU8 offset;
145
/**
146
* The size of the segment, in bytes.
147
*/
148
ZyanU8 size;
149
} segments[ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT];
150
} ZydisInstructionSegments;
151
152
/* ============================================================================================== */
153
/* Exported functions */
154
/* ============================================================================================== */
155
156
/**
157
* Returns offsets and sizes of all logical instruction segments (e.g. `OPCODE`,
158
* `MODRM`, ...).
159
*
160
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
161
* @param segments Receives the instruction segments information.
162
*
163
* @return A zyan status code.
164
*/
165
ZYDIS_EXPORT ZyanStatus ZydisGetInstructionSegments(const ZydisDecodedInstruction* instruction,
166
ZydisInstructionSegments* segments);
167
168
/* ============================================================================================== */
169
170
/**
171
* @}
172
*/
173
174
#ifdef __cplusplus
175
}
176
#endif
177
178
#endif /* ZYDIS_SEGMENT_H */
179
180