R_EGG(3)
π NAME π
r_egg β the radare2 egg shellcode generation library. yes bestie, that's really what it's called. π₯β¨
β¨ SYNOPSIS β¨
#include <r_egg.h>
π¦ DESCRIPTION π¦
okay so the r_egg library gives radare2 the power to generate shellcode, which is genuinely iconic. you write shellcode in a high-level language, and it compiles that down to machine code. it supports multiple architectures and hands you a whole framework for creating, compiling, and executing shellcode. main character energy fr fr. π
the core structure is REgg, and it's the one holding everything together: source code, compiled binary, assembler, syscall information, and language parsing. she does it all. π
π± INITIALIZATION π±
this section is all about creating, initializing and freeing an REgg context, plus the little helpers that (re)configure the embedded language parser and the state used while compiling. setup era. π
REgg *r_egg_new(void)β creates a brand new egg context with default settings. fresh out the box. β¨void r_egg_free(REgg *egg)β frees all the resources tied to the egg context. everything. gone. π«Άvoid r_egg_reset(REgg *egg)β resets the egg context state so you can reuse it for a whole new compilation. recycling queen. πchar *r_egg_tostring(REgg *egg)β returns a textual representation of the egg internal state (for debugging). iykyk. πvoid r_egg_lang_init(REgg *egg)β initializes the embedded language parser state (egg->lang).void r_egg_lang_free(REgg *egg)β frees the resources that the embedded language parser allocated.bool r_egg_setup(REgg *egg, const char *arch, int bits, int endian, const char *os)β configures the egg context for the architecture, bitness, endianness and operating system you picked. arch, bits, endian, os β all four, no skipping. π«
π₯ LOADING CODE π₯
these are the functions that load egg source from strings or files, append fragments, and manage include paths plus ancillary source used during compilation. feeding the egg. π
void r_egg_load(REgg *egg, const char *code, int format)β loads source code into the egg context.formattells it the input style (egg/c).void r_egg_append(REgg *egg, const char *src)β appends extra source code onto the egg context. more is more. π
π¨ COMPILATION π¨
ngl, compilation is generally a two-step process: first you parse/compile the egg language into an intermediate representation, then you assemble that IR into machine code. this section lists helpers for both stages, plus utilities to grab assembly listings so you can inspect them. π§
bool r_egg_compile(REgg *egg)β compiles the loaded source code into intermediate representation.bool r_egg_assemble(REgg *egg)β assembles the compiled code into machine code. the glow-up stage. π₯bool r_egg_assemble_asm(REgg *egg, char **asm_list)β assembles the code and hands you the assembly listing inasm_list.
π EXECUTION π
functions that run the generated shellcode, either directly or through a ROP execution helper. frontends use these to invoke or emulate the generated payload. go bestie go!! π
int r_egg_run(REgg *egg)β executes the compiled shellcode.int r_egg_run_rop(REgg *egg)β executes the shellcode using ROP (Return-Oriented Programming) techniques. fancy. π
π€ OUTPUT π€
functions to access the compilation results: the raw binary buffer, the original source text, and the emitted assembly listing. frontends love these for printing, saving or further processing the artifacts. π¦
RBuffer *r_egg_get_bin(REgg *egg)β returns the compiled binary code as a buffer.char *r_egg_get_source(REgg *egg)β returns the source code.char *r_egg_get_assembly(REgg *egg)β returns the assembly representation of the compiled code.
π―οΈ SYSCALLS π―οΈ
helpers to insert syscall invocations and manage the syscall-related language state β argument marshaling, syscall table entries and emitted code. all of it. π«Ά
void r_egg_syscall(REgg *egg, const char *arg, ...)β adds a syscall instruction to the shellcode. it's a variadic, so bring your args. β¨
π§ MEMORY MANAGEMENT π§
functions to reserve and manipulate the data your generated code uses: allocate space, place strings, and manage small data patches emitted into the output buffer. π
void r_egg_alloc(REgg *egg, int n)β allocates memory in the shellcode.
π¦ CONTROL FLOW π¦
labeling, branching and conditional helpers that the egg language uses to implement control flow β labels, if/while blocks, and simple arithmetic operations. the plot structure of your shellcode. π
void r_egg_label(REgg *egg, const char *name)β defines a label in the shellcode.void r_egg_if(REgg *egg, const char *reg, char cmp, int v)β adds a conditional statement.
π§± RAW CODE π§±
low-level helpers to shove raw bytes or preassembled snippets directly into the output buffer β for when the high-level language can't express a pattern, or when hand-crafted machine code is the vibe. π
bool r_egg_raw(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 can pick from. choose your fighter. β
bool r_egg_encode(REgg *egg, const char *name)β applies an encoder to the shellcode.bool r_egg_shellcode(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. little touch-ups. π
bool r_egg_patch(REgg *egg, int off, const ut8 *b, int l)β patches the compiled binary at the specified offset. use-1for append. π
π PLUGINS π
the plugin framework that extends r_egg with shellcode generators and encoders. hosts discover and register plugin implementations, which then get invoked during the compilation or encoding phases. plug her in. πΈ
bool r_egg_plugin_add(REgg *a, REggPlugin *plugin)β adds an egg plugin (encoder or shellcode generator).bool r_egg_plugin_remove(REgg *a, REggPlugin *plugin)β removes an egg plugin.
βοΈ OPTIONS βοΈ
key/value configuration that controls compilation and encoding behavior β the selected encoder, padding, the chosen shellcode template, and auxiliary keys used by plugins. the settings menu, basically. ποΈ
void r_egg_option_set(REgg *egg, const char *k, const char *v)β sets an option for the egg context.char *r_egg_option_get(REgg *egg, const char *k)β gets an option value from the egg context.
π INCLUDES π
include helpers that load files or strings (like C headers or inline code) referenced by egg source. also holds the helpers that manage the include search paths the preprocessor uses. π§
bool r_egg_include(REgg *egg, const char *file, int format)β includes a file in the egg compilation.bool r_egg_include_str(REgg *egg, const char *arg)β includes a string in the egg compilation.void r_egg_lang_include_path(REgg *egg, const char *path)β adds an include path used by the egg preprocessor.void r_egg_lang_include_init(REgg *egg)β initializes include-related state (called at setup time by hosts).
π¬ FINALIZATION π¬
finalizers and convenience helpers you call after compilation to finish transformations, apply padding/encoders, and release temporary resources. the closing credits. π«Ά
void r_egg_finalize(REgg *egg)β finalizes the egg compilation process.void r_egg_printf(REgg *egg, const char *fmt, ...)β printf-style helper that appends formatted text to the current egg output (used by emitters/plugins during code generation).void r_egg_option_set(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 π
and that's the whole page, bestie!! this one came from Debian, dated September 20, 2025, and it lives in the manual as R_EGG(3). go write some shellcode, you absolute legend πβ¨π¦ππ
π
π¦ where this page comes from
- alpine 3.24: radare2-doc 6.1.6-r0 Β· GPL-3.0-or-later AND LGPL-2.0-or-later AND LGPL-2.1-or-later
- arch rolling: radare2 6.2.2-1 Β· GPL-3.0-only AND LGPL-3.0-only
- nixos 26.05: radare2 6.1.8
- 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
- ubuntu resolute: radare2 6.0.7+ds-1 Β· LGPL-3.0-only
- ubuntu stonking: radare2 6.1.8+ds-1 Β· LGPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms