Rizin
unix-like reverse engineering framework and cli tools
utils.h File Reference
#include <stddef.h>
#include "include/capstone/capstone.h"
#include "cs_priv.h"

Go to the source code of this file.

Classes

struct  insn_map
 
struct  name_map
 

Macros

#define HEX_THRESHOLD   9
 
#define ARR_SIZE(a)   (sizeof(a)/sizeof(a[0]))
 
#define MATRIX_SIZE(a)   (sizeof(a[0])/sizeof(a[0][0]))
 
#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 
#define CS_AC_IGNORE   (1 << 7)
 

Typedefs

typedef struct insn_map insn_map
 
typedef struct name_map name_map
 

Functions

unsigned short insn_find (const insn_map *m, unsigned int max, unsigned int id, unsigned short **cache)
 
int name2id (const name_map *map, int max, const char *name)
 
const char * id2name (const name_map *map, int max, const unsigned int id)
 
unsigned int count_positive (const uint16_t *list)
 
unsigned int count_positive8 (const unsigned char *list)
 
char * cs_strdup (const char *str)
 
int cs_snprintf (char *buffer, size_t size, const char *fmt,...)
 
bool arr_exist8 (unsigned char *arr, unsigned char max, unsigned int id)
 
bool arr_exist (uint16_t *arr, unsigned char max, unsigned int id)
 

Macro Definition Documentation

◆ ARR_SIZE

#define ARR_SIZE (   a)    (sizeof(a)/sizeof(a[0]))

Definition at line 54 of file utils.h.

◆ CS_AC_IGNORE

#define CS_AC_IGNORE   (1 << 7)

Definition at line 64 of file utils.h.

◆ HEX_THRESHOLD

#define HEX_THRESHOLD   9

Definition at line 16 of file utils.h.

◆ MATRIX_SIZE

#define MATRIX_SIZE (   a)    (sizeof(a[0])/sizeof(a[0][0]))

Definition at line 55 of file utils.h.

◆ MIN

#define MIN (   x,
 
)    ((x) < (y) ? (x) : (y))

Definition at line 59 of file utils.h.

Typedef Documentation

◆ insn_map

typedef struct insn_map insn_map

◆ name_map

typedef struct name_map name_map

Function Documentation

◆ arr_exist()

bool arr_exist ( uint16_t arr,
unsigned char  max,
unsigned int  id 
)

Definition at line 128 of file utils.c.

129 {
130  int i;
131 
132  for (i = 0; i < max; i++) {
133  if (arr[i] == id)
134  return true;
135  }
136 
137  return false;
138 }
lzma_index ** i
Definition: index.h:629
int max
Definition: enough.c:225

References syscall_preprocessing::arr, i, and max.

Referenced by cs_reg_read(), and cs_reg_write().

◆ arr_exist8()

bool arr_exist8 ( unsigned char *  arr,
unsigned char  max,
unsigned int  id 
)

Definition at line 116 of file utils.c.

117 {
118  int i;
119 
120  for (i = 0; i < max; i++) {
121  if (arr[i] == id)
122  return true;
123  }
124 
125  return false;
126 }

References syscall_preprocessing::arr, i, and max.

Referenced by cs_insn_group().

◆ count_positive()

unsigned int count_positive ( const uint16_t list)

Definition at line 72 of file utils.c.

73 {
74  unsigned int c;
75 
76  for (c = 0; list[c] > 0; c++);
77 
78  return c;
79 }
static void list(RzEgg *egg)
Definition: rz-gg.c:52
#define c(i)
Definition: sha256.c:43

References c, and list().

◆ count_positive8()

unsigned int count_positive8 ( const unsigned char *  list)

Definition at line 83 of file utils.c.

84 {
85  unsigned int c;
86 
87  for (c = 0; list[c] > 0; c++);
88 
89  return c;
90 }

References c, and list().

◆ cs_snprintf()

int cs_snprintf ( char *  buffer,
size_t  size,
const char *  fmt,
  ... 
)

Definition at line 104 of file utils.c.

105 {
106  int ret;
107 
108  va_list ap;
109  va_start(ap, fmt);
110  ret = cs_vsnprintf(buffer, size, fmt, ap);
111  va_end(ap);
112 
113  return ret;
114 }
cs_vsnprintf_t cs_vsnprintf
Definition: cs.c:352
voidpf void uLong size
Definition: ioapi.h:138
Definition: buffer.h:15

References cs_vsnprintf.

Referenced by cs_winkernel_vsnprintf_test(), and skipdata_opstr().

◆ cs_strdup()

char* cs_strdup ( const char *  str)

Definition at line 92 of file utils.c.

93 {
94  size_t len = strlen(str)+ 1;
95  void *new = cs_mem_malloc(len);
96 
97  if (new == NULL)
98  return NULL;
99 
100  return (char *)memmove(new, str, len);
101 }
size_t len
Definition: 6502dis.c:15
#define NULL
Definition: cris-opc.c:27
cs_malloc_t cs_mem_malloc
Definition: cs.c:348

References cs_mem_malloc, len, NULL, and cmd_descs_generate::str.

◆ id2name()

const char* id2name ( const name_map map,
int  max,
const unsigned int  id 
)

Definition at line 56 of file utils.c.

57 {
58  int i;
59 
60  for (i = 0; i < max; i++) {
61  if (map[i].id == id) {
62  return map[i].name;
63  }
64  }
65 
66  // nothing match
67  return NULL;
68 }
size_t map(int syms, int left, int len)
Definition: enough.c:237

References i, map(), max, and NULL.

Referenced by M68K_group_name().

◆ insn_find()

unsigned short insn_find ( const insn_map m,
unsigned int  max,
unsigned int  id,
unsigned short **  cache 
)

Definition at line 31 of file utils.c.

32 {
33  if (id > insns[max - 1].id)
34  return 0;
35 
36  if (*cache == NULL)
37  *cache = make_id2insn(insns, max);
38 
39  return (*cache)[id];
40 }
int id
Definition: op.c:540
static unsigned short * make_id2insn(const insn_map *insns, unsigned int size)
Definition: utils.c:15
static struct insnlist * insns[64]
Definition: tricore-dis.c:69

References id, insns, make_id2insn(), max, and NULL.

◆ name2id()

int name2id ( const name_map map,
int  max,
const char *  name 
)

Definition at line 42 of file utils.c.

43 {
44  int i;
45 
46  for (i = 0; i < max; i++) {
47  if (!strcmp(map[i].name, name)) {
48  return map[i].id;
49  }
50  }
51 
52  // nothing match
53  return -1;
54 }
Definition: z80asm.h:102

References i, map(), and max.