Scroll to navigation

R_IO(3) Library Functions Manual R_IO(3)

NAME

r_ioRadare2 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 * (void)

Creates and initializes a new I/O context. void (RIO *io)

Initializes an existing I/O structure. void (RIO *io)

Frees an I/O context and all associated resources.

FILE OPERATIONS

RIODesc * (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 * (RIO *io, const char *uri, int perm, int mode, ut64 at)

Opens a resource and maps it at the specified address. bool (RIO *io)

Closes the current descriptor. bool (RIO *io, ut64 addr, ut8 *buf, int len)

Reads len bytes from virtual address addr into buf. bool (RIO *io, ut64 addr, const ut8 *buf, int len)

Writes len bytes from buf to virtual address addr. ut64 (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 * (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 (RIO *io, ut32 id)

Deletes the map with the given id. RIOMap * (RIO *io, ut32 id)

Retrieves the map with the given id. RIOMap * (RIO *io, ut64 vaddr)

Gets the map covering the virtual address vaddr.

BANKING

RIOBank * (const char *name)

Creates a new bank with the given name. bool (RIO *io, RIOBank *bank)

Adds a bank to the I/O context. bool (RIO *io, ut32 bankid)

Switches to the specified bank.

CACHING

bool (RIO *io, ut64 addr, const ut8 *buf, int len)

Writes to the cache at the specified address. bool (RIO *io, ut64 addr, ut8 *buf, int len)

Reads from the cache at the specified address. void (RIO *io, ut64 from, ut64 to, bool many)

Commits cached changes to the underlying storage.

UNDO FUNCTIONALITY

int (RIO *io)

Initializes undo functionality. void (RIO *io, int seek, int write)

Enables seek and/or write undo tracking. void (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

r_core(3), r_bin(3), r_anal(3)

AUTHORS

The radare2 project team.

September 20, 2025 Debian