Debian Codegraph @

cs_priv.h

raw symbols SCIP
1 /* Capstone Disassembly Engine */
2 /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */
3
4 #ifndef CS_PRIV_H
5 #define CS_PRIV_H
6
7 #ifdef CAPSTONE_DEBUG
8 #include <assert.h>
9 #endif
10 #include <capstone/capstone.h>
11
12 #include "MCInst.h"
13 #include "SStream.h"
14
15 typedef void (*Printer_t)(MCInst *MI, 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_t)(csh handle, cs_insn *, char *mnem, MCInst *mci);
20
21 typedef bool (*Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);
22
23 typedef const char *(*GetName_t)(csh handle, unsigned int id);
24
25 typedef void (*GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id);
26
27 // return register name, given register ID
28 typedef const char *(*GetRegisterName_t)(unsigned RegNo);
29
30 // return registers accessed by instruction
31 typedef void (*GetRegisterAccess_t)(const cs_insn *insn,
32 cs_regs regs_read, uint8_t *regs_read_count,
33 cs_regs regs_write, uint8_t *regs_write_count);
34
35 // for ARM only
36 typedef struct ARM_ITStatus {
37 unsigned char ITStates[8];
38 unsigned int size;
39 } ARM_ITStatus;
40
41 // Customize mnemonic for instructions with alternative name.
42 struct customized_mnem {
43 // ID of instruction to be customized.
44 unsigned int id;
45 // Customized instruction mnemonic.
46 char mnemonic[CS_MNEMONIC_SIZE];
47 };
48
49 struct insn_mnem {
50 struct customized_mnem insn;
51 struct insn_mnem *next; // linked list of customized mnemonics
52 };
53
54 struct cs_struct {
55 cs_arch arch;
56 cs_mode mode;
57 Printer_t printer; // asm printer
58 void *printer_info; // aux info for printer
59 Disasm_t disasm; // disassembler
60 void *getinsn_info; // auxiliary info for printer
61 GetName_t reg_name;
62 GetName_t insn_name;
63 GetName_t group_name;
64 GetID_t insn_id;
65 PostPrinter_t post_printer;
66 cs_err errnum;
67 ARM_ITStatus ITBlock; // for Arm only
68 cs_opt_value detail, imm_unsigned;
69 int syntax; // asm syntax for simple printer such as ARM, Mips & PPC
70 bool doing_mem; // handling memory operand in InstPrinter code
71 bool doing_SME_Index; // handling a SME instruction that has index
72 unsigned short *insn_cache; // index caching for mapping.c
73 GetRegisterName_t get_regname;
74 // per-handle O(1) lookup tables for x86 (freed on cs_close)
75 uint16_t *x86_insn_lut; // insn id -> index in insns[] array, 0xffff for none
76 uint32_t *x86_insn_reg_lut; // packed Intel/ATT reg+access entries
77 unsigned int x86_insn_lut_max; // max insn id in lookup tables
78 bool skipdata; // set this to True if we skip data when disassembling
79 uint8_t skipdata_size; // how many bytes to skip
80 cs_opt_skipdata skipdata_setup; // user-defined skipdata setup
81 const uint8_t *regsize_map; // map to register size (x86-only for now)
82 GetRegisterAccess_t reg_access;
83 struct insn_mnem *mnem_list; // linked list of customized instruction mnemonic
84 };
85
86 #define MAX_ARCH CS_ARCH_MAX
87
88 // Returns a bool (0 or 1) whether big endian is enabled for a mode
89 #define MODE_IS_BIG_ENDIAN(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0)
90
91 extern cs_malloc_t cs_mem_malloc;
92 extern cs_calloc_t cs_mem_calloc;
93 extern cs_realloc_t cs_mem_realloc;
94 extern cs_free_t cs_mem_free;
95 extern cs_vsnprintf_t 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_ASSERT(expr)
104 #define CS_ASSERT_RET(expr) \
105 do { \
106 if (!(expr)) { \
107 return; \
108 } \
109 } while (0)
110 #endif
111
112 #endif