Zydis: include/Zydis/Decoder.h Source File

Zydis v4.1.0

Loading...
Searching...
No Matches
Decoder.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_DECODER_H
33#define ZYDIS_DECODER_H
34
35#include <Zycore/Types.h>
36#include <Zycore/Defines.h>
37#include <Zydis/DecoderTypes.h>
38#include <Zydis/Status.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* ============================================================================================== */
45/* Enums and types */
46/* ============================================================================================== */
47
48/* ---------------------------------------------------------------------------------------------- */
49/* Decoder mode */
50/* ---------------------------------------------------------------------------------------------- */
51
55 typedef enum ZydisDecoderMode_
56{
69 ZYDIS_DECODER_MODE_MINIMAL,
80 ZYDIS_DECODER_MODE_AMD_BRANCHES,
89 ZYDIS_DECODER_MODE_KNC,
97 ZYDIS_DECODER_MODE_MPX,
105 ZYDIS_DECODER_MODE_CET,
113 ZYDIS_DECODER_MODE_LZCNT,
121 ZYDIS_DECODER_MODE_TZCNT,
130 ZYDIS_DECODER_MODE_WBNOINVD,
138 ZYDIS_DECODER_MODE_CLDEMOTE,
146 ZYDIS_DECODER_MODE_IPREFETCH,
155 ZYDIS_DECODER_MODE_UD0_COMPAT,
156
160 ZYDIS_DECODER_MODE_MAX_VALUE = ZYDIS_DECODER_MODE_UD0_COMPAT,
164 ZYDIS_DECODER_MODE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_DECODER_MODE_MAX_VALUE)
165} ZydisDecoderMode;
166
167/* ---------------------------------------------------------------------------------------------- */
168/* Decoder struct */
169/* ---------------------------------------------------------------------------------------------- */
170
177 typedef struct ZydisDecoder_
178{
182 ZydisMachineMode machine_mode;
186 ZydisStackWidth stack_width;
190 ZyanU32 decoder_mode;
191} ZydisDecoder;
192
193/* ---------------------------------------------------------------------------------------------- */
194
195/* ============================================================================================== */
196/* Exported functions */
197/* ============================================================================================== */
198
214 ZYDIS_EXPORT ZyanStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machine_mode,
215 ZydisStackWidth stack_width);
216
226 ZYDIS_EXPORT ZyanStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDecoderMode mode,
227 ZyanBool enabled);
228
257 ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeFull(const ZydisDecoder* decoder,
258 const void* buffer, ZyanUSize length, ZydisDecodedInstruction* instruction,
259 ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT]);
260
278 ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeInstruction(const ZydisDecoder* decoder,
279 ZydisDecoderContext* context, const void* buffer, ZyanUSize length,
280 ZydisDecodedInstruction* instruction);
281
308 ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeOperands(const ZydisDecoder* decoder,
309 const ZydisDecoderContext* context, const ZydisDecodedInstruction* instruction,
310 ZydisDecodedOperand* operands, ZyanU8 operand_count);
311
314/* ============================================================================================== */
315
316#ifdef __cplusplus
317}
318#endif
319
320#endif /* ZYDIS_DECODER_H */
DecoderTypes.h
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
ZydisDecoder
struct ZydisDecoder_ ZydisDecoder
Defines the ZydisDecoder struct.
ZydisDecoderMode_
ZydisDecoderMode_
Defines the ZydisDecoderMode enum.
Definition Decoder.h:56
ZYDIS_DECODER_MODE_WBNOINVD
@ ZYDIS_DECODER_MODE_WBNOINVD
Enables the WBNOINVD mode.
Definition Decoder.h:130
ZYDIS_DECODER_MODE_KNC
@ ZYDIS_DECODER_MODE_KNC
Enables KNC compatibility-mode.
Definition Decoder.h:89
ZYDIS_DECODER_MODE_REQUIRED_BITS
@ ZYDIS_DECODER_MODE_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition Decoder.h:164
ZYDIS_DECODER_MODE_IPREFETCH
@ ZYDIS_DECODER_MODE_IPREFETCH
Enables the IPREFETCH mode.
Definition Decoder.h:146
ZYDIS_DECODER_MODE_LZCNT
@ ZYDIS_DECODER_MODE_LZCNT
Enables the LZCNT mode.
Definition Decoder.h:113
ZYDIS_DECODER_MODE_MINIMAL
@ ZYDIS_DECODER_MODE_MINIMAL
Enables minimal instruction decoding without semantic analysis.
Definition Decoder.h:69
ZYDIS_DECODER_MODE_TZCNT
@ ZYDIS_DECODER_MODE_TZCNT
Enables the TZCNT mode.
Definition Decoder.h:121
ZYDIS_DECODER_MODE_MAX_VALUE
@ ZYDIS_DECODER_MODE_MAX_VALUE
Maximum value of this enum.
Definition Decoder.h:160
ZYDIS_DECODER_MODE_UD0_COMPAT
@ ZYDIS_DECODER_MODE_UD0_COMPAT
Enables the UD0 compatibility mode.
Definition Decoder.h:155
ZYDIS_DECODER_MODE_AMD_BRANCHES
@ ZYDIS_DECODER_MODE_AMD_BRANCHES
Enables the AMD-branch mode.
Definition Decoder.h:80
ZYDIS_DECODER_MODE_MPX
@ ZYDIS_DECODER_MODE_MPX
Enables the MPX mode.
Definition Decoder.h:97
ZYDIS_DECODER_MODE_CLDEMOTE
@ ZYDIS_DECODER_MODE_CLDEMOTE
Enables the CLDEMOTE mode.
Definition Decoder.h:138
ZYDIS_DECODER_MODE_CET
@ ZYDIS_DECODER_MODE_CET
Enables the CET mode.
Definition Decoder.h:105
ZydisDecoderMode
enum ZydisDecoderMode_ ZydisDecoderMode
Defines the ZydisDecoderMode enum.
ZYDIS_EXPORT
#define ZYDIS_EXPORT
Symbol is exported in shared library builds.
Definition Defines.h:67
ZYDIS_MAX_OPERAND_COUNT
#define ZYDIS_MAX_OPERAND_COUNT
Definition SharedTypes.h:50
ZydisStackWidth
enum ZydisStackWidth_ ZydisStackWidth
Defines the ZydisStackWidth enum.
ZydisMachineMode
enum ZydisMachineMode_ ZydisMachineMode
Defines the ZydisMachineMode enum.
Status.h
Status code definitions and check macros.
ZydisDecoderDecodeFull
ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeFull(const ZydisDecoder *decoder, const void *buffer, ZyanUSize length, ZydisDecodedInstruction *instruction, ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT])
Decodes the instruction in the given input buffer and returns all details (e.g.
ZydisDecoderDecodeInstruction
ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeInstruction(const ZydisDecoder *decoder, ZydisDecoderContext *context, const void *buffer, ZyanUSize length, ZydisDecodedInstruction *instruction)
Decodes the instruction in the given input buffer.
ZydisDecoderInit
ZYDIS_EXPORT ZyanStatus ZydisDecoderInit(ZydisDecoder *decoder, ZydisMachineMode machine_mode, ZydisStackWidth stack_width)
Initializes the given ZydisDecoder instance.
ZydisDecoderEnableMode
ZYDIS_EXPORT ZyanStatus ZydisDecoderEnableMode(ZydisDecoder *decoder, ZydisDecoderMode mode, ZyanBool enabled)
Enables or disables the specified decoder-mode.
ZydisDecoderDecodeOperands
ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeOperands(const ZydisDecoder *decoder, const ZydisDecoderContext *context, const ZydisDecodedInstruction *instruction, ZydisDecodedOperand *operands, ZyanU8 operand_count)
Decodes the instruction operands.
ZydisDecodedInstruction_
Information about a decoded instruction.
Definition DecoderTypes.h:1238
ZydisDecodedOperand_
Defines the ZydisDecodedOperand struct.
Definition DecoderTypes.h:200
ZydisDecoderContext_
The decoder context is used to preserve some internal state between subsequent decode operations for ...
Definition DecoderTypes.h:1339
ZydisDecoder_
Defines the ZydisDecoder struct.
Definition Decoder.h:178
ZydisDecoder_::stack_width
ZydisStackWidth stack_width
The stack width.
Definition Decoder.h:186
ZydisDecoder_::machine_mode
ZydisMachineMode machine_mode
The machine mode.
Definition Decoder.h:182
ZydisDecoder_::decoder_mode
ZyanU32 decoder_mode
The decoder mode bitmap.
Definition Decoder.h:190