Some fixes for the latest rsearch changes

This commit is contained in:
pancake 2014-06-04 22:18:02 +02:00
parent 87cce7a2c2
commit 84e1bc6eb5
4 changed files with 54 additions and 47 deletions

View File

@ -169,12 +169,17 @@ R_API void r_core_get_boundaries (RCore *core, const char *mode, ut64 *from, ut6
if (core->io->va) {
RListIter *iter;
RIOSection *s;
*from = *to = core->offset;
*from = *to = 0;
r_list_foreach (core->io->sections, iter, s) {
if (!*from) {
*from = s->vaddr;
*to = s->vaddr+s->vsize;
continue;
}
if (((s->vaddr) < *from) && s->vaddr)
*from = s->vaddr;
if ((s->vaddr+s->size) > *to && *from>=s->vaddr)
*to = s->vaddr+s->size;
if ((s->vaddr+s->vsize) > *to && *from>=s->vaddr)
*to = s->vaddr+s->vsize;
}
if (*to == 0LL || *to == UT64_MAX || *to == UT32_MAX)
*to = r_io_size (core->io);
@ -190,7 +195,12 @@ R_API void r_core_get_boundaries (RCore *core, const char *mode, ut64 *from, ut6
RIOSection *s;
*from = *to = core->offset;
r_list_foreach (core->io->sections, iter, s) {
if (*from >= s->vaddr && *from < (s->vaddr+s->size)) {
if (*from >= s->offset && *from < (s->offset+s->size)) {
*from = s->vaddr;
*to = s->vaddr+s->vsize;
break;
}
if (*from >= s->vaddr && *from < (s->vaddr+s->vsize)) {
*to = s->vaddr+s->size;
break;
}
@ -220,6 +230,7 @@ R_API void r_core_get_boundaries (RCore *core, const char *mode, ut64 *from, ut6
}
}
}
eprintf ("RNG %llx %llx\n", *from, *to);
}
// TODO: handle more than one?
@ -390,6 +401,10 @@ static int cmd_search(void *data, const char *input) {
from = __from;
core->search->bckwrds = R_FALSE;
if (from == to) {
eprintf ("WARNING from == to?\n");
}
reread:
switch (*input) {
case '!':

View File

@ -47,7 +47,7 @@ typedef struct r_io_map_t {
typedef struct r_io_section_t {
char name[64]; // use strpool
ut64 offset;
ut64 offset; // TODO: rename to paddr
ut64 vaddr;
ut64 size;
ut64 vsize;

View File

@ -4,88 +4,80 @@
R_API RSearchKeyword* r_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut8 *bmbuf, int bmlen, const char *data) {
RSearchKeyword *kw;
if (!kw || kwlen < 1 || bmlen < 0)
return NULL;
kw = R_NEW0(RSearchKeyword);
if (!kw)
if (kwlen < 1 || bmlen < 0)
return NULL;
kw = R_NEW0 (RSearchKeyword);
if (!kw) return NULL;
kw->type = R_SEARCH_KEYWORD_TYPE_BINARY;
kw->keyword_length = kwlen;
memcpy(kw->bin_keyword, kwbuf, kwlen);
memcpy (kw->bin_keyword, kwbuf, kwlen);
if (bmbuf && bmlen > 0) {
memcpy(kw->bin_binmask, bmbuf, bmlen);
memcpy (kw->bin_binmask, bmbuf, bmlen);
kw->binmask_length = bmlen;
}
return kw;
}
R_API RSearchKeyword* r_search_keyword_new_str(const char *kwbuf, const char *bmstr, const char *data, int ignore_case) {
RSearchKeyword *kw;
ut8 *bmbuf;
int bmlen;
ut8 *bmbuf = NULL;
int bmlen = 0;
bmbuf = NULL;
if (bmstr) {
bmbuf = malloc (strlen(bmstr)+1);
if (!bmbuf)
return NULL;
bmbuf = malloc (strlen (bmstr)+1);
if (!bmbuf) return NULL;
bmlen = r_hex_str2bin (bmstr, bmbuf);
if (bmlen < 1) {
free (bmbuf);
bmbuf = NULL;
}
}
kw = r_search_keyword_new((ut8 *)kwbuf, strlen(kwbuf), bmbuf, bmlen, data);
kw = r_search_keyword_new ((ut8 *)kwbuf, strlen (kwbuf),
bmbuf, bmlen, data);
if (kw) {
kw->icase = ignore_case;
kw->type = R_SEARCH_KEYWORD_TYPE_STRING;
}
free(bmbuf);
free (bmbuf);
return kw;
}
R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data) {
RSearchKeyword *kw;
ut8 *kwbuf, *bmbuf;
int bmlen, kwlen;
int kwlen, bmlen = 0;
if (!kwstr)
return NULL;
kwbuf = malloc(strlen(kwstr)+1);
kwbuf = malloc (strlen (kwstr)+1);
if (!kwbuf)
return NULL;
kwlen = r_hex_str2bin(kwstr, kwbuf);
kwlen = r_hex_str2bin (kwstr, kwbuf);
if (kwlen < 1) {
free(kwbuf);
free (kwbuf);
return NULL;
}
bmbuf = NULL;
if (bmstr) {
bmbuf = malloc(strlen(bmstr)+1);
bmbuf = malloc (strlen (bmstr)+1);
if (!bmbuf) {
free(kwbuf);
free (kwbuf);
return NULL;
}
bmlen = r_hex_str2bin(bmstr, bmbuf);
bmlen = r_hex_str2bin (bmstr, bmbuf);
if (bmlen < 1) {
free(bmbuf);
free(kwbuf);
free (bmbuf);
free (kwbuf);
return NULL;
}
}
kw = r_search_keyword_new(kwbuf, kwlen, bmbuf, bmlen, data);
free(kwbuf);
free(bmbuf);
kw = r_search_keyword_new (kwbuf, kwlen, bmbuf, bmlen, data);
free (kwbuf);
free (bmbuf);
return kw;
}

View File

@ -14,7 +14,7 @@ R_API int r_search_regexp_update(void *_s, ut64 from, const ut8 *buf, int len) {
RSearchKeyword *kw;
r_list_foreach (s->kws, iter, kw) {
char *skipz, *end;
char *skipz, *end;
int reflags = R_REGEX_EXTENDED;
int ret, delta = 0;
RRegexMatch matches[10];
@ -23,17 +23,17 @@ R_API int r_search_regexp_update(void *_s, ut64 from, const ut8 *buf, int len) {
if (kw->icase)
reflags |= R_REGEX_ICASE;
if (r_regex_comp (&compiled, kw->bin_keyword, reflags)) {
eprintf ("Cannot compile '%s' regexp\n",kw->bin_keyword);
free(buffer);
if (r_regex_comp (&compiled, (const char *)kw->bin_keyword, reflags)) {
eprintf ("Cannot compile '%s' regexp\n", kw->bin_keyword);
free (buffer);
return -1;
}
foo:
ret = r_regex_exec (&compiled, buffer+delta, 1, matches, 0);
if (ret){
free(buffer);
return 0;
}
free(buffer);
return 0;
}
do {
r_search_hit_new (s, kw, (ut64)(from+matches[0].rm_so+delta));
delta += matches[0].rm_so+1;
@ -41,9 +41,9 @@ R_API int r_search_regexp_update(void *_s, ut64 from, const ut8 *buf, int len) {
count++;
} while (!r_regex_exec (&compiled, buffer+delta, 1, matches, 0));
if (delta == 0){
free(buffer);
free(buffer);
return 0;
}
}
/* TODO: check if skip 0 works */
skipz = strchr (buffer, '\0');
@ -55,6 +55,6 @@ R_API int r_search_regexp_update(void *_s, ut64 from, const ut8 *buf, int len) {
goto foo;
}
}
free(buffer);
free(buffer);
return count;
}