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
29
}
insn_map
;
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
;
39
}
name_map
;
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
cs_priv.h
max
int max
Definition:
enough.c:225
map
size_t map(int syms, int left, int len)
Definition:
enough.c:237
size
voidpf void uLong size
Definition:
ioapi.h:138
list
static void list(RzEgg *egg)
Definition:
rz-gg.c:52
cmd_descs_generate.str
str
Definition:
cmd_descs_generate.py:785
regress.m
m
Definition:
regress.py:25
syscall_preprocessing.arr
arr
Definition:
syscall_preprocessing.py:15
uint16_t
unsigned short uint16_t
Definition:
sftypes.h:30
buffer
Definition:
buffer.h:15
insn_map
Definition:
utils.h:19
insn_map::regs_use
uint16_t regs_use[12]
Definition:
utils.h:23
insn_map::branch
bool branch
Definition:
utils.h:26
insn_map::indirect_branch
bool indirect_branch
Definition:
utils.h:27
insn_map::id
unsigned short id
Definition:
utils.h:20
insn_map::mapid
unsigned short mapid
Definition:
utils.h:21
insn_map::groups
unsigned char groups[8]
Definition:
utils.h:25
insn_map::regs_mod
uint16_t regs_mod[20]
Definition:
utils.h:24
name_map
Definition:
utils.h:36
name_map::name
const char * name
Definition:
utils.h:38
name_map::id
unsigned int id
Definition:
utils.h:37
name
Definition:
z80asm.h:102
name_map
struct name_map name_map
cs_snprintf
int cs_snprintf(char *buffer, size_t size, const char *fmt,...)
Definition:
utils.c:104
name2id
int name2id(const name_map *map, int max, const char *name)
Definition:
utils.c:42
arr_exist8
bool arr_exist8(unsigned char *arr, unsigned char max, unsigned int id)
Definition:
utils.c:116
arr_exist
bool arr_exist(uint16_t *arr, unsigned char max, unsigned int id)
Definition:
utils.c:128
count_positive
unsigned int count_positive(const uint16_t *list)
Definition:
utils.c:72
count_positive8
unsigned int count_positive8(const unsigned char *list)
Definition:
utils.c:83
cs_strdup
char * cs_strdup(const char *str)
Definition:
utils.c:92
insn_map
struct insn_map insn_map
insn_find
unsigned short insn_find(const insn_map *m, unsigned int max, unsigned int id, unsigned short **cache)
Definition:
utils.c:31
id2name
const char * id2name(const name_map *map, int max, const unsigned int id)
Definition:
utils.c:56
subprojects
capstone-bundled
utils.h
Generated by
1.9.1