Scroll to navigation

R_EGG(3) Library Functions Manual R_EGG(3)

NAME

r_eggradare2 egg shellcode generation library

SYNOPSIS

#include <r_egg.h>

DESCRIPTION

The r_egg library provides shellcode generation capabilities for radare2, allowing users to write shellcode in a high-level language and compile it to machine code. It supports multiple architectures and provides a framework for creating, compiling, and executing shellcode.

The core structure is REgg, which manages source code, compiled binary, assembler, syscall information, and language parsing.

INITIALIZATION

This section describes functions to create, initialize and free an REgg context and contains helpers to (re)configure the embedded language parser and state used during compilation. REgg * (void)

Creates a new egg context with default settings.

void (REgg *egg)

Frees all resources associated with the egg context. Pp void (REgg *egg)

Resets the egg context state so it can be reused for a new compilation.

char * (REgg *egg)

Returns a textual representation of the egg internal state (for debugging).

void (REgg *egg)

Initializes the embedded language parser state (`egg->lang`).

void (REgg *egg)

Frees resources allocated by the embedded language parser.

bool (REgg *egg, const char *arch, int bits, int endian, const char *os)

Configures the egg context for the specified architecture, bitness, endianness, and operating system.

LOADING CODE

Functions to load egg source from strings or files, append fragments, and manage include paths and ancillary source used during compilation. void (REgg *egg, const char *code, int format)

Loads source code into the egg context. `format` indicates input style (egg/c).

void (REgg *egg, const char *src)

Appends additional source code to the egg context.

COMPILATION

Compilation is generally a two-step process: parse/compile the egg language into an intermediate representation, then assemble that IR into machine code. This section lists helpers for both stages and utilities to obtain assembly listings for inspection. bool (REgg *egg)

Compiles the loaded source code into intermediate representation.

bool (REgg *egg)

Assembles the compiled code into machine code.

bool (REgg *egg, char **asm_list)

Assembles the code and returns the assembly listing in `asm_list`.

EXECUTION

Functions that run the generated shellcode either directly or via a ROP execution helper; frontends use these to invoke or emulate the generated payload. int (REgg *egg)

Executes the compiled shellcode.

int (REgg *egg)

Executes the shellcode using ROP (Return-Oriented Programming) techniques.

OUTPUT

Functions to access compilation results: the raw binary buffer, the original source text, and the emitted assembly listing. These are commonly used by frontends to print, save or further process the produced artifacts. RBuffer * (REgg *egg)

Returns the compiled binary code as a buffer.

char * (REgg *egg)

Returns the source code.

char * (REgg *egg)

Returns the assembly representation of the compiled code.

SYSCALLS

Helpers to insert syscall invocations and to manage syscall-related language state (argument marshaling, syscall table entries and emitted code). void (REgg *egg, const char *arg, ...)

Adds a syscall instruction to the shellcode.

MEMORY MANAGEMENT

Functions to reserve and manipulate data used by generated code: allocate space, place strings and manage small data patches emitted into the output buffer. void (REgg *egg, int n)

Allocates memory in the shellcode.

CONTROL FLOW

Labeling, branching and conditional helpers used by the egg language to implement control flow constructs such as labels, if/while blocks and simple arithmetic operations. void (REgg *egg, const char *name)

Defines a label in the shellcode.

void (REgg *egg, const char *reg, char cmp, int v)

Adds a conditional statement.

RAW CODE

Low-level helpers to insert raw bytes or preassembled snippets directly into the output buffer for cases where the high-level language cannot express a pattern or when hand-crafted machine code is required. bool (REgg *egg, const ut8 *b, int len)

Inserts raw binary code into the shellcode.

ENCODING

Encoder and shellcode-template helpers. Encoders transform the produced binary (for obfuscation or packing) while shellcode templates provide parameterizable payloads and generators that frontends may select. bool (REgg *egg, const char *name)

Applies an encoder to the shellcode.

bool (REgg *egg, const char *name)

Generates shellcode using a specific shellcode template.

PATCHING

Binary patching helpers to apply small modifications to the compiled output (bytes, words, qwords). The CLI uses these to apply user-specified patches before finalizing output. bool (REgg *egg, int off, const ut8 *b, int l)

Patches the compiled binary at the specified offset. Use `-1` for append.

PLUGINS

The plugin framework used to extend r_egg with shellcode generators and encoders. Hosts discover and register plugin implementations which are then invoked during compilation or encoding phases. bool (REgg *a, REggPlugin *plugin)

Adds an egg plugin (encoder or shellcode generator).

bool (REgg *a, REggPlugin *plugin)

Removes an egg plugin.

OPTIONS

Key/value configuration used to control compilation and encoding behavior (selected encoder, padding, chosen shellcode template and auxiliary keys used by plugins). void (REgg *egg, const char *k, const char *v)

Sets an option for the egg context.

char * (REgg *egg, const char *k)

Gets an option value from the egg context.

INCLUDES

Include helpers to load files or strings (for example C headers or inline code) referenced by egg source. Also contains helpers to manage include search paths used by the preprocessor. bool (REgg *egg, const char *file, int format)

Includes a file in the egg compilation.

bool (REgg *egg, const char *arg)

Includes a string in the egg compilation.

void (REgg *egg, const char *path)

Adds an include path used by the egg preprocessor.

void (REgg *egg)

Initializes include-related state (called at setup time by hosts).

FINALIZATION

Finalizers and convenience helpers called after compilation to finish transformations, apply padding/encoders and release temporary resources. void (REgg *egg)

Finalizes the egg compilation process.

void (REgg *egg, const char *fmt, ...)

Printf-style helper to append formatted text to the current egg output (used by emitters/plugins during code generation).

void (REgg *egg, const char *k, const char *v)

Helper noted above; kept here to emphasize lifecycle usage by frontends.

EXAMPLES

Basic shellcode generation:

REgg *egg = r_egg_new();
r_egg_setup(egg, "x86", 32, 0, "linux");
r_egg_load(egg, "write(1,
r_egg_compile(egg);
r_egg_assemble(egg);
RBuffer *bin = r_egg_get_bin(egg);

Using syscalls:

r_egg_syscall(egg, "exit", 0);

Adding raw code:

ut8 code[] = {0x90, 0x90}; // NOP NOP
r_egg_raw(egg, code, 2);

SEE ALSO

r_asm(3), r_syscall(3)

September 20, 2025 Debian