From 34bc40fd919cbc1edb6a7aa5b525479bbfc0e20c Mon Sep 17 00:00:00 2001 From: condret Date: Mon, 25 Nov 2024 00:02:29 +0100 Subject: [PATCH] Rewrite r_io_p2v ##io --- libr/core/cmd_print.inc.c | 10 ++-------- libr/include/r_io.h | 4 ++-- libr/io/io.c | 13 +++++++------ libr/util/print.c | 5 +---- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/libr/core/cmd_print.inc.c b/libr/core/cmd_print.inc.c index 844112061e..7543db3210 100644 --- a/libr/core/cmd_print.inc.c +++ b/libr/core/cmd_print.inc.c @@ -2532,10 +2532,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { echars = chars; ut64 ea = addr; if (core->print->pava) { - ut64 va = r_io_p2v (core->io, addr); - if (va != UT64_MAX) { - ea = va; - } + r_io_p2v (core->io, addr, &ea); } if (usecolor) { append (ebytes, core->cons->context->pal.offset); @@ -6163,10 +6160,7 @@ static void cmd_print_pxb(RCore *core, int len, const char *input) { if (c == 0) { ut64 ea = core->offset + i; if (core->print->pava) { - ut64 va = r_io_p2v (core->io, ea); - if (va != UT64_MAX) { - ea = va; - } + r_io_p2v (core->io, ea, &ea); } r_print_section (core->print, ea); r_print_offset (core->print, ea, 0, 0, NULL); diff --git a/libr/include/r_io.h b/libr/include/r_io.h index 6f9ce672df..7624c5786a 100644 --- a/libr/include/r_io.h +++ b/libr/include/r_io.h @@ -284,7 +284,7 @@ typedef bool (*RIOFdClose)(RIO *io, int fd); typedef ut64 (*RIOFdSeek)(RIO *io, int fd, ut64 addr, int whence); typedef ut64 (*RIOFdSize)(RIO *io, int fd); typedef bool (*RIOFdResize)(RIO *io, int fd, ut64 newsize); -typedef ut64 (*RIOP2V)(RIO *io, ut64 pa); +typedef bool (*RIOP2V)(RIO *io, ut64 p, ut64 *v); typedef ut64 (*RIOV2P)(RIO *io, ut64 va); typedef int (*RIOFdRead)(RIO *io, int fd, ut8 *buf, int len); typedef int (*RIOFdWrite)(RIO *io, int fd, const ut8 *buf, int len); @@ -384,7 +384,7 @@ R_API bool r_io_map_locate(RIO *io, ut64 *addr, const ut64 size, ut64 load_align // p2v/v2p -R_API ut64 r_io_p2v(RIO *io, ut64 pa); +R_API bool r_io_p2v(RIO *io, ut64 p, ut64 *v); R_API ut64 r_io_v2p(RIO *io, ut64 va); //io_submap.c diff --git a/libr/io/io.c b/libr/io/io.c index 4012c1cd0f..7b7a60cfca 100644 --- a/libr/io/io.c +++ b/libr/io/io.c @@ -449,13 +449,14 @@ R_API bool r_io_set_write_mask(RIO* io, const ut8* mask, int len) { return true; } -R_API ut64 r_io_p2v(RIO *io, ut64 pa) { - R_RETURN_VAL_IF_FAIL (io, 0); - RIOMap *map = r_io_map_get_paddr (io, pa); - if (map) { - return pa - map->delta + r_io_map_begin (map); +R_API bool r_io_p2v(RIO *io, ut64 p, ut64 *v) { + R_RETURN_VAL_IF_FAIL (io && v, false); + RIOMap *map = r_io_map_get_paddr (io, p); + if (!map) { + return false; } - return UT64_MAX; + *v = p - map->delta + r_io_map_begin (map); + return true; } R_API ut64 r_io_v2p(RIO *io, ut64 va) { diff --git a/libr/util/print.c b/libr/util/print.c index a28ab8d6ae..c0b55f6e6a 100644 --- a/libr/util/print.c +++ b/libr/util/print.c @@ -444,10 +444,7 @@ R_API void r_print_addr(RPrint *p, ut64 addr) { ch = '|'; } if (p && p->pava) { - ut64 va = p->iob.p2v (p->iob.io, addr); - if (va != UT64_MAX) { - addr = va; - } + p->iob.p2v (p->iob.io, addr, &addr); } if (use_segoff) { ut32 s, a;