Rizin
unix-like reverse engineering framework and cli tools
io_malloc.c File Reference
#include "rz_lib.h"
#include <stdio.h>
#include <stdlib.h>
#include "../io_memory.h"

Go to the source code of this file.

Functions

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_malloc
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ __check()

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

Definition at line 9 of file io_malloc.c.

9  {
10  return (!strncmp(pathname, "malloc://", 9)) || (!strncmp(pathname, "hex://", 6));
11 }
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

References pathname.

Referenced by __open().

◆ __open()

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

Definition at line 13 of file io_malloc.c.

13  {
14  if (__check(io, pathname, 0)) {
16  if (!mal) {
17  return NULL;
18  }
19  if (!strncmp(pathname, "hex://", 6)) {
20  mal->size = strlen(pathname);
21  mal->buf = calloc(1, mal->size + 1);
22  if (!mal->buf) {
23  free(mal);
24  return NULL;
25  }
26  mal->offset = 0;
27  mal->size = rz_hex_str2bin(pathname + 6, mal->buf);
28  if ((int)mal->size < 1) {
29  RZ_FREE(mal->buf);
30  }
31  } else {
32  mal->size = rz_num_math(NULL, pathname + 9);
33  if (((int)mal->size) <= 0) {
34  free(mal);
35  eprintf("Cannot allocate (%s) 0 bytes\n", pathname + 9);
36  return NULL;
37  }
38  mal->offset = 0;
39  mal->buf = calloc(1, mal->size + 1);
40  }
41  if (mal->buf) {
43  }
44  eprintf("Cannot allocate (%s) %d byte(s)\n", pathname + 9, mal->size);
45  free(mal);
46  }
47  return NULL;
48 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static bool __check(RzIO *io, const char *pathname, bool many)
Definition: io_malloc.c:9
RzIOPlugin rz_io_plugin_malloc
Definition: io_malloc.c:50
const char int mode
Definition: ioapi.h:137
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
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
#define RZ_FREE(x)
Definition: rz_types.h:369
static struct @626 mal

References __check(), calloc(), eprintf, free(), mal, NULL, pathname, RZ_FREE, rz_hex_str2bin(), rz_io_desc_new(), rz_io_plugin_malloc, RZ_NEW0, rz_num_math(), and RZ_PERM_RW.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
}
@ 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 65 of file io_malloc.c.

◆ rz_io_plugin_malloc

RzIOPlugin rz_io_plugin_malloc
Initial value:
= {
.name = "malloc",
.desc = "Memory allocation plugin",
.uris = "malloc://,hex://",
.license = "LGPL3",
.open = __open,
.close = io_memory_close,
.read = io_memory_read,
.check = __check,
.lseek = io_memory_lseek,
.write = io_memory_write,
.resize = io_memory_resize,
}
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_malloc.c:13
bool io_memory_resize(RzIO *io, RzIODesc *fd, ut64 count)
Definition: io_memory.c:74
int io_memory_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_memory.c:97
int io_memory_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_memory.c:56
ut64 io_memory_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_memory.c:125
int io_memory_close(RzIODesc *fd)
Definition: io_memory.c:114

Definition at line 50 of file io_malloc.c.

Referenced by __open().