Rizin
unix-like reverse engineering framework and cli tools
regexp.c File Reference
#include "rz_search.h"
#include <rz_regex.h>

Go to the source code of this file.

Functions

RZ_API int rz_search_regexp_update (RzSearch *s, ut64 from, const ut8 *buf, int len)
 

Function Documentation

◆ rz_search_regexp_update()

RZ_API int rz_search_regexp_update ( RzSearch s,
ut64  from,
const ut8 buf,
int  len 
)

Definition at line 8 of file regexp.c.

8  {
9  RzSearchKeyword *kw;
12  RzRegex compiled = { 0 };
13  const int old_nhits = s->nhits;
14  int ret = 0;
15 
16  rz_list_foreach (s->kws, iter, kw) {
17  int reflags = RZ_REGEX_EXTENDED;
18 
19  if (kw->icase) {
20  reflags |= RZ_REGEX_ICASE;
21  }
22 
23  if (rz_regex_comp(&compiled, (char *)kw->bin_keyword, reflags)) {
24  eprintf("Cannot compile '%s' regexp\n", kw->bin_keyword);
25  return -1;
26  }
27 
28  match.rm_so = 0;
29  match.rm_eo = len;
30 
31  while (!rz_regex_exec(&compiled, (char *)buf, 1, &match, RZ_REGEX_STARTEND)) {
32  int t = rz_search_hit_new(s, kw, from + match.rm_so);
33  if (!t) {
34  ret = -1;
35  goto beach;
36  }
37  if (t > 1) {
38  goto beach;
39  }
40  /* Setup the boundaries for RZ_REGEX_STARTEND */
41  match.rm_so = match.rm_eo;
42  match.rm_eo = len;
43  }
44  }
45 
46 beach:
47  rz_regex_fini(&compiled);
48  if (!ret) {
49  ret = s->nhits - old_nhits;
50  }
51  return ret;
52 }
size_t len
Definition: 6502dis.c:15
unsigned char match[65280+2]
Definition: gun.c:165
voidpf void * buf
Definition: ioapi.h:138
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
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
#define RZ_REGEX_ICASE
Definition: rz_regex.h:24
RZ_API void rz_regex_fini(RzRegex *)
Definition: regcomp.c:226
#define RZ_REGEX_EXTENDED
Definition: rz_regex.h:23
RZ_API int rz_regex_comp(RzRegex *, const char *, int)
Definition: regcomp.c:258
RZ_API int rz_search_hit_new(RzSearch *s, RzSearchKeyword *kw, ut64 addr)
Definition: search.c:107
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
Definition: engine.c:71

References rz_search_keyword_t::bin_keyword, eprintf, from, rz_search_keyword_t::icase, len, match, rz_regex_comp(), rz_regex_exec(), RZ_REGEX_EXTENDED, rz_regex_fini(), RZ_REGEX_ICASE, RZ_REGEX_STARTEND, rz_search_hit_new(), and s.

Referenced by rz_search_set_mode().