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

Go to the source code of this file.

Functions

RZ_API int rz_io_fd_open (RzIO *io, const char *uri, int flags, int mode)
 
RZ_API bool rz_io_fd_close (RzIO *io, int fd)
 
RZ_API int rz_io_fd_read (RzIO *io, int fd, ut8 *buf, int len)
 
RZ_API int rz_io_fd_write (RzIO *io, int fd, const ut8 *buf, int len)
 
RZ_API ut64 rz_io_fd_seek (RzIO *io, int fd, ut64 addr, int whence)
 
RZ_API ut64 rz_io_fd_size (RzIO *io, int fd)
 
RZ_API ut8rz_io_fd_get_buf (RzIO *io, int fd, RZ_OUT RZ_NONNULL ut64 *size)
 Returns the underlying buffer of the file descriptor. More...
 
RZ_API bool rz_io_fd_resize (RzIO *io, int fd, ut64 newsize)
 
RZ_API bool rz_io_fd_is_blockdevice (RzIO *io, int fd)
 
RZ_API bool rz_io_fd_is_chardevice (RzIO *io, int fd)
 
RZ_API int rz_io_fd_read_at (RzIO *io, int fd, ut64 addr, ut8 *buf, int len)
 
RZ_API int rz_io_fd_write_at (RzIO *io, int fd, ut64 addr, const ut8 *buf, int len)
 
RZ_API bool rz_io_fd_is_dbg (RzIO *io, int fd)
 
RZ_API int rz_io_fd_get_pid (RzIO *io, int fd)
 
RZ_API int rz_io_fd_get_tid (RzIO *io, int fd)
 
RZ_API bool rz_io_fd_get_base (RzIO *io, int fd, ut64 *base)
 
RZ_API const char * rz_io_fd_get_name (RzIO *io, int fd)
 
RZ_API bool rz_io_use_fd (RzIO *io, int fd)
 
RZ_API int rz_io_fd_get_current (RzIO *io)
 
RZ_API int rz_io_fd_get_next (RzIO *io, int fd)
 
RZ_API int rz_io_fd_get_prev (RzIO *io, int fd)
 
RZ_API int rz_io_fd_get_highest (RzIO *io)
 
RZ_API int rz_io_fd_get_lowest (RzIO *io)
 

Function Documentation

◆ rz_io_fd_close()

RZ_API bool rz_io_fd_close ( RzIO io,
int  fd 
)

Definition at line 11 of file io_fd.c.

11  {
12  return rz_io_desc_close(rz_io_desc_get(io, fd));
13 }
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
RZ_API bool rz_io_desc_close(RzIODesc *desc)
Definition: io_desc.c:165
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, rz_io_desc_close(), and rz_io_desc_get().

Referenced by ds_free(), ds_init(), get_bin_info(), GetHeapGlobalsOffset(), rz_core_analysis_esil_init_mem(), rz_core_analysis_esil_init_mem_del(), rz_core_file_close_fd(), and rz_io_bind().

◆ rz_io_fd_get_base()

RZ_API bool rz_io_fd_get_base ( RzIO io,
int  fd,
ut64 base 
)

Definition at line 106 of file io_fd.c.

106  {
107  rz_return_val_if_fail(io && io->files && base, false);
108  RzIODesc *desc = rz_io_desc_get(io, fd);
109  return rz_io_desc_get_base(desc, base);
110 }
const char * desc
Definition: bin_vsf.c:19
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_io_desc_get_base(RzIODesc *desc, ut64 *base)
Definition: io_desc.c:344
RzIDStorage * files
Definition: rz_io.h:75

References desc, fd, rz_io_t::files, rz_io_desc_get(), rz_io_desc_get_base(), and rz_return_val_if_fail.

◆ rz_io_fd_get_buf()

RZ_API ut8* rz_io_fd_get_buf ( RzIO io,
int  fd,
RZ_OUT RZ_NONNULL ut64 size 
)

Returns the underlying buffer of the file descriptor.

Parameters
[in]ioThe RzIO instance
[in]fdThe file descriptor
[out]sizeSize of the buffer returned
Returns
The buffer or NULL if the file descriptor is invalid or the buffer is not available

Definition at line 53 of file io_fd.c.

53  {
56 }
#define NULL
Definition: cris-opc.c:27
voidpf void uLong size
Definition: ioapi.h:138
RZ_API ut8 * rz_io_desc_get_buf(RzIODesc *desc, RZ_OUT RZ_NONNULL ut64 *size)
Returns the underlying buffer of the io descriptor.
Definition: io_desc.c:241

References fd, NULL, rz_io_desc_get(), rz_io_desc_get_buf(), and rz_return_val_if_fail.

Referenced by rz_io_bind().

◆ rz_io_fd_get_current()

◆ rz_io_fd_get_highest()

RZ_API int rz_io_fd_get_highest ( RzIO io)

Definition at line 161 of file io_fd.c.

161  {
162  rz_return_val_if_fail(io, -1);
163  int fd = -1;
164  if (!rz_id_storage_get_highest(io->files, (ut32 *)&fd)) {
165  return -1;
166  }
167  return fd;
168 }
uint32_t ut32
RZ_API bool rz_id_storage_get_highest(RzIDStorage *storage, ut32 *id)
Definition: idpool.c:178

References fd, rz_io_t::files, rz_id_storage_get_highest(), and rz_return_val_if_fail.

Referenced by rz_io_desc_get_highest().

◆ rz_io_fd_get_lowest()

RZ_API int rz_io_fd_get_lowest ( RzIO io)

Definition at line 170 of file io_fd.c.

170  {
171  rz_return_val_if_fail(io, -1);
172  int fd = -1;
173  if (!rz_id_storage_get_lowest(io->files, (ut32 *)&fd)) {
174  return -1;
175  }
176  return fd;
177 }
RZ_API bool rz_id_storage_get_lowest(RzIDStorage *storage, ut32 *id)
Definition: idpool.c:169

References fd, rz_io_t::files, rz_id_storage_get_lowest(), and rz_return_val_if_fail.

Referenced by rz_io_desc_get_lowest(), and rz_open_prioritize_next_rotate_handler().

◆ rz_io_fd_get_name()

RZ_API const char* rz_io_fd_get_name ( RzIO io,
int  fd 
)

Definition at line 112 of file io_fd.c.

112  {
113  rz_return_val_if_fail(io && io->files, NULL);
114  RzIODesc *desc = rz_io_desc_get(io, fd);
115  return desc ? desc->name : NULL;
116 }

References desc, fd, rz_io_t::files, NULL, rz_io_desc_get(), and rz_return_val_if_fail.

Referenced by rz_io_bind().

◆ rz_io_fd_get_next()

RZ_API int rz_io_fd_get_next ( RzIO io,
int  fd 
)

Definition at line 143 of file io_fd.c.

143  {
144  rz_return_val_if_fail(io, -1);
145  int ret = fd;
146  if (!rz_id_storage_get_next(io->files, (ut32 *)&ret)) {
147  return -1;
148  }
149  return ret;
150 }
RZ_API bool rz_id_storage_get_next(RzIDStorage *storage, ut32 *id)
Definition: idpool.c:191

References fd, rz_io_t::files, rz_id_storage_get_next(), and rz_return_val_if_fail.

Referenced by rz_io_desc_get_next(), rz_open_prioritize_next_handler(), and rz_open_prioritize_next_rotate_handler().

◆ rz_io_fd_get_pid()

RZ_API int rz_io_fd_get_pid ( RzIO io,
int  fd 
)

Definition at line 92 of file io_fd.c.

92  {
93  if (!io || !io->files) {
94  return -2;
95  }
97  return rz_io_desc_get_pid(desc);
98 }
RZ_API int rz_io_desc_get_pid(RzIODesc *desc)
Definition: io_desc.c:310

References desc, fd, rz_io_t::files, rz_io_desc_get(), and rz_io_desc_get_pid().

