From 0ec20ce172a58f0c791056dc5d6af333a692f8d0 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 21 Nov 2023 23:56:12 +0100 Subject: [PATCH] Initial support for xref sizes ##analysis --- libr/anal/xrefs.c | 18 ++++++++++++++++-- libr/core/cmd_anal.inc.c | 3 ++- libr/include/r_anal.h | 14 +++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/libr/anal/xrefs.c b/libr/anal/xrefs.c index 81c00d6610..dc258846b1 100644 --- a/libr/anal/xrefs.c +++ b/libr/anal/xrefs.c @@ -344,11 +344,11 @@ static void r_anal_xrefs_list_table(RAnal *anal, RVecAnalRef *anal_refs, const c if (!t) { t = ' '; } - char *fromname = anal->coreb.getNameDelta (anal->coreb.core, ref->addr); char *toname = anal->coreb.getNameDelta (anal->coreb.core, ref->at); r_table_add_rowf (table, "xxnssss", - ref->at, ref->addr, ref->size, + ref->at, ref->addr, + r_anal_ref_size (ref), r_anal_ref_type_tostring (t), r_anal_ref_perm_tostring (ref), toname, fromname @@ -597,6 +597,20 @@ R_API const char *r_anal_ref_perm_tostring(RAnalRef *ref) { return r_str_rwx_i (perm); } +R_API int r_anal_ref_size(RAnalRef *ref) { + int size = R_ANAL_REF_TYPE_SIZE (ref->type); + if (size) { + return size; + } + switch (R_ANAL_REF_TYPE_MASK (ref->type)) { + case R_ANAL_REF_TYPE_ICOD: + return 4; // or 8? + case R_ANAL_REF_TYPE_DATA: + return 4; // or 8? + } + return 0; +} + R_API const char *r_anal_ref_type_tostring(RAnalRefType type) { switch (R_ANAL_REF_TYPE_MASK (type)) { case ' ': diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index a9fe571fe1..410ecd4d09 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -10096,12 +10096,13 @@ static bool cmd_anal_refs(RCore *core, const char *input) { } const char *typestr = r_anal_ref_type_tostring (ref->type); const char *permstr = r_anal_ref_perm_tostring (ref); + int size = r_anal_ref_size (ref); r_table_add_rowf (table, "sxxxnss", fcn_name, fcn_addr, ref->addr, addr, - ref->size, + size, typestr, permstr ); diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 7db5875476..a2772e013f 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -631,22 +631,29 @@ typedef enum { R_ANAL_REF_TYPE_DATA = 'd', // mem ref R_ANAL_REF_TYPE_ICOD = 'i', // indirect code reference R_ANAL_REF_TYPE_STRN = 's', // string ref + R_ANAL_REF_TYPE_MASK = 0xff, // perm / direction R_ANAL_REF_TYPE_READ = 4 << 8, R_ANAL_REF_TYPE_WRITE = 2 << 8, R_ANAL_REF_TYPE_EXEC = 1 << 8, - R_ANAL_REF_TYPE_MASK = 0xff, - R_ANAL_REF_TYPE_DIRECTION_MASK = 0xff00 + R_ANAL_REF_PERM_MASK = 0xff00, // direction -> perm + R_ANAL_REF_DIRECTION_MASK = 0xff00, // direction -> perm + // SIZE + R_ANAL_REF_TYPE_SIZE_1 = 1 << 16, + R_ANAL_REF_TYPE_SIZE_2 = 2 << 16, + R_ANAL_REF_TYPE_SIZE_4 = 4 << 16, + R_ANAL_REF_TYPE_SIZE_8 = 8 << 16, + R_ANAL_REF_SIZE_MASK = 0xff0000 } RAnalRefType; #define R_ANAL_REF_TYPE_PERM(x) (((x)>>8) & 0xff) #define R_ANAL_REF_TYPE_MASK(x) r_anal_ref_typemask((x)) +#define R_ANAL_REF_TYPE_SIZE(x) (((x)>>16) & 0xff) typedef struct r_anal_ref_t { ut64 at; ut64 addr; RAnalRefType type; - ut8 size; } RAnalRef; typedef struct r_vec_RVecAnalRef_t RVecAnalRef; @@ -1073,6 +1080,7 @@ R_API bool r_anal_pin_set(RAnal *a, const char *name, const char *cmd); typedef bool (* RAnalRefCmp)(RAnalRef *ref, void *data); R_API RList *r_anal_ref_list_new(void); R_API const char *r_anal_ref_type_tostring(RAnalRefType t); +R_API int r_anal_ref_size(RAnalRef *ref); R_API int r_anal_ref_typemask(int x); R_DEPRECATE R_API RAnalRefType r_anal_xrefs_type(char ch);