Skip to content

Commit

Permalink
Rewrite r_io_p2v ##io
Browse files Browse the repository at this point in the history
  • Loading branch information
condret committed Nov 25, 2024
1 parent b4ccc0f commit 34bc40f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
10 changes: 2 additions & 8 deletions libr/core/cmd_print.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions libr/include/r_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions libr/io/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions libr/util/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34bc40f

Please sign in to comment.