mirror of
https://github.com/radareorg/r2flutter.git
synced 2026-11-07 06:26:00 -10:00
4.4 KiB
4.4 KiB
Agent Notes for r2flutter Work
Scope
- This document is for agents working in this repo to implement and iterate on the Dart AOT snapshot/ObjectPool parser and CLI.
Build
- Requires radare2 (
r2binary in PATH) to resolve include/link flags viar2 -H. - Do NOT use
pkg-config— the build system usesr2 -H R2_CFLAGSandr2 -H R2_LDFLAGSinstead. - Build with
make(usesr2 -Hto resolve r2 includes/libs). - Do not build with gcc oneliners, always use
make - Run
make fmtto format/indent the source code - To update the version change it in configure.acr and then run autogen.sh
- running meson or configure will generate the version.h from the version.h.in
Usage
- Use bin/r2flutter cli program to test the changes and implementation of the dart aot snapshots
- Update doc/learn.md to record anotations and important findings and discoveries while solving more tasks
- When using radare2 to read the raw contents of a file you should use
r2 -nto not load the sections and actually read physical address instead of the virtual mapped ones.
Coding Rules
R_NEW/R_NEW0macros never return NULL- Do not check for null before calling free methods
r_list_new/r_list_newfdo not return NULL here; do not add defensive null checks after creating listsr_list_freeaccepts NULL; call it directly instead of wrapping it inif (x) { ... }r_list_containsis pointer-based; for string-content lookups user_list_find (..., (RListComparator)strcmp)instead- The
r_json_parsedoes not own the string passed, we must free it after freeing the parser - Prefer
R_STR_ISEMPTY/R_STR_ISNOTEMPTYover hand-written!s || !*schecks - Prefer
r_str_startswith/r_str_endswithoverstrncmpprefix checks or localendswithhelpers - Prefer
isupper,islower,isdigit, andisalphaover manual ASCII range checks - When rendering string lists, prefer helpers like
r_str_list_joininstead of open-coded separator loops - Function calls require a space before the parenthesis. (p.ex: Use
foo ()instead offoo()) - Use tabs instead of spaces to indent the code
- Follow the
radare2coding style
Core plugin
- The -q, -j and -r flags are modifiers, all commands that print stuff must be modified to print quiet, json or r2 commands
- Help message of the core plugin must include the
r2flutterprefix, not just the flag
Reference Sources
- Third party code is found in the
./third_partydirectory - radare2 source code
./third_party/radare2see thelibr/includedirectory for the headers - blutter is the original project in python+c++ that we used as inspiration for this project. the source code is in
./third_party/blutter - dart and its VM are also available in there
Tests
- Uses r2r to run tests in
test/db. - The
test/binsdirectory contains android and ios binaries for testing the implementation - Run with
make testwhich wrapsr2r test/dbin a Python timeout (180s) to avoid hanging on heavy samples. - Add each new test as a single file under
test/db/cmd/.- Example:
test/db/cmd/json-androidruns the CLI and expects a single JSON line.
- Example:
- It's important to ensure the behaviour is correct on both iOS and Android binaries before accepting a fix
CLI Flags (debugging)
-v/-vv: increase stderr verbosity for snapshot discovery.-j -H: emit one JSON line with snapshot + cluster info.-i: print InstructionTable entries to stdout. Supports plain text,-j, and-r.-q: suppress non-essential stdout (handy for JSON-only tests).
Function dumps skip loader-provided ELF/Mach-O stub symbols by default; rely on plain r2/RBin for those and keep r2flutter focused on Dart-derived names.
Iteration Loop
- Implement a focused change (parser or flags), build with
make. - Add a minimal r2r test exercising the new behavior under
test/db/cmd/. - Run
make testto validate. If it times out, reduce test output (use-q). - When failures occur, use the debug flags (
-v,-vv,-i) and small inputs to triage. Adjust parser heuristics accordingly. - Keep tests deterministic: prefer single-line stable outputs and avoid large dumps.
Parser Notes
- Snapshot discovery prefers symbol names, then falls back to section scan+magic.
- InstructionTable decoding reconstructs entrypoints for AOT bare-instructions.
- Offsets/layout can be enriched via
offsets.jsonkeyed by snapshot hash. - Keep memory reads bounded and walk headers conservatively to avoid large reads.
Links Of Interest: