Remove r_io_map_new from public API ##io

This commit is contained in:
condret 2021-10-29 21:23:25 +02:00
parent b00d8c6e0f
commit 44e3ff56ce
7 changed files with 53 additions and 31 deletions

View File

@ -662,7 +662,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
if (!strcmp (plugin->name, "any")) {
ut64 size = (desc->name && (r_str_startswith (desc->name, "rap") && strstr (desc->name, "://")))
? UT64_MAX : r_io_desc_size (desc);
r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, size);
r_io_map_add (r->io, desc->fd, desc->perm, 0, laddr, size);
// set use of raw strings
//r_config_set (r->config, "bin.rawstr", "true");
// r_config_set_i (r->config, "io.va", false);
@ -678,7 +678,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
}
//workaround to map correctly malloc:// and raw binaries
if (r_io_desc_is_dbg (desc) || (!obj->sections || !va)) {
r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
r_io_map_add (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
}
RBinInfo *info = obj->info;
if (info) {
@ -692,7 +692,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
}
} else {
if (desc) {
r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
r_io_map_add (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc));
}
if (binfile) {
r_core_bin_set_arch_bits (r, binfile->file,

View File

@ -4031,7 +4031,7 @@ repeat_arroba:
if (pamode) {
r_config_set_b (core->config, "io.va", true);
}
r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_io_map_add (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
}
}
} else {
@ -4107,7 +4107,7 @@ repeat_arroba:
if (pamode) {
r_config_set_b (core->config, "io.va", true);
}
r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_io_map_add (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_core_block_size (core, len);
r_core_block_read (core);
}
@ -4132,7 +4132,7 @@ repeat_arroba:
if (pamode) {
r_config_set_b (core->config, "io.va", true);
}
r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_io_map_add (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_core_block_size (core, len);
r_core_block_read (core);
}
@ -4196,7 +4196,7 @@ repeat_arroba:
if (pamode) {
r_config_set_b (core->config, "io.va", true);
}
r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_io_map_add (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b));
r_core_block_size (core, len);
// r_core_block_read (core);
}
@ -4259,7 +4259,7 @@ ignore:
if (addr) {
RIODesc *d = tmpdesc;
if (d) {
r_io_map_new (core->io, d->fd, d->perm, 0, addr, r_io_desc_size (d));
r_io_map_add (core->io, d->fd, d->perm, 0, addr, r_io_desc_size (d));
}
}
next_arroba:

View File

@ -51,7 +51,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
yank_file_sz = r_io_size (core->io);
ut64 addr = 0;
r_io_map_locate (core->io, &addr, yank_file_sz, load_align);
map = r_io_map_new (core->io, yankdesc->fd, R_PERM_R, 0, addr, yank_file_sz);
map = r_io_map_add (core->io, yankdesc->fd, R_PERM_R, 0, addr, yank_file_sz);
loadaddr = map? r_io_map_begin (map): -1;
if (yankdesc && map && loadaddr != -1) {
// ***NOTE*** this is important, we need to

View File

@ -319,7 +319,6 @@ typedef struct r_io_bind_t {
} RIOBind;
//map.c
R_API RIOMap *r_io_map_new(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size);
R_API void r_io_map_init(RIO *io);
R_API bool r_io_map_remap(RIO *io, ut32 id, ut64 addr);
R_API bool r_io_map_remap_fd(RIO *io, int fd, ut64 addr);

View File

@ -65,7 +65,7 @@ R_API RIODesc* r_io_open(RIO* io, const char* uri, int perm, int mode) {
r_return_val_if_fail (io, NULL);
RIODesc* desc = r_io_open_nomap (io, uri, perm, mode);
if (desc) {
r_io_map_new (io, desc->fd, desc->perm, 0LL, 0LL, r_io_desc_size (desc));
r_io_map_add (io, desc->fd, desc->perm, 0LL, 0LL, r_io_desc_size (desc));
}
return desc;
}
@ -79,15 +79,16 @@ R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int perm, int mode, ut64 a
return NULL;
}
ut64 size = r_io_desc_size (desc);
#if 0
// second map
if (size && ((UT64_MAX - size + 1) < at)) {
// split map into 2 maps if only 1 big map results into interger overflow
r_io_map_new (io, desc->fd, desc->perm, UT64_MAX - at + 1, 0LL, size - (UT64_MAX - at) - 1);
r_io_map_add (io, desc->fd, desc->perm, UT64_MAX - at + 1, 0LL, size - (UT64_MAX - at) - 1);
// someone pls take a look at this confusing stuff
size = UT64_MAX - at + 1;
}
// skyline not updated
r_io_map_new (io, desc->fd, desc->perm, 0LL, at, size);
#endif
r_io_map_add (io, desc->fd, desc->perm, 0LL, at, size);
return desc;
}

View File

