Path: blob/master/dep/zydis/include/Zydis/Internal/FormatterIntel.h
4219 views
/***************************************************************************************************12Zyan Disassembler Library (Zydis)34Original Author : Florian Bernd, Joel Hoener56* 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* Implements the `INTEL` style instruction-formatter.29*/3031#ifndef ZYDIS_FORMATTER_INTEL_H32#define ZYDIS_FORMATTER_INTEL_H3334#include <Zydis/Formatter.h>35#include <Zydis/Internal/FormatterBase.h>36#include <Zydis/Internal/String.h>3738#ifdef __cplusplus39extern "C" {40#endif4142/* ============================================================================================== */43/* Formatter functions */44/* ============================================================================================== */4546/* ---------------------------------------------------------------------------------------------- */47/* Intel */48/* ---------------------------------------------------------------------------------------------- */4950ZyanStatus ZydisFormatterIntelFormatInstruction(const ZydisFormatter* formatter,51ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);5253ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,54ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);5556ZyanStatus ZydisFormatterIntelPrintMnemonic(const ZydisFormatter* formatter,57ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);5859ZyanStatus ZydisFormatterIntelPrintRegister(const ZydisFormatter* formatter,60ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg);6162ZyanStatus ZydisFormatterIntelPrintDISP(const ZydisFormatter* formatter,63ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);6465ZyanStatus ZydisFormatterIntelPrintTypecast(const ZydisFormatter* formatter,66ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);6768/* ---------------------------------------------------------------------------------------------- */69/* MASM */70/* ---------------------------------------------------------------------------------------------- */7172ZyanStatus ZydisFormatterIntelFormatInstructionMASM(const ZydisFormatter* formatter,73ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);7475ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter,76ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);7778/* ---------------------------------------------------------------------------------------------- */7980/* ============================================================================================== */81/* Fomatter presets */82/* ============================================================================================== */8384/* ---------------------------------------------------------------------------------------------- */85/* INTEL */86/* ---------------------------------------------------------------------------------------------- */8788/**89* The default formatter configuration for `INTEL` style disassembly.90*/91static const ZydisFormatter FORMATTER_INTEL =92{93/* style */ ZYDIS_FORMATTER_STYLE_INTEL,94/* force_memory_size */ ZYAN_FALSE,95/* force_memory_seg */ ZYAN_FALSE,96/* force_memory_scale */ ZYAN_TRUE,97/* force_relative_branches */ ZYAN_FALSE,98/* force_relative_riprel */ ZYAN_FALSE,99/* print_branch_size */ ZYAN_FALSE,100/* detailed_prefixes */ ZYAN_FALSE,101/* addr_base */ ZYDIS_NUMERIC_BASE_HEX,102/* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,103/* addr_padding_absolute */ ZYDIS_PADDING_AUTO,104/* addr_padding_relative */ 2,105/* disp_base */ ZYDIS_NUMERIC_BASE_HEX,106/* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,107/* disp_padding */ 2,108/* imm_base */ ZYDIS_NUMERIC_BASE_HEX,109/* imm_signedness */ ZYDIS_SIGNEDNESS_UNSIGNED,110/* imm_padding */ 2,111/* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,112/* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,113/* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,114/* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,115/* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,116/* hex_uppercase */ ZYAN_TRUE,117/* hex_force_leading_number */ ZYAN_FALSE,118/* number_format */119{120// ZYDIS_NUMERIC_BASE_DEC121{122// Prefix123{124/* string */ ZYAN_NULL,125/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),126/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },127},128// Suffix129{130/* string */ ZYAN_NULL,131/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),132/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },133}134},135// ZYDIS_NUMERIC_BASE_HEX136{137// Prefix138{139/* string */ &FORMATTER_INTEL.number_format[140ZYDIS_NUMERIC_BASE_HEX][0].string_data,141/* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"),142/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },143},144// Suffix145{146/* string */ ZYAN_NULL,147/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),148/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },149}150}151},152/* func_pre_instruction */ ZYAN_NULL,153/* func_post_instruction */ ZYAN_NULL,154/* func_format_instruction */ &ZydisFormatterIntelFormatInstruction,155/* func_pre_operand */ ZYAN_NULL,156/* func_post_operand */ ZYAN_NULL,157/* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,158/* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,159/* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,160/* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,161/* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,162/* func_print_register */ &ZydisFormatterIntelPrintRegister,163/* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS,164/* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL,165/* func_print_disp */ &ZydisFormatterIntelPrintDISP,166/* func_print_imm */ &ZydisFormatterBasePrintIMM,167/* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,168/* func_print_segment */ &ZydisFormatterBasePrintSegment,169/* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,170/* func_print_decorator */ &ZydisFormatterBasePrintDecorator171};172173/* ---------------------------------------------------------------------------------------------- */174/* MASM */175/* ---------------------------------------------------------------------------------------------- */176177/**178* The default formatter configuration for `MASM` style disassembly.179*/180static const ZydisFormatter FORMATTER_INTEL_MASM =181{182/* style */ ZYDIS_FORMATTER_STYLE_INTEL_MASM,183/* force_memory_size */ ZYAN_TRUE,184/* force_memory_seg */ ZYAN_FALSE,185/* force_memory_scale */ ZYAN_TRUE,186/* force_relative_branches */ ZYAN_FALSE,187/* force_relative_riprel */ ZYAN_FALSE,188/* print_branch_size */ ZYAN_FALSE,189/* detailed_prefixes */ ZYAN_FALSE,190/* addr_base */ ZYDIS_NUMERIC_BASE_HEX,191/* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,192/* addr_padding_absolute */ ZYDIS_PADDING_DISABLED,193/* addr_padding_relative */ ZYDIS_PADDING_DISABLED,194/* disp_base */ ZYDIS_NUMERIC_BASE_HEX,195/* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,196/* disp_padding */ ZYDIS_PADDING_DISABLED,197/* imm_base */ ZYDIS_NUMERIC_BASE_HEX,198/* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO,199/* imm_padding */ ZYDIS_PADDING_DISABLED,200/* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,201/* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,202/* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,203/* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,204/* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,205/* hex_uppercase */ ZYAN_TRUE,206/* hex_force_leading_number */ ZYAN_TRUE,207/* number_format */208{209// ZYDIS_NUMERIC_BASE_DEC210{211// Prefix212{213/* string */ ZYAN_NULL,214/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),215/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },216},217// Suffix218{219/* string */ ZYAN_NULL,220/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),221/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },222}223},224// ZYDIS_NUMERIC_BASE_HEX225{226// Prefix227{228/* string */ ZYAN_NULL,229/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),230/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },231},232// Suffix233{234/* string */ &FORMATTER_INTEL_MASM.number_format[235ZYDIS_NUMERIC_BASE_HEX][1].string_data,236/* string_data */ ZYAN_DEFINE_STRING_VIEW("h"),237/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },238}239}240},241/* func_pre_instruction */ ZYAN_NULL,242/* func_post_instruction */ ZYAN_NULL,243/* func_format_instruction */ &ZydisFormatterIntelFormatInstructionMASM,244/* func_pre_operand */ ZYAN_NULL,245/* func_post_operand */ ZYAN_NULL,246/* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,247/* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,248/* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,249/* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,250/* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,251/* func_print_register */ &ZydisFormatterIntelPrintRegister,252/* func_print_address_abs */ &ZydisFormatterIntelPrintAddressMASM,253/* func_print_address_rel */ &ZydisFormatterIntelPrintAddressMASM,254/* func_print_disp */ &ZydisFormatterIntelPrintDISP,255/* func_print_imm */ &ZydisFormatterBasePrintIMM,256/* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,257/* func_print_segment */ &ZydisFormatterBasePrintSegment,258/* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,259/* func_print_decorator */ &ZydisFormatterBasePrintDecorator260};261262/* ---------------------------------------------------------------------------------------------- */263264/* ============================================================================================== */265266#ifdef __cplusplus267}268#endif269270#endif // ZYDIS_FORMATTER_INTEL_H271272273