Rizin
unix-like reverse engineering framework and cli tools
utils.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_UTILS_H
5 #define CS_UTILS_H
6 
7 #if defined(CAPSTONE_HAS_OSXKERNEL)
8 #include <libkern/libkern.h>
9 #else
10 #include <stddef.h>
11 #include "include/capstone/capstone.h"
12 #endif
13 #include "cs_priv.h"
14 
15 // threshold number, so above this number will be printed in hexa mode
16 #define HEX_THRESHOLD 9
17 
18 // map instruction to its characteristics
19 typedef struct insn_map {
20  unsigned short id;
21  unsigned short mapid;
22 #ifndef CAPSTONE_DIET
23  uint16_t regs_use[12]; // list of implicit registers used by this instruction
24  uint16_t regs_mod[20]; // list of implicit registers modified by this instruction
25  unsigned char groups[8]; // list of group this instruction belong to
26  bool branch; // branch instruction?
27  bool indirect_branch; // indirect branch instruction?
28 #endif
30 
31 // look for @id in @m, given its size in @max. first time call will update @cache.
32 // return 0 if not found
33 unsigned short insn_find(const insn_map *m, unsigned int max, unsigned int id, unsigned short **cache);
34 
35 // map id to string
36 typedef struct name_map {
37  unsigned int id;
38  const char *name;
40 
41 // map a name to its ID
42 // return 0 if not found
43 int name2id(const name_map* map, int max, const char *name);
44 
45 // map ID to a name
46 // return NULL if not found
47 const char *id2name(const name_map* map, int max, const unsigned int id);
48 
49 // count number of positive members in a list.
50 // NOTE: list must be guaranteed to end in 0
51 unsigned int count_positive(const uint16_t *list);
52 unsigned int count_positive8(const unsigned char *list);
53 
54 #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))
55 #define MATRIX_SIZE(a) (sizeof(a[0])/sizeof(a[0][0]))
56 
57 char *cs_strdup(const char *str);
58 
59 #define MIN(x, y) ((x) < (y) ? (x) : (y))
60 
61 // we need this since Windows doesn't have snprintf()
62 int cs_snprintf(char *buffer, size_t size, const char *fmt, ...);
63 
64 #define CS_AC_IGNORE (1 << 7)
65 
66 // check if an id is existent in an array
67 bool arr_exist8(unsigned char *arr, unsigned char max, unsigned int id);
68 
69 bool arr_exist(uint16_t *arr, unsigned char max, unsigned int id);
70 
71 #endif
72 
int max
Definition: enough.c:225
size_t map(int syms, int left, int len)
Definition: enough.c:237
voidpf void uLong size
Definition: ioapi.h:138
static void list(RzEgg *egg)
Definition: rz-gg.c:52
unsigned short uint16_t
Definition: sftypes.h:30
Definition: buffer.h:15
Definition: utils.h:19
uint16_t regs_use[12]
Definition: utils.h:23
bool branch
Definition: utils.h:26
bool indirect_branch
Definition: utils.h:27
unsigned short id
Definition: utils.h:20
unsigned short mapid
Definition: utils.h:21
unsigned char groups[8]
Definition: utils.h:25
uint16_t regs_mod[20]
Definition: utils.h:24
Definition: utils.h:36
const char * name
Definition: utils.h:38
unsigned int id
Definition: utils.h:37
Definition: z80asm.h:102
struct name_map name_map
int cs_snprintf(char *buffer, size_t size, const char *fmt,...)
Definition: utils.c:104
int name2id(const name_map *map, int max, const char *name)
Definition: utils.c:42
bool arr_exist8(unsigned char *arr, unsigned char max, unsigned int id)
Definition: utils.c:116
bool arr_exist(uint16_t *arr, unsigned char max, unsigned int id)
Definition: utils.c:128
unsigned int count_positive(const uint16_t *list)
Definition: utils.c:72
unsigned int count_positive8(const unsigned char *list)
Definition: utils.c:83
char * cs_strdup(const char *str)
Definition: utils.c:92
struct insn_map insn_map
unsigned short insn_find(const insn_map *m, unsigned int max, unsigned int id, unsigned short **cache)
Definition: utils.c:31
const char * id2name(const name_map *map, int max, const unsigned int id)
Definition: utils.c:56