Fix s/ command and autocomplete e?

This commit is contained in:
pancake 2012-12-30 01:05:12 +01:00
parent 562480a01d
commit e600bf9168
4 changed files with 43 additions and 31 deletions

View File

@ -434,10 +434,13 @@ static int cmd_eval(void *data, const char *input) {
case 'e':
if (input[1]==' ') {
char *p;
const char *val = r_config_get (core->config, input+2);
const char *val;
char *input2 = strchr (input+2, ' ');
if (input2) input2++; else input2 = input+2;
val = r_config_get (core->config, input2);
p = r_core_editor (core, val);
r_str_replace_char (p, '\n', ';');
r_config_set (core->config, input+2, p);
r_config_set (core->config, input2, p);
} else eprintf ("Usage: ee varname\n");
break;
case '!':
@ -462,7 +465,10 @@ static int cmd_eval(void *data, const char *input) {
break;
default:
if (input[2]) {
const char *desc = r_config_desc (core->config, input+1, NULL);
char *input2 = strchr (input+2, ' ');
if (input2) input2++; else input2 = input+2;
const char *desc = r_config_desc (
core->config, input2, NULL);
if (desc) r_cons_strcat (desc);
r_cons_newline ();
}

View File

@ -86,7 +86,7 @@ static int __cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
searchhits = kw->count+1;
if (searchcount) {
if (!--searchcount) {
eprintf ("\nsearch stop: search.count reached\n");
//eprintf ("\nsearch stop: search.count reached\n");
return R_FALSE;
}
}
@ -135,9 +135,9 @@ static int __cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
return R_TRUE;
}
static int c = 0;
static inline void print_search_progress(ut64 at, ut64 to, int n) {
static int c = 0;
if ((++c%23))
if ((++c%64))
return;
eprintf ("\r[ ] 0x%08"PFMT64x" < 0x%08"PFMT64x" hits = %d \r%s",
at, to, n, (c%2)?"[ #]":"[# ]");
@ -157,6 +157,7 @@ static int cmd_search(void *data, const char *input) {
ut16 n16;
ut8 *buf;
c = 0;
__from = r_config_get_i (core->config, "search.from");
__to = r_config_get_i (core->config, "search.to");
@ -540,8 +541,8 @@ static int cmd_search(void *data, const char *input) {
}
//ret = r_core_read_at (core, at, buf, core->blocksize);
// ret = r_io_read_at (core->io, at, buf, core->blocksize);
r_io_seek (core->io, at, R_IO_SEEK_SET);
ret = r_io_read (core->io, buf, core->blocksize);
r_io_seek (core->io, at, R_IO_SEEK_SET);
ret = r_io_read (core->io, buf, core->blocksize);
/*
if (ignorecase) {
int i;
@ -561,7 +562,7 @@ static int cmd_search(void *data, const char *input) {
}
} else
if (r_search_update (core->search, &at, buf, ret) == -1) {
eprintf ("search: update read error at 0x%08"PFMT64x"\n", at);
//eprintf ("search: update read error at 0x%08"PFMT64x"\n", at);
break;
}
}
@ -574,7 +575,7 @@ static int cmd_search(void *data, const char *input) {
searchhits,
searchprefix, core->search->n_kws-1,
searchprefix, core->search->n_kws-1, searchcount-1);
} else eprintf ("hits: %d\n", searchhits);
} else eprintf ("hits: %d\n", searchhits>0?searchhits-1:0);
} else eprintf ("No keywords defined\n");
}
return R_TRUE;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 // pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 - pancake */
static int cmd_seek(void *data, const char *input) {
RCore *core = (RCore *)data;
@ -15,13 +15,15 @@ static int cmd_seek(void *data, const char *input) {
} else eprintf ("Usage: 'sr pc' ; seek to register\n");
} else
if (*input) {
char *inputnum = strchr (input+1, ' ');
int sign = 1;
st32 delta = (input[1]==' ')? 2: 1;
off = r_num_math (core->num, input + delta);
if (inputnum) inputnum++;
else inputnum = input+1;
off = r_num_math (core->num, inputnum);
if ((st64)off<0) off = -off; // hack to fix s-2;s -2
if (isalpha (input[delta]) && off == 0) {
if (delta==1 && !r_flag_get (core->flags, input+delta)) {
eprintf ("Cannot find address for '%s'\n", input+delta);
if (input[0]!='/' && inputnum && isalpha (inputnum[0]) && off == 0) {
if (!r_flag_get (core->flags, inputnum)) {
eprintf ("Cannot find address for '%s'\n", inputnum);
return R_FALSE;
}
}
@ -81,18 +83,19 @@ static int cmd_seek(void *data, const char *input) {
case '/':
{
const char *pfx = r_config_get (core->config, "search.prefix");
int kwidx = (int)r_config_get_i (core->config, "search.kwidx")-1;
//kwidx cfg var is ignored
int kwidx = core->search->n_kws; //(int)r_config_get_i (core->config, "search.kwidx")-1;
if (kwidx<0) kwidx = 0;
switch (input[1]) {
case 'x':
//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;
case ' ':
//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);
case 'x':
r_config_set_i (core->config, "search.count", 1);
r_core_cmdf (core, "s+1; p8 ; .%s;s-1;s %s%d_0;f-%s%d_0",
input, pfx, kwidx, pfx, kwidx, pfx, kwidx);
r_config_set_i (core->config, "search.count", 0);
break;
default:
eprintf ("unknown search method\n");
break;
}
}
@ -102,7 +105,7 @@ static int cmd_seek(void *data, const char *input) {
break;
case '+':
if (input[1]!='\0') {
delta = (input[1]=='+')? core->blocksize: off;
int delta = (input[1]=='+')? core->blocksize: off;
r_io_sundo_push (core->io, core->offset);
r_core_seek_delta (core, delta);
} else {
@ -113,7 +116,7 @@ static int cmd_seek(void *data, const char *input) {
break;
case '-':
if (input[1]!='\0') {
if (input[1]=='-') delta = -core->blocksize; else delta = -off;
int delta = (input[1]=='-') ? -core->blocksize: -off;
r_io_sundo_push (core->io, core->offset);
r_core_seek_delta (core, delta);
} else {

View File

@ -167,7 +167,7 @@ static const char *radare_argv[] = {
"aa", "ab", "af", "ar", "ag", "at", "a?",
"af", "afc", "afi", "afb", "afr", "afs", "af*",
"aga", "agc", "agd", "agl", "agfl",
"e", "e-", "e*", "e!",
"e", "e-", "e*", "e!", "e?",
"i", "ii", "iI", "is", "iS", "iz",
"q",
"f", "fl", "fr", "f-", "f*", "fs", "fS", "fr", "fo", "f?",
@ -324,12 +324,14 @@ static int autocomplete(RLine *line) {
line->completion.argv = NULL;
}
} else
if (!memcmp (line->buffer.data, "e ", 2)) {
if ( (!memcmp (line->buffer.data, "e ", 2))
||(!memcmp (line->buffer.data, "e? ", 3))) {
int m = (line->buffer.data[1] == '?')? 3: 2;
int i = 0, n = strlen (line->buffer.data+m);
RConfigNode *bt;
RListIter *iter;
int i = 0, n = strlen (line->buffer.data+2);
r_list_foreach (core->config->nodes, iter, bt) {
if (!memcmp (bt->name, line->buffer.data+2, n)) {
if (!memcmp (bt->name, line->buffer.data+m, n)) {
tmp_argv[i++] = bt->name;
if (i==TMP_ARGV_SZ)
break;