@ -8,7 +8,7 @@
#define END_OF_MAP_IDS UT32_MAX
R_API RIOMap *r_io_map_new(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) {
RIOMap *io_map_new(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) {
r_return_val_if_fail (io && io->maps, NULL);
if (!size) {
return NULL;
@ -22,20 +22,11 @@ R_API RIOMap *r_io_map_new(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut6
map->fd = fd;
map->delta = delta;
map->ts = io->mts++;
if ((UT64_MAX - size + 1) < addr) {
r_io_map_new (io, fd, perm, delta - addr, 0LL, size + addr);
size = -(st64)addr;
}
// RIOMap describes an interval of addresses
// r_io_map_from (map) -> r_io_map_to (map)
map->itv = (RInterval){ addr, size };
map->perm = perm;
map->delta = delta;
if (!r_io_bank_map_add_top (io, io->bank, map->id)) {
r_id_storage_delete (io->maps, map->id);
free (map);
return NULL;
}
return map;
}
@ -50,7 +41,7 @@ R_API bool r_io_map_remap(RIO *io, ut32 id, ut64 addr) {
st64 saddr = (st64)addr;
const ut64 osize = r_io_map_size (map);
r_io_map_set_size (map, -saddr);
RIOMap *newmap = r_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, size + addr);
RIOMap *newmap = r_io_map_add (io, map->fd, map->perm, map->delta - addr, 0, size + addr);
if (newmap) {
if (!io_bank_has_map (io, io->bank, id)) {
r_io_bank_del_map (io, io->bank, newmap->id);
@ -137,8 +128,39 @@ R_API RIOMap *r_io_map_add(RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut6
RIODesc* desc = r_io_desc_get (io, fd);
if (desc) {
//a map cannot have higher permissions than the desc belonging to it
return r_io_map_new (io, fd, (perm & desc->perm) | (perm & R_PERM_X),
delta, addr, size);
perm &= desc->perm | R_PERM_X;
RIOMap *map[2] = {NULL, NULL};
if ((UT64_MAX - size + 1) < addr) {
map[0] = io_map_new (io, fd, perm, delta - addr, 0LL, size + addr);
size = -(st64)addr;
if (!map[0]) {
return NULL;
}
if (!r_io_bank_map_add_top (io, io->bank, map[0]->id)) {
r_id_storage_delete (io->maps, map[0]->id);
free (map[0]);
return NULL;
}
}
map[1] = io_map_new (io, fd, perm, delta, addr, size);
if (!map[1]) {
if (map[0]) {
r_id_storage_delete (io->maps, map[0]->id);
free (map[0]);
}
free (map[1]);
return NULL;
}
if (!r_io_bank_map_add_top (io, io->bank, map[1]->id)) {
if (map[0]) {
r_id_storage_delete (io->maps, map[0]->id);
free (map[0]);
}
r_id_storage_delete (io->maps, map[1]->id);
free (map[1]);
return NULL;
}
return map[1];
}
return NULL;
}
@ -318,7 +340,7 @@ R_API bool r_io_map_resize(RIO *io, ut32 id, ut64 newsize) {
st64 saddr = (st64)addr;
const ut64 osize = r_io_map_size (map);
r_io_map_set_size (map, -saddr);
RIOMap *newmap = r_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, newsize + addr);
RIOMap *newmap = r_io_map_add (io, map->fd, map->perm, map->delta - addr, 0, newsize + addr);
if (newmap) {
if (!io_bank_has_map (io, io->bank, id)) {
r_io_bank_del_map (io, io->bank, newmap->id);

View File

@ -968,7 +968,7 @@ R_API int r_main_radare2(int argc, const char **argv) {
R_FREE (debugbackend);
return 1;
}
r_io_map_new (r->io, fh->fd, 7, 0LL, mapaddr,
r_io_map_add (r->io, fh->fd, 7, 0LL, mapaddr,
r_io_fd_size (r->io, fh->fd));
r_io_write_at (r->io, mapaddr, (const ut8 *)buf, sz);
r_core_block_read (r);
@ -1182,7 +1182,7 @@ R_API int r_main_radare2(int argc, const char **argv) {
}
}
} else {
r_io_map_new (r->io, iod->fd, perms, 0LL, mapaddr, r_io_desc_size (iod));
r_io_map_add (r->io, iod->fd, perms, 0LL, mapaddr, r_io_desc_size (iod));
if (load_bin == LOAD_BIN_STRUCTURES_ONLY) {
r_core_bin_load_structs (r, iod->name);
}
@ -1206,7 +1206,7 @@ R_API int r_main_radare2(int argc, const char **argv) {
iod = r->io ? r_io_desc_get (r->io, fh->fd) : NULL;
if (iod) {
perms = iod->perm;
r_io_map_new (r->io, iod->fd, perms, 0LL, 0LL, r_io_desc_size (iod));
r_io_map_add (r->io, iod->fd, perms, 0LL, 0LL, r_io_desc_size (iod));
}
}
}