diff --git a/librz/include/rz_io.h b/librz/include/rz_io.h index 06ef40c1d1..87f206a57d 100644 --- a/librz/include/rz_io.h +++ b/librz/include/rz_io.h @@ -491,7 +491,6 @@ extern RzIOPlugin rz_io_plugin_http; extern RzIOPlugin rz_io_plugin_bfdbg; extern RzIOPlugin rz_io_plugin_w32; extern RzIOPlugin rz_io_plugin_zip; -extern RzIOPlugin rz_io_plugin_mmap; extern RzIOPlugin rz_io_plugin_default; extern RzIOPlugin rz_io_plugin_ihex; extern RzIOPlugin rz_io_plugin_self; diff --git a/librz/io/meson.build b/librz/io/meson.build index 6b9188b687..8712d0f24a 100644 --- a/librz/io/meson.build +++ b/librz/io/meson.build @@ -22,7 +22,6 @@ rz_io_sources = [ 'p/io_ihex.c', 'p/io_mach.c', 'p/io_malloc.c', - 'p/io_mmap.c', 'p/io_null.c', 'p/io_procpid.c', 'p/io_ptrace.c', diff --git a/librz/io/p/io_mmap.c b/librz/io/p/io_mmap.c deleted file mode 100644 index d3253750b1..0000000000 --- a/librz/io/p/io_mmap.c +++ /dev/null @@ -1,216 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-only - -#include -#include -#include - -typedef struct rz_io_mmo_t { - char * filename; - int mode; - int flags; - int fd; - int opened; - ut8 modified; - RzBuffer *buf; - RzIO * io_backref; -} RzIOMMapFileObj; - -static ut64 rz_io_mmap_seek(RzIO *io, RzIOMMapFileObj *mmo, ut64 offset, int whence) { - ut64 seek_val = rz_buf_tell (mmo->buf); - switch (whence) { - case SEEK_SET: - seek_val = (rz_buf_size (mmo->buf) < offset)? rz_buf_size (mmo->buf): offset; - rz_buf_seek (mmo->buf, io->off = seek_val, RZ_BUF_SET); - return seek_val; - case SEEK_CUR: - seek_val = (rz_buf_size (mmo->buf) < (offset + rz_buf_tell (mmo->buf)))? rz_buf_size (mmo->buf): offset + rz_buf_tell (mmo->buf); - rz_buf_seek (mmo->buf, io->off = seek_val, RZ_BUF_SET); - return seek_val; - case SEEK_END: - seek_val = rz_buf_size (mmo->buf); - rz_buf_seek (mmo->buf, io->off = seek_val, RZ_BUF_SET); - return seek_val; - } - return seek_val; -} - -static bool rz_io_mmap_refresh_buf(RzIOMMapFileObj *mmo) { - RzIO* io = mmo->io_backref; - ut64 cur = mmo->buf? rz_buf_tell (mmo->buf): 0; - if (mmo->buf) { - rz_buf_free (mmo->buf); - mmo->buf = NULL; - } - mmo->buf = rz_buf_new_mmap (mmo->filename, mmo->flags); - if (mmo->buf) { - rz_io_mmap_seek (io, mmo, cur, SEEK_SET); - } - return mmo->buf != NULL; -} - -static void rz_io_mmap_free(RzIOMMapFileObj *mmo) { - free (mmo->filename); - rz_buf_free (mmo->buf); - memset (mmo, 0, sizeof (RzIOMMapFileObj)); - free (mmo); -} - -RzIOMMapFileObj *rz_io_mmap_create_new_file(RzIO *io, const char *filename, int mode, int flags) { - RzIOMMapFileObj *mmo; - if (!io) { - return NULL; - } - mmo = RZ_NEW0 (RzIOMMapFileObj); - if (!mmo) { - return NULL; - } - mmo->filename = strdup (filename); - mmo->fd = rz_num_rand (0xFFFF); // XXX: Use rz_io_fd api - mmo->mode = mode; - mmo->flags = flags; - mmo->io_backref = io; - if (!rz_io_mmap_refresh_buf (mmo)) { - rz_io_mmap_free (mmo); - mmo = NULL; - } - return mmo; -} - -static int rz_io_mmap_close(RzIODesc *fd) { - if (!fd || !fd->data) { - return -1; - } - rz_io_mmap_free ((RzIOMMapFileObj *) fd->data); - fd->data = NULL; - return 0; -} - -static int rz_io_mmap_check (const char *filename) { - return (filename && !strncmp (filename, "mmap://", 7) && *(filename + 7)); -} - -static int rz_io_mmap_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { - RzIOMMapFileObj *mmo = NULL; - if (!fd || !fd->data || !buf) { - return -1; - } - mmo = fd->data; - if (rz_buf_size (mmo->buf) < io->off) { - io->off = rz_buf_size (mmo->buf); - } - int r = rz_buf_read_at (mmo->buf, io->off, buf, count); - if (r >= 0) { - rz_buf_seek (mmo->buf, r, RZ_BUF_CUR); - } - return r; -} - -static int rz_io_mmap_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { - RzIOMMapFileObj *mmo; - int len = count; - ut64 addr; - - if (!io || !fd || !fd->data || !buf) { - return -1; - } - mmo = fd->data; - addr = io->off; - if ( !(mmo->flags & RZ_PERM_W)) { - return -1; - } - if ( (count + addr > rz_buf_size (mmo->buf)) || rz_buf_size (mmo->buf) == 0) { - ut64 sz = count + addr; - rz_file_truncate (mmo->filename, sz); - } - len = rz_file_mmap_write (mmo->filename, io->off, buf, len); - if (!rz_io_mmap_refresh_buf (mmo) ) { - eprintf ("io_mmap: failed to refresh the mmap backed buffer.\n"); - // XXX - not sure what needs to be done here (error handling). - } - return len; -} - -static RzIODesc *rz_io_mmap_open(RzIO *io, const char *file, int flags, int mode) { - if (!strncmp (file, "mmap://", 7)) { - file += 7; - } - RzIOMMapFileObj *mmo = rz_io_mmap_create_new_file (io, file, mode, flags); - return mmo? rz_io_desc_new (io, &rz_io_plugin_mmap, mmo->filename, flags, mode, mmo): NULL; -} - -static ut64 rz_io_mmap_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { - RzIOMMapFileObj *mmo; - if (!fd || !fd->data) { - return -1; - } - mmo = fd->data; - return rz_io_mmap_seek (io, mmo, offset, whence); -} - -static bool rz_io_mmap_truncate(RzIOMMapFileObj *mmo, ut64 size) { - int res = rz_file_truncate (mmo->filename, size); - if (res && !rz_io_mmap_refresh_buf (mmo)) { - eprintf ("rz_io_mmap_truncate: Error trying to refresh the mmap'ed file."); - res = false; - } else if (res) { - eprintf ("rz_io_mmap_truncate: Error trying to resize the file."); - } - return res; -} - - -static bool __plugin_open(RzIO *io, const char *file, bool many) { - return rz_io_mmap_check (file); -} - -static RzIODesc *__open(RzIO *io, const char *file, int flags, int mode) { - if (!rz_io_mmap_check (file)) { - return NULL; - } - return rz_io_mmap_open (io, file, flags, mode); -} - -static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) { - return rz_io_mmap_read (io, fd, buf, len); -} - -static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { - return rz_io_mmap_write(io, fd, buf, len); -} - -static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { - return rz_io_mmap_lseek (io, fd, offset, whence); -} - -static int __close(RzIODesc *fd) { - return rz_io_mmap_close (fd); -} - -static bool __resize(RzIO *io, RzIODesc *fd, ut64 size) { - if (!fd || !fd->data) { - return false; - } - return rz_io_mmap_truncate ((RzIOMMapFileObj*)fd->data, size); -} - -struct rz_io_plugin_t rz_io_plugin_mmap = { - .name = "mmap", - .desc = "Open files using mmap", - .uris = "mmap://", - .license = "LGPL3", - .open = __open, - .close = __close, - .read = __read, - .check = __plugin_open, - .lseek = __lseek, - .write = __write, - .resize = __resize, -}; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_IO, - .data = &rz_io_plugin_mmap, - .version = RZ_VERSION -}; -#endif diff --git a/librz/io/p/mmap.mk b/librz/io/p/mmap.mk deleted file mode 100644 index 66d24d42d2..0000000000 --- a/librz/io/p/mmap.mk +++ /dev/null @@ -1,16 +0,0 @@ -OBJ_MMAP=io_mmap.o - -STATIC_OBJ+=${OBJ_MMAP} -TARGET_MMAP=io_mmap.${EXT_SO} -ALL_TARGETS+=${TARGET_MMAP} - -ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/librz_util.a -LINKFLAGS+=../../io/librz_io.a -else -LINKFLAGS+=-L../../util -lrz_util -LINKFLAGS+=-L.. -lrz_io -endif - -${TARGET_MMAP}: ${OBJ_MMAP} - ${CC_LIB} $(call libname,io_mmap) ${CFLAGS} -o ${TARGET_MMAP} ${OBJ_MMAP} ${LINKFLAGS} diff --git a/librz/meson.build b/librz/meson.build index 6d6e1975f7..e1fa1dd651 100644 --- a/librz/meson.build +++ b/librz/meson.build @@ -253,7 +253,6 @@ io_plugins = [ 'ihex', 'mach', 'malloc', - 'mmap', 'null', 'procpid', 'ptrace', diff --git a/plugins.android.cfg b/plugins.android.cfg index 0f7ad472c0..8526ba8555 100644 --- a/plugins.android.cfg +++ b/plugins.android.cfg @@ -62,7 +62,6 @@ io.rap io.gzip io.http io.bfdbg -io.mmap io.default io.self io.mach diff --git a/plugins.bin.cfg b/plugins.bin.cfg index 840df39212..76381d6860 100644 --- a/plugins.bin.cfg +++ b/plugins.bin.cfg @@ -39,7 +39,6 @@ asm.ppc_cs analysis.ppc_cs io.mach io.debug -io.mmap io.w32 io.w32dbg io.ihex diff --git a/plugins.def.cfg b/plugins.def.cfg index 9b9232e1c1..ed087d281b 100644 --- a/plugins.def.cfg +++ b/plugins.def.cfg @@ -229,7 +229,6 @@ io.ihex io.mach io.malloc io.sparse -io.mmap io.procpid io.ptrace io.rap diff --git a/plugins.emscripten.cfg b/plugins.emscripten.cfg index 29fc99bee4..40b44e5fb0 100644 --- a/plugins.emscripten.cfg +++ b/plugins.emscripten.cfg @@ -48,7 +48,6 @@ asm.ppc_cs analysis.ppc_cs io.mach io.debug -io.mmap io.w32 io.w32dbg io.ihex diff --git a/plugins.ios-store.cfg b/plugins.ios-store.cfg index 1ed9c837d0..5ac87cf0a6 100644 --- a/plugins.ios-store.cfg +++ b/plugins.ios-store.cfg @@ -59,7 +59,6 @@ io.rap io.gzip io.http io.bfdbg -io.mmap io.rzpipe io.rzweb io.default diff --git a/plugins.ios.cfg b/plugins.ios.cfg index 665afff89b..2ab22bbc56 100644 --- a/plugins.ios.cfg +++ b/plugins.ios.cfg @@ -62,7 +62,6 @@ io.rap io.gzip io.http io.bfdbg -io.mmap io.default io.self io.mach diff --git a/plugins.nogpl.cfg b/plugins.nogpl.cfg index 491ded0e4b..e6c177c6a5 100644 --- a/plugins.nogpl.cfg +++ b/plugins.nogpl.cfg @@ -110,7 +110,6 @@ io.ihex io.mach io.malloc io.sparse -io.mmap io.procpid io.ptrace io.rap diff --git a/plugins.static.cfg b/plugins.static.cfg index 46e32f7579..e8f242a1e3 100644 --- a/plugins.static.cfg +++ b/plugins.static.cfg @@ -181,7 +181,6 @@ io.ihex io.mach io.malloc io.sparse -io.mmap io.procpid io.ptrace io.rap diff --git a/plugins.static.nogpl.cfg b/plugins.static.nogpl.cfg index 62b4e5a4ac..5c81ba185f 100644 --- a/plugins.static.nogpl.cfg +++ b/plugins.static.nogpl.cfg @@ -182,7 +182,6 @@ io.ihex io.mach io.malloc io.sparse -io.mmap io.procpid io.ptrace io.rap diff --git a/plugins.tiny.cfg b/plugins.tiny.cfg index 1ac1b3d72e..843ac4a0eb 100644 --- a/plugins.tiny.cfg +++ b/plugins.tiny.cfg @@ -60,7 +60,6 @@ io.http io.bfdbg io.gdb io.bochs -io.mmap io.default io.self io.mach