From daff6aff5deadf82b8e5bb6f14560bcbd0e11703 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 24 Mar 2011 00:54:09 +0100 Subject: [PATCH] * Fix set_reg_profile callback in r_anal_arm * Fix dupness issue between RDebug and RAnal sharing RReg - Move reg_profile string into inner RReg * Remove vm.arch setup in rasm2 -ri --- binr/rabin2/rabin2.c | 3 +-- libr/anal/p/anal_arm.c | 4 ++-- libr/core/cmd.c | 8 +++++--- libr/core/config.c | 5 ++--- libr/core/core.c | 2 +- libr/debug/plugin.c | 9 ++++----- libr/include/r_debug.h | 1 - libr/include/r_reg.h | 1 + libr/reg/reg.c | 11 +++++++---- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/binr/rabin2/rabin2.c b/binr/rabin2/rabin2.c index 1636538b4b..5acbdac61b 100644 --- a/binr/rabin2/rabin2.c +++ b/binr/rabin2/rabin2.c @@ -419,10 +419,9 @@ static int rabin_show_info() { "e asm.arch=%s\n" "e anal.plugin=%s\n" "e asm.bits=%i\n" - "e vm.arch=%s\n" "e asm.dwarf=%s\n", info->rclass, info->big_endian?"true":"false", info->os, - info->arch, info->arch, info->bits, info->arch, + info->arch, info->arch, info->bits, R_BIN_DBG_STRIPPED (info->dbg_info)?"false":"true"); } else { eprintf ("[File info]\n"); diff --git a/libr/anal/p/anal_arm.c b/libr/anal/p/anal_arm.c index b9c9360f0b..0459b8176d 100644 --- a/libr/anal/p/anal_arm.c +++ b/libr/anal/p/anal_arm.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2007-2010 */ +/* radare - LGPL - Copyright 2007-2011 */ /* pancake */ #include @@ -275,7 +275,7 @@ struct r_anal_plugin_t r_anal_plugin_arm = { .init = NULL, .fini = NULL, .op = &arm_op, - .set_reg_profile = NULL, + .set_reg_profile = set_reg_profile, .fingerprint_bb = NULL, .fingerprint_fcn = NULL, .diff_bb = NULL, diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 43e52a48ef..23cbbdc5e8 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -837,9 +837,11 @@ static void cmd_reg(RCore *core, const char *str) { break; case 'p': if (!str[1]) { - if (core->dbg->reg_profile) - r_cons_printf ("%s\n", core->dbg->reg_profile); - else eprintf ("No register profile defined. Try 'dr.'\n"); + if (core->dbg->reg->reg_profile) { + //core->anal->reg = core->dbg->reg; + r_cons_printf ("%s\n", core->dbg->reg->reg_profile); + //r_cons_printf ("%s\n", core->anal->reg->reg_profile); + } else eprintf ("No register profile defined. Try 'dr.'\n"); } else r_reg_set_profile (core->dbg->reg, str+2); core->anal->reg = core->dbg->reg; break; diff --git a/libr/core/config.c b/libr/core/config.c index 06f3e3ae95..97c3fd2093 100644 --- a/libr/core/config.c +++ b/libr/core/config.c @@ -77,8 +77,7 @@ static int config_analplugin_callback(void *user, void *data) { if (node->value[0] == '?') { r_anal_list (core->anal); return R_FALSE; - } - else if (!r_anal_use (core->anal, node->value)) { + } else if (!r_anal_use (core->anal, node->value)) { eprintf ("Cannot use '%s' anal plugin.\n", node->value); return R_FALSE; } @@ -309,7 +308,7 @@ R_API int r_core_config_init(RCore *core) { r_config_set_i (cfg, "anal.depth", 100); r_config_set_i (cfg, "anal.ptrdepth", 3); r_config_set_cb (cfg, "anal.split", "true", &config_analsplit_callback); - r_config_set_cb (cfg, "anal.plugin", "x86", &config_analplugin_callback); + r_config_set_cb (cfg, "anal.plugin", R_SYS_ARCH, &config_analplugin_callback); /* asm */ r_config_set_cb (cfg, "asm.arch", R_SYS_ARCH, &config_asmarch_callback); // XXX: not portable diff --git a/libr/core/core.c b/libr/core/core.c index 6922fdbe97..6ae5e74dc7 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -312,8 +312,8 @@ R_API int r_core_init(RCore *core) { r_core_cmd_init (core); core->flags = r_flag_new (); core->dbg = r_debug_new (R_TRUE); - r_debug_use (core->dbg, "native"); core->dbg->anal = core->anal; // XXX: dupped instance.. can cause lost pointerz + r_debug_use (core->dbg, "native"); r_reg_arena_push (core->dbg->reg); // create a 2 level register state stack // core->dbg->anal->reg = core->anal->reg; // XXX: dupped instance.. can cause lost pointerz core->sign->printf = r_cons_printf; diff --git a/libr/debug/plugin.c b/libr/debug/plugin.c index f6f4a92c62..5a9234b764 100644 --- a/libr/debug/plugin.c +++ b/libr/debug/plugin.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ #include #include "../config.h" @@ -14,7 +14,6 @@ R_API int r_debug_plugin_init(RDebug *dbg) { RDebugPlugin *static_plugin; int i; - dbg->reg_profile = NULL; INIT_LIST_HEAD (&dbg->plugins); for (i=0; debug_static_plugins[i]; i++) { static_plugin = R_NEW (RDebugPlugin); @@ -33,13 +32,13 @@ R_API int r_debug_use(RDebug *dbg, const char *str) { dbg->bp->breakpoint = dbg->h->breakpoint; dbg->bp->user = dbg; if (h->reg_profile) { - free (dbg->reg_profile); - dbg->reg_profile = dbg->h->reg_profile (); + free (dbg->reg->reg_profile); + dbg->reg->reg_profile = dbg->h->reg_profile (); if (dbg->anal) dbg->anal->reg = dbg->reg; if (h->init) h->init (dbg); - r_reg_set_profile_string (dbg->reg, dbg->reg_profile); + r_reg_set_profile_string (dbg->reg, dbg->reg->reg_profile); } return R_TRUE; } diff --git a/libr/include/r_debug.h b/libr/include/r_debug.h index 2fda20a7de..cacc9ed5e4 100644 --- a/libr/include/r_debug.h +++ b/libr/include/r_debug.h @@ -91,7 +91,6 @@ typedef struct r_debug_t { int reason; /* stop reason */ RDebugTrace *trace; int stop_all_threads; - char *reg_profile; struct r_reg_t *reg; RBreakpoint *bp; void *user; diff --git a/libr/include/r_reg.h b/libr/include/r_reg.h index 9368eb5e05..33e1152351 100644 --- a/libr/include/r_reg.h +++ b/libr/include/r_reg.h @@ -51,6 +51,7 @@ typedef struct r_reg_set_t { typedef struct r_reg_t { char *profile; + char *reg_profile; char *name[R_REG_NAME_LAST]; RRegSet regset[R_REG_TYPE_LAST]; int iters; diff --git a/libr/reg/reg.c b/libr/reg/reg.c index 989f537438..9fc08a75d1 100644 --- a/libr/reg/reg.c +++ b/libr/reg/reg.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ #include #include @@ -35,7 +35,6 @@ R_API int r_reg_get_name_idx(const char *type) { return -1; } - R_API int r_reg_set_name(RReg *reg, int role, const char *name) { if (role>=0 && rolename[role] = r_str_dup (reg->name[role], name); @@ -151,6 +150,8 @@ R_API int r_reg_set_profile_string(RReg *reg, const char *str) { if (!str||!reg) return R_FALSE; + free (reg->reg_profile); + reg->reg_profile = strdup (str); buf[0] = '\0'; /* format file is: 'type name size offset packedsize' */ r_reg_free_internal (reg); @@ -183,15 +184,17 @@ R_API int r_reg_set_profile_string(RReg *reg, const char *str) { r_reg_set_word (item, word, buf); if (item->name != NULL) { r_list_append (reg->regset[item->type].regs, item); - item = r_reg_item_new(); + item = r_reg_item_new (); } } chidx = word = 0; setname = -1; break; default: - if (chidx>128) // WTF!! + if (chidx>128) {// WTF!! + eprintf ("PARSE FAILED\n"); return R_FALSE; + } buf[chidx++] = *str; buf[chidx] = 0; break;