Rizin
unix-like reverse engineering framework and cli tools
regexp.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2008-2020 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2008-2020 LemonBoy <thatlemon@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include "rz_search.h"
6 #include <rz_regex.h>
7 
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
#define RZ_API
unsigned char match[65280+2]
Definition: gun.c:165
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API int rz_search_regexp_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: regexp.c:8
#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
ut64(WINAPI *w32_GetEnabledXStateFeatures)()