Scroll to navigation

R_UTIL(3) Library Functions Manual R_UTIL(3)

NAME

r_utilradare2 utility library

SYNOPSIS

#include <r_util.h>

DESCRIPTION

The r_util library provides a comprehensive collection of utility functions for radare2, including number parsing, string manipulation, buffer management, memory operations, file handling, and various data structures. It serves as the foundation for many other radare2 libraries.

NUMBERS

Parse and format numeric values, convert textual representations into integers, recognize human-friendly unit suffixes, and evaluate simple mathematical expressions. Useful for configuration parsing, user input handling and preparing numbers for display.

RNum * (RNumCallback cb, RNumCallback2 cb2, void *ptr)

Creates a new number parsing context with custom callbacks.

ut64 (RNum *num, const char *str)

Parses a string into a 64-bit unsigned integer, supporting various formats.

ut64 (RNum *num, const char *str)

Evaluates mathematical expressions in strings.

char * (char *buf, size_t len, ut64 number)

Formats a number with appropriate units (KB, MB, etc.).

BUFFERS

Create and manipulate in-memory buffers that support reading, writing, seeking and size queries — handy for temporary storage, streaming data between components, or abstracting underlying storage.

RBuffer * (void)

Creates a new buffer.

st64 (RBuffer *b, ut8 *buf, ut64 len)

Reads data from a buffer.

st64 (RBuffer *b, const ut8 *buf, ut64 len)

Writes data to a buffer.

st64 (RBuffer *b, st64 addr, int whence)

Seeks to a position in the buffer.

ut64 (RBuffer *b)

Returns the size of the buffer.

STRINGS

Common string helpers for allocation, concatenation, searching, replacement and splitting. They make safe text manipulation and higher-level processing simpler and less error-prone.

char * (const char *str)

Creates a new string (duplicate).

char * (char *str, const char *new)

Appends a string to another.

bool (const char *str, const char *needle)

Checks if a string starts with a prefix.

char * (char *str, const char *find, const char *replace, int *count)

Replaces substrings in a string.

RList * (char *str, const char *c, int n)

Splits a string into a list.

LISTS

Lightweight linked-list utilities for creating, appending, indexing and querying lists of pointers. Use these when a simple ordered collection is sufficient.

RList * (void)

Creates a new linked list.

void (RList *list, void *data)

Appends data to a list.

void * (RList *list, int n)

Gets the nth element from a list.

int (RList *list)

Returns the length of a list.

MEMORY

Convenience wrappers for allocating, duplicating and comparing raw memory blocks. These helpers centralize routine memory tasks and can be adapted for custom allocator hooks or debugging instrumentation.

void * (size_t sz)

Allocates memory.

void * (const void *src, size_t len)

Duplicates memory.

int (const void *a, const void *b, size_t len)

Compares memory regions.

FILES

Simple filesystem helpers to check existence, read entire files into memory, and write buffers to disk. Intended for straightforward file I/O needs in tools and utilities.

bool r_file_exists(const char *str)

Checks if a file exists.

char * r_file_slurp(const char *str, size_t *usz)

Reads an entire file into memory.

bool r_file_dump(const char *file, const ut8 *buf, int len, bool append)

Writes data to a file.

HEX

Routines to convert between hexadecimal text and binary data, commonly used when presenting or parsing hex-encoded blobs.

int (const char *str, ut8 *buf)

Converts a hex string to binary.

char * (const ut8 *bin, int len)

Converts binary data to a hex string.

BASE64

Utilities to encode binary data to base64 and decode it back, useful for transporting or embedding binary content in text contexts.

char * (const ut8 *bin, int len)

Encodes data to base64.

ut8 * (const char *str, int *olen)

Decodes base64 data.

TABLES

Helpers for building textual tables: create table objects, add columns and rows, and format output for display when presenting structured, columnar data.

RTable * (void)

Creates a new table.

void (RTable *t, RTableColumnType *type, const char *name, int maxwidth)

Adds a column to a table.

void (RTable *t, const char *name, ...)

Adds a row to a table.

GRAPHS

APIs to build and traverse basic graph structures made of nodes and edges. Suitable for representing relationships, control-flow, or dependency graphs.

RGraph * (void)

Creates a new graph.

RGraphNode * (RGraph *graph, void *data)

Adds a node to a graph.

void (RGraph *graph, RGraphNode *from, RGraphNode *to)

Adds an edge between nodes.

QUEUES

A compact FIFO queue API for enqueuing and dequeuing pointer elements; useful in producer/consumer patterns and simple task scheduling.

RQueue * (int n)

Creates a new queue.

void (RQueue *q, void *el)

Enqueues an element.

void * (RQueue *q)

Dequeues an element.

STACKS

A lightweight LIFO stack API for pushing and popping pointer elements, handy for depth-first traversals, undo stacks and transient state storage.

RStack * (ut32 n)

Creates a new stack.

void (RStack *s, void *el)

Pushes an element onto the stack.

void * (RStack *s)

Pops an element from the stack.

TIME

Helpers to obtain timestamps and format them as human-readable strings, used for logging, profiling and displaying time-related information.

ut64 (void)

Gets the current time in microseconds.

char * (ut64 ts)

Converts a timestamp to a string.

LOGGING

Minimal logging helpers to emit error and informational messages, acting as thin wrappers for diagnostics and user-facing feedback.

void (const char *fmt, ...)

Logs an error message.

void (const char *fmt, ...)

Logs an info message.

EXAMPLES

Number parsing:

RNum *num = r_num_new(NULL, NULL, NULL);
ut64 val = r_num_get(num, "0x100");
r_num_free(num);

String manipulation:

char *str = r_str_new("hello");
str = r_str_append(str, " world");

Buffer operations:

RBuffer *buf = r_buf_new();
r_buf_write(buf, data, len);
ut8 *read_data = malloc(len);
r_buf_read(buf, read_data, len);

List usage:

RList *list = r_list_new();
r_list_append(list, item);
void *first = r_list_get_n(list, 0);

SEE ALSO

r_types(3)

September 20, 2025 Debian