From bcf7d46e363259ca9a5c2fc69abd7263d3417770 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 23 Nov 2014 22:44:38 +0100 Subject: [PATCH] Fix #1726 - ESIL brainfuck is back (and fix io.maps test case) - Thanks @trndr --- libr/include/r_io.h | 1 + libr/io/cache.c | 11 +++++++++-- libr/io/io.c | 7 +------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libr/include/r_io.h b/libr/include/r_io.h index 58a0037a1b..26fb15e322 100644 --- a/libr/include/r_io.h +++ b/libr/include/r_io.h @@ -303,6 +303,7 @@ R_API int r_io_use_desc(RIO *io, RIODesc *fd); R_API const ut8* r_io_get_raw (RIO *io, ut64 addr, int *len); R_API RBuffer *r_io_read_buf(RIO *io, ut64 addr, int len); R_API int r_io_vread (RIO *io, ut64 vaddr, ut8 *buf, int len); +R_API int r_io_read_internal(RIO *io, ut8 *buf, int len); R_API int r_io_mread (RIO *io, int fd, ut64 maddr, ut8 *buf, int len); R_API int r_io_pread (RIO *io, ut64 paddr, ut8 *buf, int len); R_API int r_io_read(RIO *io, ut8 *buf, int len); diff --git a/libr/io/cache.c b/libr/io/cache.c index a918ea3283..a0309f907b 100644 --- a/libr/io/cache.c +++ b/libr/io/cache.c @@ -105,14 +105,21 @@ R_API int r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) { RIOCache *ch; if (io->cached == 2) // magic hackaround return 0; - ch = R_NEW (RIOCache); + ch = R_NEW0 (RIOCache); ch->from = addr; ch->to = addr + len; ch->size = len; ch->odata = (ut8*)malloc (len); ch->data = (ut8*)malloc (len); - r_io_read_at (io, addr, ch->odata, len); ch->written = io->cached? 0: 1; +#if 1 + // we must use raw io here to avoid calling to cacheread and get wrong reads + if (r_io_seek (io, addr, R_IO_SEEK_SET)==UT64_MAX) + memset (ch->odata, 0xff, len); + r_io_read_internal (io, ch->odata, len); +#else + r_io_read_at (io, addr, ch->odata, len); +#endif memcpy (ch->data, buf, len); r_list_append (io->cache, ch); return len; diff --git a/libr/io/io.c b/libr/io/io.c index f27d0c34c5..60e616c952 100644 --- a/libr/io/io.c +++ b/libr/io/io.c @@ -286,8 +286,7 @@ R_API RIODesc *r_io_use_fd (RIO *io, int fd) { return desc; } -#if !USE_P_API -static inline int r_io_read_internal(RIO *io, ut8 *buf, int len) { +R_API int r_io_read_internal(RIO *io, ut8 *buf, int len) { int bytes_read = 0; const char *read_from = NULL; if (io->desc && io->desc->plugin && io->desc->plugin->read){ @@ -309,7 +308,6 @@ static inline int r_io_read_internal(RIO *io, ut8 *buf, int len) { } return bytes_read; } -#endif R_API int r_io_read(RIO *io, ut8 *buf, int len) { int ret; @@ -605,9 +603,6 @@ R_API int r_io_write(RIO *io, const ut8 *buf, int len) { buf += ret; } } - if (1) { //io->history) { - r_io_cache_write (io, io->off, buf, len); - } /* TODO: implement IO cache here. to avoid dupping work on vm for example */