* Initial hacky implementation of s/ command

* e search.from is -1 by default
This commit is contained in:
pancake 2011-05-22 01:36:23 +02:00
parent 9c6d905c92
commit 9c84e94862
3 changed files with 16 additions and 11 deletions

View File

@ -1418,7 +1418,7 @@ static int cmd_seek(void *data, const char *input) {
char *cmd, *p; char *cmd, *p;
ut64 off; ut64 off;
if (input[0]=='r') { if (*input=='r') {
if (input[1] && input[2]) { if (input[1] && input[2]) {
off = r_debug_reg_get (core->dbg, input+2); off = r_debug_reg_get (core->dbg, input+2);
r_io_sundo_push (core->io); r_io_sundo_push (core->io);
@ -1437,10 +1437,14 @@ static int cmd_seek(void *data, const char *input) {
r_core_block_read (core, 0); r_core_block_read (core, 0);
break; break;
case '/': case '/':
r_core_cmdf (core, ".%s ; ? %s0_0 ; ?! s %s0_0", {
input, "hit", "hit"); const char *pfx = r_config_get (core->config, "search.prefix");
eprintf (".%s ; ? %s0_0 ; ?! s %s0_0\n", int kwidx = (int)r_config_get_i (core->config, "search.kwidx")-1;
input, "hit", "hit"); if (kwidx<0) kwidx=0;
//r_core_seek (core, off+1, 0);
eprintf ("s+1;.%s ; ? %s%d_0 ; ?! s %s%d_0\n", input, pfx, kwidx, pfx, kwidx);
r_core_cmdf (core, "s+1;.%s ; ? %s%d_0 ; ?! s %s%d_0", input, pfx, kwidx, pfx, kwidx);
}
break; break;
case '*': case '*':
r_io_sundo_list (core->io); r_io_sundo_list (core->io);
@ -1505,7 +1509,8 @@ static int cmd_seek(void *data, const char *input) {
" s+ 512 ; seek 512 bytes forward\n" " s+ 512 ; seek 512 bytes forward\n"
" s- 512 ; seek 512 bytes backward\n" " s- 512 ; seek 512 bytes backward\n"
" sa [[+-]a] [asz] ; seek asz (or bsize) aligned to addr\n" " sa [[+-]a] [asz] ; seek asz (or bsize) aligned to addr\n"
" sf/sF ; seek next/prev scr.fkey\n" " sf|sF ; seek next/prev scr.fkey\n"
" s/ DATA ; search for next occurrence of 'DATA'\n"
" sb ; seek aligned to bb start\n" " sb ; seek aligned to bb start\n"
" sr pc ; seek to register\n"); " sr pc ; seek to register\n");
break; break;
@ -3291,6 +3296,8 @@ static int cmd_search(void *data, const char *input) {
// TODO: repeat last search doesnt works for /a // TODO: repeat last search doesnt works for /a
from = r_config_get_i (core->config, "search.from"); from = r_config_get_i (core->config, "search.from");
if (from == UT64_MAX)
from = core->offset;
to = r_config_get_i (core->config, "search.to"); to = r_config_get_i (core->config, "search.to");
core->search->align = r_config_get_i (core->config, "search.align"); core->search->align = r_config_get_i (core->config, "search.align");
//TODO: handle section ranges if from&&to==0 //TODO: handle section ranges if from&&to==0
@ -3501,7 +3508,6 @@ static int cmd_search(void *data, const char *input) {
r_cons_printf ("fs hits\n"); r_cons_printf ("fs hits\n");
core->search->inverse = inverse; core->search->inverse = inverse;
searchcount = r_config_get_i (core->config, "search.count"); searchcount = r_config_get_i (core->config, "search.count");
eprintf ("inverse = %d\n", core->search->inverse);
if (searchcount) if (searchcount)
searchcount++; searchcount++;
if (core->search->n_kws>0 || aes_search) { if (core->search->n_kws>0 || aes_search) {

View File

@ -425,8 +425,8 @@ R_API int r_core_config_init(RCore *core) {
r_config_set_i (cfg, "search.kwidx", 0); r_config_set_i (cfg, "search.kwidx", 0);
r_config_set_i (cfg, "search.count", 0); r_config_set_i (cfg, "search.count", 0);
r_config_set (cfg, "search.prefix", "hit"); r_config_set (cfg, "search.prefix", "hit");
r_config_set_i (cfg, "search.from", 0); r_config_set_i (cfg, "search.from", UT64_MAX);
r_config_set_i (cfg, "search.to", 0); r_config_set_i (cfg, "search.to", UT64_MAX);
r_config_set_i (cfg, "search.distance", 0); // TODO: use i_cb here and remove code in cmd.c r_config_set_i (cfg, "search.distance", 0); // TODO: use i_cb here and remove code in cmd.c
r_config_set_i_cb (cfg, "search.align", 0, &config_searchalign_callback); r_config_set_i_cb (cfg, "search.align", 0, &config_searchalign_callback);
r_config_set (cfg, "search.asmstr", "true"); r_config_set (cfg, "search.asmstr", "true");

View File

@ -107,7 +107,7 @@ R_API int r_search_mybinparse_update(void *_s, ut64 from, const ut8 *buf, int le
RSearchKeyword *kw; RSearchKeyword *kw;
r_list_foreach (s->kws, iter, kw) { r_list_foreach (s->kws, iter, kw) {
if (s->inverse && s->nhits>0) { if (s->inverse && s->nhits>0) {
eprintf ("nhits = %d\n", s->nhits); //eprintf ("nhits = %d\n", s->nhits);
return -1; return -1;
} }
for (j=0; j<=kw->distance; j++) { for (j=0; j<=kw->distance; j++) {
@ -159,7 +159,6 @@ R_API int r_search_mybinparse_update(void *_s, ut64 from, const ut8 *buf, int le
kw->distance = 0; kw->distance = 0;
kw->count++; kw->count++;
count++; count++;
eprintf ("NTHIS JKSL +++\n");
//s->nhits++; //s->nhits++;
} }
} }