1 /* Capstone Disassembly Engine */ 2 /* By Dang Hoang Vu <danghvu@gmail.com> 2013 */ 3 4 #ifdef CAPSTONE_HAS_ARM 5 6 #include "../../cs_priv.h" 7 #include "../../MCRegisterInfo.h" 8 #include "ARMDisassembler.h" 9 #include "ARMInstPrinter.h" 10 #include "ARMMapping.h" 11 init(cs_struct * ud)12static cs_err init(cs_struct *ud) 13 { 14 MCRegisterInfo *mri; 15 16 // verify if requested mode is valid 17 if (ud->mode & ~(CS_MODE_LITTLE_ENDIAN | CS_MODE_ARM | CS_MODE_V8 | 18 CS_MODE_MCLASS | CS_MODE_THUMB | CS_MODE_BIG_ENDIAN)) 19 return CS_ERR_MODE; 20 21 mri = cs_mem_malloc(sizeof(*mri)); 22 23 ARM_init(mri); 24 ARM_getRegName(ud, 0); // use default get_regname 25 26 ud->printer = ARM_printInst; 27 ud->printer_info = mri; 28 ud->reg_name = ARM_reg_name; 29 ud->insn_id = ARM_get_insn_id; 30 ud->insn_name = ARM_insn_name; 31 ud->group_name = ARM_group_name; 32 ud->post_printer = ARM_post_printer; 33 34 if (ud->mode & CS_MODE_THUMB) 35 ud->disasm = Thumb_getInstruction; 36 else 37 ud->disasm = ARM_getInstruction; 38 39 return CS_ERR_OK; 40 } 41 option(cs_struct * handle,cs_opt_type type,size_t value)42static cs_err option(cs_struct *handle, cs_opt_type type, size_t value) 43 { 44 switch(type) { 45 case CS_OPT_MODE: 46 if (value & CS_MODE_THUMB) 47 handle->disasm = Thumb_getInstruction; 48 else 49 handle->disasm = ARM_getInstruction; 50 51 handle->mode = (cs_mode)value; 52 handle->big_endian = ((handle->mode & CS_MODE_BIG_ENDIAN) != 0); 53 54 break; 55 case CS_OPT_SYNTAX: 56 ARM_getRegName(handle, (int)value); 57 handle->syntax = (int)value; 58 break; 59 default: 60 break; 61 } 62 63 return CS_ERR_OK; 64 } 65 destroy(cs_struct * handle)66static void destroy(cs_struct *handle) 67 { 68 } 69 ARM_enable(void)70void ARM_enable(void) 71 { 72 arch_init[CS_ARCH_ARM] = init; 73 arch_option[CS_ARCH_ARM] = option; 74 arch_destroy[CS_ARCH_ARM] = destroy; 75 76 // support this arch 77 all_arch |= (1 << CS_ARCH_ARM); 78 } 79 80 #endif 81