Fix minstrlen issue with elf binaries and Cd -X

This commit is contained in:
pancake 2013-12-29 03:42:18 +01:00
parent 1531e965b3
commit 35d14529a4
5 changed files with 30 additions and 10 deletions

View File

@ -21,19 +21,26 @@ static void get_strings_range(RBinArch *arch, RList *list, int min, ut64 from, u
int i, matches = 0, ctr = 0;
RBinString *ptr = NULL;
if (min <= 0)
return;
if (!arch->rawstr)
if (!arch->curplugin || !arch->curplugin->info)
return;
if (arch->curplugin && min==0) {
min = arch->curplugin->minstrlen;
}
if (min==0)
min = 4; // defaults
if (min <= 0)
return;
if (arch && arch->buf && (!to || to > arch->buf->length))
to = arch->buf->length;
if (to != 0 && (to<1 || to > 0xf00000)) {
eprintf ("WARNING: bin_strings buffer is too big at 0x%08"PFMT64x"\n", from);
return;
}
if (to == 0)
if (!arch->buf)
return;
if (to == 0 && arch->buf)
to = arch->buf->length;
if (arch->buf && arch->buf->buf)
for (i = from; i < to; i++) {
@ -497,14 +504,15 @@ R_API RList* r_bin_reset_strings(RBin *bin) {
RBinArch *a = &bin->cur;
RBinObject *o = a->o;
if (o->strings) {
r_list_destroy(o->strings);
r_list_destroy (o->strings);
bin->cur.o->strings = NULL;
}
if (bin->minstrlen <= 0)
return NULL;
if (a->curplugin && a->curplugin->strings) o->strings = a->curplugin->strings (a);
if (a->curplugin && a->curplugin->strings)
o->strings = a->curplugin->strings (a);
else o->strings = get_strings (a, bin->minstrlen);
return o->strings;
}

View File

@ -593,7 +593,7 @@ RBinPlugin r_bin_plugin_elf = {
.meta = &r_bin_meta_elf,
.create = &create,
.write = &r_bin_write_elf,
.get_vaddr = &get_elf_vaddr
.get_vaddr = &get_elf_vaddr,
};
#ifndef CORELIB

View File

@ -28,7 +28,13 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) {
minstr = r_config_get_i (r->config, "bin.minstr");
//if (r->bin->minstrlen == 0 && minstr>0) r->bin->minstrlen = minstr;
//else if (r->bin->minstrlen > 0) r_config_set_i (r->config, "bin.minstr", r->bin->minstrlen);
if (r->bin->minstrlen <=0) return -1;
if (r->bin->minstrlen==0) {
r->bin->minstrlen = r->bin->cur.curplugin->minstrlen;
if (r->bin->minstrlen==0)
r->bin->minstrlen = 4;
}
if (r->bin->minstrlen <=0)
return -1;
/* code */
if ((list = r_bin_get_strings (r->bin)) == NULL)

View File

@ -189,6 +189,9 @@ static int cmd_meta(void *data, const char *input) {
fi = r_flag_get_i (core->flags, addr);
if (fi) strncpy (name, fi->name, sizeof (name)-1);
}
} else if (n<1) {
eprintf ("Invalid length\n");
return R_FALSE;
}
}
if (!n) n++;

View File

@ -550,8 +550,11 @@ static int cb_binminstr(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
if (core->bin) {
core->bin->minstrlen = node->i_value;
r_core_bin_refresh_strings(core);
int v = node->i_value;
if (v<1) v = 4; // HACK
core->bin->minstrlen = v;
// TODO: Do not refresh if nothing changed (minstrlen ?)
r_core_bin_refresh_strings (core);
return R_TRUE;
}
return R_TRUE;