R_UTIL(3)
๐ NAME ๐
Okay so bestie, meet r_util โ the radare2 utility library โ and this is its section 3 library-functions manual page. Itโs literally the utility drawer of radare2: number parsing, strings, buffers, memory stuff, file stuff, and a whole bunch of data structures. Slay.
โจ SYNOPSIS โจ
#include <r_util.h>
๐ฆ DESCRIPTION ๐ฆ
The r_util library is a comprehensive collection of utility functions for radare2, including number parsing, string manipulation, buffer management, memory operations, file handling, and various data structures. Itโs lowkey the foundation for many other radare2 libraries โ main character energy, fr fr.
๐ข NUMBERS ๐ข
Parse and format numeric values, convert textual representations into integers, recognize human-friendly unit suffixes, and evaluate simple mathematical expressions. Itโs giving handy for configuration parsing, user input handling, and preparing numbers for display. Obsessed.
RNum * r_num_new(RNumCallback cb, RNumCallback2 cb2, void *ptr)โ creates a new number parsing context with custom callbacks.ut64 r_num_get(RNum *num, const char *str)โ parses a string into a 64-bit unsigned integer, supporting various formats.ut64 r_num_math(RNum *num, const char *str)โ evaluates mathematical expressions in strings.char * r_num_units(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. The versatility is iconic.
RBuffer * r_buf_new(void)โ creates a new buffer.st64 r_buf_read(RBuffer *b, ut8 *buf, ut64 len)โ reads data from a buffer.st64 r_buf_write(RBuffer *b, const ut8 *buf, ut64 len)โ writes data to a buffer.st64 r_buf_seek(RBuffer *b, st64 addr, int whence)โ seeks to a position in the buffer.ut64 r_buf_size(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 โ no cap.
char * r_str_new(const char *str)โ creates a new string (duplicate).char * r_str_append(char *str, const char *new)โ appends a string to another.bool r_str_startswith(const char *str, const char *needle)โ checks if a string starts with a prefix.char * r_str_replace(char *str, const char *find, const char *replace, int *count)โ replaces substrings in a string.RList * r_str_split_list(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 โ itโs giving โjust the basics, but make it useful.โ
RList * r_list_new(void)โ creates a new linked list.void r_list_append(RList *list, void *data)โ appends data to a list.void * r_list_get_n(RList *list, int n)โ gets the nth element from a list.int r_list_length(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. Lowkey essential.
void * r_mem_alloc(size_t sz)โ allocates memory.void * r_mem_dup(const void *src, size_t len)โ duplicates memory.int r_mem_cmp(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 โ periodt.
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. Iykyk.
int r_hex_str2bin(const char *str, ut8 *buf)โ converts a hex string to binary.char * r_hex_bin2str(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. Text-mode glow-up.
int r_base64_encode(char *bout, const ut8 *bin, int len)โ encodes data to base64.int r_base64_decode(ut8 *bout, const char *bin, int len, bool strict)โ decodes base64 data. In strict mode any invalid character, misaligned length or misplaced padding fails with-1; otherwise invalid bytes are skipped and as much data as possible is recovered.ut8 * r_base64_decode_dyn(const char *in, int len, int *olen, bool strict)โ decodes base64 data into a heap-allocated buffer, returningNULLon strict decoding failures.
๐ช TABLES ๐ช
Helpers for building textual tables: create table objects, add columns and rows, and format output for display when presenting structured, columnar data. Itโs giving โorganized and cute.โ
RTable * r_table_new(void)โ creates a new table.void r_table_add_column(RTable *t, RTableColumnType *type, const char *name, int maxwidth)โ adds a column to a table.void r_table_add_row(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 โ main character data structure.
RGraph * r_graph_new(void)โ creates a new graph.RGraphNode * r_graph_add_node(RGraph *graph, void *data)โ adds a node to a graph.void r_graph_add_edge(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. First in, first out, slay.
RQueue * r_queue_new(int n)โ creates a new queue.void r_queue_enqueue(RQueue *q, void *el)โ enqueues an element.void * r_queue_dequeue(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. Last in, first out, iconic behavior.
RStack * r_stack_new(ut32 n)โ creates a new stack.void r_stack_push(RStack *s, void *el)โ pushes an element onto the stack.void * r_stack_pop(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. Time is literally passing.
ut64 r_time_now(void)โ gets the current time in microseconds.char * r_time_stamp_to_str(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. Not me being the group chatโs diagnostics queen.
void r_log_error(const char *fmt, ...)โ logs an error message.void r_log_info(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)
Cute sign-off bestie: this page came from Debian, dated September 20, 2025, and yes itโs the R_UTIL(3) manual page. Mwah ๐โจ
๐ฆ where this page comes from
- arch rolling: radare2 6.2.2-1 ยท GPL-3.0-only AND LGPL-3.0-only
- nixpkgs unstable: radare2 6.2.4
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 ยท GPL-3.0-only AND LGPL-3.0-only
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 ยท GPL-3.0-only AND LGPL-3.0-only
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 ยท GPL-3.0-only AND LGPL-3.0-only
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 ยท GPL-3.0-only AND LGPL-3.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms