Add memory allocation support to Binary Ninja Debugger
This PR implements comprehensive memory allocation and deallocation functionality for the Binary Ninja Debugger, allowing users to allocate memory buffers in target processes during debugging sessions.
Overview
The implementation adds AllocateMemory() and FreeMemory() methods across all debugger adapters, providing a unified interface for dynamic memory management in target processes. This enables advanced debugging scenarios including memory patching, dynamic analysis, and runtime data injection.
Key Features
-
Universal API: Added pure virtual methods to
DebugAdapterbase class with consistent interface across all adapters -
Smart Implementation: Each adapter uses the most appropriate allocation method:
-
LLDB: Native
SBProcess::AllocateMemory/DeallocateMemoryAPIs - RSP-based (GDB, Corellium, LldbRsp, ESReven): GDB remote protocol monitor commands
- Read-only adapters: Appropriate failure responses for core dumps and TTD traces
-
LLDB: Native
-
Thread Safety: Full support through
QueuedAdapterwith proper operation queuing - Complete API Integration: C++ core, FFI bindings, and Python API with documentation
Usage Example
# Allocate 1KB with read/write/execute permissions
addr = dbg.allocate_memory(1024, 0x7)
if addr != 0:
# Write data to allocated memory
dbg.write_memory(addr, b"Hello, World!")
# Read it back
data = dbg.read_memory(addr, 13)
# Clean up
dbg.free_memory(addr)
Implementation Details
- Permissions: Standard memory protection flags (default 0x7 for read/write/execute)
-
Return Values:
AllocateMemory()returns 0 on failure, allocated address on success - Error Handling: Graceful handling of unsupported adapters and network failures
- Testing: Comprehensive unit test covering allocation, I/O operations, and cleanup
Adapter Support
| Adapter | Support | Implementation |
|---|---|---|
| LldbAdapter | ✅ Full | Native LLDB APIs |
| GDB/Corellium/LldbRsp/ESReven | ✅ Partial | RSP monitor commands |
| DbgEng/CoreDump/TTD | ❌ N/A | Returns failure (read-only/unsupported) |
The implementation maintains full backward compatibility and provides a solid foundation for advanced debugging workflows.
Fixes #404.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.