From 637543c541824049b3d21a0c111a2ed94246b046 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 9 Oct 2017 00:51:51 +0200 Subject: [PATCH] Enhance ax, axk lists and axq is the old ax --- libr/anal/xrefs.c | 45 ++++++++++++++++++++++++++++++++++++++++--- libr/core/cmd_anal.c | 6 ++++-- libr/core/core.c | 12 ++++++++++++ libr/include/r_bind.h | 4 +++- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/libr/anal/xrefs.c b/libr/anal/xrefs.c index 8f51a4046a..83559056bd 100644 --- a/libr/anal/xrefs.c +++ b/libr/anal/xrefs.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2016 - pancake, nibble */ +/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */ #include #include @@ -196,8 +196,7 @@ static int xrefs_list_cb_quiet(RAnal *anal, const char *k, const char *v) { dst = r_num_get (NULL, p + 1); char * type = strchr (k, '.'); if (type) { - type ++; - type = strdup (type); + type = strdup (type + 1); char *t = strchr (type, '.'); if (t) { *t = ' '; @@ -212,7 +211,44 @@ static int xrefs_list_cb_quiet(RAnal *anal, const char *k, const char *v) { } free (type); } + } + } + return 1; +} +static int xrefs_list_cb_normal(RAnal *anal, const char *k, const char *v) { + ut64 dst, src = r_num_get (NULL, v); + if (!strncmp (k, "ref.", 4)) { + const char *p = r_str_rchr (k, NULL, '.'); + if (p) { + dst = r_num_get (NULL, p + 1); + char * type = strchr (k, '.'); + if (type) { + type = strdup (type + 1); + char *t = strchr (type, '.'); + if (t) { + *t = ' '; + } + t = (char *)r_str_rchr (type, NULL, '.'); + if (t) { + t = (char *)r_str_rchr (t, NULL, '.'); + if (t) { + *t = 0; + char *name = anal->coreb.getNameDelta (anal->coreb.core, src); + anal->cb_printf ("%40s", name? name: ""); + free (name); + anal->cb_printf (" 0x%"PFMT64x" -> %9s -> 0x%"PFMT64x, src, type, dst); + name = anal->coreb.getNameDelta (anal->coreb.core, dst); + if (name && *name) { + anal->cb_printf (" %s\n", name? name: ""); + } else { + anal->cb_printf ("\n"); + } + free (name); + } + } + free (type); + } } } return 1; @@ -247,6 +283,9 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) { case '*': sdb_foreach (DB, (SdbForeachCallback)xrefs_list_cb_rad, anal); break; + case '\0': + sdb_foreach (DB, (SdbForeachCallback)xrefs_list_cb_normal, anal); + break; case 'q': sdb_foreach (DB, (SdbForeachCallback)xrefs_list_cb_quiet, anal); break; diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index e2bf9ae43f..9d979cae1c 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -4680,10 +4680,12 @@ static bool cmd_anal_refs(RCore *core, const char *input) { } break; case 'k': // "axk" - if (input[1] == ' ') { + if (input[1] == '?') { + eprintf ("Usage: axk [query]\n"); + } else if (input[1] == ' ') { sdb_query (core->anal->sdb_xrefs, input + 2); } else { - eprintf ("|ERROR| Usage: axk [query]\n"); + r_core_anal_ref_list (core, 0); } break; case '\0': // "ax" diff --git a/libr/core/core.c b/libr/core/core.c index 4ebfd3b304..51c0e56191 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -220,6 +220,17 @@ static const char *getName(RCore *core, ut64 addr) { return item ? item->name : NULL; } +static char *getNameDelta(RCore *core, ut64 addr) { + RFlagItem *item = r_flag_get_at (core->flags, addr, true); + if (item) { + if (item->offset != addr) { + return r_str_newf ("%s + %d", item->name, (int)(addr - item->offset)); + } + return strdup (item->name); + } + return NULL; +} + static void archbits(RCore *core, ut64 addr) { r_anal_build_range_on_hints (core->anal); r_core_seek_archbits (core, addr); @@ -239,6 +250,7 @@ R_API int r_core_bind(RCore *core, RCoreBind *bnd) { bnd->puts = (RCorePuts)r_cons_strcat; bnd->setab = (RCoreSetArchBits)setab; bnd->getName = (RCoreGetName)getName; + bnd->getNameDelta = (RCoreGetNameDelta)getNameDelta; bnd->archbits = (RCoreSeekArchBits)archbits; bnd->cfggeti = (RCoreConfigGetI)cfggeti; return true; diff --git a/libr/include/r_bind.h b/libr/include/r_bind.h index 9b8ecf0bbe..eeb378ada9 100644 --- a/libr/include/r_bind.h +++ b/libr/include/r_bind.h @@ -12,7 +12,8 @@ typedef char* (*RCoreCmdStr)(void *core, const char *cmd); typedef char* (*RCoreCmdStrF)(void *core, const char *cmd, ...); typedef void (*RCorePuts)(const char *cmd); typedef void (*RCoreSetArchBits)(void *core, const char *arch, int bits); -typedef char *(*RCoreGetName)(void *core, ut64 off); +typedef const char *(*RCoreGetName)(void *core, ut64 off); +typedef char *(*RCoreGetNameDelta)(void *core, ut64 off); typedef void (*RCoreSeekArchBits)(void *core, ut64 addr); typedef int (*RCoreConfigGetI)(void *core, const char *key); @@ -26,6 +27,7 @@ typedef struct r_core_bind_t { RCoreDebugBpHit bphit; RCoreSetArchBits setab; RCoreGetName getName; + RCoreGetNameDelta getNameDelta; RCoreSeekArchBits archbits; RCoreConfigGetI cfggeti; } RCoreBind;