Rizin
unix-like reverse engineering framework and cli tools
rz_regex.h File Reference
#include <rz_types.h>
#include <rz_list.h>
#include <sys/types.h>

Go to the source code of this file.

Classes

struct  rz_regex_t
 
struct  rz_regmatch_t
 

Macros

#define RZ_REGEX_BASIC   0000
 
#define RZ_REGEX_EXTENDED   0001
 
#define RZ_REGEX_ICASE   0002
 
#define RZ_REGEX_NOSUB   0004
 
#define RZ_REGEX_NEWLINE   0010
 
#define RZ_REGEX_NOSPEC   0020
 
#define RZ_REGEX_PEND   0040
 
#define RZ_REGEX_DUMP   0200
 
#define RZ_REGEX_ENOSYS   (-1) /* Reserved */
 
#define RZ_REGEX_NOMATCH   1
 
#define RZ_REGEX_BADPAT   2
 
#define RZ_REGEX_ECOLLATE   3
 
#define RZ_REGEX_ECTYPE   4
 
#define RZ_REGEX_EESCAPE   5
 
#define RZ_REGEX_ESUBREG   6
 
#define RZ_REGEX_EBRACK   7
 
#define RZ_REGEX_EPAREN   8
 
#define RZ_REGEX_EBRACE   9
 
#define RZ_REGEX_BADBR   10
 
#define RZ_REGEX_ERANGE   11
 
#define RZ_REGEX_ESPACE   12
 
#define RZ_REGEX_BADRPT   13
 
#define RZ_REGEX_EMPTY   14
 
#define RZ_REGEX_ASSERT   15
 
#define RZ_REGEX_INVARG   16
 
#define RZ_REGEX_ILLSEQ   17
 
#define RZ_REGEX_ATOI   255 /* convert name to number (!) */
 
#define RZ_REGEX_ITOA   0400 /* convert number to name (!) */
 
#define RZ_REGEX_NOTBOL   00001
 
#define RZ_REGEX_NOTEOL   00002
 
#define RZ_REGEX_STARTEND   00004
 
#define RZ_REGEX_TRACE   00400 /* tracing of execution */
 
#define RZ_REGEX_LARGE   01000 /* force large representation */
 
#define RZ_REGEX_BACKR   02000 /* force use of backref code */
 

Typedefs

typedef struct rz_regex_t RzRegex
 
typedef struct rz_regmatch_t RzRegexMatch
 

Functions

RZ_API RzRegexrz_regex_new (const char *pattern, const char *cflags)
 
RZ_API int rz_regex_match (const char *pattern, const char *flags, const char *text)
 
RZ_API RzListrz_regex_get_match_list (const char *pattern, const char *flags, const char *text)
 
RZ_API int rz_regex_flags (const char *flags)
 
RZ_API int rz_regex_comp (RzRegex *, const char *, int)
 
RZ_API size_t rz_regex_error (int, const RzRegex *, char *, size_t)
 
RZ_API bool rz_regex_check (const RzRegex *rr, const char *str)
 
RZ_API int rz_regex_exec (const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
 
RZ_API void rz_regex_free (RzRegex *)
 
RZ_API void rz_regex_fini (RzRegex *)
 

Macro Definition Documentation

◆ RZ_REGEX_ASSERT

#define RZ_REGEX_ASSERT   15

Definition at line 47 of file rz_regex.h.

◆ RZ_REGEX_ATOI

#define RZ_REGEX_ATOI   255 /* convert name to number (!) */

Definition at line 50 of file rz_regex.h.

◆ RZ_REGEX_BACKR

#define RZ_REGEX_BACKR   02000 /* force use of backref code */

Definition at line 59 of file rz_regex.h.

◆ RZ_REGEX_BADBR

#define RZ_REGEX_BADBR   10

Definition at line 42 of file rz_regex.h.

◆ RZ_REGEX_BADPAT

#define RZ_REGEX_BADPAT   2

Definition at line 34 of file rz_regex.h.

◆ RZ_REGEX_BADRPT

#define RZ_REGEX_BADRPT   13

Definition at line 45 of file rz_regex.h.

◆ RZ_REGEX_BASIC

#define RZ_REGEX_BASIC   0000

Definition at line 22 of file rz_regex.h.

◆ RZ_REGEX_DUMP

#define RZ_REGEX_DUMP   0200

Definition at line 29 of file rz_regex.h.

◆ RZ_REGEX_EBRACE

#define RZ_REGEX_EBRACE   9

Definition at line 41 of file rz_regex.h.

◆ RZ_REGEX_EBRACK

#define RZ_REGEX_EBRACK   7

Definition at line 39 of file rz_regex.h.

◆ RZ_REGEX_ECOLLATE

#define RZ_REGEX_ECOLLATE   3

Definition at line 35 of file rz_regex.h.

◆ RZ_REGEX_ECTYPE

#define RZ_REGEX_ECTYPE   4

Definition at line 36 of file rz_regex.h.

◆ RZ_REGEX_EESCAPE

#define RZ_REGEX_EESCAPE   5

Definition at line 37 of file rz_regex.h.

◆ RZ_REGEX_EMPTY

#define RZ_REGEX_EMPTY   14

Definition at line 46 of file rz_regex.h.

◆ RZ_REGEX_ENOSYS

#define RZ_REGEX_ENOSYS   (-1) /* Reserved */

Definition at line 32 of file rz_regex.h.

◆ RZ_REGEX_EPAREN

#define RZ_REGEX_EPAREN   8

Definition at line 40 of file rz_regex.h.

◆ RZ_REGEX_ERANGE

#define RZ_REGEX_ERANGE   11

Definition at line 43 of file rz_regex.h.

◆ RZ_REGEX_ESPACE

#define RZ_REGEX_ESPACE   12

Definition at line 44 of file rz_regex.h.

◆ RZ_REGEX_ESUBREG

#define RZ_REGEX_ESUBREG   6

Definition at line 38 of file rz_regex.h.

◆ RZ_REGEX_EXTENDED

#define RZ_REGEX_EXTENDED   0001

Definition at line 23 of file rz_regex.h.

◆ RZ_REGEX_ICASE

#define RZ_REGEX_ICASE   0002

Definition at line 24 of file rz_regex.h.

◆ RZ_REGEX_ILLSEQ

#define RZ_REGEX_ILLSEQ   17

Definition at line 49 of file rz_regex.h.

◆ RZ_REGEX_INVARG

#define RZ_REGEX_INVARG   16

Definition at line 48 of file rz_regex.h.

◆ RZ_REGEX_ITOA

#define RZ_REGEX_ITOA   0400 /* convert number to name (!) */

Definition at line 51 of file rz_regex.h.

◆ RZ_REGEX_LARGE

#define RZ_REGEX_LARGE   01000 /* force large representation */

Definition at line 58 of file rz_regex.h.

◆ RZ_REGEX_NEWLINE

#define RZ_REGEX_NEWLINE   0010

Definition at line 26 of file rz_regex.h.

◆ RZ_REGEX_NOMATCH

#define RZ_REGEX_NOMATCH   1

Definition at line 33 of file rz_regex.h.

◆ RZ_REGEX_NOSPEC

#define RZ_REGEX_NOSPEC   0020

Definition at line 27 of file rz_regex.h.

◆ RZ_REGEX_NOSUB

#define RZ_REGEX_NOSUB   0004

Definition at line 25 of file rz_regex.h.

◆ RZ_REGEX_NOTBOL

#define RZ_REGEX_NOTBOL   00001

Definition at line 54 of file rz_regex.h.

◆ RZ_REGEX_NOTEOL

#define RZ_REGEX_NOTEOL   00002

Definition at line 55 of file rz_regex.h.

◆ RZ_REGEX_PEND

#define RZ_REGEX_PEND   0040

Definition at line 28 of file rz_regex.h.

◆ RZ_REGEX_STARTEND

#define RZ_REGEX_STARTEND   00004

Definition at line 56 of file rz_regex.h.

◆ RZ_REGEX_TRACE

#define RZ_REGEX_TRACE   00400 /* tracing of execution */

Definition at line 57 of file rz_regex.h.

Typedef Documentation

◆ RzRegex

typedef struct rz_regex_t RzRegex

◆ RzRegexMatch

typedef struct rz_regmatch_t RzRegexMatch

Function Documentation

◆ rz_regex_check()

RZ_API bool rz_regex_check ( const RzRegex rr,
const char *  str 
)

Definition at line 138 of file regexec.c.

138  {
139  return rz_regex_exec(rr, str, 0, NULL, rr->re_flags);
140 }
#define NULL
Definition: cris-opc.c:27
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch pmatch[], int eflags)
Definition: regexec.c:149
int re_flags
Definition: rz_regex.h:13

References NULL, rz_regex_t::re_flags, rz_regex_exec(), and cmd_descs_generate::str.

Referenced by test_or().

◆ rz_regex_comp()

RZ_API int rz_regex_comp ( RzRegex preg,
const char *  pattern,
int  cflags 
)

Definition at line 258 of file regcomp.c.

258  {
259  struct parse pa;
260  struct re_guts *g;
261  struct parse *p = &pa;
262  int i;
263  size_t len;
264 #ifdef REDEBUG
265 #define GOODFLAGS(f) (f)
266 #else
267 #define GOODFLAGS(f) ((f) & ~RZ_REGEX_DUMP)
268 #endif
269  cflags = GOODFLAGS(cflags);
270  if (!preg || ((cflags & RZ_REGEX_EXTENDED) && (cflags & RZ_REGEX_NOSPEC))) {
271  return RZ_REGEX_INVARG;
272  }
273  if (cflags & RZ_REGEX_PEND) {
274  if (preg->re_endp < pattern) {
275  return RZ_REGEX_INVARG;
276  }
277  len = preg->re_endp - pattern;
278  } else {
279  len = strlen((char *)pattern);
280  }
281  /* do the mallocs early so failure handling is easy */
282  g = calloc(1, sizeof(struct re_guts) + (NC - 1));
283  if (!g) {
284  return RZ_REGEX_ESPACE;
285  }
286  /*
287  * Limit the pattern space to avoid a 32-bit overflow on buffer
288  * extension. Also avoid any signed overflow in case of conversion
289  * so make the real limit based on a 31-bit overflow.
290  *
291  * Likely not applicable on 64-bit systems but handle the case
292  * generically (who are we to stop people from using ~715MB+
293  * patterns?).
294  */
295  size_t maxlen = ((size_t)-1 >> 1) / sizeof(sop) * 2 / 3;
296  if (len >= maxlen) {
297  free(g);
298  return RZ_REGEX_ESPACE;
299  }
300  preg->re_flags = cflags;
301  p->ssize = len / (size_t)2 * (size_t)3 + (size_t)1; /* ugh */
302  if (p->ssize < len) {
303  free(g);
304  return RZ_REGEX_ESPACE;
305  }
306 
307  p->strip = (sop *)calloc(p->ssize, sizeof(sop));
308  if (!p->strip) {
309  free(g);
310  return RZ_REGEX_ESPACE;
311  }
312  p->slen = 0;
313  if (!p->strip) {
314  free(g);
315  return RZ_REGEX_ESPACE;
316  }
317 
318  /* set things up */
319  p->g = g;
320  p->next = (char *)pattern; /* convenience; we do not modify it */
321  p->end = p->next + len;
322  p->error = 0;
323  p->ncsalloc = 0;
324  for (i = 0; i < NPAREN; i++) {
325  p->pbegin[i] = 0;
326  p->pend[i] = 0;
327  }
328  g->csetsize = NC;
329  g->sets = NULL;
330  g->setbits = NULL;
331  g->ncsets = 0;
332  g->cflags = cflags;
333  g->iflags = 0;
334  g->nbol = 0;
335  g->neol = 0;
336  g->must = NULL;
337  g->mlen = 0;
338  g->nsub = 0;
339  g->ncategories = 1; /* category 0 is "everything else" */
340  g->categories = &g->catspace[-(CHAR_MIN)];
341  (void)memset((char *)g->catspace, 0, NC * sizeof(cat_t));
342  g->backrefs = 0;
343 
344  /* do it */
345  EMIT(OEND, 0);
346  g->firststate = THERE();
347  if (cflags & RZ_REGEX_EXTENDED) {
348  p_ere(p, OUT);
349  } else if (cflags & RZ_REGEX_NOSPEC) {
350  p_str(p);
351  } else {
352  p_bre(p, OUT, OUT);
353  }
354  EMIT(OEND, 0);
355  g->laststate = THERE();
356 
357  /* tidy up loose ends and fill things in */
358  categorize(p, g);
359  stripsnug(p, g);
360  findmust(p, g);
361  g->nplus = pluscount(p, g);
362  g->magic = MAGIC2;
363  preg->re_nsub = g->nsub;
364  preg->re_g = g;
365  preg->re_magic = MAGIC1;
366 #ifndef REDEBUG
367  /* not debugging, so can't rely on the asssert() in regexec() */
368  if (g->iflags & BAD) {
370  }
371 #endif
372  if (p->error) {
373  rz_regex_fini(preg);
374  }
375  return p->error;
376 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
struct @667 g
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
return memset(p, 0, total)
void * p
Definition: libc.cpp:67
#define NC
Definition: utils.h:42
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static void stripsnug(struct parse *, struct re_guts *)
Definition: regcomp.c:1630
#define NPAREN
Definition: regcomp.c:66
#define SETERROR(e)
Definition: regcomp.c:128
static void categorize(struct parse *, struct re_guts *)
Definition: regcomp.c:1475
static void p_str(struct parse *)
Definition: regcomp.c:573
#define GOODFLAGS(f)
static void p_bre(struct parse *, int, int)
Definition: regcomp.c:590
#define THERE()
Definition: regcomp.c:138
static sopno pluscount(struct parse *, struct re_guts *)
Definition: regcomp.c:1732
static void p_ere(struct parse *, int)
Definition: regcomp.c:381
static void findmust(struct parse *, struct re_guts *)
Definition: regcomp.c:1649
RZ_API void rz_regex_fini(RzRegex *preg)
Definition: regcomp.c:226
#define EMIT(op, sopnd)
Definition: regcomp.c:133
unsigned long sop
Definition: regex2.h:62
#define OEND
Definition: regex2.h:72
#define MAGIC1
Definition: regex2.h:41
#define MAGIC2
Definition: regex2.h:128
#define OUT
Definition: regex2.h:157
unsigned char cat_t
Definition: regex2.h:121
#define BAD
Definition: regex2.h:141
#define RZ_REGEX_PEND
Definition: rz_regex.h:28
#define RZ_REGEX_ESPACE
Definition: rz_regex.h:44
#define RZ_REGEX_EXTENDED
Definition: rz_regex.h:23
#define RZ_REGEX_NOSPEC
Definition: rz_regex.h:27
#define RZ_REGEX_INVARG
Definition: rz_regex.h:48
#define RZ_REGEX_ASSERT
Definition: rz_regex.h:47
int size_t
Definition: sftypes.h:40
Definition: regcomp.c:57
const char * re_endp
Definition: rz_regex.h:11
size_t re_nsub
Definition: rz_regex.h:10
int re_magic
Definition: rz_regex.h:9
struct re_guts * re_g
Definition: rz_regex.h:12
ut64 maxlen
Definition: core.c:76

References BAD, calloc(), categorize(), EMIT, findmust(), free(), g, GOODFLAGS, i, len, MAGIC1, MAGIC2, maxlen, memset(), NC, NPAREN, NULL, OEND, OUT, p, p_bre(), p_ere(), p_str(), pluscount(), rz_regex_t::re_endp, rz_regex_t::re_flags, rz_regex_t::re_g, rz_regex_t::re_magic, rz_regex_t::re_nsub, RZ_REGEX_ASSERT, RZ_REGEX_ESPACE, RZ_REGEX_EXTENDED, rz_regex_fini(), RZ_REGEX_INVARG, RZ_REGEX_NOSPEC, RZ_REGEX_PEND, SETERROR, stripsnug(), and THERE.

Referenced by _main(), check_fmt(), magiccheck(), rz_regex_get_match_list(), rz_regex_match(), rz_regex_new(), and rz_search_regexp_update().

◆ rz_regex_error()

RZ_API size_t rz_regex_error ( int  errcode,
const RzRegex preg,
char *  errbuf,
size_t  errbuf_size 
)

Definition at line 78 of file regerror.c.

78  {
79  struct rerr *r;
80  size_t len;
81  int target = errcode & ~RZ_REGEX_ITOA;
82  char *s;
83  char convbuf[50];
84 
85  if (errcode == RZ_REGEX_ATOI) {
86  s = regatoi(preg, convbuf, sizeof convbuf);
87  } else {
88  for (r = rerrs; r->code != 0; r++) {
89  if (r->code == target) {
90  break;
91  }
92  }
93 
94  if (errcode & RZ_REGEX_ITOA) {
95  if (r->code != 0) {
96  STRLCPY(convbuf, r->name, sizeof(convbuf) - 1);
97  } else {
98  snprintf(convbuf, sizeof convbuf, "RZ_REGEX_0x%x", target);
99  }
100  s = convbuf;
101  } else {
102  s = r->explain;
103  }
104  }
105 
106  len = strlen(s) + 1;
107  if (errbuf_size > 0) {
108  STRLCPY(errbuf, s, errbuf_size - 1);
109  }
110 
111  return len;
112 }
#define r
Definition: crypto_rc6.c:12
snprintf
Definition: kernel.h:364
#define STRLCPY(x, y, z)
Definition: utils.h:44
static struct rerr rerrs[]
static char * regatoi(const RzRegex *, char *, int)
Definition: regerror.c:118
static RzSocket * s
Definition: rtr.c:28
#define RZ_REGEX_ITOA
Definition: rz_regex.h:51
#define RZ_REGEX_ATOI
Definition: rz_regex.h:50
Definition: regerror.c:49

References len, r, regatoi(), rerrs, RZ_REGEX_ATOI, RZ_REGEX_ITOA, s, snprintf, and STRLCPY.

Referenced by check_fmt(), and magiccheck().

◆ rz_regex_exec()

RZ_API int rz_regex_exec ( const RzRegex preg,
const char *  string,
size_t  nmatch,
RzRegexMatch  __pmatch[],
int  eflags 
)

Definition at line 149 of file regexec.c.

150  {
151  struct re_guts *g;
152 #ifdef REDEBUG
153 #define GOODFLAGS(f) (f)
154 #else
155 #define GOODFLAGS(f) ((f) & (RZ_REGEX_NOTBOL | RZ_REGEX_NOTEOL | RZ_REGEX_STARTEND | RZ_REGEX_LARGE))
156 #endif
157  if (!preg || !string) {
158  return RZ_REGEX_ASSERT;
159  }
160 
161  g = preg->re_g;
162  if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) {
163  return (RZ_REGEX_BADPAT);
164  }
165  if (g->iflags & BAD) { /* backstop for no-debug case */
166  return (RZ_REGEX_BADPAT);
167  }
168  eflags = GOODFLAGS(eflags);
169  if (g->nstates <= CHAR_BIT * sizeof(states1) && !(eflags & RZ_REGEX_LARGE)) {
170  return (smatcher(g, (char *)string, nmatch, pmatch, eflags));
171  } else {
172  return (lmatcher(g, (char *)string, nmatch, pmatch, eflags));
173  }
174 }
#define CHAR_BIT
Definition: readbits.h:99
#define states1
Definition: regexec.c:56
#define GOODFLAGS(f)
#define RZ_REGEX_BADPAT
Definition: rz_regex.h:34
#define RZ_REGEX_LARGE
Definition: rz_regex.h:58

References BAD, CHAR_BIT, g, GOODFLAGS, MAGIC1, MAGIC2, rz_regex_t::re_g, rz_regex_t::re_magic, RZ_REGEX_ASSERT, RZ_REGEX_BADPAT, RZ_REGEX_LARGE, and states1.

Referenced by _main(), check_fmt(), find_e_opts(), magiccheck(), main(), pager_all_matches(), rz_asm_tokenize_asm_regex(), rz_core_asm_strsearch(), rz_regex_check(), rz_regex_get_match_list(), rz_regex_match(), rz_search_regexp_update(), str_split_list_common_regex(), and test_or().

◆ rz_regex_fini()

RZ_API void rz_regex_fini ( RzRegex preg)

Definition at line 226 of file regcomp.c.

226  {
227  struct re_guts *g;
228  if (!preg) {
229  return;
230  }
231  if (preg->re_magic != MAGIC1) { /* oops */
232  return; /* nice to complain, but hard */
233  }
234 
235  g = preg->re_g;
236  if (!g || g->magic != MAGIC2) { /* oops again */
237  return;
238  }
239  preg->re_magic = 0; /* mark it invalid */
240  g->magic = 0; /* mark it invalid */
241 
242  free(g->strip);
243  free(g->sets);
244  free(g->setbits);
245  free(g->must);
246  free(g);
247 }

References free(), g, MAGIC1, MAGIC2, rz_regex_t::re_g, and rz_regex_t::re_magic.

Referenced by check_fmt(), magiccheck(), rz_regex_comp(), rz_regex_free(), rz_regex_get_match_list(), rz_regex_match(), and rz_search_regexp_update().

◆ rz_regex_flags()

RZ_API int rz_regex_flags ( const char *  flags)

Definition at line 197 of file regcomp.c.

197  {
198  int flags = 0;
199  if (!f || !*f) {
200  return 0;
201  }
202  if (strchr(f, 'e')) {
204  }
205  if (strchr(f, 'i')) {
207  }
208  if (strchr(f, 's')) {
210  }
211  if (strchr(f, 'n')) {
213  }
214  if (strchr(f, 'N')) {
216  }
217  if (strchr(f, 'p')) {
218  flags |= RZ_REGEX_PEND;
219  }
220  if (strchr(f, 'd')) {
221  flags |= RZ_REGEX_DUMP;
222  }
223  return flags;
224 }
#define RZ_REGEX_ICASE
Definition: rz_regex.h:24
#define RZ_REGEX_NEWLINE
Definition: rz_regex.h:26
#define RZ_REGEX_NOSUB
Definition: rz_regex.h:25
#define RZ_REGEX_DUMP
Definition: rz_regex.h:29
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define f(i)
Definition: sha256.c:46

