From 0ca7d6c3c16def8e92598926852aee0152c03765 Mon Sep 17 00:00:00 2001 From: GustavoLCR Date: Thu, 29 Oct 2020 19:46:48 -0300 Subject: [PATCH] Add RIO on write event ##io --- libr/include/r_io.h | 1 + libr/include/r_util/r_event.h | 7 +++++++ libr/io/io.c | 2 ++ libr/io/io_cache.c | 2 ++ libr/io/io_plugin.c | 6 +++++- libr/io/p_cache.c | 2 ++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libr/include/r_io.h b/libr/include/r_io.h index 7101b4675d..107db11e25 100644 --- a/libr/include/r_io.h +++ b/libr/include/r_io.h @@ -107,6 +107,7 @@ typedef struct r_io_t { struct w32dbg_wrap_instance_t *w32dbg_wrap; #endif char *args; + REvent *event; PrintfCallback cb_printf; RCoreBind corebind; } RIO; diff --git a/libr/include/r_util/r_event.h b/libr/include/r_util/r_event.h index f2dd52cca3..f08ea86265 100644 --- a/libr/include/r_util/r_event.h +++ b/libr/include/r_util/r_event.h @@ -37,6 +37,7 @@ typedef enum { R_EVENT_CLASS_ATTR_DEL, // REventClassAttrSet R_EVENT_CLASS_ATTR_RENAME, // REventClassAttrRename R_EVENT_DEBUG_PROCESS_FINISHED, // REventDebugProcessFinished + R_EVENT_IO_WRITE, // REventIOWrite R_EVENT_MAX, } REventType; @@ -75,6 +76,12 @@ typedef struct r_event_debug_process_finished_t { int pid; } REventDebugProcessFinished; +typedef struct r_event_io_write_t { + ut64 addr; + const ut8 *buf; + int len; +} REventIOWrite; + R_API REvent *r_event_new(void *user); R_API void r_event_free(REvent *ev); R_API REventCallbackHandle r_event_hook(REvent *ev, int type, REventCallback cb, void *user); diff --git a/libr/io/io.c b/libr/io/io.c index 67a88582c1..a51c8bf898 100644 --- a/libr/io/io.c +++ b/libr/io/io.c @@ -111,6 +111,7 @@ R_API RIO* r_io_init(RIO* io) { r_io_cache_init (io); r_io_plugin_init (io); r_io_undo_init (io); + io->event = r_event_new (io); return io; } @@ -670,6 +671,7 @@ R_API int r_io_fini(RIO* io) { if (io->runprofile) { R_FREE (io->runprofile); } + r_event_free (io->event); #if R_IO_USE_PTRACE_WRAP if (io->ptrace_wrap) { ptrace_wrap_instance_stop (io->ptrace_wrap); diff --git a/libr/io/io_cache.c b/libr/io/io_cache.c index 0e5baf8e93..bfcc61f629 100644 --- a/libr/io/io_cache.c +++ b/libr/io/io_cache.c @@ -169,6 +169,8 @@ R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) { } memcpy (ch->data, buf, len); r_list_append (io->cache, ch); + REventIOWrite iow = { addr, buf, len }; + r_event_send (io->event, R_EVENT_IO_WRITE, &iow); return true; } diff --git a/libr/io/io_plugin.c b/libr/io/io_plugin.c index 2de4228c59..d667b59e35 100644 --- a/libr/io/io_plugin.c +++ b/libr/io/io_plugin.c @@ -172,7 +172,11 @@ R_API int r_io_plugin_write(RIODesc *desc, const ut8 *buf, int len) { if (!desc->plugin->write) { return -1; } - return desc->plugin->write (desc->io, desc, buf, len); + const ut64 cur_addr = r_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR); + int ret = desc->plugin->write (desc->io, desc, buf, len); + REventIOWrite iow = { cur_addr, buf, len }; + r_event_send (desc->io->event, R_EVENT_IO_WRITE, &iow); + return ret; } R_API int r_io_plugin_read_at(RIODesc *desc, ut64 addr, ut8 *buf, int len) { diff --git a/libr/io/p_cache.c b/libr/io/p_cache.c index ccdb4f5ec2..884eb58bef 100644 --- a/libr/io/p_cache.c +++ b/libr/io/p_cache.c @@ -132,6 +132,8 @@ R_API int r_io_desc_cache_write(RIODesc *desc, ut64 paddr, const ut8 *buf, int l caddr++; cbaddr = 0; } + REventIOWrite iow = { paddr, buf, len }; + r_event_send (desc->io->event, R_EVENT_IO_WRITE, &iow); return written; }