2024-05-11 23:52:16 +00:00
|
|
|
/* radare - LGPL - Copyright 2019-2024 - pancake */
|
2019-07-10 16:31:16 +00:00
|
|
|
|
|
|
|
#include <r_core.h>
|
|
|
|
|
2021-12-21 18:52:17 +00:00
|
|
|
R_API RCoreItem *r_core_item_at(RCore *core, ut64 addr) {
|
2024-05-11 23:52:16 +00:00
|
|
|
R_RETURN_VAL_IF_FAIL (core, NULL);
|
2019-07-10 16:31:16 +00:00
|
|
|
RCoreItem *ci = R_NEW0 (RCoreItem);
|
|
|
|
ci->addr = addr;
|
2021-03-12 15:35:12 +00:00
|
|
|
RIOMap *map = r_io_map_get_at (core->io, addr);
|
2019-07-10 16:31:16 +00:00
|
|
|
if (map) {
|
|
|
|
ci->perm = map->perm;
|
|
|
|
// TODO: honor section perms too?
|
|
|
|
if (map->perm & R_PERM_X) {
|
|
|
|
// if theres a meta consider it data
|
2020-05-09 18:49:28 +00:00
|
|
|
ut64 size;
|
|
|
|
RAnalMetaItem *item = r_meta_get_at (core->anal, addr, R_META_TYPE_ANY, &size);
|
2019-07-10 16:31:16 +00:00
|
|
|
if (item) {
|
|
|
|
switch (item->type) {
|
|
|
|
case R_META_TYPE_DATA:
|
|
|
|
ci->type = "data";
|
2020-05-09 18:49:28 +00:00
|
|
|
ci->size = size;
|
2019-07-10 16:31:16 +00:00
|
|
|
ci->data = r_core_cmd_strf (core, "pdi 1 @e:asm.flags=0@e:asm.lines=0@e:scr.color=0@0x%08"PFMT64x, addr);
|
|
|
|
r_str_trim (ci->data);
|
|
|
|
break;
|
|
|
|
case R_META_TYPE_FORMAT:
|
|
|
|
ci->type = "format"; // struct :?
|
2020-05-09 18:49:28 +00:00
|
|
|
ci->size = size;
|
2019-07-10 16:31:16 +00:00
|
|
|
break;
|
|
|
|
case R_META_TYPE_STRING:
|
|
|
|
ci->type = "string";
|
2020-05-09 18:49:28 +00:00
|
|
|
ci->size = size;
|
|
|
|
break;
|
|
|
|
default:
|
2019-07-10 16:31:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (item->str) {
|
|
|
|
if (!ci->data) {
|
|
|
|
ci->data = strdup (item->str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 1);
|
|
|
|
if (fcn) {
|
|
|
|
ci->fcnname = strdup (fcn->name);
|
|
|
|
}
|
|
|
|
RBinObject *o = r_bin_cur_object (core->bin);
|
2022-11-19 11:55:51 +00:00
|
|
|
if (o) {
|
|
|
|
RBinSection *sec = r_bin_get_section_at (o, addr, core->io->va);
|
|
|
|
if (sec) {
|
|
|
|
ci->sectname = strdup (sec->name);
|
|
|
|
}
|
2019-07-10 16:31:16 +00:00
|
|
|
}
|
|
|
|
if (!ci->data) {
|
2022-10-16 19:26:13 +00:00
|
|
|
RAnalOp* op = r_core_anal_op (core, addr, R_ARCH_OP_MASK_ESIL | R_ARCH_OP_MASK_HINT);
|
2019-07-10 16:31:16 +00:00
|
|
|
if (op) {
|
|
|
|
if (!ci->data) {
|
|
|
|
if (op->mnemonic) {
|
|
|
|
ci->data = strdup (op->mnemonic);
|
|
|
|
} else {
|
|
|
|
ci->data = r_core_cmd_strf (core, "pi 1 @e:scr.color=0@0x%08"PFMT64x, addr);
|
|
|
|
r_str_trim (ci->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ci->size = op->size;
|
|
|
|
r_anal_op_free (op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char *cmt = r_core_cmd_strf (core, "CC.@0x%08"PFMT64x, addr);
|
|
|
|
if (cmt) {
|
|
|
|
if (*cmt) {
|
|
|
|
ci->comment = strdup (cmt);
|
|
|
|
r_str_trim (ci->comment);
|
|
|
|
}
|
|
|
|
free (cmt);
|
|
|
|
}
|
|
|
|
if (!ci->type) {
|
2024-05-11 23:52:16 +00:00
|
|
|
if (ci->perm) {
|
|
|
|
ci->type = "code";
|
|
|
|
} else {
|
|
|
|
ci->type = "void";
|
|
|
|
}
|
2019-07-10 16:31:16 +00:00
|
|
|
}
|
|
|
|
ci->next = ci->addr + ci->size;
|
|
|
|
char *prev = r_core_cmd_strf (core, "pd -1@e:asm.lines=0~[0]");
|
|
|
|
r_str_trim (prev);
|
|
|
|
ci->prev = r_num_get (NULL, prev);
|
|
|
|
free (prev);
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
2021-12-21 18:52:17 +00:00
|
|
|
R_API void r_core_item_free(RCoreItem *ci) {
|
2024-05-11 23:52:16 +00:00
|
|
|
if (ci) {
|
|
|
|
free (ci->data);
|
|
|
|
free (ci);
|
|
|
|
}
|
2019-07-10 16:31:16 +00:00
|
|
|
}
|