2014-06-05 00:55:45 +00:00
|
|
|
/* radare - LGPL - Copyright 2008-2014 - pancake, TheLemonMan */
|
2009-02-15 22:32:17 +00:00
|
|
|
|
|
|
|
#include "r_search.h"
|
2011-09-14 00:07:06 +00:00
|
|
|
#include <r_regex.h>
|
2009-02-15 22:32:17 +00:00
|
|
|
|
2010-04-08 10:29:47 +00:00
|
|
|
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;
|
2010-08-08 17:03:51 +00:00
|
|
|
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;
|
2009-02-15 22:32:17 +00:00
|
|
|
|
2010-08-08 17:03:51 +00:00
|
|
|
r_list_foreach (s->kws, iter, kw) {
|
2011-09-14 00:07:06 +00:00
|
|
|
int reflags = R_REGEX_EXTENDED;
|
2009-02-15 22:32:17 +00:00
|
|
|
|
2014-06-03 20:23:08 +00:00
|
|
|
if (kw->icase)
|
2011-09-14 00:07:06 +00:00
|
|
|
reflags |= R_REGEX_ICASE;
|
2009-02-15 22:32:17 +00:00
|
|
|
|
2014-06-04 21:35:53 +00:00
|
|
|
if (r_regex_comp (&compiled, (char *)kw->bin_keyword, reflags)) {
|
2014-06-04 20:18:02 +00:00
|
|
|
eprintf ("Cannot compile '%s' regexp\n", kw->bin_keyword);
|
2009-02-16 23:09:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-02-15 22:32:17 +00:00
|
|
|
|
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
|
|
|
}
|
2009-02-15 22:32:17 +00:00
|
|
|
}
|
2014-06-04 21:35:53 +00:00
|
|
|
|
2009-02-15 22:32:17 +00:00
|
|
|
return count;
|
|
|
|
}
|