mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-03 10:51:01 +00:00
Fix #6075 - Add CCf to list all comments in current function
This commit is contained in:
parent
b04e1f2c4c
commit
e7009d9be2
@ -349,7 +349,7 @@ static ut64 search_reg_val(RAnal *anal, ut8 *buf, ut64 len, ut64 addr, char *reg
|
||||
#define gotoBeach(x) ret=x;goto beach;
|
||||
#define gotoBeachRet() goto beach;
|
||||
|
||||
void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char *reg, const char *sign, char type) {
|
||||
static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char *reg, const char *sign, char type) {
|
||||
char *varname, *esil_buf, *ptr_end, *addr, *op_esil;
|
||||
st64 ptr;
|
||||
char *sig = r_str_newf (",%s,%s", reg, sign);
|
||||
@ -1298,7 +1298,7 @@ R_API RAnalFunction *r_anal_get_fcn_in(RAnal *anal, ut64 addr, int type) {
|
||||
|
||||
|
||||
R_API bool r_anal_fcn_in(RAnalFunction *fcn, ut64 addr) {
|
||||
return r_tinyrange_in (&fcn->bbr, addr);
|
||||
return fcn? r_tinyrange_in (&fcn->bbr, addr): false;
|
||||
}
|
||||
|
||||
R_API RAnalFunction *r_anal_get_fcn_in_bounds(RAnal *anal, ut64 addr, int type) {
|
||||
|
@ -469,47 +469,68 @@ static int meta_print_item(void *user, const char *k, const char *v) {
|
||||
const char *v2; // space_idx
|
||||
RAnalMetaUserItem *ui = user;
|
||||
RAnalMetaItem it;
|
||||
if (strlen (k)<8)
|
||||
if (strlen (k) < 8) {
|
||||
return 1;
|
||||
if (memcmp (k+6, ".0x", 3))
|
||||
}
|
||||
if (memcmp (k + 6, ".0x", 3)) {
|
||||
return 1;
|
||||
}
|
||||
it.type = k[5];
|
||||
it.size = sdb_atoi (v);
|
||||
it.from = sdb_atoi (k+7);
|
||||
|
||||
it.from = sdb_atoi (k + 7);
|
||||
int uirad = ui->rad;
|
||||
if (ui->rad == 'f') {
|
||||
if (!r_anal_fcn_in (ui->fcn, it.from)) {
|
||||
goto beach;
|
||||
}
|
||||
ui->rad = 0;
|
||||
}
|
||||
v2 = strchr (v, ',');
|
||||
if (!v2) goto beach;
|
||||
it.space = atoi (v2+1);
|
||||
if (!v2) {
|
||||
goto beach;
|
||||
}
|
||||
it.space = atoi (v2 + 1);
|
||||
it.to = it.from + it.size;
|
||||
it.str = strchr (v2+1, ',');
|
||||
if (it.str)
|
||||
it.str = (char *)sdb_decode ((const char*)it.str+1, 0);
|
||||
else {
|
||||
it.str = strchr (v2 + 1, ',');
|
||||
if (it.str) {
|
||||
it.str = (char *)sdb_decode ((const char*)it.str + 1, 0);
|
||||
} else {
|
||||
it.str = strdup (it.str? it.str: ""); // don't break in free
|
||||
if (!it.str) goto beach;
|
||||
if (!it.str) {
|
||||
goto beach;
|
||||
}
|
||||
}
|
||||
printmetaitem (ui->anal, &it, ui->rad);
|
||||
free (it.str);
|
||||
beach:
|
||||
ui->rad = uirad;
|
||||
return 1;
|
||||
}
|
||||
|
||||
R_API int r_meta_list_cb(RAnal *a, int type, int rad, SdbForeachCallback cb, void *user) {
|
||||
RAnalMetaUserItem ui = { a, type, rad, cb, user, 0 };
|
||||
if (rad=='j') a->cb_printf ("[");
|
||||
R_API int r_meta_list_cb(RAnal *a, int type, int rad, SdbForeachCallback cb, void *user, ut64 addr) {
|
||||
RAnalFunction *fcn = (addr != UT64_MAX) ? r_anal_get_fcn_at (a, addr, 0) : NULL;
|
||||
RAnalMetaUserItem ui = { a, type, rad, cb, user, 0, fcn};
|
||||
if (rad == 'j') {
|
||||
a->cb_printf ("[");
|
||||
}
|
||||
if (cb) {
|
||||
sdb_foreach (DB, cb, &ui);
|
||||
} else {
|
||||
sdb_foreach (DB, meta_print_item, &ui);
|
||||
}
|
||||
if (rad=='j') a->cb_printf ("]\n");
|
||||
if (rad == 'j') {
|
||||
a->cb_printf ("]\n");
|
||||
}
|
||||
return ui.count;
|
||||
}
|
||||
|
||||
R_API int r_meta_list(RAnal *a, int type, int rad) {
|
||||
return r_meta_list_cb (a, type, rad, NULL, NULL);
|
||||
return r_meta_list_cb (a, type, rad, NULL, NULL, UT64_MAX);
|
||||
}
|
||||
|
||||
R_API int r_meta_list_at(RAnal *a, int type, int rad, ut64 addr) {
|
||||
return r_meta_list_cb (a, type, rad, NULL, NULL, addr);
|
||||
}
|
||||
static int meta_enumerate_cb(void *user, const char *k, const char *v) {
|
||||
const char *v2;
|
||||
RAnalMetaUserItem *ui = user;
|
||||
@ -548,19 +569,21 @@ beach:
|
||||
|
||||
R_API RList *r_meta_enumerate(RAnal *a, int type) {
|
||||
RList *list = r_list_new ();
|
||||
r_meta_list_cb (a, type, 0, meta_enumerate_cb, list);
|
||||
r_meta_list_cb (a, type, 0, meta_enumerate_cb, list, UT64_MAX);
|
||||
return list;
|
||||
}
|
||||
|
||||
static int deserialize(RAnalMetaItem *it, const char *k, const char *v) {
|
||||
const char *v2;
|
||||
if (strlen (k)<8)
|
||||
if (strlen (k) < 8) {
|
||||
return 1;
|
||||
if (memcmp (k+6, ".0x", 3))
|
||||
}
|
||||
if (memcmp (k + 6, ".0x", 3)) {
|
||||
return 1;
|
||||
}
|
||||
it->type = k[5];
|
||||
it->size = sdb_atoi (v);
|
||||
it->from = sdb_atoi (k+7);
|
||||
it->from = sdb_atoi (k + 7);
|
||||
it->to = it->from + it->size;
|
||||
v2 = strchr (v, ',');
|
||||
if (!v2) goto beach;
|
||||
@ -593,7 +616,7 @@ static int meta_unset_cb(void *user, const char *k, const char *v) {
|
||||
}
|
||||
|
||||
R_API void r_meta_space_unset_for(RAnal *a, int type) {
|
||||
r_meta_list_cb (a, type, 0, meta_unset_cb, NULL);
|
||||
r_meta_list_cb (a, type, 0, meta_unset_cb, NULL, UT64_MAX);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@ -621,6 +644,6 @@ R_API int r_meta_space_count_for(RAnal *a, int ctx) {
|
||||
myMetaUser mu = {0};
|
||||
mu.ctx = ctx;
|
||||
int type = a->meta_spaces.space_idx;
|
||||
r_meta_list_cb (a, type, 0, meta_count_cb, &mu);
|
||||
r_meta_list_cb (a, type, 0, meta_count_cb, &mu, UT64_MAX);
|
||||
return mu.count;
|
||||
}
|
||||
|
@ -2005,7 +2005,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) {
|
||||
case 'a': // call
|
||||
break;
|
||||
default:
|
||||
r_meta_list_cb (core->anal, R_META_TYPE_COMMENT, 0, foreach_comment, (void*)cmd);
|
||||
r_meta_list_cb (core->anal, R_META_TYPE_COMMENT, 0, foreach_comment, (void*)cmd, UT64_MAX);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -209,8 +209,9 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
||||
"CC*", "", "list all comments in r2 commands",
|
||||
"CC.", "", "show comment at current offset",
|
||||
"CC,", " [file]", "show or set comment file",
|
||||
"CC", " or maybe not", "append comment at current address",
|
||||
"CC+", " same as above", "append comment at current address",
|
||||
"CC", " [text]", "append comment at current address",
|
||||
"CCf", "", "list comments in function",
|
||||
"CC+", " [text]", "append comment at current address",
|
||||
"CC!", "", "edit comment using cfg.editor (vim, ..)",
|
||||
"CC-", " @ cmt_addr", "remove comment at given address",
|
||||
"CCu", " good boy @ addr", "add good boy comment at given address",
|
||||
@ -263,6 +264,9 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
||||
case 0:
|
||||
r_meta_list (core->anal, R_META_TYPE_COMMENT, 0);
|
||||
break;
|
||||
case 'f':
|
||||
r_meta_list_at (core->anal, R_META_TYPE_COMMENT, 'f', core->offset);
|
||||
break;
|
||||
case 'j':
|
||||
r_meta_list (core->anal, R_META_TYPE_COMMENT, 'j');
|
||||
break;
|
||||
@ -471,14 +475,14 @@ static int cmd_meta_hsdmf(RCore *core, const char *input) {
|
||||
n = r_num_math (core->num, t);
|
||||
if (type == 'f') { // "Cf"
|
||||
p = strchr (t, ' ');
|
||||
if (n < 1) {
|
||||
n = r_print_format_struct_size (p + 1, core->print, 0);
|
||||
if (n < 1) {
|
||||
eprintf ("Cannot resolve struct size\n");
|
||||
n = 32; //
|
||||
}
|
||||
}
|
||||
if (p) {
|
||||
if (n < 1) {
|
||||
n = r_print_format_struct_size (p + 1, core->print, 0);
|
||||
if (n < 1) {
|
||||
eprintf ("Cannot resolve struct size\n");
|
||||
n = 32; //
|
||||
}
|
||||
}
|
||||
r_print_format (core->print, addr, core->block,
|
||||
n, p + 1, 0, NULL, NULL);
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ typedef struct {
|
||||
SdbForeachCallback cb;
|
||||
void *user;
|
||||
int count;
|
||||
struct r_anal_type_function_t *fcn;
|
||||
} RAnalMetaUserItem;
|
||||
|
||||
typedef struct r_anal_range_t {
|
||||
@ -1454,7 +1455,8 @@ R_API int r_meta_cleanup(RAnal *m, ut64 from, ut64 to);
|
||||
R_API const char *r_meta_type_to_string(int type);
|
||||
R_API RList *r_meta_enumerate(RAnal *a, int type);
|
||||
R_API int r_meta_list(RAnal *m, int type, int rad);
|
||||
R_API int r_meta_list_cb(RAnal *m, int type, int rad, SdbForeachCallback cb, void *user);
|
||||
R_API int r_meta_list_at(RAnal *m, int type, int rad, ut64 addr);
|
||||
R_API int r_meta_list_cb(RAnal *m, int type, int rad, SdbForeachCallback cb, void *user, ut64 addr);
|
||||
R_API void r_meta_item_free(void *_item);
|
||||
R_API RAnalMetaItem *r_meta_item_new(int type);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user