Rizin
unix-like reverse engineering framework and cli tools
io_plugin.c File Reference
#include "rz_io.h"
#include "config.h"
#include <stdio.h>

Go to the source code of this file.

Functions

RZ_API bool rz_io_plugin_add (RzIO *io, RZ_BORROW RzIOPlugin *plugin)
 
RZ_API bool rz_io_plugin_init (RzIO *io)
 
RZ_API RzIOPluginrz_io_plugin_get_default (RzIO *io, const char *filename, bool many)
 
RZ_API RzIOPluginrz_io_plugin_resolve (RzIO *io, const char *filename, bool many)
 
RZ_API RzIOPluginrz_io_plugin_byname (RzIO *io, const char *name)
 
RZ_API int rz_io_plugin_read (RzIODesc *desc, ut8 *buf, int len)
 
RZ_API int rz_io_plugin_write (RzIODesc *desc, const ut8 *buf, int len)
 
RZ_API int rz_io_plugin_read_at (RzIODesc *desc, ut64 addr, ut8 *buf, int len)
 
RZ_API int rz_io_plugin_write_at (RzIODesc *desc, ut64 addr, const ut8 *buf, int len)
 

Variables

static volatile RzIOPlugindefault_plugin = NULL
 
static RzIOPluginio_static_plugins [] = { RZ_IO_STATIC_PLUGINS }
 

Function Documentation

◆ rz_io_plugin_add()

RZ_API bool rz_io_plugin_add ( RzIO io,
RZ_BORROW RzIOPlugin plugin 
)

Definition at line 12 of file io_plugin.c.

12  {
13  if (!io || !io->plugins || !plugin || !plugin->name) {
14  return false;
15  }
16  RzListIter *it;
17  RzIOPlugin *nplugin;
18  rz_list_foreach (io->plugins, it, nplugin) {
19  if (!strcmp(nplugin->name, plugin->name)) {
20  return false;
21  }
22  }
23  nplugin = RZ_NEW0(RzIOPlugin);
24  if (!nplugin) {
25  return false;
26  }
27  memcpy(nplugin, plugin, sizeof(RzIOPlugin));
28  rz_list_append(io->plugins, nplugin);
29  return true;
30 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
const char * name
Definition: rz_io.h:115
RzList * plugins
Definition: rz_io.h:80

References memcpy(), rz_io_plugin_t::name, rz_io_t::plugins, rz_list_append(), and RZ_NEW0.

Referenced by rz_core_init(), and rz_io_plugin_init().

◆ rz_io_plugin_byname()

RZ_API RzIOPlugin* rz_io_plugin_byname ( RzIO io,
const char *  name 
)

Definition at line 68 of file io_plugin.c.

68  {
70  RzIOPlugin *iop;
71  rz_list_foreach (io->plugins, iter, iop) {
72  if (!strcmp(name, iop->name)) {
73  return iop;
74  }
75  }
76  return rz_io_plugin_get_default(io, name, false);
77 }
RZ_API RzIOPlugin * rz_io_plugin_get_default(RzIO *io, const char *filename, bool many)
Definition: io_plugin.c:47
Definition: z80asm.h:102

References rz_io_plugin_t::name, rz_io_t::plugins, and rz_io_plugin_get_default().

◆ rz_io_plugin_get_default()

RZ_API RzIOPlugin* rz_io_plugin_get_default ( RzIO io,
const char *  filename,
bool  many 
)

Definition at line 47 of file io_plugin.c.

47  {
48  if (!default_plugin || !default_plugin->check || !default_plugin->check(io, filename, many)) {
49  return NULL;
50  }
51  return (RzIOPlugin *)default_plugin;
52 }
#define NULL
Definition: cris-opc.c:27
static volatile RzIOPlugin * default_plugin
Definition: io_plugin.c:8
const char * filename
Definition: ioapi.h:137
bool(* check)(RzIO *io, const char *, bool many)
Definition: rz_io.h:141

References rz_io_plugin_t::check, default_plugin, and NULL.

Referenced by rz_io_plugin_byname(), and rz_io_plugin_resolve().

◆ rz_io_plugin_init()

RZ_API bool rz_io_plugin_init ( RzIO io)

Definition at line 32 of file io_plugin.c.

32  {
33  int i;
34  if (!io) {
35  return false;
36  }
37  io->plugins = rz_list_newf(free);
38  for (i = 0; i < RZ_ARRAY_SIZE(io_static_plugins); i++) {
39  if (!io_static_plugins[i]->name) {
40  continue;
41  }
43  }
44  return true;
45 }
lzma_index ** i
Definition: index.h:629
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static RzIOPlugin * io_static_plugins[]
Definition: io_plugin.c:10
RZ_API bool rz_io_plugin_add(RzIO *io, RZ_BORROW RzIOPlugin *plugin)
Definition: io_plugin.c:12
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300

References free(), i, io_static_plugins, rz_io_t::plugins, RZ_ARRAY_SIZE, rz_io_plugin_add(), and rz_list_newf().

Referenced by rz_io_init().

◆ rz_io_plugin_read()

RZ_API int rz_io_plugin_read ( RzIODesc desc,
ut8 buf,
int  len 
)

Definition at line 79 of file io_plugin.c.

79  {
80  if (!buf || !desc || !desc->plugin || len < 1 || !(desc->perm & RZ_PERM_R)) {
81  return 0;
82  }
83  if (!desc->plugin->read) {
84  return -1;
85  }
86  return desc->plugin->read(desc->io, desc, buf, len);
87 }
size_t len
Definition: 6502dis.c:15
const char * desc
Definition: bin_vsf.c:19
voidpf void * buf
Definition: ioapi.h:138
#define RZ_PERM_R
Definition: rz_types.h:93

References desc, len, and RZ_PERM_R.

Referenced by rz_io_desc_read(), and rz_io_plugin_read_at().

◆ rz_io_plugin_read_at()

RZ_API int rz_io_plugin_read_at ( RzIODesc desc,
ut64  addr,
ut8 buf,
int  len 
)

Definition at line 103 of file io_plugin.c.

103  {
105  return rz_io_plugin_read(desc, buf, len);
106  }
107  return 0;
108 }
RZ_API int rz_io_plugin_read(RzIODesc *desc, ut8 *buf, int len)
Definition: io_plugin.c:79
RZ_API ut64 rz_io_desc_seek(RzIODesc *desc, ut64 offset, int whence)
Definition: io_desc.c:217
RZ_API bool rz_io_desc_is_chardevice(RzIODesc *desc)
Definition: io_desc.c:268
#define RZ_IO_SEEK_SET
Definition: rz_io.h:15
static int addr
Definition: z80asm.c:58

