From e807868b784030dd7adc8cacbbd5eef5516e09f0 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 24 Oct 2014 20:13:18 +0200 Subject: [PATCH] Honor rabin2 -N minstrlen for -z,-zz,-zzz --- binr/rabin2/rabin2.c | 10 ++++------ libr/bin/bin.c | 13 ++++++++++--- libr/include/r_bin.h | 5 +++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/binr/rabin2/rabin2.c b/binr/rabin2/rabin2.c index 478ff82640..8725c4d763 100644 --- a/binr/rabin2/rabin2.c +++ b/binr/rabin2/rabin2.c @@ -476,8 +476,7 @@ int main(int argc, char **argv) { break; case '@': at = r_num_math (NULL, optarg); break; case 'n': name = optarg; break; - case 'N': - { + case 'N': { char *q, *p = strdup (optarg); q = strchr (p, ':'); if (q) { @@ -487,8 +486,7 @@ int main(int argc, char **argv) { r_config_set (core.config, "bin.minstr", optarg); } free (p); - } - break; + } break; //case 'V': return blob_version ("rabin2"); case 'h': r_core_fini (&core); @@ -570,6 +568,7 @@ int main(int argc, char **argv) { return 1; } + bin->minstrlen = r_config_get_i (core.config, "bin.minstr"); if (!r_bin_load (bin, file, laddr, 0, xtr_idx, fd, rawstr)) { if (!r_bin_load (bin, file, laddr, 0, xtr_idx, fd, rawstr)) { eprintf ("r_bin: Cannot open file\n"); @@ -579,7 +578,6 @@ int main(int argc, char **argv) { } if (rawstr == 2) { rawstr = R_FALSE; - bin->minstrlen = r_config_get_i (core.config, "bin.minstr"); r_bin_dump_strings (core.bin->cur, bin->minstrlen); } @@ -667,7 +665,7 @@ int main(int argc, char **argv) { if (action&x) {\ if (isradjson) r_cons_printf ("\"%s\":",n);\ if (!r_core_bin_info (&core, y, rad, va, &filter, laddr, chksum)) {\ - if (isradjson) r_cons_printf("false");\ + if (isradjson) r_cons_printf ("false");\ };\ actions_done++;\ if (isradjson) r_cons_printf (actions==actions_done? "":",");\ diff --git a/libr/bin/bin.c b/libr/bin/bin.c index 3d2d313eb7..a8c4a584f9 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -213,8 +213,10 @@ static void get_strings_range(RBinFile *arch, RList *list, int min, ut64 from, u if (min == 0) min = plugin? plugin->minstrlen: 4; +#if 0 if (arch->rawstr == R_TRUE) min = 1; +#endif /* Some plugins return zero, fix it up */ if (min == 0) @@ -347,7 +349,11 @@ static int r_bin_object_set_items(RBinFile *binfile, RBinObject *o) { if (!binfile || !o || !o->plugin) return R_FALSE; cp = o->plugin; - minlen = cp->minstrlen; + if (binfile->rbin->minstrlen>0) { + minlen = binfile->rbin->minstrlen; + } else { + minlen = cp->minstrlen; + } binfile->o = o; if (cp->baddr) o->baddr = cp->baddr (binfile); o->loadaddr = o->baddr; @@ -1190,7 +1196,7 @@ R_API RBin* r_bin_new() { bin->printf = (PrintfCallback)printf; bin->plugins = r_list_new(); bin->plugins->free = free; - bin->minstrlen = -2; + bin->minstrlen = 0; bin->cur = NULL; bin->binfiles = r_list_newf ((RListFree)r_bin_file_free); @@ -1673,7 +1679,8 @@ R_API int r_bin_file_set_cur_binfile_obj (RBin * bin, RBinFile *bf, RBinObject * bin->narch = bf->narch; bf->o = obj; plugin = r_bin_file_cur_plugin (bf); - bin->minstrlen = plugin ? plugin->minstrlen : bin->minstrlen; + if (bin->minstrlen <1) + bin->minstrlen = plugin ? plugin->minstrlen : bin->minstrlen; r_bin_object_set_sections (bf, obj); return R_TRUE; diff --git a/libr/include/r_bin.h b/libr/include/r_bin.h index 14f6dc365a..b794c8edfe 100644 --- a/libr/include/r_bin.h +++ b/libr/include/r_bin.h @@ -146,6 +146,9 @@ typedef struct r_bin_file_t { RBinObject *o; void *xtr_obj; ut64 loadaddr; + /* values used when searching the strings */ + int minstrlen; + int maxstrlen; int narch; struct r_bin_xtr_plugin_t *curxtr; struct r_bin_plugin_t *curplugin; @@ -161,6 +164,7 @@ typedef struct r_bin_t { RBinFile *cur; int narch; void *user; + /* preconfigured values */ int minstrlen; int maxstrlen; int rawstr; @@ -238,6 +242,7 @@ typedef struct r_bin_plugin_t { int (*get_offset)(RBinFile *arch, int type, int idx); ut64 (*get_vaddr)(RBinFile *arch, ut64 baddr, ut64 paddr, ut64 vaddr); RBuffer* (*create)(RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen); + /* default value if not specified by user */ int minstrlen; void *user; } RBinPlugin;