debugger icon indicating copy to clipboard operation
debugger copied to clipboard

Add memory allocation support to Binary Ninja Debugger

Open Copilot opened this issue 5 months ago • 1 comments

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 DebugAdapter base class with consistent interface across all adapters
  • Smart Implementation: Each adapter uses the most appropriate allocation method:
    • LLDB: Native SBProcess::AllocateMemory/DeallocateMemory APIs
    • RSP-based (GDB, Corellium, LldbRsp, ESReven): GDB remote protocol monitor commands
    • Read-only adapters: Appropriate failure responses for core dumps and TTD traces
  • Thread Safety: Full support through QueuedAdapter with 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.

Copilot avatar Sep 03 '25 10:09 Copilot

CLA assistant check
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.

CLAassistant avatar Sep 03 '25 10:09 CLAassistant