From baae1f6e6a3be1532676eba2e383ea8290e7abbc Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 14 Dec 2012 10:51:25 +0100 Subject: [PATCH] Honor $. variables to get regs and fix Ps string filter bug --- libr/anal/meta.c | 3 ++- libr/core/bin.c | 11 +++++++++-- libr/core/core.c | 21 +++++---------------- libr/core/project.c | 2 +- libr/util/name.c | 5 ++++- libr/util/str.c | 7 ++++++- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/libr/anal/meta.c b/libr/anal/meta.c index f7b3f4d95b..88fb1a248a 100644 --- a/libr/anal/meta.c +++ b/libr/anal/meta.c @@ -285,7 +285,8 @@ static void printmetaitem(RMeta *m, RMetaItem *d, int rad) { if (str) { if (d->type=='s' && !*str) return; - r_str_sanitize (str); + r_name_filter (str, 0); + // XXX r_str_sanitize (str); if (rad) m->printf ("%s %d %s @ 0x%08"PFMT64x"\n", r_meta_type_to_string (d->type), diff --git a/libr/core/bin.c b/libr/core/bin.c index 8aa5a46a57..f46e4a11f7 100644 --- a/libr/core/bin.c +++ b/libr/core/bin.c @@ -11,7 +11,7 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) { char str[R_FLAG_NAME_SIZE]; /* bin str limits */ - int hasstr= r_config_get_i (r->config, "bin.strings"); + int hasstr = r_config_get_i (r->config, "bin.strings"); int rawstr = r_config_get_i (r->config, "bin.rawstr"); int minstr = r_config_get_i (r->config, "bin.minstr"); if (!hasstr) return 0; @@ -52,7 +52,9 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) { if ((mode & R_CORE_BIN_SET)) { if (r_config_get_i (r->config, "bin.strings")) r_flag_space_set (r->flags, "strings"); + r_cons_break (NULL, NULL); r_list_foreach (list, iter, string) { + if (r_cons_singleton()->breaked) break; /* Jump the withespaces before the string */ for (i=0; *(string->string+i)==' '; i++); r_meta_add (r->anal->meta, R_META_TYPE_STRING, @@ -64,6 +66,7 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) { va? baddr+string->rva:string->offset, string->size, 0); } + r_cons_break_end (); } else { if (mode) r_cons_printf ("fs strings\n"); else r_cons_printf ("[strings]\n"); @@ -147,7 +150,8 @@ static int bin_info (RCore *r, int mode) { r_config_set (r->config, "anal.plugin", info->arch); snprintf (str, R_FLAG_NAME_SIZE, "%i", info->bits); r_config_set (r->config, "asm.bits", str); - r_config_set (r->config, "asm.dwarf", R_BIN_DBG_STRIPPED (info->dbg_info)?"false":"true"); + r_config_set (r->config, "asm.dwarf", + R_BIN_DBG_STRIPPED (info->dbg_info)?"false":"true"); } } else { if (mode) { @@ -226,7 +230,9 @@ static int bin_dwarf (RCore *core, int mode) { } } if (!list) return R_FALSE; + r_cons_break (NULL, NULL); r_list_foreach (list, iter, row) { + if (r_cons_singleton()->breaked) break; if (mode) { // TODO: use 'Cl' instead of CC const char *path = row->file; @@ -249,6 +255,7 @@ static int bin_dwarf (RCore *core, int mode) { r_cons_printf ("0x%08"PFMT64x"\t%s\t%d\n", row->address, row->file, row->line); } } + r_cons_break_end (); r_list_destroy (list); return R_TRUE; } diff --git a/libr/core/core.c b/libr/core/core.c index 1f873fe7c4..cbd42b6c14 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -82,23 +82,12 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { } else if (str[0]=='$') { *ok = 1; - r_anal_op (core->anal, &op, core->offset, core->block, core->blocksize); - /* debug */ // XXX spaguetti! - if (!strcmp (str+1, "pc")) { - return r_debug_reg_get (core->dbg, "pc"); - } else if (!strcmp (str+1, "sp")) { - return r_debug_reg_get (core->dbg, "sp"); - } else if (!strcmp (str+1, "bp")) { - return r_debug_reg_get (core->dbg, "bp"); - } else if (!strcmp (str+1, "a0")) { - return r_debug_reg_get (core->dbg, "a0"); - } else if (!strcmp (str+1, "a1")) { - return r_debug_reg_get (core->dbg, "a1"); - } else if (!strcmp (str+1, "a2")) { - return r_debug_reg_get (core->dbg, "a2"); - } - /* other */ + // TODO: group analop-dependant vars after a char, so i can filter + r_anal_op (core->anal, &op, core->offset, + core->block, core->blocksize); switch (str[1]) { + case '.': // can use pc, sp, a0, a1, ... + return r_debug_reg_get (core->dbg, str+2); case '{': { char *ptr, *bptr = strdup (str+2); diff --git a/libr/core/project.c b/libr/core/project.c index 62729f6dff..199a5a25bc 100644 --- a/libr/core/project.c +++ b/libr/core/project.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2010-2012 pancake */ +/* radare - LGPL - Copyright 2010-2012 - pancake */ #include #include diff --git a/libr/util/name.c b/libr/util/name.c index b85b6e29b6..ea4057d811 100644 --- a/libr/util/name.c +++ b/libr/util/name.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2012 - pancake */ #include @@ -6,6 +6,9 @@ static int r_name_validate_char(const char ch) { switch (ch) { + case '{': + case '}': + case '$': case '=': case '*': case '/': diff --git a/libr/util/str.c b/libr/util/str.c index e574646380..4cb6fabc19 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -634,6 +634,10 @@ R_API void r_str_sanitize(char *c) { char *d = c; for (; *d; c++, d++) { switch (*d) { + case '`': + case '$': + case '{': + case '}': case '~': case '|': case ';': @@ -643,7 +647,8 @@ R_API void r_str_sanitize(char *c) { case '<': case '>': d++; - break; + *c = '_'; + continue; } *c = *d; }