• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <capstone/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 // return registers accessed by instruction
28 typedef void (*GetRegisterAccess_t)(const cs_insn *insn,
29 		cs_regs regs_read, uint8_t *regs_read_count,
30 		cs_regs regs_write, uint8_t *regs_write_count);
31 
32 // for ARM only
33 typedef struct ARM_ITStatus {
34 	unsigned char ITStates[8];
35 	unsigned int size;
36 } ARM_ITStatus;
37 
38 // Customize mnemonic for instructions with alternative name.
39 struct customized_mnem {
40 	// ID of instruction to be customized.
41 	unsigned int id;
42 	// Customized instruction mnemonic.
43 	char mnemonic[CS_MNEMONIC_SIZE];
44 };
45 
46 struct insn_mnem {
47 	struct customized_mnem insn;
48 	struct insn_mnem *next;	// linked list of customized mnemonics
49 };
50 
51 struct cs_struct {
52 	cs_arch arch;
53 	cs_mode mode;
54 	Printer_t printer;	// asm printer
55 	void *printer_info; // aux info for printer
56 	Disasm_t disasm;	// disassembler
57 	void *getinsn_info; // auxiliary info for printer
58 	GetName_t reg_name;
59 	GetName_t insn_name;
60 	GetName_t group_name;
61 	GetID_t insn_id;
62 	PostPrinter_t post_printer;
63 	cs_err errnum;
64 	ARM_ITStatus ITBlock;	// for Arm only
65 	cs_opt_value detail, imm_unsigned;
66 	int syntax;	// asm syntax for simple printer such as ARM, Mips & PPC
67 	bool doing_mem;	// handling memory operand in InstPrinter code
68 	unsigned short *insn_cache;	// index caching for mapping.c
69 	GetRegisterName_t get_regname;
70 	bool skipdata;	// set this to True if we skip data when disassembling
71 	uint8_t skipdata_size;	// how many bytes to skip
72 	cs_opt_skipdata skipdata_setup;	// user-defined skipdata setup
73 	const uint8_t *regsize_map;	// map to register size (x86-only for now)
74 	GetRegisterAccess_t reg_access;
75 	struct insn_mnem *mnem_list;	// linked list of customized instruction mnemonic
76 };
77 
78 #define MAX_ARCH CS_ARCH_MAX
79 
80 // Returns a bool (0 or 1) whether big endian is enabled for a mode
81 #define MODE_IS_BIG_ENDIAN(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0)
82 
83 extern cs_malloc_t cs_mem_malloc;
84 extern cs_calloc_t cs_mem_calloc;
85 extern cs_realloc_t cs_mem_realloc;
86 extern cs_free_t cs_mem_free;
87 extern cs_vsnprintf_t cs_vsnprintf;
88 
89 #endif
90