radare2/libr/search/regexp.c

40 lines
906 B
C
Raw Normal View History

2014-06-05 00:55:45 +00:00
/* radare - LGPL - Copyright 2008-2014 - pancake, TheLemonMan */
#include "r_search.h"
#include <r_regex.h>
R_API int r_search_regexp_update(void *_s, ut64 from, const ut8 *buf, int len) {
RSearch *s = (RSearch*)_s;
2014-06-04 21:35:53 +00:00
RSearchKeyword *kw;
RListIter *iter;
2014-06-04 21:35:53 +00:00
RRegexMatch match;
RRegex compiled;
2014-06-04 22:32:01 +00:00
int count = 0;
r_list_foreach (s->kws, iter, kw) {
int reflags = R_REGEX_EXTENDED;
2014-06-03 20:23:08 +00:00
if (kw->icase)
reflags |= R_REGEX_ICASE;
2014-06-04 21:35:53 +00:00
if (r_regex_comp (&compiled, (char *)kw->bin_keyword, reflags)) {
eprintf ("Cannot compile '%s' regexp\n", kw->bin_keyword);
return -1;
}
2014-06-04 21:35:53 +00:00
match.rm_so = 0;
match.rm_eo = len;
2014-06-04 22:32:01 +00:00
while (!r_regex_exec (&compiled, (char *)buf, 1, &match, R_REGEX_STARTEND)) {
r_search_hit_new (s, kw, from+match.rm_so);
2014-06-04 21:35:53 +00:00
kw->count++;
2014-06-04 22:32:01 +00:00
/* Setup the boundaries for R_REGEX_STARTEND */
match.rm_so = match.rm_eo;
match.rm_eo = len;
count++;
2014-06-04 21:35:53 +00:00
}
}
2014-06-04 21:35:53 +00:00
return count;
}