1 /* Capstone Disassembly Engine */ 2 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */ 3 4 #ifndef CS_PRIV_H 5 #define CS_PRIV_H 6 7 #include <capstone.h> 8 9 #include "MCInst.h" 10 #include "SStream.h" 11 12 typedef void (*Printer_t)(MCInst *MI, SStream *OS, void *info); 13 14 // function to be called after Printer_t 15 // this is the best time to gather insn's characteristics 16 typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem, MCInst *mci); 17 18 typedef bool (*Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info); 19 20 typedef const char *(*GetName_t)(csh handle, unsigned int id); 21 22 typedef void (*GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id); 23 24 // return register name, given register ID 25 typedef char *(*GetRegisterName_t)(unsigned RegNo); 26 27 // for ARM only 28 typedef struct ARM_ITStatus { 29 unsigned char ITStates[8]; 30 unsigned int size; 31 } ARM_ITStatus; 32 33 struct cs_struct { 34 cs_arch arch; 35 cs_mode mode; 36 Printer_t printer; // asm printer 37 void *printer_info; // aux info for printer 38 Disasm_t disasm; // disassembler 39 void *getinsn_info; // auxiliary info for printer 40 bool big_endian; 41 GetName_t reg_name; 42 GetName_t insn_name; 43 GetName_t group_name; 44 GetID_t insn_id; 45 PostPrinter_t post_printer; 46 cs_err errnum; 47 ARM_ITStatus ITBlock; // for Arm only 48 cs_opt_value detail; 49 int syntax; // asm syntax for simple printer such as ARM, Mips & PPC 50 bool doing_mem; // handling memory operand in InstPrinter code 51 unsigned short *insn_cache; // index caching for mapping.c 52 GetRegisterName_t get_regname; 53 bool skipdata; // set this to True if we skip data when disassembling 54 uint8_t skipdata_size; // how many bytes to skip 55 cs_opt_skipdata skipdata_setup; // user-defined skipdata setup 56 uint8_t *regsize_map; // map to register size (x86-only for now) 57 }; 58 59 #define MAX_ARCH 8 60 61 // constructor initialization for all archs 62 extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *); 63 64 // support cs_option() for all archs 65 extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value); 66 67 // deinitialized functions: to be called when cs_close() is called 68 extern void (*arch_destroy[MAX_ARCH]) (cs_struct*); 69 70 extern unsigned int all_arch; 71 72 extern cs_malloc_t cs_mem_malloc; 73 extern cs_calloc_t cs_mem_calloc; 74 extern cs_realloc_t cs_mem_realloc; 75 extern cs_free_t cs_mem_free; 76 extern cs_vsnprintf_t cs_vsnprintf; 77 78 #endif 79