Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 3, 2025

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.

Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
@CLAassistant
Copy link

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.

Copilot AI and others added 3 commits September 3, 2025 10:29
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Support allocating a new buffer in the target Add memory allocation support to Binary Ninja Debugger Sep 3, 2025
@Copilot Copilot AI requested a review from xusheng6 September 3, 2025 10:33
Copilot finished work on behalf of xusheng6 September 3, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support allocating a new buffer in the target
3 participants