References f, flags, RZ_REGEX_DUMP, RZ_REGEX_EXTENDED, RZ_REGEX_ICASE, RZ_REGEX_NEWLINE, RZ_REGEX_NOSPEC, RZ_REGEX_NOSUB, and RZ_REGEX_PEND.

Referenced by rz_regex_get_match_list(), rz_regex_match(), and rz_regex_new().

◆ rz_regex_free()

RZ_API void rz_regex_free ( RzRegex preg)

◆ rz_regex_get_match_list()

RZ_API RzList* rz_regex_get_match_list ( const char *  pattern,
const char *  flags,
const char *  text 
)

Definition at line 155 of file regcomp.c.

155  {
157  RzRegex rx;
159  char *entry;
160  size_t entry_len = 0;
161  int re_flags = rz_regex_flags(flags);
162  if (rz_regex_comp(&rx, pattern, re_flags)) {
163  eprintf("Failed to compile regexp: %s\n", pattern);
164  return NULL;
165  }
166 
167  /* Initialize the boundaries for RZ_REGEX_STARTEND */
168  match.rm_so = 0;
169  match.rm_eo = strlen(text);
170  while (!rz_regex_exec(&rx, text, 1, &match, re_flags | RZ_REGEX_STARTEND)) {
171  entry_len = match.rm_eo - match.rm_so + 1;
172  entry = RZ_NEWS0(char, entry_len);
173  rz_str_ncpy(entry, text + match.rm_so, entry_len);
175  /* Update the boundaries for RZ_REGEX_STARTEND */
176  match.rm_so = match.rm_eo;
177  match.rm_eo = strlen(text);
178  }
179  rz_regex_fini(&rx);
180  return list;
181 }
unsigned char match[65280+2]
Definition: gun.c:165
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API int rz_regex_flags(const char *f)
Definition: regcomp.c:197
RZ_API int rz_regex_comp(RzRegex *preg, const char *pattern, int cflags)
Definition: regcomp.c:258
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
Definition: regexec.c:149
#define RZ_REGEX_STARTEND
Definition: rz_regex.h:56
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
Definition: str.c:923
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
Definition: zipcmp.c:77
Definition: engine.c:71

