Add RIO on write event ##io

This commit is contained in:
GustavoLCR 2020-10-29 19:46:48 -03:00 committed by pancake
parent bafc2e2b72
commit 0ca7d6c3c1
6 changed files with 19 additions and 1 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}