References addr, desc, len, rz_io_desc_is_chardevice(), rz_io_desc_seek(), rz_io_plugin_read(), and RZ_IO_SEEK_SET.

◆ rz_io_plugin_resolve()

RZ_API RzIOPlugin* rz_io_plugin_resolve ( RzIO io,
const char *  filename,
bool  many 
)

Definition at line 54 of file io_plugin.c.

54  {
56  RzIOPlugin *ret;
57  rz_list_foreach (io->plugins, iter, ret) {
58  if (!ret || !ret->check) {
59  continue;
60  }
61  if (ret->check(io, filename, many)) {
62  return ret;
63  }
64  }
65  return rz_io_plugin_get_default(io, filename, many);
66 }

References rz_io_plugin_t::check, rz_io_t::plugins, and rz_io_plugin_get_default().

Referenced by dmp_open(), rz_io_desc_open(), and rz_io_open_many().

◆ rz_io_plugin_write()

RZ_API int rz_io_plugin_write ( RzIODesc desc,
const ut8 buf,
int  len 
)

Definition at line 89 of file io_plugin.c.

89  {
90  if (!buf || !desc || !desc->plugin || len < 1 || !(desc->perm & RZ_PERM_W)) {
91  return 0;
92  }
93  if (!desc->plugin->write) {
94  return -1;
95  }
96  const ut64 cur_addr = rz_io_desc_seek(desc, 0LL, RZ_IO_SEEK_CUR);
97  int ret = desc->plugin->write(desc->io, desc, buf, len);
98  RzEventIOWrite iow = { cur_addr, buf, len };
99  rz_event_send(desc->io->event, RZ_EVENT_IO_WRITE, &iow);
100  return ret;
101 }
RZ_API void rz_event_send(RzEvent *ev, int type, void *data)
Definition: event.c:115
@ RZ_EVENT_IO_WRITE
Definition: rz_event.h:42
#define RZ_IO_SEEK_CUR
Definition: rz_io.h:16
#define RZ_PERM_W
Definition: rz_types.h:94
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References desc, len, RZ_EVENT_IO_WRITE, rz_event_send(), rz_io_desc_seek(), RZ_IO_SEEK_CUR, RZ_PERM_W, and ut64().

Referenced by rz_io_desc_write(), and rz_io_plugin_write_at().

◆ rz_io_plugin_write_at()

RZ_API int rz_io_plugin_write_at ( RzIODesc desc,
ut64  addr,
const ut8 buf,
int  len 
)

Definition at line 110 of file io_plugin.c.

110  {
112  return rz_io_plugin_write(desc, buf, len);
113  }
114  return 0;
115 }
RZ_API int rz_io_plugin_write(RzIODesc *desc, const ut8 *buf, int len)
Definition: io_plugin.c:89

References addr, desc, len, rz_io_desc_is_chardevice(), rz_io_desc_seek(), rz_io_plugin_write(), and RZ_IO_SEEK_SET.

Variable Documentation

◆ default_plugin

volatile RzIOPlugin* default_plugin = NULL
static

Definition at line 8 of file io_plugin.c.

Referenced by rz_io_plugin_get_default().

◆ io_static_plugins

RzIOPlugin* io_static_plugins[] = { RZ_IO_STATIC_PLUGINS }
static

Definition at line 10 of file io_plugin.c.

Referenced by rz_io_plugin_init().