binary-re-static-analysis
Use when analyzing binary structure, disassembling code, or decompiling functions. Deep static analysis via radare2 (r2) and Ghidra headless - function enumeration, cross-references (xrefs), decompilation, control flow graphs. Keywords - "disassemble", "decompile", "what does this function do", "find functions", "analyze code", "r2", "ghidra", "pdg", "afl"
What this skill does
# Static Analysis (Phases 2-3)
## Purpose
Understand binary structure and logic without execution. Map functions, trace data flow, decompile critical code.
## When to Use
- After triage has established architecture and ABI
- To understand specific functions identified as interesting
- When dynamic analysis is impractical or risky
- To build hypotheses before dynamic verification
## Pre-Analysis: Compare Known I/O First
**CRITICAL:** Before diving into disassembly, check if known inputs/outputs exist.
⚠️ **REQUIRES HUMAN APPROVAL** - Get explicit approval before any execution, even for I/O comparison.
```bash
# SAFE: Use emulation for cross-arch binaries (after human approval)
# ARM32:
qemu-arm -L /usr/arm-linux-gnueabihf -- ./binary < input.txt > actual.txt
# ARM64:
qemu-aarch64 -L /usr/aarch64-linux-gnu -- ./binary < input.txt > actual.txt
# Docker-based (macOS/cross-arch - see dynamic-analysis Option D):
docker run --rm --platform linux/arm/v7 -v ~/samples:/work:ro \
arm32v7/debian:bullseye-slim sh -c '/work/binary < /work/input.txt' > actual.txt
# x86-64 native (still requires approval):
./binary < input.txt > actual.txt
# Compare outputs:
diff expected.txt actual.txt
cmp -l expected.txt actual.txt | head -20 # Byte-level differences
# Record findings:
# - Where does output first diverge?
# - Does file size match? (logic bug vs truncation)
# - What pattern appears in corruption?
```
This step often reveals the bug category before any code analysis.
---
## Two-Stage Approach
**Stage 1 (Light):** Function enumeration, strings, imports - fast, broad coverage
**Stage 2 (Deep):** Targeted decompilation, CFG analysis - slow, focused
## Stage 1: Light Analysis (radare2)
### Analysis Depth Selection
| Binary Size | Command | Tradeoff |
|-------------|---------|----------|
| < 500KB | `aaa` | Full analysis, may be slow |
| 500KB - 5MB | `aa; aac` | Functions + all call targets |
| > 5MB | `aa` + targeted `af @addr` | Fast, manual depth control |
### Session Setup
```bash
# Launch r2 with controlled analysis
r2 -q0 -e scr.color=false -e anal.timeout=120 -e anal.maxsize=67108864 binary
# Inside r2 (choose based on binary size):
aa # Basic analysis
aac # Also analyze all call targets (recommended for most binaries)
```
**Critical settings:**
- `anal.timeout=120` - Prevent runaway analysis
- `anal.maxsize=67108864` - 64MB max function size
- Use `aa; aac` for medium binaries, `aaa` only for small ones
### Handling Unanalyzed Call Targets
If `axtj` returns empty for known imports:
```bash
# The import may be called indirectly or analysis was too shallow
# Option 1: Deeper analysis
aac # Analyze all calls
# Option 2: Manually create function at call target
af @0x8048abc
# Option 3: Search for references to import address
axtj @sym.imp.connect
```
### Function Enumeration
```bash
# All functions as JSON
aflj
# Filter by name pattern
aflj~main
aflj~init
aflj~network
aflj~send
aflj~recv
# Function count
afl~?
```
### Cross-Reference Analysis
```bash
# Who calls this function?
axtj @sym.imp.connect
# What does this function call?
axfj @sym.main
# Data references to address
axtj @0x12345
```
### String-Function Correlation
```bash
# Find which function contains a string
izj~api.vendor.com
# Note the vaddr, then find containing function
afi @0xVADDR
# Or search and map
"/j api" # Search for string
axtj @@hit* # Xrefs to all hits
```
### Import/Export Mapping
```bash
# Imports with addresses
iij
# Exports with addresses
iEj
# Symbols (if not stripped)
isj
```
### Quick Disassembly
```bash
# Disassemble function as JSON
pdfj @sym.main
# Disassemble N instructions from address
pdj 20 @0x8400
# Print function summary
afi @sym.main
```
## Stage 2: Deep Analysis
### r2ghidra Availability Check
**Before attempting decompilation, verify r2ghidra is installed:**
```bash
# Check if r2ghidra is available
r2 -qc 'pdg?' - 2>/dev/null | grep -q Usage && echo "r2ghidra OK" || echo "SKIP: r2ghidra not installed"
# If missing, install with:
r2pm -ci r2ghidra
```
**If r2ghidra unavailable:** Rely on disassembly (`pdf`) and cross-reference analysis (`axt/axf`).
### Targeted Decompilation (r2ghidra)
```bash
# Decompile specific function
pdgj @sym.target_function
# Or named function
pdgj @sym.main
```
### Ghidra Headless (Large Binaries)
For complex functions or when r2ghidra struggles:
```bash
# Create analysis project and run script
analyzeHeadless /tmp/ghidra_proj proj \
-import binary \
-overwrite \
-processor ARM:LE:32:v7 \
-postScript ExportDecompilation.java sym.target_function \
-deleteProject
```
**Processor strings:**
- ARM 32-bit: `ARM:LE:32:v7` or `ARM:LE:32:Cortex`
- ARM 64-bit: `AARCH64:LE:64:v8A`
- x86_64: `x86:LE:64:default`
- MIPS LE: `MIPS:LE:32:default`
- MIPS BE: `MIPS:BE:32:default`
### Control Flow Analysis
```bash
# Basic blocks in function
afbj @sym.main
# Function call graph (dot format)
agCd @sym.main > callgraph.dot
# Control flow graph
agfd @sym.main > cfg.dot
```
### Data Structure Recovery
```bash
# Analyze local variables
afvj @sym.main
# Stack frame layout
afvd @sym.main
# Global data references
adrj
```
## Analysis Patterns
### Pattern: Network Function Tracing
```bash
# Find all network-related calls
axtj @sym.imp.socket
axtj @sym.imp.connect
axtj @sym.imp.send
axtj @sym.imp.recv
axtj @sym.imp.SSL_read
axtj @sym.imp.SSL_write
# Trace caller chain
for func in $(aflj | jq -r '.[].name'); do
axfj @$func | grep -q "socket\|connect" && echo $func
done
```
### Pattern: Configuration File Analysis
```bash
# Find file operations
axtj @sym.imp.open
axtj @sym.imp.fopen
# Trace string arguments
"/j /etc"
"/j .conf"
"/j .json"
# Check what functions reference these paths
```
### Pattern: Crypto Identification
```bash
# Common crypto imports
axtj @sym.imp.EVP_EncryptInit
axtj @sym.imp.AES_encrypt
axtj @sym.imp.SHA256
# Hardcoded keys (check strings near crypto calls)
izj | jq '.strings[] | select(.length == 16 or .length == 32)'
```
## r2 JSON Commands Reference
| Command | Output | Use Case |
|---------|--------|----------|
| `aflj` | Functions list | Map code structure |
| `axtj @addr` | Xrefs TO address | Who uses this? |
| `axfj @addr` | Xrefs FROM address | What does it call? |
| `pdfj @addr` | Disassembly | Understand instructions |
| `pdgj @addr` | Decompilation | Pseudo-C output |
| `afbj @addr` | Basic blocks | Control flow |
| `izj` | Data strings | Configuration, URLs |
| `iij` | Imports | External dependencies |
| `iEj` | Exports | Public interface |
| `afvj @addr` | Local variables | Stack analysis |
## Output Format
Record analysis findings as structured facts:
```json
{
"functions_analyzed": [
{
"name": "sub_8400",
"address": "0x8400",
"size": 256,
"calls": ["socket", "connect", "send"],
"called_by": ["main", "init_network"],
"strings_referenced": ["api.vendor.com"],
"hypothesis": "network_initialization"
}
],
"call_graph": {
"main": ["init_config", "init_network", "main_loop"],
"init_network": ["sub_8400", "SSL_CTX_new"]
},
"data_flow": [
{
"source": "config_file_read",
"through": ["parse_config", "extract_url"],
"sink": "connect_to_server"
}
]
}
```
## Knowledge Journaling
After static analysis, record findings for episodic memory:
```
[BINARY-RE:static] {filename} (sha256: {hash})
Functions analyzed: {count}
Decompilation performed: {yes|no}
Key functions:
FACT: Function at {addr} calls {imports} (source: r2 axfj)
FACT: Function at {addr} references string "{string}" (source: r2 axtj)
FACT: Function {name} appears to {purpose} (source: decompilation)
Cross-references:
FACT: {caller} calls {callee} (source: r2 axtj)
HYPOTHESIS UPDATE: {refined theory} (confidence: {new_value})
Supporting: {fact_ids}
Contradicting: {fact_ids}
New questions:
QUESTION: {discovered unknown}
Answered questions:
RESOLVED: {question} → {anRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.