Skip to content

Commit

Permalink
Fix search hit between blocks bug. Needs rework
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jun 3, 2015
1 parent e5d2683 commit f182a72
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
16 changes: 11 additions & 5 deletions libr/core/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,9 @@ static void do_string_search(RCore *core, struct search_parameters *param) {
if (fd == -1 && core->io->desc) {
fd = core->io->desc->fd;
}
if (!json)
if (!json) {
eprintf ("# %d [0x%"PFMT64x"-0x%"PFMT64x"]\n", fd, param->from, param->to);
}

if (param->bckwrds) {
if (param->to < param->from + bufsz) {
Expand Down Expand Up @@ -1387,13 +1388,18 @@ static void do_string_search(RCore *core, struct search_parameters *param) {
break;
}
if (param->bckwrds) {
if (!param->do_bckwrd_srch) break;
if (at > param->from + bufsz) at -= bufsz;
else {
if (!param->do_bckwrd_srch) {
break;
}
if (at > param->from + bufsz) {
at -= bufsz;
} else {
param->do_bckwrd_srch = R_FALSE;
at = param->from;
}
} else at += bufsz;
} else {
at += bufsz;
}
}
print_search_progress (at, param->to, searchhits);
r_cons_break_end ();
Expand Down
11 changes: 10 additions & 1 deletion libr/search/keyword.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

#include <r_search.h>

static int ignoreMask(const ut8 *bm, int len) {
int i;
for (i=0; i<len; i++) {
if (bm[i] != 0xff)
return 0;
}
return 1;
}

R_API RSearchKeyword* r_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut8 *bmbuf, int bmlen, const char *data) {
RSearchKeyword *kw;
if (kwlen < 1 || bmlen < 0)
Expand All @@ -12,7 +21,7 @@ R_API RSearchKeyword* r_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut
kw->keyword_length = kwlen;
kw->bin_keyword = malloc (kwlen);
memcpy (kw->bin_keyword, kwbuf, kwlen);
if (bmbuf && bmlen > 0) {
if (bmbuf && bmlen > 0 && !ignoreMask (bmbuf, bmlen)) {
kw->bin_binmask = malloc (bmlen);
memcpy (kw->bin_binmask, bmbuf, bmlen);
kw->binmask_length = bmlen;
Expand Down
20 changes: 19 additions & 1 deletion libr/search/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ static int maskHits(const ut8* buf, int len, RSearchKeyword *kw) {

R_API int r_search_mybinparse_update(void *_s, ut64 from, const ut8 *buf, int len) {
RSearch *s = (RSearch*)_s;
RSearchKeyword *kw;
RListIter *iter;
int count = 0;

Expand All @@ -247,8 +248,25 @@ R_API int r_search_mybinparse_update(void *_s, ut64 from, const ut8 *buf, int le
}
#else
int i, j, hit;
#if 0
int hasmask;
// XXX this shouldnt be necessary
/** remove unnecesary binmasks here */
r_list_foreach (s->kws, iter, kw) {
if (kw->binmask_length) {
hasmask = 1;
for (i=0;i<kw->binmask_length; i++) {
if (kw->bin_binmask[i] != 0xff) {
hasmask = 0;
break;
}
}
if (!hasmask)
kw->binmask_length = 0;
}
}
#endif
for (i=0; i<len; i++) {
RSearchKeyword *kw;
r_list_foreach (s->kws, iter, kw) {
if (s->inverse && s->nhits>0) {
//eprintf ("nhits = %d\n", s->nhits);
Expand Down

0 comments on commit f182a72

Please sign in to comment.