Coverage Report

Created: 2026-01-22 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zydis/src/SharedData.c
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
#include <Zydis/Internal/SharedData.h>
28
29
/* ============================================================================================== */
30
/* Data tables                                                                                    */
31
/* ============================================================================================== */
32
33
/* ---------------------------------------------------------------------------------------------- */
34
/* Instruction definitions                                                                        */
35
/* ---------------------------------------------------------------------------------------------- */
36
37
#ifdef ZYDIS_MINIMAL_MODE
38
#   define ZYDIS_NOTMIN(x)
39
#else
40
#   define ZYDIS_NOTMIN(x) , x
41
#endif
42
43
#include <Generated/InstructionDefinitions.inc>
44
45
#undef ZYDIS_NOTMIN
46
47
/* ---------------------------------------------------------------------------------------------- */
48
/* Operand definitions                                                                            */
49
/* ---------------------------------------------------------------------------------------------- */
50
51
#define ZYDIS_OPERAND_DEFINITION(type, encoding, access) \
52
    { type, encoding, access }
53
54
#include <Generated/OperandDefinitions.inc>
55
56
#undef ZYDIS_OPERAND_DEFINITION
57
58
/* ---------------------------------------------------------------------------------------------- */
59
/* Accessed CPU flags                                                                             */
60
/* ---------------------------------------------------------------------------------------------- */
61
62
#include <Generated/AccessedFlags.inc>
63
64
/* ---------------------------------------------------------------------------------------------- */
65
66
/* ============================================================================================== */
67
/* Functions                                                                                      */
68
/* ============================================================================================== */
69
70
/* ---------------------------------------------------------------------------------------------- */
71
/* Instruction definition                                                                         */
72
/* ---------------------------------------------------------------------------------------------- */
73
74
void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding, ZyanU16 id,
75
    const ZydisInstructionDefinition** definition)
76
23.9k
{
77
23.9k
    switch (encoding)
78
23.9k
    {
79
12.3k
    case ZYDIS_INSTRUCTION_ENCODING_LEGACY:
80
12.8k
    case ZYDIS_INSTRUCTION_ENCODING_REX2:
81
12.8k
        *definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_LEGACY[id];
82
12.8k
        break;
83
36
    case ZYDIS_INSTRUCTION_ENCODING_3DNOW:
84
36
        *definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_3DNOW[id];
85
36
        break;
86
84
    case ZYDIS_INSTRUCTION_ENCODING_XOP:
87
84
        *definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_XOP[id];
88
84
        break;
89
924
    case ZYDIS_INSTRUCTION_ENCODING_VEX:
90
924
        *definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_VEX[id];
91
924
        break;
92
0
#ifndef ZYDIS_DISABLE_AVX512
93
9.17k
    case ZYDIS_INSTRUCTION_ENCODING_EVEX:
94
9.17k
        *definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_EVEX[id];
95
9.17k
        break;
96
0
#endif
97
0
#ifndef ZYDIS_DISABLE_KNC
98
851
    case ZYDIS_INSTRUCTION_ENCODING_MVEX:
99
851
        *definition = (ZydisInstructionDefinition*)&ISTR_DEFINITIONS_MVEX[id];
100
851
        break;
101
0
#endif
102
0
    default:
103
0
        ZYAN_UNREACHABLE;
104
23.9k
    }
105
23.9k
}
106
107
/* ---------------------------------------------------------------------------------------------- */
108
/* Operand definition                                                                             */
109
/* ---------------------------------------------------------------------------------------------- */
110
111
#ifndef ZYDIS_MINIMAL_MODE
112
const ZydisOperandDefinition* ZydisGetOperandDefinitions(
113
    const ZydisInstructionDefinition* definition)