Referenced by cb_cfgdebug(), cmd_debug_pid(), core_file_do_load_for_debug(), rz_core_debug_attach(), and rz_core_file_reopen().

◆ rz_io_fd_get_prev()

RZ_API int rz_io_fd_get_prev ( RzIO io,
int  fd 
)

Definition at line 152 of file io_fd.c.

152  {
153  rz_return_val_if_fail(io, -1);
154  int ret = fd;
155  if (!rz_id_storage_get_prev(io->files, (ut32 *)&ret)) {
156  return -1;
157  }
158  return ret;
159 }
RZ_API bool rz_id_storage_get_prev(RzIDStorage *storage, ut32 *id)
Definition: idpool.c:206

References fd, rz_io_t::files, rz_id_storage_get_prev(), and rz_return_val_if_fail.

Referenced by rz_io_desc_get_prev(), and rz_open_prioritize_prev_handler().

◆ rz_io_fd_get_tid()

RZ_API int rz_io_fd_get_tid ( RzIO io,
int  fd 
)

Definition at line 100 of file io_fd.c.

100  {
101  rz_return_val_if_fail(io && io->files, -2);
102  RzIODesc *desc = rz_io_desc_get(io, fd);
103  return rz_io_desc_get_tid(desc);
104 }
RZ_API int rz_io_desc_get_tid(RzIODesc *desc)
Definition: io_desc.c:327

References desc, fd, rz_io_t::files, rz_io_desc_get(), rz_io_desc_get_tid(), and rz_return_val_if_fail.

Referenced by cb_cfgdebug(), cmd_debug_pid(), core_file_do_load_for_debug(), and rz_core_file_reopen().

◆ rz_io_fd_is_blockdevice()

RZ_API bool rz_io_fd_is_blockdevice ( RzIO io,
int  fd 
)

Definition at line 62 of file io_fd.c.

62  {
64 }
RZ_API bool rz_io_desc_is_blockdevice(RzIODesc *desc)
Definition: io_desc.c:261

References fd, rz_io_desc_get(), and rz_io_desc_is_blockdevice().

◆ rz_io_fd_is_chardevice()

RZ_API bool rz_io_fd_is_chardevice ( RzIO io,
int  fd 
)

Definition at line 66 of file io_fd.c.

66  {
68 }
RZ_API bool rz_io_desc_is_chardevice(RzIODesc *desc)
Definition: io_desc.c:268

References fd, rz_io_desc_get(), and rz_io_desc_is_chardevice().

◆ rz_io_fd_is_dbg()

RZ_API bool rz_io_fd_is_dbg ( RzIO io,
int  fd 
)

Definition at line 86 of file io_fd.c.

86  {
87  rz_return_val_if_fail(io && io->files, false);
89  return desc ? rz_io_desc_is_dbg(desc) : false;
90 }
#define false
RZ_API bool rz_io_desc_is_dbg(RzIODesc *desc)
Definition: io_desc.c:303

References desc, fd, rz_io_t::files, rz_io_desc_get(), rz_io_desc_is_dbg(), and rz_return_val_if_fail.

Referenced by rz_io_bind().

◆ rz_io_fd_open()

RZ_API int rz_io_fd_open ( RzIO io,
const char *  uri,
int  flags,
int  mode 
)

Definition at line 6 of file io_fd.c.

6  {
7  RzIODesc *desc = rz_io_desc_open(io, uri, flags, mode);
8  return desc ? desc->fd : -1;
9 }
const char int mode
Definition: ioapi.h:137
RZ_API RzIODesc * rz_io_desc_open(RzIO *io, const char *uri, int flags, int mode)
Definition: io_desc.c:112
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References desc, flags, and rz_io_desc_open().

Referenced by ds_init(), get_bin_info(), GetHeapGlobalsOffset(), rz_core_analysis_esil_init_mem(), and rz_io_bind().

◆ rz_io_fd_read()

RZ_API int rz_io_fd_read ( RzIO io,
int  fd,
ut8 buf,
int  len 
)

Definition at line 16 of file io_fd.c.

