Initial support for search.overlap

This commit is contained in:
pancake 2016-02-12 11:37:48 -06:00
parent 0b8a589e16
commit 1a89cac78f
4 changed files with 14 additions and 5 deletions

View File

@ -261,7 +261,7 @@ static int __cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
eprintf ("Error: Callback has an invalid RCore.\n");
return false;
}
if (maxhits && searchhits>=maxhits) {
if (maxhits && searchhits >= maxhits) {
//eprintf ("Error: search.maxhits reached.\n");
return false;
}
@ -292,7 +292,7 @@ static int __cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
default:
len = kw->keyword_length; // 8 byte context
mallocsize = (len*2)+extra;
str = (len>0xffff)? NULL: malloc (mallocsize);
str = (len > 0xffff)? NULL: malloc (mallocsize);
if (str) {
p = str;
memset (str, 0, len);
@ -1686,6 +1686,7 @@ static int cmd_search(void *data, const char *input) {
*/
maxhits = r_config_get_i (core->config, "search.maxhits");
searchprefix = r_config_get (core->config, "search.prefix");
core->search->overlap = r_config_get_i (core->config, "search.overlap");
// TODO: get ranges from current IO section
/* XXX: Think how to get the section ranges here */
if (param.from == 0LL) param.from = core->offset;

View File

@ -1778,6 +1778,7 @@ R_API int r_core_config_init(RCore *core) {
SETI("search.count", 0, "Start index number at search hits");
SETI("search.distance", 0, "Search string distance");
SETPREF("search.flags", "true", "All search results are flagged, otherwise only printed");
SETPREF("search.overlap", "false", "Look for overlapped search hits");
SETI("search.maxhits", 0, "Maximum number of hits (0: no limit)");
SETI("search.from", -1, "Search start address");
SETCB("search.in", "file", &cb_searchin, "Specify search boundaries (raw, block, file, section, range)");

View File

@ -65,6 +65,7 @@ typedef struct r_search_t {
RMemoryPool *pool;
int distance;
int inverse;
bool overlap;
int contiguous;
int align;
RSearchUpdate update;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2015 pancake */
/* radare - LGPL - Copyright 2008-2016 pancake */
#include <r_search.h>
#include <r_list.h>
@ -23,6 +23,7 @@ R_API RSearch *r_search_new(int mode) {
s->align = 0;
s->distance = 0;
s->contiguous = 0;
s->overlap = false;
s->pattern_size = 0;
s->string_max = 255;
s->string_min = 3;
@ -139,7 +140,7 @@ R_API int r_search_deltakey_update(void *_s, ut64 from, const ut8 *buf, int len)
kw->idx[j]++;
if (kw->idx[j] == kw->keyword_length) {
if (!r_search_hit_new (s, kw, (ut64)
from+i-kw->keyword_length+1))
from + i - kw->keyword_length + 1))
return -1;
kw->idx[j] = 0;
//kw->idx[0] = 0;
@ -355,13 +356,18 @@ R_API int r_search_mybinparse_update(void *_s, ut64 from, const ut8 *buf, int le
continue;
}
if (!r_search_hit_new (s, kw, (ut64)
from+i-kw->keyword_length+1)) {
from + i - kw->keyword_length + 1)) {
return -1;
}
kw->idx[j] = 0;
kw->distance = 0;
kw->count++;
count++;
if (s->overlap) {
if (kw->keyword_length > 1) {
i -= kw->keyword_length - 1;
}
}
//s->nhits++;
}
}