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
12typedef 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
16typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem, MCInst *mci);
17
18typedef bool (*Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);
19
20typedef const char *(*GetName_t)(csh handle, unsigned int id);
21
22typedef void (*GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id);
23
24// return register name, given register ID
25typedef const char *(*GetRegisterName_t)(unsigned RegNo);
26
27// for ARM only
28typedef struct ARM_ITStatus {
29 unsigned char ITStates[8];
30 unsigned int size;
31} ARM_ITStatus;
32
33struct 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// constructor initialization for all archs
64extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *);
65
66// support cs_option() for all archs
67extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
68
69// deinitialized functions: to be called when cs_close() is called
70extern void (*arch_destroy[MAX_ARCH]) (cs_struct*);
71
72// bitmask for finding disallowed modes for an arch:
73// to be called in cs_open()/cs_option()
74extern cs_mode arch_disallowed_mode_mask[MAX_ARCH];
75
76extern unsigned int all_arch;
77
78extern cs_malloc_t cs_mem_malloc;
79extern cs_calloc_t cs_mem_calloc;
80extern cs_realloc_t cs_mem_realloc;
81extern cs_free_t cs_mem_free;
82extern cs_vsnprintf_t cs_vsnprintf;
83
84#endif
85