16  {
17  rz_return_val_if_fail(io && buf, -1);
18  if (len < 0) {
19  return -1;
20  }
22  return desc ? rz_io_desc_read(desc, buf, len) : -1;
23 }
size_t len
Definition: 6502dis.c:15
voidpf void * buf
Definition: ioapi.h:138
RZ_API int rz_io_desc_read(RzIODesc *desc, ut8 *buf, int count)
Definition: io_desc.c:197

References desc, fd, len, rz_io_desc_get(), rz_io_desc_read(), and rz_return_val_if_fail.

Referenced by rz_io_bind().

◆ rz_io_fd_read_at()

RZ_API int rz_io_fd_read_at ( RzIO io,
int  fd,
ut64  addr,
ut8 buf,
int  len 
)

Definition at line 71 of file io_fd.c.

71  {
72  RzIODesc *desc;
73  if (!io || !buf || (len < 1) || !(desc = rz_io_desc_get(io, fd))) {
74  return 0;
75  }
76  return rz_io_desc_read_at(desc, addr, buf, len);
77 }
RZ_API int rz_io_desc_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, int len)
Definition: io_desc.c:351
static int addr
Definition: z80asm.c:58

References addr, desc, fd, len, rz_io_desc_get(), and rz_io_desc_read_at().

Referenced by fd_read_at_wrap(), and rz_io_bind().

◆ rz_io_fd_resize()

RZ_API bool rz_io_fd_resize ( RzIO io,
int  fd,
ut64  newsize 
)

Definition at line 58 of file io_fd.c.

58  {
59  return rz_io_desc_resize(rz_io_desc_get(io, fd), newsize);
60 }
RZ_API bool rz_io_desc_resize(RzIODesc *desc, ut64 newsize)
Definition: io_desc.c:250

References fd, rz_io_desc_get(), and rz_io_desc_resize().

Referenced by rz_io_bind().

◆ rz_io_fd_seek()

RZ_API ut64 rz_io_fd_seek ( RzIO io,
int  fd,
ut64  addr,
int  whence 
)

Definition at line 35 of file io_fd.c.

35  {
36  if (!io) {
37  return (ut64)-2;
38  }
39  return rz_io_desc_seek(rz_io_desc_get(io, fd), addr, whence);
40 }
RZ_API ut64 rz_io_desc_seek(RzIODesc *desc, ut64 offset, int whence)
Definition: io_desc.c:217
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References addr, fd, rz_io_desc_get(), rz_io_desc_seek(), and ut64().

Referenced by rz_io_bind().

◆ rz_io_fd_size()

◆ rz_io_fd_write()

RZ_API int rz_io_fd_write ( RzIO io,
int  fd,
const ut8 buf,
int  len 
)

Definition at line 26 of file io_fd.c.

26  {
27  rz_return_val_if_fail(io && buf, -1);
28  if (len < 0) {
29  return -1;
30  }
32  return desc ? rz_io_desc_write(desc, buf, len) : -1;
33 }
RZ_API int rz_io_desc_write(RzIODesc *desc, const ut8 *buf, int count)
Definition: io_desc.c:183

References desc, fd, len, rz_io_desc_get(), rz_io_desc_write(), and rz_return_val_if_fail.

Referenced by rz_io_bind().

◆ rz_io_fd_write_at()

RZ_API int rz_io_fd_write_at ( RzIO io,
int  fd,
ut64  addr,
const ut8 buf,
int  len 
)

Definition at line 80 of file io_fd.c.

80  {
81  rz_return_val_if_fail(io && buf, false);
83  return desc ? rz_io_desc_write_at(desc, addr, buf, len) : -1;
84 }
RZ_API int rz_io_desc_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, int len)
Definition: io_desc.c:358

References addr, desc, fd, len, rz_io_desc_get(), rz_io_desc_write_at(), and rz_return_val_if_fail.

Referenced by fd_write_at_wrap(), and rz_io_bind().

◆ rz_io_use_fd()

RZ_API bool rz_io_use_fd ( RzIO io,
int  fd 
)