References eprintf, flags, free(), list(), match, NULL, rz_list_append(), rz_list_newf(), RZ_NEWS0, rz_regex_comp(), rz_regex_exec(), rz_regex_fini(), rz_regex_flags(), RZ_REGEX_STARTEND, rz_str_ncpy(), and create_tags_rz::text.

Referenced by print_diff(), and rz_test_cmp_cmd_output().

◆ rz_regex_match()

RZ_API int rz_regex_match ( const char *  pattern,
const char *  flags,
const char *  text 
)

Definition at line 142 of file regcomp.c.

142  {
143  int ret;
144  RzRegex rx;
145  int re_flags = rz_regex_flags(flags);
146  if (rz_regex_comp(&rx, pattern, re_flags)) {
147  eprintf("FAIL TO COMPILE %s\n", pattern);
148  return 0;
149  }
150  ret = rz_regex_exec(&rx, text, 0, 0, re_flags);
151  rz_regex_fini(&rx);
152  return ret ? 0 : 1;
153 }

References eprintf, flags, rz_regex_comp(), rz_regex_exec(), rz_regex_fini(), rz_regex_flags(), and create_tags_rz::text.

Referenced by classdump_objc(), construct_rop_gadget(), is_lea(), step_until_inst(), and test_or().

◆ rz_regex_new()

RZ_API RzRegex* rz_regex_new ( const char *  pattern,
const char *  cflags 
)

Definition at line 183 of file regcomp.c.

183  {
184  rz_return_val_if_fail(pattern, NULL);
185  RzRegex *r, rx = { 0 };
186  if (rz_regex_comp(&rx, pattern, rz_regex_flags(flags))) {
187  return NULL;
188  }
189  r = RZ_NEW(RzRegex);
190  if (!r) {
191  return NULL;
192  }
193  memcpy(r, &rx, sizeof(RzRegex));
194  return r;
195 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_NEW(x)
Definition: rz_types.h:285

References flags, memcpy(), NULL, r, RZ_NEW, rz_regex_comp(), rz_regex_flags(), and rz_return_val_if_fail.

Referenced by find_e_opts(), main(), rz_cons_less_str(), rz_core_asm_strsearch(), rz_str_split_duplist_n_regex(), rz_str_split_list_regex(), and test_or().