114
18.9k
{
115
18.9k
    if (definition->operand_count == 0)
116
12
    {
117
12
        return ZYAN_NULL;
118
12
    }
119
18.9k
    ZYAN_ASSERT(definition->operand_reference != 0x7FFF);
120
18.9k
    return &OPERAND_DEFINITIONS[definition->operand_reference];
121
18.9k
}
122
123
const ZyanU16 *ZydisGetOperandSizes(const ZydisOperandDefinition *definition)
124
13.3k
{
125
13.3k
    return OPERAND_SIZES[definition->size_reference];
126
13.3k
}
127
128
const ZydisOperandDetails *ZydisGetOperandDetails(const ZydisOperandDefinition *definition)
129
27.3k
{
130
27.3k
    return &OPERAND_DETAILS[definition->details_reference];
131
27.3k
}
132
#endif
133
134
/* ---------------------------------------------------------------------------------------------- */
135
/* Element info                                                                                   */
136
/* ---------------------------------------------------------------------------------------------- */
137
138
#ifndef ZYDIS_MINIMAL_MODE
139
void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
140
    ZydisElementSize* size)
141
4.70k
{
142
4.70k
    static const struct
143
4.70k
    {
144
4.70k
        ZydisElementType type;
145
4.70k
        ZydisElementSize size;
146
4.70k
    } lookup[] =
147
4.70k
    {
148
4.70k
        { ZYDIS_ELEMENT_TYPE_INVALID  ,   0 },
149
4.70k
        { ZYDIS_ELEMENT_TYPE_INVALID  ,   0 },
150
4.70k
        { ZYDIS_ELEMENT_TYPE_STRUCT   ,   0 },
151
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,   0 },
152
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,   0 },
153
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,   1 },
154
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,   8 },
155
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,  32 }, // TODO: Should indicate 4 INT8 elements
156
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,  16 },
157
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,  32 }, // TODO: Should indicate 2 INT16 elements
158
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,  32 },
159
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      ,  64 },
160
4.70k
        { ZYDIS_ELEMENT_TYPE_INT      , 128 },
161
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,   8 },
162
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,  32 }, // TODO: Should indicate 4 UINT8 elements
163
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,  16 },
164
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,  32 }, // TODO: Should indicate 2 UINT16 elements
165
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,  32 },
166
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     ,  64 },
167
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     , 128 },
168
4.70k
        { ZYDIS_ELEMENT_TYPE_UINT     , 256 },
169
4.70k
        { ZYDIS_ELEMENT_TYPE_FLOAT16  ,  16 },
170
4.70k
        { ZYDIS_ELEMENT_TYPE_FLOAT16  ,  32 }, // TODO: Should indicate 2 FLOAT16 elements
171
4.70k
        { ZYDIS_ELEMENT_TYPE_FLOAT32  ,  32 },
172
4.70k
        { ZYDIS_ELEMENT_TYPE_FLOAT64  ,  64 },
173
4.70k
        { ZYDIS_ELEMENT_TYPE_FLOAT80  ,  80 },
174
4.70k
        { ZYDIS_ELEMENT_TYPE_BFLOAT16 ,  32 }, // TODO: Should indicate 2 BFLOAT16 elements
175
4.70k
        { ZYDIS_ELEMENT_TYPE_LONGBCD  ,  80 },
176
4.70k
        { ZYDIS_ELEMENT_TYPE_CC       ,   3 },
177
4.70k
        { ZYDIS_ELEMENT_TYPE_CC       ,   5 }
178
4.70k
    };
179
4.70k
    ZYAN_STATIC_ASSERT(ZYAN_ARRAY_LENGTH(lookup) == ZYDIS_IELEMENT_TYPE_MAX_VALUE + 1);
180
4.70k
    ZYAN_ASSERT((ZyanUSize)element < ZYAN_ARRAY_LENGTH(lookup));
181
182
4.70k
    *type = lookup[element].type;
183
4.70k
    *size = lookup[element].size;
184
4.70k
}
185
#endif
186
187
/* ---------------------------------------------------------------------------------------------- */
188
/* Accessed CPU flags                                                                             */
189
/* ---------------------------------------------------------------------------------------------- */
190
191
#ifndef ZYDIS_MINIMAL_MODE
192
ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
193
    const ZydisDefinitionAccessedFlags** flags)
194
2.58k
{
195
2.58k
    ZYAN_ASSERT(definition->flags_reference < ZYAN_ARRAY_LENGTH(ACCESSED_FLAGS));
196
2.58k
    *flags = &ACCESSED_FLAGS[definition->flags_reference];
197
2.58k
    return (definition->flags_reference != 0);
198
2.58k
}
199
#endif
200
201
/* ---------------------------------------------------------------------------------------------- */
202
203
/* ============================================================================================== */