Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/capstone/cs_priv.h
4387 views
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
bool skipdata; // set this to True if we skip data when disassembling
75
uint8_t skipdata_size; // how many bytes to skip
76
cs_opt_skipdata skipdata_setup; // user-defined skipdata setup
77
const uint8_t *regsize_map; // map to register size (x86-only for now)
78
GetRegisterAccess_t reg_access;
79
struct insn_mnem *mnem_list; // linked list of customized instruction mnemonic
80
};
81
82
#define MAX_ARCH CS_ARCH_MAX
83
84
// Returns a bool (0 or 1) whether big endian is enabled for a mode
85
#define MODE_IS_BIG_ENDIAN(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0)
86
87
extern cs_malloc_t cs_mem_malloc;
88
extern cs_calloc_t cs_mem_calloc;
89
extern cs_realloc_t cs_mem_realloc;
90
extern cs_free_t cs_mem_free;
91
extern cs_vsnprintf_t cs_vsnprintf;
92
93
// By defining CAPSTONE_DEBUG assertions can be used.
94
// For any release build CAPSTONE_DEBUG has to be undefined.
95
#ifdef CAPSTONE_DEBUG
96
#define CS_ASSERT(expr) assert(expr)
97
#else
98
#define CS_ASSERT(expr)
99
#endif
100
101
#endif
102
103