$npx -y skills add meltedinhex/analyst-ai-pack --skill automating-analysis-with-r2pipeAutomates radare2/rizin analysis through r2pipe to script function enumeration, string
| 1 | # Automating Analysis With r2pipe |
| 2 | |
| 3 | ## When to Use |
| 4 | |
| 5 | - You want to script radare2/rizin to extract functions, imports, strings, and cross-references |
| 6 | programmatically, across one or many samples. |
| 7 | - You are building a repeatable triage pipeline on top of r2's analysis commands. |
| 8 | |
| 9 | **Do not use** r2 to debug/run the sample here — this skill drives static analysis commands |
| 10 | (`aaa`, `aflj`, `izj`, `iij`). Run inside an isolated environment. |
| 11 | |
| 12 | ## Prerequisites |
| 13 | |
| 14 | - radare2 (or rizin) installed and the `r2pipe` Python package (the script degrades gracefully and |
| 15 | reports unavailability if absent). |
| 16 | |
| 17 | ## Safety & Handling |
| 18 | |
| 19 | - r2 static analysis does not execute the sample; keep the working directory isolated. |
| 20 | |
| 21 | ## Workflow |
| 22 | |
| 23 | ### Step 1: Confirm r2pipe availability |
| 24 | |
| 25 | ```bash |
| 26 | python scripts/analyst.py check |
| 27 | ``` |
| 28 | |
| 29 | Reports whether `r2pipe` and an `r2`/`rizin` binary are available. |
| 30 | |
| 31 | ### Step 2: Extract an analysis summary |
| 32 | |
| 33 | ```bash |
| 34 | python scripts/analyst.py summary sample.bin |
| 35 | ``` |
| 36 | |
| 37 | Opens the binary, runs analysis (`aaa`), and collects functions (`aflj`), imports (`iij`), and |
| 38 | strings (`izj`) as structured JSON. |
| 39 | |
| 40 | ### Step 3: Query cross-references |
| 41 | |
| 42 | For a function of interest, gather xrefs to/from to map call relationships. |
| 43 | |
| 44 | ### Step 4: Aggregate |
| 45 | |
| 46 | Combine per-sample summaries for comparison and signature development. |
| 47 | |
| 48 | ## Validation |
| 49 | |
| 50 | - The summary returns non-empty functions/imports for a normal binary. |
| 51 | - JSON commands (`*j`) are parsed, not screen-scraped text. |
| 52 | - Missing r2pipe/r2 is reported clearly rather than crashing. |
| 53 | |
| 54 | ## Pitfalls |
| 55 | |
| 56 | - Forgetting to run `aaa` before querying functions (empty results). |
| 57 | - Mixing radare2 and rizin command differences in scripted output. |
| 58 | - Very large binaries making `aaa` slow — scope analysis as needed. |
| 59 | |
| 60 | ## References |
| 61 | |
| 62 | - See [`references/api-reference.md`](references/api-reference.md) for the automation wrapper. |
| 63 | - r2pipe and radare2 command references (linked in frontmatter). |