Path: blob/master/dep/zydis/include/Zydis/Internal/DecoderData.h
4219 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#ifndef ZYDIS_INTERNAL_DECODERDATA_H27#define ZYDIS_INTERNAL_DECODERDATA_H2829#include <Zycore/Defines.h>30#include <Zycore/Types.h>31#include <Zydis/Defines.h>3233#ifdef __cplusplus34extern "C" {35#endif3637/* ============================================================================================== */38/* Enums and types */39/* ============================================================================================== */4041// MSVC does not like types other than (un-)signed int for bit-fields42#ifdef ZYAN_MSVC43# pragma warning(push)44# pragma warning(disable:4214)45#endif4647#pragma pack(push, 1)4849/* ---------------------------------------------------------------------------------------------- */50/* Decoder tree */51/* ---------------------------------------------------------------------------------------------- */5253/**54* Defines the `ZydisDecoderTreeNodeType` data-type.55*/56typedef ZyanU8 ZydisDecoderTreeNodeType;5758/**59* Values that represent zydis decoder tree node types.60*/61enum ZydisDecoderTreeNodeTypes62{63ZYDIS_NODETYPE_INVALID = 0x00,64/**65* Reference to an instruction-definition.66*/67ZYDIS_NODETYPE_DEFINITION_MASK = 0x80,68/**69* Reference to an XOP-map filter.70*/71ZYDIS_NODETYPE_FILTER_XOP = 0x01,72/**73* Reference to an VEX-map filter.74*/75ZYDIS_NODETYPE_FILTER_VEX = 0x02,76/**77* Reference to an EVEX/MVEX-map filter.78*/79ZYDIS_NODETYPE_FILTER_EMVEX = 0x03,80/**81* Reference to an opcode filter.82*/83ZYDIS_NODETYPE_FILTER_OPCODE = 0x04,84/**85* Reference to an instruction-mode filter.86*/87ZYDIS_NODETYPE_FILTER_MODE = 0x05,88/**89* Reference to an compacted instruction-mode filter.90*/91ZYDIS_NODETYPE_FILTER_MODE_COMPACT = 0x06,92/**93* Reference to a ModRM.mod filter.94*/95ZYDIS_NODETYPE_FILTER_MODRM_MOD = 0x07,96/**97* Reference to a compacted ModRM.mod filter.98*/99ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x08,100/**101* Reference to a ModRM.reg filter.102*/103ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x09,104/**105* Reference to a ModRM.rm filter.106*/107ZYDIS_NODETYPE_FILTER_MODRM_RM = 0x0A,108/**109* Reference to a PrefixGroup1 filter.110*/111ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1 = 0x0B,112/**113* Reference to a mandatory-prefix filter.114*/115ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX = 0x0C,116/**117* Reference to an operand-size filter.118*/119ZYDIS_NODETYPE_FILTER_OPERAND_SIZE = 0x0D,120/**121* Reference to an address-size filter.122*/123ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE = 0x0E,124/**125* Reference to a vector-length filter.126*/127ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH = 0x0F,128/**129* Reference to an REX/VEX/EVEX.W filter.130*/131ZYDIS_NODETYPE_FILTER_REX_W = 0x10,132/**133* Reference to an REX/VEX/EVEX.B filter.134*/135ZYDIS_NODETYPE_FILTER_REX_B = 0x11,136/**137* Reference to an EVEX.b filter.138*/139ZYDIS_NODETYPE_FILTER_EVEX_B = 0x12,140/**141* Reference to an MVEX.E filter.142*/143ZYDIS_NODETYPE_FILTER_MVEX_E = 0x13,144/**145* Reference to a AMD-mode filter.146*/147ZYDIS_NODETYPE_FILTER_MODE_AMD = 0x14,148/**149* Reference to a KNC-mode filter.150*/151ZYDIS_NODETYPE_FILTER_MODE_KNC = 0x15,152/**153* Reference to a MPX-mode filter.154*/155ZYDIS_NODETYPE_FILTER_MODE_MPX = 0x16,156/**157* Reference to a CET-mode filter.158*/159ZYDIS_NODETYPE_FILTER_MODE_CET = 0x17,160/**161* Reference to a LZCNT-mode filter.162*/163ZYDIS_NODETYPE_FILTER_MODE_LZCNT = 0x18,164/**165* Reference to a TZCNT-mode filter.166*/167ZYDIS_NODETYPE_FILTER_MODE_TZCNT = 0x19,168/**169* Reference to a WBNOINVD-mode filter.170*/171ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD = 0x1A,172/**173* Reference to a CLDEMOTE-mode filter.174*/175ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE = 0x1B176};177178/* ---------------------------------------------------------------------------------------------- */179180/**181* Defines the `ZydisDecoderTreeNodeValue` data-type.182*/183typedef ZyanU16 ZydisDecoderTreeNodeValue;184185/* ---------------------------------------------------------------------------------------------- */186187/**188* Defines the `ZydisDecoderTreeNode` struct.189*/190typedef struct ZydisDecoderTreeNode_191{192ZydisDecoderTreeNodeType type;193ZydisDecoderTreeNodeValue value;194} ZydisDecoderTreeNode;195196/* ---------------------------------------------------------------------------------------------- */197198#pragma pack(pop)199200#ifdef ZYAN_MSVC201# pragma warning(pop)202#endif203204/* ---------------------------------------------------------------------------------------------- */205/* Physical instruction encoding info */206/* ---------------------------------------------------------------------------------------------- */207208/**209* Defines the `ZydisInstructionEncodingFlags` data-type.210*/211typedef ZyanU8 ZydisInstructionEncodingFlags;212213/**214* The instruction has an optional modrm byte.215*/216#define ZYDIS_INSTR_ENC_FLAG_HAS_MODRM 0x01217218/**219* The instruction has an optional displacement value.220*/221#define ZYDIS_INSTR_ENC_FLAG_HAS_DISP 0x02222223/**224* The instruction has an optional immediate value.225*/226#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 0x04227228/**229* The instruction has a second optional immediate value.230*/231#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM1 0x08232233/**234* The instruction ignores the value of `modrm.mod` and always assumes `modrm.mod == 3`235* ("reg, reg" - form).236*237* Instructions with this flag can't have a SIB byte or a displacement value.238*/239#define ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM 0x10240241/**242* Defines the `ZydisInstructionEncodingInfo` struct.243*/244typedef struct ZydisInstructionEncodingInfo_245{246/**247* Contains flags with information about the physical instruction-encoding.248*/249ZydisInstructionEncodingFlags flags;250/**251* Displacement info.252*/253struct254{255/**256* The size of the displacement value.257*/258ZyanU8 size[3];259} disp;260/**261* Immediate info.262*/263struct264{265/**266* The size of the immediate value.267*/268ZyanU8 size[3];269/**270* Signals, if the value is signed.271*/272ZyanBool is_signed;273/**274* Signals, if the value is a relative offset.275*/276ZyanBool is_relative;277} imm[2];278} ZydisInstructionEncodingInfo;279280/* ---------------------------------------------------------------------------------------------- */281282/* ============================================================================================== */283/* Functions */284/* ============================================================================================== */285286/* ---------------------------------------------------------------------------------------------- */287/* Decoder tree */288/* ---------------------------------------------------------------------------------------------- */289290extern const ZydisDecoderTreeNode zydis_decoder_tree_root;291292/**293* Returns the root node of the instruction tree.294*295* @return The root node of the instruction tree.296*/297ZYAN_INLINE const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void)298{299return &zydis_decoder_tree_root;300}301302/**303* Returns the child node of `parent` specified by `index`.304*305* @param parent The parent node.306* @param index The index of the child node to retrieve.307*308* @return The specified child node.309*/310ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(311const ZydisDecoderTreeNode* parent, ZyanU16 index);312313/**314* Returns information about optional instruction parts (like modrm, displacement or315* immediates) for the instruction that is linked to the given `node`.316*317* @param node The instruction definition node.318* @param info A pointer to the `ZydisInstructionParts` struct.319*/320ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node,321const ZydisInstructionEncodingInfo** info);322323/* ---------------------------------------------------------------------------------------------- */324325/* ============================================================================================== */326327#ifdef __cplusplus328}329#endif330331#endif /* ZYDIS_INTERNAL_DECODERDATA_H */332333334