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>
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 
xds_interop_client.str
str
Definition: xds_interop_client.py:487
name_map::id
unsigned int id
Definition: utils.h:37
id2name
const char * id2name(const name_map *map, int max, const unsigned int id)
Definition: utils.c:56
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
count_positive8
unsigned int count_positive8(const unsigned char *list)
Definition: utils.c:83
insn_map::groups
unsigned char groups[8]
Definition: utils.h:25
setup.name
name
Definition: setup.py:542
cs_snprintf
int cs_snprintf(char *buffer, size_t size, const char *fmt,...)
Definition: utils.c:104
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
insn_find
unsigned short insn_find(const insn_map *m, unsigned int max, unsigned int id, unsigned short **cache)
Definition: utils.c:31
insn_map
Definition: utils.h:19
capstone.h
insn_map::regs_mod
uint16_t regs_mod[20]
Definition: utils.h:24
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
insn_map::indirect_branch
bool indirect_branch
Definition: utils.h:27
insn_map::mapid
unsigned short mapid
Definition: utils.h:21
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
testing::internal::fmt
GTEST_API_ const char * fmt
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1808
insn_map
struct insn_map insn_map
name_map
struct name_map name_map
arr_exist8
bool arr_exist8(unsigned char *arr, unsigned char max, unsigned int id)
Definition: utils.c:116
insn_map::id
unsigned short id
Definition: utils.h:20
cs_strdup
char * cs_strdup(const char *str)
Definition: utils.c:92
name2id
int name2id(const name_map *map, int max, const char *name)
Definition: utils.c:42
name_map::name
const char * name
Definition: utils.h:38
count_positive
unsigned int count_positive(const uint16_t *list)
Definition: utils.c:72
arr_exist
bool arr_exist(uint16_t *arr, unsigned char max, unsigned int id)
Definition: utils.c:128
insn_map::branch
bool branch
Definition: utils.h:26
insn_map::regs_use
uint16_t regs_use[12]
Definition: utils.h:23
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
regress.m
m
Definition: regress/regress.py:25
name_map
Definition: utils.h:36
cs_priv.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:48