1 /* Capstone Disassembly Engine */ 2 /* By Dang Hoang Vu <danghvu@gmail.com> 2013 */ 3 4 #ifdef CAPSTONE_HAS_X86 5 6 #include "../../cs_priv.h" 7 #include "../../MCRegisterInfo.h" 8 #include "X86Disassembler.h" 9 #include "X86InstPrinter.h" 10 #include "X86Mapping.h" 11 #include "X86Module.h" 12 X86_global_init(cs_struct * ud)13cs_err X86_global_init(cs_struct *ud) 14 { 15 MCRegisterInfo *mri; 16 mri = cs_mem_malloc(sizeof(*mri)); 17 18 X86_init(mri); 19 20 // by default, we use Intel syntax 21 ud->printer = X86_Intel_printInst; 22 ud->syntax = CS_OPT_SYNTAX_INTEL; 23 ud->printer_info = mri; 24 ud->disasm = X86_getInstruction; 25 ud->reg_name = X86_reg_name; 26 ud->insn_id = X86_get_insn_id; 27 ud->insn_name = X86_insn_name; 28 ud->group_name = X86_group_name; 29 ud->post_printer = NULL;; 30 #ifndef CAPSTONE_DIET 31 ud->reg_access = X86_reg_access; 32 #endif 33 34 if (ud->mode == CS_MODE_64) 35 ud->regsize_map = regsize_map_64; 36 else 37 ud->regsize_map = regsize_map_32; 38 39 return CS_ERR_OK; 40 } 41 X86_option(cs_struct * handle,cs_opt_type type,size_t value)42cs_err X86_option(cs_struct *handle, cs_opt_type type, size_t value) 43 { 44 switch(type) { 45 default: 46 break; 47 case CS_OPT_MODE: 48 if (value == CS_MODE_64) 49 handle->regsize_map = regsize_map_64; 50 else 51 handle->regsize_map = regsize_map_32; 52 53 handle->mode = (cs_mode)value; 54 break; 55 case CS_OPT_SYNTAX: 56 switch(value) { 57 default: 58 // wrong syntax value 59 handle->errnum = CS_ERR_OPTION; 60 return CS_ERR_OPTION; 61 62 case CS_OPT_SYNTAX_DEFAULT: 63 case CS_OPT_SYNTAX_INTEL: 64 handle->syntax = CS_OPT_SYNTAX_INTEL; 65 handle->printer = X86_Intel_printInst; 66 break; 67 68 case CS_OPT_SYNTAX_MASM: 69 handle->printer = X86_Intel_printInst; 70 handle->syntax = (int)value; 71 break; 72 73 case CS_OPT_SYNTAX_ATT: 74 #if !defined(CAPSTONE_DIET) && !defined(CAPSTONE_X86_ATT_DISABLE) 75 handle->printer = X86_ATT_printInst; 76 handle->syntax = CS_OPT_SYNTAX_ATT; 77 break; 78 #elif !defined(CAPSTONE_DIET) && defined(CAPSTONE_X86_ATT_DISABLE) 79 // ATT syntax is unsupported 80 handle->errnum = CS_ERR_X86_ATT; 81 return CS_ERR_X86_ATT; 82 #else // CAPSTONE_DIET 83 // this is irrelevant in CAPSTONE_DIET mode 84 handle->errnum = CS_ERR_DIET; 85 return CS_ERR_DIET; 86 #endif 87 } 88 break; 89 } 90 91 return CS_ERR_OK; 92 } 93 94 #endif 95