Fix #3807 - write on maps issue

This commit is contained in:
pancake 2015-12-07 22:35:34 +01:00
parent eb51d68d3a
commit 61fba1e663
3 changed files with 16 additions and 3 deletions

View File

@ -121,7 +121,7 @@ typedef struct r_io_t {
int raised;
int va;
int raw;
int vio; //remove that when vio replaces the old stuff
int vio; // remove that when vio replaces the old stuff
int sectonly;
char *referer;
char *redirect;

View File

@ -626,7 +626,11 @@ R_API int r_io_write(RIO *io, const ut8 *buf, int len) {
/* apply write binary mask */
if (io->write_mask_fd != -1) {
data = malloc (len);
data = (len>0)? malloc (len): NULL;
if (!data) {
eprintf ("malloc failed in write_mask_fd");
return -1;
}
r_io_seek (io, io->off, R_IO_SEEK_SET);
r_io_read (io, data, len);
r_io_seek (io, io->off, R_IO_SEEK_SET);
@ -642,6 +646,12 @@ R_API int r_io_write(RIO *io, const ut8 *buf, int len) {
r_io_map_select (io, io->off);
io->off = addr;
}
{
RIOMap *map = r_io_map_get (io, io->off);
if (map) {
io->off -= map->from;
}
}
if (io->plugin) {
if (io->plugin->write) {

View File

@ -76,8 +76,11 @@ R_API RIOMap *r_io_map_get(RIO *io, ut64 addr) {
RIOMap *map;
RListIter *iter;
r_list_foreach (io->maps, iter, map) {
if ((map->from <= addr) && (addr < map->to))
if (map->from == map->to && map >= map->from) {
return map;
} else if (map >= map->from && map < map->to) {
return map;
}
}
return NULL;
}