- unstable 6.0.4+dfsg-1
R_IO(3) | Library Functions Manual | R_IO(3) |
NAME¶
r_io
— Radare2
Input/Output Library API
SYNOPSIS¶
#include
<r_io.h>
DESCRIPTION¶
The r_io
library provides a unified
interface for input/output operations in radare2, supporting various
backends such as files, memory, network connections, and debuggers. It
abstracts file descriptors, memory mappings, caching, and undo
functionality.
Key concepts:
RIO
is the main structure representing an I/O context.RIODesc
represents an open file or resource descriptor.RIOMap
defines memory mappings from file offsets to virtual addresses.RIOBank
groups maps for banked memory architectures.- Caching allows temporary modifications without altering the underlying data.
INITIALIZATION¶
RIO *
r_io_new
(void)
Creates and initializes a new I/O context.
void
r_io_init
(RIO
*io)
Initializes an existing I/O structure.
void
r_io_free
(RIO
*io)
Frees an I/O context and all associated resources.
FILE OPERATIONS¶
RIODesc *
r_io_open
(RIO
*io, const char *uri, int
perm, int mode)
Opens a resource specified by URI with given
permissions and mode, and maps it at address 0. RIODesc
*
r_io_open_at
(RIO
*io, const char *uri, int
perm, int mode, ut64
at)
Opens a resource and maps it at the specified
address. bool
r_io_close
(RIO
*io)
Closes the current descriptor.
bool
r_io_read_at
(RIO
*io, ut64 addr, ut8 *buf,
int len)
Reads len bytes from virtual address addr into
buf. bool
r_io_write_at
(RIO
*io, ut64 addr, const ut8
*buf, int len)
Writes len bytes from buf to virtual address addr.
ut64
r_io_seek
(RIO
*io, ut64 offset, int
whence)
Seeks to the specified offset. whence can be R_IO_SEEK_SET, R_IO_SEEK_CUR, or R_IO_SEEK_END.
MEMORY MAPPING¶
RIOMap *
r_io_map_add
(RIO
*io, int fd, int flags,
ut64 delta, ut64 addr,
ut64 size)
Creates a new memory map from file descriptor fd
at virtual address addr with size size, starting from file offset delta.
bool
r_io_map_del
(RIO
*io, ut32 id)
Deletes the map with the given id.
RIOMap *
r_io_map_get
(RIO
*io, ut32 id)
Retrieves the map with the given id.
RIOMap *
r_io_map_get_at
(RIO
*io, ut64 vaddr)
Gets the map covering the virtual address vaddr.
BANKING¶
RIOBank *
r_io_bank_new
(const
char *name)
Creates a new bank with the given name.
bool
r_io_bank_add
(RIO
*io, RIOBank *bank)
Adds a bank to the I/O context.
bool
r_io_bank_use
(RIO
*io, ut32 bankid)
Switches to the specified bank.
CACHING¶
bool
r_io_cache_write_at
(RIO
*io, ut64 addr, const ut8
*buf, int len)
Writes to the cache at the specified
address. bool
r_io_cache_read_at
(RIO
*io, ut64 addr, ut8 *buf,
int len)
Reads from the cache at the specified
address. void
r_io_cache_commit
(RIO
*io, ut64 from, ut64 to,
bool many)
Commits cached changes to the underlying storage.
UNDO FUNCTIONALITY¶
int
r_io_undo_init
(RIO
*io)
Initializes undo functionality.
void
r_io_undo_enable
(RIO
*io, int seek, int
write)
Enables seek and/or write undo tracking.
void
r_io_wundo_new
(RIO
*io, ut64 off, const ut8
*data, int len)
Records a write operation for undo.
EXAMPLES¶
Opening and reading a file:
RIO *io = r_io_new(); RIODesc *desc = r_io_open(io, "/bin/ls", R_PERM_R, 0); if (desc) { ut8 buf[64]; r_io_read_at(io, 0, buf, sizeof(buf)); } r_io_free(io);
Creating a memory map:
RIO *io = r_io_new(); RIODesc *desc = r_io_open_nomap(io, "malloc://1024", R_PERM_RW, 0); if (desc) { RIOMap *map = r_io_map_add(io, desc->fd, R_PERM_RW, 0, 0x1000, 1024); } r_io_free(io);
Using cache for temporary modifications:
RIO *io = r_io_new(); r_io_open(io, "file.bin", R_PERM_RW, 0); ut8 data[] = {0x90, 0x90}; // NOP NOP r_io_cache_write_at(io, 0x100, data, 2); // Changes are cached, not written to file yet r_io_cache_commit(io, 0x100, 0x102, false); // Now changes are committed r_io_free(io);
SEE ALSO¶
AUTHORS¶
The radare2 project team.
September 20, 2025 | Debian |