Rizin
unix-like reverse engineering framework and cli tools
cs_priv.h
Go to the documentation of this file.
1 /* Capstone Disassembly Engine */
2 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
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;
40 
41 // Customize mnemonic for instructions with alternative name.
43  // ID of instruction to be customized.
44  unsigned int id;
45  // Customized instruction mnemonic.
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 {
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
66  cs_err errnum;
67  ARM_ITStatus ITBlock; // for Arm only
69  int syntax; // asm syntax for simple printer such as ARM, Mips & PPC
70  bool doing_mem; // handling memory operand in InstPrinter code
71  unsigned short *insn_cache; // index caching for mapping.c
73  bool skipdata; // set this to True if we skip data when disassembling
74  uint8_t skipdata_size; // how many bytes to skip
75  cs_opt_skipdata skipdata_setup; // user-defined skipdata setup
76  const uint8_t *regsize_map; // map to register size (x86-only for now)
78  struct insn_mnem *mnem_list; // linked list of customized instruction mnemonic
79 };
80 
81 #define MAX_ARCH CS_ARCH_MAX
82 
83 // Returns a bool (0 or 1) whether big endian is enabled for a mode
84 #define MODE_IS_BIG_ENDIAN(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0)
85 
89 extern cs_free_t cs_mem_free;
91 
92 // By defining CAPSTONE_DEBUG assertions can be used.
93 // For any release build CAPSTONE_DEBUG has to be undefined.
94 #ifdef CAPSTONE_DEBUG
95 #define CS_ASSERT(expr) assert(expr)
96 #else
97 #define CS_ASSERT(expr)
98 #endif
99 
100 #endif
#define mnem(n, mn)
static mcore_handle handle
Definition: asm_mcore.c:8
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
cs_arch
Architecture type.
Definition: capstone.h:74
cs_mode
Mode type.
Definition: capstone.h:102
size_t csh
Definition: capstone.h:71
void(CAPSTONE_API * cs_free_t)(void *ptr)
Definition: capstone.h:142
#define CS_MNEMONIC_SIZE
Maximum size of an instruction mnemonic string.
Definition: capstone.h:68
cs_opt_value
Runtime option value (associated with option type above)
Definition: capstone.h:181
void *(CAPSTONE_API * cs_malloc_t)(size_t size)
Definition: capstone.h:139
void *(CAPSTONE_API * cs_calloc_t)(size_t nmemb, size_t size)
Definition: capstone.h:140
int(CAPSTONE_API * cs_vsnprintf_t)(char *str, size_t size, const char *format, va_list ap)
Definition: capstone.h:143
void *(CAPSTONE_API * cs_realloc_t)(void *ptr, size_t size)
Definition: capstone.h:141
void(* PostPrinter_t)(csh handle, cs_insn *, char *mnem, MCInst *mci)
Definition: cs_priv.h:19
cs_free_t cs_mem_free
Definition: cs.c:351
cs_malloc_t cs_mem_malloc
Definition: cs.c:348
cs_realloc_t cs_mem_realloc
Definition: cs.c:350
void(* Printer_t)(MCInst *MI, SStream *OS, void *info)
Definition: cs_priv.h:15
cs_vsnprintf_t cs_vsnprintf
Definition: cs.c:352
void(* GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id)
Definition: cs_priv.h:25
const char *(* GetRegisterName_t)(unsigned RegNo)
Definition: cs_priv.h:28
cs_calloc_t cs_mem_calloc
Definition: cs.c:349
bool(* Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info)
Definition: cs_priv.h:21
const char *(* GetName_t)(csh handle, unsigned int id)
Definition: cs_priv.h:23
struct ARM_ITStatus ARM_ITStatus
void(* GetRegisterAccess_t)(const cs_insn *insn, cs_regs regs_read, uint8_t *regs_read_count, cs_regs regs_write, uint8_t *regs_write_count)
Definition: cs_priv.h:31
@ OS
Definition: inflate.h:24
voidpf void uLong size
Definition: ioapi.h:138
int id
Definition: op.c:540
const char * code
Definition: pal.c:98
unsigned short uint16_t
Definition: sftypes.h:30
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
#define h(i)
Definition: sha256.c:48
unsigned char ITStates[8]
Definition: cs_priv.h:37
unsigned int size
Definition: cs_priv.h:38
Definition: MCInst.h:88
Definition: SStream.h:9
GetName_t insn_name
Definition: cs_priv.h:62
cs_err errnum
Definition: cs_priv.h:66
GetName_t reg_name
Definition: cs_priv.h:61
ARM_ITStatus ITBlock
Definition: cs_priv.h:67
void * printer_info
Definition: cs_priv.h:58
bool skipdata
Definition: cs_priv.h:73
bool doing_mem
Definition: cs_priv.h:70
int syntax
Definition: cs_priv.h:69
Printer_t printer
Definition: cs_priv.h:57
GetID_t insn_id
Definition: cs_priv.h:64
GetName_t group_name
Definition: cs_priv.h:63
GetRegisterAccess_t reg_access
Definition: cs_priv.h:77
Disasm_t disasm
Definition: cs_priv.h:59
unsigned short * insn_cache
Definition: cs_priv.h:71
GetRegisterName_t get_regname
Definition: cs_priv.h:72
struct insn_mnem * mnem_list
Definition: cs_priv.h:78
cs_mode mode
Definition: cs_priv.h:56
cs_opt_value imm_unsigned
Definition: cs_priv.h:68
cs_opt_skipdata skipdata_setup
Definition: cs_priv.h:75
void * getinsn_info
Definition: cs_priv.h:60
PostPrinter_t post_printer
Definition: cs_priv.h:65
uint8_t skipdata_size
Definition: cs_priv.h:74
cs_opt_value detail
Definition: cs_priv.h:68
const uint8_t * regsize_map
Definition: cs_priv.h:76
cs_arch arch
Definition: cs_priv.h:55
unsigned int id
Definition: cs_priv.h:44
struct insn_mnem * next
Definition: cs_priv.h:51
struct customized_mnem insn
Definition: cs_priv.h:50
#define bool
Definition: sysdefs.h:146
mnemonic
Definition: z80asm.h:48