Path: blob/master/dep/zydis/include/Zydis/Segment.h
4216 views
/***************************************************************************************************12Zyan Disassembler Library (Zydis)34Original Author : Florian Bernd56* Permission is hereby granted, free of charge, to any person obtaining a copy7* of this software and associated documentation files (the "Software"), to deal8* in the Software without restriction, including without limitation the rights9* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10* copies of the Software, and to permit persons to whom the Software is11* furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included in all14* copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22* SOFTWARE.2324***************************************************************************************************/2526/**27* @file28* Functions and types providing encoding information about individual instruction bytes.29*/3031#ifndef ZYDIS_SEGMENT_H32#define ZYDIS_SEGMENT_H3334#include <Zycore/Defines.h>35#include <Zydis/DecoderTypes.h>36#include <Zydis/Status.h>3738#ifdef __cplusplus39extern "C" {40#endif4142/**43* @addtogroup segment Segment44* Functions and types providing encoding information about individual instruction bytes.45* @{46*/4748/* ============================================================================================== */49/* Macros */50/* ============================================================================================== */5152/* ---------------------------------------------------------------------------------------------- */53/* Constants */54/* ---------------------------------------------------------------------------------------------- */5556#define ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT 95758/* ---------------------------------------------------------------------------------------------- */5960/* ============================================================================================== */61/* Enums and types */62/* ============================================================================================== */6364/**65* Defines the `ZydisInstructionSegment` struct.66*/67typedef enum ZydisInstructionSegment_68{69ZYDIS_INSTR_SEGMENT_NONE,70/**71* The legacy prefixes (including ignored `REX` prefixes).72*/73ZYDIS_INSTR_SEGMENT_PREFIXES,74/**75* The effective `REX` prefix byte.76*/77ZYDIS_INSTR_SEGMENT_REX,78/**79* The `XOP` prefix bytes.80*/81ZYDIS_INSTR_SEGMENT_XOP,82/**83* The `VEX` prefix bytes.84*/85ZYDIS_INSTR_SEGMENT_VEX,86/**87* The `EVEX` prefix bytes.88*/89ZYDIS_INSTR_SEGMENT_EVEX,90/**91* The `MVEX` prefix bytes.92*/93ZYDIS_INSTR_SEGMENT_MVEX,94/**95* The opcode bytes.96*/97ZYDIS_INSTR_SEGMENT_OPCODE,98/**99* The `ModRM` byte.100*/101ZYDIS_INSTR_SEGMENT_MODRM,102/**103* The `SIB` byte.104*/105ZYDIS_INSTR_SEGMENT_SIB,106/**107* The displacement bytes.108*/109ZYDIS_INSTR_SEGMENT_DISPLACEMENT,110/**111* The immediate bytes.112*/113ZYDIS_INSTR_SEGMENT_IMMEDIATE,114115/**116* Maximum value of this enum.117*/118ZYDIS_INSTR_SEGMENT_MAX_VALUE = ZYDIS_INSTR_SEGMENT_IMMEDIATE,119/**120* The minimum number of bits required to represent all values of this enum.121*/122ZYDIS_INSTR_SEGMENT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_INSTR_SEGMENT_MAX_VALUE)123} ZydisInstructionSegment;124125/**126* Defines the `ZydisInstructionSegments` struct.127*/128typedef struct ZydisInstructionSegments_129{130/**131* The number of logical instruction segments.132*/133ZyanU8 count;134struct135{136/**137* The type of the segment.138*/139ZydisInstructionSegment type;140/**141* The offset of the segment relative to the start of the instruction (in bytes).142*/143ZyanU8 offset;144/**145* The size of the segment, in bytes.146*/147ZyanU8 size;148} segments[ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT];149} ZydisInstructionSegments;150151/* ============================================================================================== */152/* Exported functions */153/* ============================================================================================== */154155/**156* Returns offsets and sizes of all logical instruction segments (e.g. `OPCODE`,157* `MODRM`, ...).158*159* @param instruction A pointer to the `ZydisDecodedInstruction` struct.160* @param segments Receives the instruction segments information.161*162* @return A zyan status code.163*/164ZYDIS_EXPORT ZyanStatus ZydisGetInstructionSegments(const ZydisDecodedInstruction* instruction,165ZydisInstructionSegments* segments);166167/* ============================================================================================== */168169/**170* @}171*/172173#ifdef __cplusplus174}175#endif176177#endif /* ZYDIS_SEGMENT_H */178179180