| name | r2frida |
| description | Use this skill for dynamic binary analysis combining radare2 static analysis with Frida's runtime instrumentation. Triggers include any mention of r2frida, dynamic instrumentation, runtime analysis, memory hooking, function tracing,n runtime manipulation, live debugging, or combining radare2 with Frida. Also use when the user needs to trace function calls, hook native functions, dump memory at runtime, modify return values, search memory patterns in running processes, or analyze obfuscated mobile applications. |
r2frida Dynamic Analysis Guide
Overview
r2frida is a radare2 plugin that bridges static analysis capabilities of radare2 with Frida's dynamic instrumentation. This allows you to analyze running processes, hook functions, trace calls, modify memory, and manipulate program execution in real-time.
Important: In current versions of r2frida, commands start with : (colon) instead of the legacy \ (backslash). Both =! and : prefixes work, but : is preferred.
Installation
r2pm -ci r2frida
r2 frida://0
:?V
Connection Methods
URI Syntax
r2 frida://[action]/[link]/[device]/[target]
Actions: list | apps | attach | spawn | launch
Links: local | usb | remote host:port
Device: '' | host:port | device-id
Target: pid | appname | process-name | program-path
Local Process Analysis
r2 frida://
r2 frida://0
r2 frida:///usr/bin/ls
r2 "frida:///usr/bin/wget google.com"
r2 frida://attach/local//1234
r2 frida://notepad.exe
Android Device Analysis
r2 frida://list/usb//
r2 frida://apps/usb//
r2 frida://attach/usb//12345
r2 frida://spawn/usb//com.target.app
r2 frida://launch/usb//com.target.app
r2 frida://spawn/usb/DEVICE_ID/com.target.app
iOS Device Analysis
r2 frida://list/usb//
r2 frida://spawn/usb//com.example.app
r2 frida://attach/usb//Gadget
Remote Frida Server
r2 frida://attach/remote/192.168.1.100:27042/target
Core Commands Reference
Getting Help
:? Show all r2frida commands
:?V Show Frida version as JSON
Information Commands (:i)
:i Target information (arch, bits, os, pid, etc.)
:i* Target information in radare2 format
.:i* Import target info into radare2 session
:il List loaded libraries/modules
:il. Show library at current offset
:ii List all imports
:ii <lib> List imports of specific library
:ii* <lib> List imports in radare2 format
:iE List all exports (WARNING: large output)
:iE <lib> List exports of specific library
:iE* <lib> Exports in radare2 format
.:iE* <lib> Import exports as flags
:iEa <lib> <sym> Get address of export symbol
:iEa* <lib> <sym> Get address in radare2 format
:is <lib> List symbols (local and global)
:isa <sym> Get address of symbol
:isa <lib> <sym> Get address of symbol in library
Objective-C / Swift Commands
:ic List all Objective-C classes
:ic <class> List methods of class
:ic* Classes in radare2 format
:ip List all protocols
:ip <protocol> List methods of protocol
Java / Android Commands
:icj List Java classes (Android)
:icj <class> List methods of Java class
Memory Commands (:dm)
:dm Show memory regions (like /proc/PID/maps)
:dm. Show memory region at current offset
:dm. @ addr Show memory region containing address
:dmj Memory regions as JSON
:dm* Memory regions as radare2 flags
:dmm List named/squashed maps
:dmh List heap chunks
:dmhj Heap chunks as JSON
:dmh* Heap chunks as radare2 flags
:dmhm Show maps used for heap allocation
:dma <size> Allocate bytes on heap, returns address
:dmas <string> Allocate string on heap, returns address
:dmad <addr> <size> Allocate and copy from address
:dmal List live allocations from dma/dmas
:dma- [addr] Free allocation (all if no addr)
:dmp <addr> <size> <perms> Change memory protection (rwx)
Search Commands (:\/)
:\/ <string> Search string in memory
:\/j <string> Search with JSON output
:\/x <hex> Search hex pattern
:\/xj <hex> Search hex with JSON output
:\/w <string> Search wide string (UTF-16)
:\/v4 <value> Search 4-byte value
:\/v8 <value> Search 8-byte value
Debugging Commands (:d)
:dp Show current PID
:dpt List threads
:dr Show thread registers
:db <addr|sym> Set breakpoint
:db List breakpoints
:db- <addr> Remove breakpoint
:db- * Remove all breakpoints
:dc Continue execution / resume spawned process
:dd List file descriptors
:dd- <fd> Close file descriptor
:dd <fd> <newfd> Duplicate file descriptor (dup2)
Tracing Commands (:dt)
:dt <addr|sym> Add trace at address/symbol
:dt- [addr] Remove trace (all if no addr)
:dth <addr> <args> Define trace with argument types
Types: z=string, i=int, v=hex array, s=byte array
:dtf <addr> <fmt> Trace with format specifiers
:dtf? Show format help
:dtr <addr> <regs> Trace register values
:dtSf <addr> Trace with Stalker (code tracing)
:dtS <seconds> Trace all threads with Stalker
Trace Format Specifiers (:dtf)
^ Trace onEnter instead of onExit
+ Show backtrace
p/x Show pointer in hexadecimal
c Show value as char
i Show decimal integer
z Show pointer to UTF-8 string
w Show pointer to UTF-16 string
a Show pointer to ANSI string
h Hexdump from pointer (h16 = 16 bytes)
H Hexdump with length from argument (H1 = args[1] bytes)
s Show string in place
O Show pointer to ObjC object
Interceptor Commands (:di)
:di? Interceptor help
:di0 <addr> Make function return 0
:di1 <addr> Make function return 1
:di-1 <addr> Make function return -1
:dii <addr> Intercept and return custom int
:dis <addr> Intercept and return custom string
:div <addr> Intercept as void
:dif0 <addr> Replace function return with 0
:dif1 <addr> Replace function return with 1
:dif-1 <addr> Replace function return with -1
Function Call Commands (:dx)
:dxc <addr> [args...] Call function at address with arguments
:dxo <sel> [args...] Call Objective-C method
:dxs <num> [args...] Perform syscall
Script Loading (:\.)
:. <script.js> Load and run Frida script
:. List loaded plugins
:.- <name> Unload plugin
:.. <script.js> Eternalize script (survives detach)
:eval <code> Evaluate JavaScript in agent
Environment Variables
:env List all environment variables
:env <var> Get specific variable
:env <var>=<val> Set variable
Configuration (:e)
:e List evaluable variables
:e <var>=<val> Set configuration
# Available variables:
patch.code=true Enable code patching
search.in=perm:r-- Memory search permissions
search.quiet=false Quiet search output
stalker.event=compile Stalker event type
stalker.timeout=300 Stalker timeout
stalker.in=raw Stalker input mode
Library Loading
:dl <libname> dlopen a library
:dl2 <libname> Inject library (Frida >= 8.2)
Practical Examples
Example 1: Basic Target Analysis
:i
.:i*
:il
:il~crypto
:il~ssl
Example 2: Finding and Tracing Functions
:dm~wget
s 0x560be7abb000
:iE~open
:iE~fopen
:dm~libc
:iE libc~fopen
:dt <fopen_address> z^
:dtf <fopen_address> z^
Example 3: Function Tracing with Arguments
:dtf 0x7ff0a9e37de0 zz^+
:dc
Example 4: Tracing strcmp for Password Analysis
:dm~libc
:iEa libc.so strcmp
:dt strcmp
:dtf strcmp zz
:dc
Example 5: Memory Search
:\/ "root"
:\/x 7f454c46
:\/v4 1234
:\/j "password"
Example 6: Heap Manipulation
:dmas "injected_string"
:dma 256
:dmal
:dma- 0x7fd21c121cb0
Example 7: Calling Functions Dynamically
:iEa libc.so system
:dmas "id"
:dxc 0x7f12345678 0xaabbccdd
Example 8: Return Value Manipulation
:ic~Jailbreak
:ic JailbreakDetection
:iEa AppBinary isJailbroken
:di0 0x100123456
:eval Interceptor.attach(ptr(0x100123456), {onLeave: function(retval) {retval.replace(0x0)}})
Example 9: iOS Class Analysis
r2 frida://spawn/usb//com.example.app
:dc
:ic~ViewController
:ic LoginViewController
:iEa AppBinary "-[LoginViewController validatePassword:]"
:dtf 0x100045678 O^
Example 10: Android Native Library Analysis
r2 frida://spawn/usb//com.target.app
:dm~libnative
:iE libnative.so~JNI
:dt `iEa libnative.so JNI_OnLoad`
:dth `iEa libnative.so JNI_OnLoad` v
:dc
Example 11: Anti-Debug Bypass
:dt ptrace
:dth ptrace i i i i
:di0 `iEa libc.so ptrace`
:. antiroot.js
:dc
Example 12: Dynamic Disassembly
:dm~target
s 0x55bf4aefa000
? 0x55bf4aefa000 + 0x71a
af @ 0x55bf4aefa71a
pdf @ 0x55bf4aefa71a
Example 13: SSL Pinning Bypass Analysis
:iE libssl~verify
:iE libssl~SSL_CTX
:dt SSL_CTX_set_verify
:dtf `iEa libssl.so SSL_CTX_set_verify` ii^+
:dc
Example 14: Breakpoint Debugging
:db `iEa libc.so strcmp`
:dc
:dr
:dc
:db- `iEa libc.so strcmp`
Example 15: Custom Frida Script Integration
r2frida.pluginRegister('myhook', function(name) {
if (name === 'myhook') {
return function(args) {
var target = args[0];
Interceptor.attach(ptr(target), {
onEnter: function(args) {
console.log("Called with: " + args[0]);
},
onLeave: function(retval) {
console.log("Returned: " + retval);
}
});
return "Hook installed at " + target;
}
}
});
:. agent.js
:myhook 0x12345678
Workflow Tips
Importing Dynamic Data to radare2
.:i*
.:iE* libtarget.so
.:ii* libtarget.so
afl
pdf @ sym.func
Using r2 Internal Grep
:il~ssl
:dm~r-x
:iE libc~strcmp
:ic~View
:dm~ssl[0]
:iE libc~open[0,2]
Combining Static and Dynamic Analysis
r2 -A target.so
afl
pdf @ main
r2 frida://spawn/usb//com.target.app
:dm~target.so
Error Handling
:?V
:dkr
:il~module_name
:dm. @ 0xaddress
Security Research Patterns
Root/Jailbreak Detection Bypass
- Find detection functions via class/method enumeration
- Trace to confirm they're called
- Use
:di0 or :di1 to manipulate returns
- Or load comprehensive bypass script
Certificate Pinning Analysis
- Find SSL/TLS related exports
- Trace verification functions
- Identify where pinning occurs
- Hook and modify as needed
Native Library Analysis
- Find library load address with
:dm
- List exports with
:iE
- Trace interesting functions with
:dtf
- Analyze call patterns and arguments
Quick Reference Card
| Task | Command |
|---|
| Show help | :? |
| Target info | :i |
| List libraries | :il |
| List exports | :iE <lib> |
| Find export address | :iEa <lib> <sym> |
| Memory map | :dm |
| Search string | :\/ <str> |
| Allocate string | :dmas <str> |
| Trace function | :dtf <addr> <fmt> |
| Set breakpoint | :db <addr> |
| Continue | :dc |
| Call function | :dxc <addr> [args] |
| Return 0 | :di0 <addr> |
| Return 1 | :di1 <addr> |
| Load script | :. script.js |
| Eval JS | :eval <code> |