Rizin
unix-like reverse engineering framework and cli tools
io_fd.c File Reference
#include "rz_io.h"
#include "rz_lib.h"
#include <stdio.h>
#include <stdlib.h>
#include <rz_cons.h>
#include <sys/types.h>

Go to the source code of this file.

Classes

struct  RzIOFdata
 

Macros

#define FDURI   "fd://"
 

Functions

static int __write (RzIO *io, RzIODesc *desc, const ut8 *buf, int count)
 
static bool __resize (RzIO *io, RzIODesc *desc, ut64 count)
 
static int __read (RzIO *io, RzIODesc *desc, ut8 *buf, int count)
 
static int __close (RzIODesc *desc)
 
static ut64 __lseek (RzIO *io, RzIODesc *desc, ut64 offset, int whence)
 
static bool __check (RzIO *io, const char *pathname, bool many)
 
static RzIODesc__open (RzIO *io, const char *pathname, int rw, int mode)
 

Variables

RzIOPlugin rz_io_plugin_fd
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ FDURI

#define FDURI   "fd://"

Definition at line 14 of file io_fd.c.

Function Documentation

◆ __check()

static bool __check ( RzIO io,
const char *  pathname,
bool  many 
)
static

Definition at line 61 of file io_fd.c.

61  {
62  return !strncmp(pathname, FDURI, strlen(FDURI));
63 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
Definition: sflib.h:66
#define FDURI
Definition: io_fd.c:14

References FDURI, and pathname.

Referenced by __open().

◆ __close()

static int __close ( RzIODesc desc)
static

Definition at line 48 of file io_fd.c.

48  {
49  RZ_FREE(desc->data);
50  return 0;
51 }
const char * desc
Definition: bin_vsf.c:19
#define RZ_FREE(x)
Definition: rz_types.h:369

References desc, and RZ_FREE.

◆ __lseek()

static ut64 __lseek ( RzIO io,
RzIODesc desc,
ut64  offset,
int  whence 
)
static

Definition at line 53 of file io_fd.c.

53  {
54  RzIOFdata *fdd = (RzIOFdata *)desc->data;
55  if (fdd) {
56  return lseek(fdd->fd, offset, whence);
57  }
58  return 0;
59 }
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep lseek
Definition: sflib.h:113
voidpf uLong offset
Definition: ioapi.h:144
int fd
Definition: io_fd.c:18
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References desc, RzIOFdata::fd, if(), and lseek.

◆ __open()

static RzIODesc* __open ( RzIO io,
const char *  pathname,
int  rw,
int  mode 
)
static

Definition at line 65 of file io_fd.c.

65  {
66  if (!__check(io, pathname, 0)) {
67  return NULL;
68  }
69  RzIOFdata *fdd = RZ_NEW0(RzIOFdata);
70  if (fdd) {
71  fdd->fd = rz_num_math(NULL, pathname + strlen(FDURI));
72 #if __WINDOWS__
73  fdd->fd = _open_osfhandle(fdd->fd, 0);
74 #endif
75  if (fdd->fd < 0) {
76  free(fdd);
77  eprintf("Invalid filedescriptor.\n");
78  return NULL;
79  }
80  }
81  return rz_io_desc_new(io, &rz_io_plugin_fd, pathname, RZ_PERM_RW | rw, mode, fdd);
82 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
const char int mode
Definition: ioapi.h:137
static bool __check(RzIO *io, const char *pathname, bool many)
Definition: io_fd.c:61
RzIOPlugin rz_io_plugin_fd
Definition: io_fd.c:84
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
Definition: io_desc.c:11
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_PERM_RW
Definition: rz_types.h:96

References __check(), eprintf, RzIOFdata::fd, FDURI, free(), NULL, pathname, rz_io_desc_new(), rz_io_plugin_fd, RZ_NEW0, rz_num_math(), and RZ_PERM_RW.

◆ __read()

static int __read ( RzIO io,
RzIODesc desc,
ut8 buf,
int  count 
)
static

Definition at line 37 of file io_fd.c.

37  {
38  RzIOFdata *fdd = (RzIOFdata *)desc->data;
39  if (fdd) {
41  int res = read(fdd->fd, buf, count);
43  return res;
44  }
45  return -1;
46 }
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
voidpf void * buf
Definition: ioapi.h:138
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References count, desc, RzIOFdata::fd, if(), NULL, read(), rz_cons_break_pop(), and rz_cons_break_push().

◆ __resize()

static bool __resize ( RzIO io,
RzIODesc desc,
ut64  count 
)
static

Definition at line 29 of file io_fd.c.

29  {
30  RzIOFdata *fdd = (RzIOFdata *)desc->data;
31  if (fdd) {
32  return ftruncate(fdd->fd, count) == 0;
33  }
34  return false;
35 }
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence ftruncate
Definition: sflib.h:113

References count, desc, RzIOFdata::fd, ftruncate, and if().

◆ __write()

static int __write ( RzIO io,
RzIODesc desc,
const ut8 buf,
int  count 
)
static

Definition at line 21 of file io_fd.c.

21  {
22  RzIOFdata *fdd = (RzIOFdata *)desc->data;
23  if (fdd) {
24  return write(fdd->fd, buf, count);
25  }
26  return -1;
27 }
static static fork write
Definition: sflib.h:33

References count, desc, RzIOFdata::fd, if(), and write.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
.data = &rz_io_plugin_fd,
}
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_io.h:117

Definition at line 104 of file io_fd.c.

◆ rz_io_plugin_fd

RzIOPlugin rz_io_plugin_fd
Initial value:
= {
.name = "fd",
.desc = "Local process filedescriptor IO",
.uris = FDURI,
.license = "MIT",
.open = __open,
.close = __close,
.read = __read,
.check = __check,
.lseek = __lseek,
.write = __write,
.resize = __resize,
}
static int __close(RzIODesc *desc)
Definition: io_fd.c:48
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_fd.c:65
static bool __resize(RzIO *io, RzIODesc *desc, ut64 count)
Definition: io_fd.c:29
static int __read(RzIO *io, RzIODesc *desc, ut8 *buf, int count)
Definition: io_fd.c:37
static ut64 __lseek(RzIO *io, RzIODesc *desc, ut64 offset, int whence)
Definition: io_fd.c:53
static int __write(RzIO *io, RzIODesc *desc, const ut8 *buf, int count)
Definition: io_fd.c:21

Definition at line 84 of file io_fd.c.

Referenced by __open().