Rizin
unix-like reverse engineering framework and cli tools
io_memory.h File Reference
#include "rz_io.h"

Go to the source code of this file.

Classes

struct  RzIOMalloc
 

Functions

int io_memory_close (RzIODesc *fd)
 
int io_memory_read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
ut64 io_memory_lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
int io_memory_write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
bool io_memory_resize (RzIO *io, RzIODesc *fd, ut64 count)
 

Function Documentation

◆ io_memory_close()

int io_memory_close ( RzIODesc fd)

Definition at line 114 of file io_memory.c.

114  {
115  RzIOMalloc *riom;
116  if (!fd || !fd->data) {
117  return -1;
118  }
119  riom = fd->data;
120  RZ_FREE(riom->buf);
121  RZ_FREE(fd->data);
122  return 0;
123 }
#define RZ_FREE(x)
Definition: rz_types.h:369
ut8 * buf
Definition: io_memory.h:10
static const z80_opcode fd[]
Definition: z80_tab.h:997

References RzIOMalloc::buf, fd, and RZ_FREE.

◆ io_memory_lseek()

ut64 io_memory_lseek ( RzIO io,
RzIODesc fd,
ut64  offset,
int  whence 
)

Definition at line 125 of file io_memory.c.

125  {
126  ut64 rz_offset = offset;
127  if (!fd || !fd->data) {
128  return offset;
129  }
130  ut32 mallocsz = _io_malloc_sz(fd);
131  switch (whence) {
132  case SEEK_SET:
133  rz_offset = (offset <= mallocsz) ? offset : mallocsz;
134  break;
135  case SEEK_CUR:
136  rz_offset = (_io_malloc_off(fd) + offset <= mallocsz) ? _io_malloc_off(fd) + offset : mallocsz;
137  break;
138  case SEEK_END:
139  rz_offset = _io_malloc_sz(fd);
140  break;
141  }
142  _io_malloc_set_off(fd, rz_offset);
143  return rz_offset;
144 }
uint32_t ut32
static void _io_malloc_set_off(RzIODesc *desc, ut64 off)
Definition: io_memory.c:48
static ut64 _io_malloc_off(RzIODesc *desc)
Definition: io_memory.c:40
static ut32 _io_malloc_sz(RzIODesc *desc)
Definition: io_memory.c:6
voidpf uLong offset
Definition: ioapi.h:144
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84

References _io_malloc_off(), _io_malloc_set_off(), _io_malloc_sz(), fd, SEEK_CUR, SEEK_END, SEEK_SET, and ut64().

◆ io_memory_read()

int io_memory_read ( RzIO io,
RzIODesc fd,
ut8 buf,
int  count 
)

Definition at line 97 of file io_memory.c.

97  {
98  memset(buf, 0xff, count);
99  if (!fd || !fd->data) {
100  return -1;
101  }
102  ut32 mallocsz = _io_malloc_sz(fd);
103  if (_io_malloc_off(fd) > mallocsz) {
104  return -1;
105  }
106  if (_io_malloc_off(fd) + count >= mallocsz) {
107  count = mallocsz - _io_malloc_off(fd);
108  }
111  return count;
112 }
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
static ut8 * _io_malloc_buf(RzIODesc *desc)
Definition: io_memory.c:24
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))

References _io_malloc_buf(), _io_malloc_off(), _io_malloc_set_off(), _io_malloc_sz(), count, fd, memcpy(), and memset().

◆ io_memory_resize()

bool io_memory_resize ( RzIO io,
RzIODesc fd,
ut64  count 
)

Definition at line 74 of file io_memory.c.

74  {
75  ut8 *new_buf = NULL;
76  if (!fd || !fd->data || count == 0) {
77  return false;
78  }
79  ut32 mallocsz = _io_malloc_sz(fd);
80  if (_io_malloc_off(fd) > mallocsz) {
81  return false;
82  }
83  new_buf = malloc(count);
84  if (!new_buf) {
85  return false;
86  }
87  memcpy(new_buf, _io_malloc_buf(fd), RZ_MIN(count, mallocsz));
88  if (count > mallocsz) {
89  memset(new_buf + mallocsz, 0, count - mallocsz);
90  }
92  _io_malloc_set_buf(fd, new_buf);
94  return true;
95 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static void _io_malloc_set_sz(RzIODesc *desc, ut32 sz)
Definition: io_memory.c:14
static ut8 * _io_malloc_set_buf(RzIODesc *desc, ut8 *buf)
Definition: io_memory.c:32
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
#define RZ_MIN(x, y)

References _io_malloc_buf(), _io_malloc_off(), _io_malloc_set_buf(), _io_malloc_set_sz(), _io_malloc_sz(), count, fd, free(), malloc(), memcpy(), memset(), NULL, and RZ_MIN.

◆ io_memory_write()

int io_memory_write ( RzIO io,
RzIODesc fd,
const ut8 buf,
int  count 
)

Definition at line 56 of file io_memory.c.

56  {
57  if (!fd || !buf || count < 0 || !fd->data) {
58  return -1;
59  }
61  return -1;
62  }
65  }
66  if (count > 0) {
69  return count;
70  }
71  return -1;
72 }

References _io_malloc_buf(), _io_malloc_off(), _io_malloc_set_off(), _io_malloc_sz(), count, fd, and memcpy().