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 const 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 	GetName_t reg_name;
41 	GetName_t insn_name;
42 	GetName_t group_name;
43 	GetID_t insn_id;
44 	PostPrinter_t post_printer;
45 	cs_err errnum;
46 	ARM_ITStatus ITBlock;	// for Arm only
47 	cs_opt_value detail;
48 	int syntax;	// asm syntax for simple printer such as ARM, Mips & PPC
49 	bool doing_mem;	// handling memory operand in InstPrinter code
50 	unsigned short *insn_cache;	// index caching for mapping.c
51 	GetRegisterName_t get_regname;
52 	bool skipdata;	// set this to True if we skip data when disassembling
53 	uint8_t skipdata_size;	// how many bytes to skip
54 	cs_opt_skipdata skipdata_setup;	// user-defined skipdata setup
55 	const uint8_t *regsize_map;	// map to register size (x86-only for now)
56 };
57 
58 #define MAX_ARCH 8
59 
60 // Returns a bool (0 or 1) whether big endian is enabled for a mode
61 #define MODE_IS_BIG_ENDIAN(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0)
62 
63 extern cs_malloc_t cs_mem_malloc;
64 extern cs_calloc_t cs_mem_calloc;
65 extern cs_realloc_t cs_mem_realloc;
66 extern cs_free_t cs_mem_free;
67 extern cs_vsnprintf_t cs_vsnprintf;
68 
69 #endif
70