From 35d14529a425bceb7e4ff4b5bd36a97d127241e9 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 29 Dec 2013 03:42:18 +0100 Subject: [PATCH] Fix minstrlen issue with elf binaries and Cd -X --- libr/bin/bin.c | 20 ++++++++++++++------ libr/bin/p/bin_elf.c | 2 +- libr/core/bin.c | 8 +++++++- libr/core/cmd_meta.c | 3 +++ libr/core/config.c | 7 +++++-- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/libr/bin/bin.c b/libr/bin/bin.c index 27701640bd..eca18dc724 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -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; } diff --git a/libr/bin/p/bin_elf.c b/libr/bin/p/bin_elf.c index 31b745a12f..f25e55e370 100644 --- a/libr/bin/p/bin_elf.c +++ b/libr/bin/p/bin_elf.c @@ -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 diff --git a/libr/core/bin.c b/libr/core/bin.c index 751cc3b40e..99a284f1e1 100644 --- a/libr/core/bin.c +++ b/libr/core/bin.c @@ -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) diff --git a/libr/core/cmd_meta.c b/libr/core/cmd_meta.c index 6c50699ff7..2fde6d4730 100644 --- a/libr/core/cmd_meta.c +++ b/libr/core/cmd_meta.c @@ -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++; diff --git a/libr/core/config.c b/libr/core/config.c index f534db2359..4499e6e0be 100644 --- a/libr/core/config.c +++ b/libr/core/config.c @@ -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;