Rizin
unix-like reverse engineering framework and cli tools
Memory watcher functions API

Functions

RZ_API void rz_core_cmpwatch_free (RzCoreCmpWatcher *w)
 
RZ_API RzCoreCmpWatcherrz_core_cmpwatch_get (RzCore *core, ut64 addr)
 Get the memory watcher at address addr. More...
 
RZ_API bool rz_core_cmpwatch_add (RzCore *core, ut64 addr, int size, const char *cmd)
 Add a memory watcher at address addr od size size and command cmd. More...
 
RZ_API bool rz_core_cmpwatch_del (RzCore *core, ut64 addr)
 Delete a memory watcher at address addr. More...
 
RZ_API void rz_core_cmpwatch_show (RzCore *core, ut64 addr, RzOutputMode mode)
 Show/print the memory watcher present at address addr. More...
 
RZ_API bool rz_core_cmpwatch_update (RzCore *core, ut64 addr)
 Update the memory watcher at address addr. More...
 
RZ_API bool rz_core_cmpwatch_revert (RzCore *core, ut64 addr)
 Revert/reset a memory watcher at address addr. More...
 

Detailed Description

API for memory watcher functions

Function Documentation

◆ rz_core_cmpwatch_add()

RZ_API bool rz_core_cmpwatch_add ( RzCore core,
ut64  addr,
int  size,
const char *  cmd 
)

Add a memory watcher at address addr od size size and command cmd.

Parameters
coreCurrent RzCore instance
addrAddress where to add the new memory watcher
sizeSize of the memory watcher to be addded
cmdCommand to be associated with the memory watcher
Returns
bool true if successful, false otherwise

Definition at line 337 of file cmp.c.

337  {
338  rz_return_val_if_fail(core, false);
339  RzCoreCmpWatcher *cmpw;
340  bool to_add = false;
341  if (size < 1) {
342  return false;
343  }
344  cmpw = rz_core_cmpwatch_get(core, addr);
345  if (!cmpw) {
346  to_add = true;
347  cmpw = RZ_NEW(RzCoreCmpWatcher);
348  if (!cmpw) {
349  return false;
350  }
351  cmpw->addr = addr;
352  }
353  cmpw->size = size;
354  snprintf(cmpw->cmd, sizeof(cmpw->cmd), "%s", cmd);
355  cmpw->odata = NULL;
356  cmpw->ndata = malloc(size);
357  if (!cmpw->ndata) {
358  free(cmpw);
359  return false;
360  }
361  rz_io_nread_at(core->io, addr, cmpw->ndata, size);
362  if (to_add) {
363  rz_list_append(core->watchers, cmpw);
364  }
365  return true;
366 }
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
RZ_API RzCoreCmpWatcher * rz_core_cmpwatch_get(RzCore *core, ut64 addr)
Get the memory watcher at address addr.
Definition: cmp.c:316
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
void * malloc(size_t size)
Definition: malloc.c:123
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API int rz_io_nread_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:338
#define RZ_NEW(x)
Definition: rz_types.h:285
Watcher which executes a command when listed.
RzIO * io
Definition: rz_core.h:313
RzList * watchers
Definition: rz_core.h:360
static int addr
Definition: z80asm.c:58

References addr, cmd, free(), rz_core_t::io, malloc(), NULL, rz_core_cmpwatch_get(), rz_io_nread_at(), rz_list_append(), RZ_NEW, rz_return_val_if_fail, snprintf, and rz_core_t::watchers.

Referenced by rz_cmd_cmp_add_memory_watcher_handler().

◆ rz_core_cmpwatch_del()

RZ_API bool rz_core_cmpwatch_del ( RzCore core,
ut64  addr 
)

Delete a memory watcher at address addr.

Parameters
coreCurrent RzCore instance
addrAddress of the memory watcher to be deleted (if UT64_MAX, then all memory watchers will be deleted)
Returns
bool true if found and deleted; false otherwise

Definition at line 375 of file cmp.c.

375  {
376  rz_return_val_if_fail(core, false);
377  int ret = false;
379  RzListIter *iter, *iter2;
380  rz_list_foreach_safe (core->watchers, iter, iter2, w) {
381  if (w->addr == addr || addr == UT64_MAX) {
382  rz_list_delete(core->watchers, iter);
383  ret = true;
384  }
385  }
386  return ret;
387 }
#define w
Definition: crypto_rc6.c:13
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
#define UT64_MAX
Definition: rz_types_base.h:86

References addr, rz_list_delete(), rz_return_val_if_fail, UT64_MAX, w, and rz_core_t::watchers.

Referenced by rz_cmd_cmp_remove_watcher_handler().

◆ rz_core_cmpwatch_free()

RZ_API void rz_core_cmpwatch_free ( RzCoreCmpWatcher w)

Definition at line 300 of file cmp.c.

300  {
301  if (!w) {
302  return;
303  }
304  free(w->ndata);
305  free(w->odata);
306  free(w);
307 }

References free(), and w.

Referenced by rz_core_init().

◆ rz_core_cmpwatch_get()

RZ_API RzCoreCmpWatcher* rz_core_cmpwatch_get ( RzCore core,
ut64  addr 
)

Get the memory watcher at address addr.

Parameters
coreCurrent RzCore instance
addrExpected address for the memory watcher to be found
Returns
RzCoreCmpWatcher* Pointer to the found memory watcher; NULL if not found

Definition at line 316 of file cmp.c.

316  {
318  RzListIter *iter;
320  rz_list_foreach (core->watchers, iter, w) {
321  if (addr == w->addr) {
322  return w;
323  }
324  }
325  return NULL;
326 }

References addr, NULL, rz_return_val_if_fail, w, and rz_core_t::watchers.

Referenced by rz_core_cmpwatch_add().

◆ rz_core_cmpwatch_revert()

RZ_API bool rz_core_cmpwatch_revert ( RzCore core,
ut64  addr 
)

Revert/reset a memory watcher at address addr.

Parameters
coreCurrent RzCore instance
addrAddress of the memory watcher to be reset (if UT64_MAX, then all memory watchers will be reset)
Returns
bool true if the memory watcher was resetted; false otherwise

Definition at line 458 of file cmp.c.

458  {
459  rz_return_val_if_fail(core, false);
461  int ret = false;
462  RzListIter *iter;
463  rz_list_foreach (core->watchers, iter, w) {
464  if (w->addr == addr || addr == UT64_MAX) {
465  if (w->odata) {
466  free(w->ndata);
467  w->ndata = w->odata;
468  w->odata = NULL;
469  ret = true;
470  }
471  }
472  }
473  return ret;
474 }

References addr, free(), NULL, rz_return_val_if_fail, UT64_MAX, w, and rz_core_t::watchers.

Referenced by rz_cmd_cmp_reset_watcher_handler().

◆ rz_core_cmpwatch_show()

RZ_API void rz_core_cmpwatch_show ( RzCore core,
ut64  addr,
RzOutputMode  mode 
)

Show/print the memory watcher present at address addr.

Parameters
coreCurrent RzCore instance
addrAddress of the memory watcher to be printed (if UT64_MAX, then all memory watchers will be printed)
modeOutput mode
Returns
void Print nothing if no memory watcher found at addr

Definition at line 397 of file cmp.c.

397  {
398  rz_return_if_fail(core);
399  char cmd[128];
400  RzListIter *iter;
402  rz_list_foreach (core->watchers, iter, w) {
403  if (addr != UT64_MAX && w->addr != addr) {
404  continue;
405  }
406  int is_diff = w->odata ? memcmp(w->odata, w->ndata, w->size) : 0;
407  switch (mode) {
409  rz_cons_printf("cw %d '%s' @ 0x%08" PFMT64x "%s\n",
410  w->size, w->cmd, w->addr, is_diff ? " # differs" : "");
411  break;
413  rz_cons_printf("0x%08" PFMT64x "%s\n", w->addr, is_diff ? " modified" : "");
414  snprintf(cmd, sizeof(cmd), "%s @ %" PFMT64d " @!%d", w->cmd, w->addr, w->size);
415  rz_core_cmd0(core, cmd);
416  break;
417  default:
419  }
420  }
421 }
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
const char int mode
Definition: ioapi.h:137
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define PFMT64d
Definition: rz_types.h:394
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define PFMT64x
Definition: rz_types.h:393

References addr, cmd, PFMT64d, PFMT64x, rz_cons_printf(), rz_core_cmd0(), RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_warn_if_reached, snprintf, UT64_MAX, w, and rz_core_t::watchers.

Referenced by rz_cmd_cmp_list_compare_watchers_handler().

◆ rz_core_cmpwatch_update()

RZ_API bool rz_core_cmpwatch_update ( RzCore core,
ut64  addr 
)

Update the memory watcher at address addr.

Parameters
coreCurrent RzCore instance
addrAddress of the memory watcher to be updated (if UT64_MAX, then all memory watchers will be updated)
Returns
bool true if any memory watcher was updated; false otherwise

Definition at line 430 of file cmp.c.

430  {
431  rz_return_val_if_fail(core, false);
433  RzListIter *iter;
434  bool ret = false;
435  rz_list_foreach (core->watchers, iter, w) {
436  if (addr != UT64_MAX && w->addr != addr) {
437  continue;
438  }
439  free(w->odata);
440  w->odata = w->ndata;
441  w->ndata = malloc(w->size);
442  if (!w->ndata) {
443  return false;
444  }
445  rz_io_nread_at(core->io, w->addr, w->ndata, w->size);
446  ret = true;
447  }
448  return ret;
449 }

References addr, free(), rz_core_t::io, malloc(), rz_io_nread_at(), rz_return_val_if_fail, UT64_MAX, w, and rz_core_t::watchers.

Referenced by rz_cmd_cmp_update_watcher_handler().