| 1 | /* Capstone Disassembly Engine */cxx . . $ `<file>/cs_priv.h`/ |
| 2 | /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */ |
| 3 | |
| 4 | #ifndef CS_PRIV_H |
| 5 | #define CS_PRIV_Hcxx . . $ `cs_priv.h:5:9`! |
| 6 | |
| 7 | #ifdef CAPSTONE_DEBUG |
| 8 | #include <assert.h> |
| 9 | #endif |
| 10 | #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/ |
| 11 | |
| 12 | #include "MCInst.h"cxx . . $ `<file>/MCInst.h`/ |
| 13 | #include "SStream.h"cxx . . $ `<file>/SStream.h`/ |
| 14 | |
| 15 | typedef void (*Printer_tcxx . . $ Printer_t#)(MCInstcxx . . $ MCInst# *MI, SStreamcxx . . $ SStream# *OS, void *info); |
| 16 | |
| 17 | // function to be called after Printer_t |
| 18 | // this is the best time to gather insn's characteristics |
| 19 | typedef void (*PostPrinter_tcxx . . $ PostPrinter_t#)(cshcxx . . $ csh# handle, cs_insncxx . . $ cs_insn# *, char *mnem, MCInstcxx . . $ MCInst# *mci); |
| 20 | |
| 21 | typedef boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! (*Disasm_tcxx . . $ Disasm_t#)(cshcxx . . $ csh# handle, const uint8_tcxx . . $ uint8_t# *code, size_tcxx . . $ size_t# code_len, MCInstcxx . . $ MCInst# *instr, uint16_tcxx . . $ uint16_t# *size, uint64_tcxx . . $ uint64_t# address, void *info); |
| 22 | |
| 23 | typedef const char *(*GetName_tcxx . . $ GetName_t#)(cshcxx . . $ csh# handle, unsigned int id); |
| 24 | |
| 25 | typedef void (*GetID_tcxx . . $ GetID_t#)(cs_structcxx . . $ cs_struct# *h, cs_insncxx . . $ cs_insn# *insn, unsigned int id); |
| 26 | |
| 27 | // return register name, given register ID |
| 28 | typedef const char *(*GetRegisterName_tcxx . . $ GetRegisterName_t#)(unsigned RegNo); |
| 29 | |
| 30 | // return registers accessed by instruction |
| 31 | typedef void (*GetRegisterAccess_tcxx . . $ GetRegisterAccess_t#)(const cs_insncxx . . $ cs_insn# *insn, |
| 32 | cs_regscxx . . $ cs_regs# regs_read, uint8_tcxx . . $ uint8_t# *regs_read_count, |
| 33 | cs_regscxx . . $ cs_regs# regs_write, uint8_tcxx . . $ uint8_t# *regs_write_count); |
| 34 | |
| 35 | // for ARM only |
| 36 | typedef struct ARM_ITStatuscxx . . $ ARM_ITStatus# { |
| 37 | unsigned char ITStatescxx . . $ ARM_ITStatus#ITStates.[8]; |
| 38 | unsigned int sizecxx . . $ ARM_ITStatus#size.; |
| 39 | } ARM_ITStatuscxx . . $ ARM_ITStatus#; |
| 40 | |
| 41 | // Customize mnemonic for instructions with alternative name. |
| 42 | struct customized_mnemcxx . . $ customized_mnem# { |
| 43 | // ID of instruction to be customized. |
| 44 | unsigned int idcxx . . $ customized_mnem#id.; |
| 45 | // Customized instruction mnemonic. |
| 46 | char mnemoniccxx . . $ customized_mnem#mnemonic.[CS_MNEMONIC_SIZEcxx . . $ `include/capstone/capstone.h:142:9`!]; |
| 47 | }; |
| 48 | |
| 49 | struct insn_mnemcxx . . $ insn_mnem# { |
| 50 | struct customized_mnemcxx . . $ customized_mnem# insncxx . . $ insn_mnem#insn.; |
| 51 | struct insn_mnemcxx . . $ insn_mnem# *nextcxx . . $ insn_mnem#next.; // linked list of customized mnemonics |
| 52 | }; |
| 53 | |
| 54 | struct cs_structcxx . . $ cs_struct# { |
| 55 | cs_archcxx . . $ cs_arch# archcxx . . $ cs_struct#arch.; |
| 56 | cs_modecxx . . $ cs_mode# modecxx . . $ cs_struct#mode.; |
| 57 | Printer_tcxx . . $ Printer_t# printercxx . . $ cs_struct#printer.; // asm printer |
| 58 | void *printer_infocxx . . $ cs_struct#printer_info.; // aux info for printer |
| 59 | Disasm_tcxx . . $ Disasm_t# disasmcxx . . $ cs_struct#disasm.; // disassembler |
| 60 | void *getinsn_infocxx . . $ cs_struct#getinsn_info.; // auxiliary info for printer |
| 61 | GetName_tcxx . . $ GetName_t# reg_namecxx . . $ cs_struct#reg_name.; |
| 62 | GetName_tcxx . . $ GetName_t# insn_namecxx . . $ cs_struct#insn_name.; |
| 63 | GetName_tcxx . . $ GetName_t# group_namecxx . . $ cs_struct#group_name.; |
| 64 | GetID_tcxx . . $ GetID_t# insn_idcxx . . $ cs_struct#insn_id.; |
| 65 | PostPrinter_tcxx . . $ PostPrinter_t# post_printercxx . . $ cs_struct#post_printer.; |
| 66 | cs_errcxx . . $ cs_err# errnumcxx . . $ cs_struct#errnum.; |
| 67 | ARM_ITStatuscxx . . $ ARM_ITStatus# ITBlockcxx . . $ cs_struct#ITBlock.; // for Arm only |
| 68 | cs_opt_valuecxx . . $ cs_opt_value# detailcxx . . $ cs_struct#detail., imm_unsignedcxx . . $ cs_struct#imm_unsigned.; |
| 69 | int syntaxcxx . . $ cs_struct#syntax.; // asm syntax for simple printer such as ARM, Mips & PPC |
| 70 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! doing_memcxx . . $ cs_struct#doing_mem.; // handling memory operand in InstPrinter code |
| 71 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! doing_SME_Indexcxx . . $ cs_struct#doing_SME_Index.; // handling a SME instruction that has index |
| 72 | unsigned short *insn_cachecxx . . $ cs_struct#insn_cache.; // index caching for mapping.c |
| 73 | GetRegisterName_tcxx . . $ GetRegisterName_t# get_regnamecxx . . $ cs_struct#get_regname.; |
| 74 | // per-handle O(1) lookup tables for x86 (freed on cs_close) |
| 75 | uint16_tcxx . . $ uint16_t# *x86_insn_lutcxx . . $ cs_struct#x86_insn_lut.; // insn id -> index in insns[] array, 0xffff for none |
| 76 | uint32_tcxx . . $ uint32_t# *x86_insn_reg_lutcxx . . $ cs_struct#x86_insn_reg_lut.; // packed Intel/ATT reg+access entries |
| 77 | unsigned int x86_insn_lut_maxcxx . . $ cs_struct#x86_insn_lut_max.; // max insn id in lookup tables |
| 78 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! skipdatacxx . . $ cs_struct#skipdata.; // set this to True if we skip data when disassembling |
| 79 | uint8_tcxx . . $ uint8_t# skipdata_sizecxx . . $ cs_struct#skipdata_size.; // how many bytes to skip |
| 80 | cs_opt_skipdatacxx . . $ cs_opt_skipdata# skipdata_setupcxx . . $ cs_struct#skipdata_setup.; // user-defined skipdata setup |
| 81 | const uint8_tcxx . . $ uint8_t# *regsize_mapcxx . . $ cs_struct#regsize_map.; // map to register size (x86-only for now) |
| 82 | GetRegisterAccess_tcxx . . $ GetRegisterAccess_t# reg_accesscxx . . $ cs_struct#reg_access.; |
| 83 | struct insn_mnemcxx . . $ insn_mnem# *mnem_listcxx . . $ cs_struct#mnem_list.; // linked list of customized instruction mnemonic |
| 84 | }; |
| 85 | |
| 86 | #define MAX_ARCHcxx . . $ `cs_priv.h:86:9`! CS_ARCH_MAX |
| 87 | |
| 88 | // Returns a bool (0 or 1) whether big endian is enabled for a mode |
| 89 | #define MODE_IS_BIG_ENDIANcxx . . $ `cs_priv.h:89:9`!(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0) |
| 90 | |
| 91 | extern cs_malloc_tcxx . . $ cs_malloc_t# cs_mem_malloccxx . . $ cs_mem_malloc.; |
| 92 | extern cs_calloc_tcxx . . $ cs_calloc_t# cs_mem_calloccxx . . $ cs_mem_calloc.; |
| 93 | extern cs_realloc_tcxx . . $ cs_realloc_t# cs_mem_realloccxx . . $ cs_mem_realloc.; |
| 94 | extern cs_free_tcxx . . $ cs_free_t# cs_mem_freecxx . . $ cs_mem_free.; |
| 95 | extern cs_vsnprintf_tcxx . . $ cs_vsnprintf_t# cs_vsnprintfcxx . . $ cs_vsnprintf.; |
| 96 | |
| 97 | // By defining CAPSTONE_DEBUG assertions can be used. |
| 98 | // For any release build CAPSTONE_DEBUG has to be undefined. |
| 99 | #ifdef CAPSTONE_DEBUG |
| 100 | #define CS_ASSERT(expr) assert(expr) |
| 101 | #define CS_ASSERT_RET(expr) assert(expr) |
| 102 | #else |
| 103 | #define CS_ASSERTcxx . . $ `cs_priv.h:103:9`!(expr) |
| 104 | #define CS_ASSERT_RETcxx . . $ `cs_priv.h:104:9`!(expr) \ |
| 105 | do { \ |
| 106 | if (!(expr)) { \ |
| 107 | return; \ |
| 108 | } \ |
| 109 | } while (0) |
| 110 | #endif |
| 111 | |
| 112 | #endif |