radare2 is a modular reverse engineering framework.
- Header files:
./libr/include - Manpages:
./man/ - Plugins:
./libr/*/p/subdirectories - Test binaries: Separate
radare2-testbinsrepository (cloned into./test/binsby r2r) - Test files:
./test/db/. Source files can use// R2Rcomments to reference tests
Do not run clang-format-radare2 unless clearly specified by the user.
Follow the already existing and defined coding style.
Optionally run sys/lint.sh script if you are unsure about the linter.
- Indent code with tabs, spaces for comments and no trailing spaces
- Space before opening parenthesis:
if (a),foo (),sizeof (int) - Function signatures do not require a space before
(and must fit in one line - Always use braces
{}for conditionals, even single statements - Switch
caselabels column-aligned with theswitchkeyword - Declare and assign variables in the same line if possible (No K&R style); they do not need to be grouped at the beginning of the block
- No C99
for (int i = ...)declarations; declare variables before the loop - Use
R_PACKED()macro for packed structures for portability - Use types from
<r_types.h>(ut8,ut16,ut32,ut64) instead of<stdint.h> - Use
PFMT64macros instead of%lldfor portable formatting
R_NEW/R_NEW0never return NULL; no null checks needed for small constant allocations- Check for integer overflow before large allocations using
r_mul_overflow_* - Never use
alloca()or variable-length stack arrays - Do not check for NULL before calling
free()or*_freefunctions r_json_parsedoes not own the input string; free it after freeing the parser
- Use
R_RETURN_*macros in publicR_APIfunctions for programming error checks - Use standard
ifstatements for runtime error checks (e.g., malloc failures) - Never use
<assert.h>; use"r_util/r_assert.h" - Prefer
!strcmp ()overstrcmp () == 0 - Use string and memory parsing functions from
libr/utilbefore libc if possible:- Use
r_str_newfinstead of manual malloc + snprintf - Use
r_strbuf_*for string concatenation in loops; avoidr_str_append - Use
r_str_pad2to create repeated character strings - Use
r_read_be32/r_read_le32for endian-safe reads
- Use
- Handle the
?subcommand to display help - Keep functions short; split complex logic into helper functions
- Use
R_LOG_*APIs for user-facing messages - Only use
eprintfduring draft/wip development for debugging purposes - Use the
R2_DEBUG=1environment to catch bugs during testing
Use these macros to document function parameters:
R_OUT: output parameter (written to)R_INOUT: read/write parameterR_OWN: ownership transferred to calleeR_BORROW: caller retains ownershipR_NONNULL: pointer must not be nullR_NULLABLE: pointer may be nullR_DEPRECATED: do not use in new code
- Never run
gccdirectly; always usemake -j > /dev/null - Do not build
.ofiles separately sudo make symstallcreates symlinked system-wide installation- Symlinks ensure working directory builds work as system installations
- The
./configurescript is generated withacrfrom the configure.acr- Never modify the
configurescript directly. always autogenerate it
- Never modify the
- For new library dependencies, update both
Makefileandmeson.build - For new plugins, register in:
dist/plugins-cfg/plugins.def.cfgdist/plugins-cfg/plugins.static.cfg- Relevant
libr/*/meson.buildplugin list
- When running
r2oneliners take this into account:- The filename to open must be always the last argument
- Use the
-nflag to avoid loading binary headers and read the plain file- Similar IO behaviour can be achieved with
-e io.va=false
- Similar IO behaviour can be achieved with
- Run the
test/dbtests withr2r <path/to/db/..> - Source files can reference tests with
// R2Rcomments - Large test binaries belong in
radare2-testbinsrepository, not this repo - Run
sys/sanitize.shto compile with address sanitizer for memory debugging
Do not create commits by yourself. Instead, at the end of your work suggest a one-line commit message following these conventions:
- Start with a capital letter
- If the change is relevant for the users and must be listed in the release changelog:
- Append one double-hash tag as the last word in the message
- Tags are lowercase, alphabetic only (no numbers or symbols)
- When in doubt; check
git logto find examples of other commits. - Security vulnerabilities must be tagged with
##crash - Available tags:
abi,analysis,arch,asm,bin,ci,cons,core,crash,debug,doc,esil,fs,http,io,r2js,lang,print,project,r2pipe,r2r,search,shell,threads,tools,trace,types,util,visual,zign