1*1003e004SJérôme Duval /*************************************************************************************************** 2*1003e004SJérôme Duval 3*1003e004SJérôme Duval Zyan Disassembler Library (Zydis) 4*1003e004SJérôme Duval 5*1003e004SJérôme Duval Original Author : Florian Bernd, Joel Hoener 6*1003e004SJérôme Duval 7*1003e004SJérôme Duval * Permission is hereby granted, free of charge, to any person obtaining a copy 8*1003e004SJérôme Duval * of this software and associated documentation files (the "Software"), to deal 9*1003e004SJérôme Duval * in the Software without restriction, including without limitation the rights 10*1003e004SJérôme Duval * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11*1003e004SJérôme Duval * copies of the Software, and to permit persons to whom the Software is 12*1003e004SJérôme Duval * furnished to do so, subject to the following conditions: 13*1003e004SJérôme Duval * 14*1003e004SJérôme Duval * The above copyright notice and this permission notice shall be included in all 15*1003e004SJérôme Duval * copies or substantial portions of the Software. 16*1003e004SJérôme Duval * 17*1003e004SJérôme Duval * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18*1003e004SJérôme Duval * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19*1003e004SJérôme Duval * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20*1003e004SJérôme Duval * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21*1003e004SJérôme Duval * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22*1003e004SJérôme Duval * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23*1003e004SJérôme Duval * SOFTWARE. 24*1003e004SJérôme Duval 25*1003e004SJérôme Duval ***************************************************************************************************/ 26*1003e004SJérôme Duval 27*1003e004SJérôme Duval /** 28*1003e004SJérôme Duval * @file 29*1003e004SJérôme Duval * Implements the `INTEL` style instruction-formatter. 30*1003e004SJérôme Duval */ 31*1003e004SJérôme Duval 32*1003e004SJérôme Duval #ifndef ZYDIS_FORMATTER_INTEL_H 33*1003e004SJérôme Duval #define ZYDIS_FORMATTER_INTEL_H 34*1003e004SJérôme Duval 35*1003e004SJérôme Duval #include <Zydis/Formatter.h> 36*1003e004SJérôme Duval #include <Zydis/Internal/FormatterBase.h> 37*1003e004SJérôme Duval #include <Zydis/Internal/String.h> 38*1003e004SJérôme Duval 39*1003e004SJérôme Duval #ifdef __cplusplus 40*1003e004SJérôme Duval extern "C" { 41*1003e004SJérôme Duval #endif 42*1003e004SJérôme Duval 43*1003e004SJérôme Duval /* ============================================================================================== */ 44*1003e004SJérôme Duval /* Formatter functions */ 45*1003e004SJérôme Duval /* ============================================================================================== */ 46*1003e004SJérôme Duval 47*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 48*1003e004SJérôme Duval /* Intel */ 49*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 50*1003e004SJérôme Duval 51*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelFormatInstruction(const ZydisFormatter* formatter, 52*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 53*1003e004SJérôme Duval 54*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter, 55*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 56*1003e004SJérôme Duval 57*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelPrintMnemonic(const ZydisFormatter* formatter, 58*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 59*1003e004SJérôme Duval 60*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelPrintRegister(const ZydisFormatter* formatter, 61*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg); 62*1003e004SJérôme Duval 63*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelPrintDISP(const ZydisFormatter* formatter, 64*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 65*1003e004SJérôme Duval 66*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelPrintTypecast(const ZydisFormatter* formatter, 67*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 68*1003e004SJérôme Duval 69*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 70*1003e004SJérôme Duval /* MASM */ 71*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 72*1003e004SJérôme Duval 73*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelFormatInstructionMASM(const ZydisFormatter* formatter, 74*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 75*1003e004SJérôme Duval 76*1003e004SJérôme Duval ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter, 77*1003e004SJérôme Duval ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 78*1003e004SJérôme Duval 79*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 80*1003e004SJérôme Duval 81*1003e004SJérôme Duval /* ============================================================================================== */ 82*1003e004SJérôme Duval /* Fomatter presets */ 83*1003e004SJérôme Duval /* ============================================================================================== */ 84*1003e004SJérôme Duval 85*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 86*1003e004SJérôme Duval /* INTEL */ 87*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 88*1003e004SJérôme Duval 89*1003e004SJérôme Duval /** 90*1003e004SJérôme Duval * The default formatter configuration for `INTEL` style disassembly. 91*1003e004SJérôme Duval */ 92*1003e004SJérôme Duval static const ZydisFormatter FORMATTER_INTEL = 93*1003e004SJérôme Duval { 94*1003e004SJérôme Duval /* style */ ZYDIS_FORMATTER_STYLE_INTEL, 95*1003e004SJérôme Duval /* force_memory_size */ ZYAN_FALSE, 96*1003e004SJérôme Duval /* force_memory_seg */ ZYAN_FALSE, 97*1003e004SJérôme Duval /* force_memory_scale */ ZYAN_TRUE, 98*1003e004SJérôme Duval /* force_relative_branches */ ZYAN_FALSE, 99*1003e004SJérôme Duval /* force_relative_riprel */ ZYAN_FALSE, 100*1003e004SJérôme Duval /* print_branch_size */ ZYAN_FALSE, 101*1003e004SJérôme Duval /* detailed_prefixes */ ZYAN_FALSE, 102*1003e004SJérôme Duval /* addr_base */ ZYDIS_NUMERIC_BASE_HEX, 103*1003e004SJérôme Duval /* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED, 104*1003e004SJérôme Duval /* addr_padding_absolute */ ZYDIS_PADDING_AUTO, 105*1003e004SJérôme Duval /* addr_padding_relative */ 2, 106*1003e004SJérôme Duval /* disp_base */ ZYDIS_NUMERIC_BASE_HEX, 107*1003e004SJérôme Duval /* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED, 108*1003e004SJérôme Duval /* disp_padding */ 2, 109*1003e004SJérôme Duval /* imm_base */ ZYDIS_NUMERIC_BASE_HEX, 110*1003e004SJérôme Duval /* imm_signedness */ ZYDIS_SIGNEDNESS_UNSIGNED, 111*1003e004SJérôme Duval /* imm_padding */ 2, 112*1003e004SJérôme Duval /* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT, 113*1003e004SJérôme Duval /* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT, 114*1003e004SJérôme Duval /* case_registers */ ZYDIS_LETTER_CASE_DEFAULT, 115*1003e004SJérôme Duval /* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT, 116*1003e004SJérôme Duval /* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT, 117*1003e004SJérôme Duval /* hex_uppercase */ ZYAN_TRUE, 118*1003e004SJérôme Duval /* hex_force_leading_number */ ZYAN_FALSE, 119*1003e004SJérôme Duval /* number_format */ 120*1003e004SJérôme Duval { 121*1003e004SJérôme Duval // ZYDIS_NUMERIC_BASE_DEC 122*1003e004SJérôme Duval { 123*1003e004SJérôme Duval // Prefix 124*1003e004SJérôme Duval { 125*1003e004SJérôme Duval /* string */ ZYAN_NULL, 126*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 127*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 128*1003e004SJérôme Duval }, 129*1003e004SJérôme Duval // Suffix 130*1003e004SJérôme Duval { 131*1003e004SJérôme Duval /* string */ ZYAN_NULL, 132*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 133*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 134*1003e004SJérôme Duval } 135*1003e004SJérôme Duval }, 136*1003e004SJérôme Duval // ZYDIS_NUMERIC_BASE_HEX 137*1003e004SJérôme Duval { 138*1003e004SJérôme Duval // Prefix 139*1003e004SJérôme Duval { 140*1003e004SJérôme Duval /* string */ &FORMATTER_INTEL.number_format[ 141*1003e004SJérôme Duval ZYDIS_NUMERIC_BASE_HEX][0].string_data, 142*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"), 143*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 144*1003e004SJérôme Duval }, 145*1003e004SJérôme Duval // Suffix 146*1003e004SJérôme Duval { 147*1003e004SJérôme Duval /* string */ ZYAN_NULL, 148*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 149*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 150*1003e004SJérôme Duval } 151*1003e004SJérôme Duval } 152*1003e004SJérôme Duval }, 153*1003e004SJérôme Duval /* func_pre_instruction */ ZYAN_NULL, 154*1003e004SJérôme Duval /* func_post_instruction */ ZYAN_NULL, 155*1003e004SJérôme Duval /* func_format_instruction */ &ZydisFormatterIntelFormatInstruction, 156*1003e004SJérôme Duval /* func_pre_operand */ ZYAN_NULL, 157*1003e004SJérôme Duval /* func_post_operand */ ZYAN_NULL, 158*1003e004SJérôme Duval /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG, 159*1003e004SJérôme Duval /* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM, 160*1003e004SJérôme Duval /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR, 161*1003e004SJérôme Duval /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM, 162*1003e004SJérôme Duval /* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic, 163*1003e004SJérôme Duval /* func_print_register */ &ZydisFormatterIntelPrintRegister, 164*1003e004SJérôme Duval /* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS, 165*1003e004SJérôme Duval /* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL, 166*1003e004SJérôme Duval /* func_print_disp */ &ZydisFormatterIntelPrintDISP, 167*1003e004SJérôme Duval /* func_print_imm */ &ZydisFormatterBasePrintIMM, 168*1003e004SJérôme Duval /* func_print_typecast */ &ZydisFormatterIntelPrintTypecast, 169*1003e004SJérôme Duval /* func_print_segment */ &ZydisFormatterBasePrintSegment, 170*1003e004SJérôme Duval /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes, 171*1003e004SJérôme Duval /* func_print_decorator */ &ZydisFormatterBasePrintDecorator 172*1003e004SJérôme Duval }; 173*1003e004SJérôme Duval 174*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 175*1003e004SJérôme Duval /* MASM */ 176*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 177*1003e004SJérôme Duval 178*1003e004SJérôme Duval /** 179*1003e004SJérôme Duval * The default formatter configuration for `MASM` style disassembly. 180*1003e004SJérôme Duval */ 181*1003e004SJérôme Duval static const ZydisFormatter FORMATTER_INTEL_MASM = 182*1003e004SJérôme Duval { 183*1003e004SJérôme Duval /* style */ ZYDIS_FORMATTER_STYLE_INTEL_MASM, 184*1003e004SJérôme Duval /* force_memory_size */ ZYAN_TRUE, 185*1003e004SJérôme Duval /* force_memory_seg */ ZYAN_FALSE, 186*1003e004SJérôme Duval /* force_memory_scale */ ZYAN_TRUE, 187*1003e004SJérôme Duval /* force_relative_branches */ ZYAN_FALSE, 188*1003e004SJérôme Duval /* force_relative_riprel */ ZYAN_FALSE, 189*1003e004SJérôme Duval /* print_branch_size */ ZYAN_FALSE, 190*1003e004SJérôme Duval /* detailed_prefixes */ ZYAN_FALSE, 191*1003e004SJérôme Duval /* addr_base */ ZYDIS_NUMERIC_BASE_HEX, 192*1003e004SJérôme Duval /* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED, 193*1003e004SJérôme Duval /* addr_padding_absolute */ ZYDIS_PADDING_DISABLED, 194*1003e004SJérôme Duval /* addr_padding_relative */ ZYDIS_PADDING_DISABLED, 195*1003e004SJérôme Duval /* disp_base */ ZYDIS_NUMERIC_BASE_HEX, 196*1003e004SJérôme Duval /* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED, 197*1003e004SJérôme Duval /* disp_padding */ ZYDIS_PADDING_DISABLED, 198*1003e004SJérôme Duval /* imm_base */ ZYDIS_NUMERIC_BASE_HEX, 199*1003e004SJérôme Duval /* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO, 200*1003e004SJérôme Duval /* imm_padding */ ZYDIS_PADDING_DISABLED, 201*1003e004SJérôme Duval /* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT, 202*1003e004SJérôme Duval /* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT, 203*1003e004SJérôme Duval /* case_registers */ ZYDIS_LETTER_CASE_DEFAULT, 204*1003e004SJérôme Duval /* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT, 205*1003e004SJérôme Duval /* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT, 206*1003e004SJérôme Duval /* hex_uppercase */ ZYAN_TRUE, 207*1003e004SJérôme Duval /* hex_force_leading_number */ ZYAN_TRUE, 208*1003e004SJérôme Duval /* number_format */ 209*1003e004SJérôme Duval { 210*1003e004SJérôme Duval // ZYDIS_NUMERIC_BASE_DEC 211*1003e004SJérôme Duval { 212*1003e004SJérôme Duval // Prefix 213*1003e004SJérôme Duval { 214*1003e004SJérôme Duval /* string */ ZYAN_NULL, 215*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 216*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 217*1003e004SJérôme Duval }, 218*1003e004SJérôme Duval // Suffix 219*1003e004SJérôme Duval { 220*1003e004SJérôme Duval /* string */ ZYAN_NULL, 221*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 222*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 223*1003e004SJérôme Duval } 224*1003e004SJérôme Duval }, 225*1003e004SJérôme Duval // ZYDIS_NUMERIC_BASE_HEX 226*1003e004SJérôme Duval { 227*1003e004SJérôme Duval // Prefix 228*1003e004SJérôme Duval { 229*1003e004SJérôme Duval /* string */ ZYAN_NULL, 230*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 231*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 232*1003e004SJérôme Duval }, 233*1003e004SJérôme Duval // Suffix 234*1003e004SJérôme Duval { 235*1003e004SJérôme Duval /* string */ &FORMATTER_INTEL_MASM.number_format[ 236*1003e004SJérôme Duval ZYDIS_NUMERIC_BASE_HEX][1].string_data, 237*1003e004SJérôme Duval /* string_data */ ZYAN_DEFINE_STRING_VIEW("h"), 238*1003e004SJérôme Duval /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 239*1003e004SJérôme Duval } 240*1003e004SJérôme Duval } 241*1003e004SJérôme Duval }, 242*1003e004SJérôme Duval /* func_pre_instruction */ ZYAN_NULL, 243*1003e004SJérôme Duval /* func_post_instruction */ ZYAN_NULL, 244*1003e004SJérôme Duval /* func_format_instruction */ &ZydisFormatterIntelFormatInstructionMASM, 245*1003e004SJérôme Duval /* func_pre_operand */ ZYAN_NULL, 246*1003e004SJérôme Duval /* func_post_operand */ ZYAN_NULL, 247*1003e004SJérôme Duval /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG, 248*1003e004SJérôme Duval /* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM, 249*1003e004SJérôme Duval /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR, 250*1003e004SJérôme Duval /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM, 251*1003e004SJérôme Duval /* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic, 252*1003e004SJérôme Duval /* func_print_register */ &ZydisFormatterIntelPrintRegister, 253*1003e004SJérôme Duval /* func_print_address_abs */ &ZydisFormatterIntelPrintAddressMASM, 254*1003e004SJérôme Duval /* func_print_address_rel */ &ZydisFormatterIntelPrintAddressMASM, 255*1003e004SJérôme Duval /* func_print_disp */ &ZydisFormatterIntelPrintDISP, 256*1003e004SJérôme Duval /* func_print_imm */ &ZydisFormatterBasePrintIMM, 257*1003e004SJérôme Duval /* func_print_typecast */ &ZydisFormatterIntelPrintTypecast, 258*1003e004SJérôme Duval /* func_print_segment */ &ZydisFormatterBasePrintSegment, 259*1003e004SJérôme Duval /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes, 260*1003e004SJérôme Duval /* func_print_decorator */ &ZydisFormatterBasePrintDecorator 261*1003e004SJérôme Duval }; 262*1003e004SJérôme Duval 263*1003e004SJérôme Duval /* ---------------------------------------------------------------------------------------------- */ 264*1003e004SJérôme Duval 265*1003e004SJérôme Duval /* ============================================================================================== */ 266*1003e004SJérôme Duval 267*1003e004SJérôme Duval #ifdef __cplusplus 268*1003e004SJérôme Duval } 269*1003e004SJérôme Duval #endif 270*1003e004SJérôme Duval 271*1003e004SJérôme Duval #endif // ZYDIS_FORMATTER_INTEL_H 272