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

Go to the source code of this file.

Classes

struct  buf_io_priv
 

Typedefs

typedef RzIOBindBufIOUser
 
typedef struct buf_io_priv BufIOPriv
 

Functions

static bool buf_io_init (RzBuffer *b, const void *user)
 
static bool buf_io_fini (RzBuffer *b)
 
static st64 buf_io_seek (RzBuffer *b, st64 addr, int whence)
 
static st64 buf_io_read (RzBuffer *b, ut8 *buf, ut64 len)
 
static st64 buf_io_write (RzBuffer *b, const ut8 *buf, ut64 len)
 

Variables

static const RzBufferMethods buffer_io_methods
 

Typedef Documentation

◆ BufIOPriv

typedef struct buf_io_priv BufIOPriv

◆ BufIOUser

typedef RzIOBind* BufIOUser

Definition at line 7 of file buf_io.c.

Function Documentation

◆ buf_io_fini()

static bool buf_io_fini ( RzBuffer b)
static

Definition at line 27 of file buf_io.c.

27  {
28  free(b->priv);
29  return true;
30 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define b(i)
Definition: sha256.c:42

References b, and free().

◆ buf_io_init()

static bool buf_io_init ( RzBuffer b,
const void *  user 
)
static

Definition at line 14 of file buf_io.c.

14  {
15  BufIOUser u = (void *)user;
16  rz_return_val_if_fail(u, false);
17  BufIOPriv *priv = RZ_NEW(BufIOPriv);
18  if (!priv) {
19  return false;
20  }
21  priv->iob = u;
22  priv->offset = 0;
23  b->priv = priv;
24  return true;
25 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_NEW(x)
Definition: rz_types.h:285
RzIOBind * iob
Definition: buf_io.c:10
ut64 offset
Definition: buf_io.c:11

References b, buf_io_priv::iob, buf_io_priv::offset, RZ_NEW, and rz_return_val_if_fail.

◆ buf_io_read()

static st64 buf_io_read ( RzBuffer b,
ut8 buf,
ut64  len 
)
static

Definition at line 40 of file buf_io.c.

40  {
41  BufIOPriv *priv = b->priv;
42  len = RZ_MIN(INT_MAX, len); // remove if read_at takes ut64 at some point
43  bool r = priv->iob->read_at(priv->iob->io, priv->offset, buf, len);
44  return r ? len : -1;
45 }
size_t len
Definition: 6502dis.c:15
#define INT_MAX
Definition: cp-demangle.c:131
#define r
Definition: crypto_rc6.c:12
voidpf void * buf
Definition: ioapi.h:138
#define RZ_MIN(x, y)
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232

References b, INT_MAX, rz_io_bind_t::io, buf_io_priv::iob, len, buf_io_priv::offset, r, rz_io_bind_t::read_at, and RZ_MIN.

◆ buf_io_seek()

static st64 buf_io_seek ( RzBuffer b,
st64  addr,
int  whence 
)
static

Definition at line 32 of file buf_io.c.

32  {
33  BufIOPriv *priv = b->priv;
34  priv->offset = rz_seek_offset(priv->offset, 0, addr, whence);
35  // can't express the seek right if the highest bit is set,
36  // but at least tell the caller there was no error:
37  return RZ_MIN(priv->offset, ST64_MAX);
38 }
static ut64 rz_seek_offset(ut64 cur, ut64 length, st64 addr, int whence)
change cur according to addr and whence (RZ_BUF_SET/RZ_BUF_CUR/RZ_BUF_END)
Definition: rz_buf.h:67
#define ST64_MAX
Definition: rz_types_base.h:84
static int addr
Definition: z80asm.c:58

References addr, b, buf_io_priv::offset, RZ_MIN, rz_seek_offset(), and ST64_MAX.

◆ buf_io_write()

static st64 buf_io_write ( RzBuffer b,
const ut8 buf,
ut64  len 
)
static

Definition at line 47 of file buf_io.c.

47  {
48  BufIOPriv *priv = b->priv;
49  len = RZ_MIN(INT_MAX, len); // remove if write_at takes ut64 at some point
50  bool r = priv->iob->write_at(priv->iob->io, priv->offset, buf, len);
51  return r ? len : -1;
52 }
RzIOWriteAt write_at
Definition: rz_io.h:241

References b, INT_MAX, rz_io_bind_t::io, buf_io_priv::iob, len, buf_io_priv::offset, r, RZ_MIN, and rz_io_bind_t::write_at.

Variable Documentation

◆ buffer_io_methods

const RzBufferMethods buffer_io_methods
static
Initial value:
= {
.init = buf_io_init,
.fini = buf_io_fini,
.read = buf_io_read,
.write = buf_io_write,
.seek = buf_io_seek,
}
static st64 buf_io_read(RzBuffer *b, ut8 *buf, ut64 len)
Definition: buf_io.c:40
static bool buf_io_init(RzBuffer *b, const void *user)
Definition: buf_io.c:14
static bool buf_io_fini(RzBuffer *b)
Definition: buf_io.c:27
static st64 buf_io_write(RzBuffer *b, const ut8 *buf, ut64 len)
Definition: buf_io.c:47
static st64 buf_io_seek(RzBuffer *b, st64 addr, int whence)
Definition: buf_io.c:32

Definition at line 54 of file buf_io.c.

Referenced by new_buffer().