Loading...
Searching...
No Matches
BinaryNinja::MemoryMap Class Reference

MemoryMap provides access to the system-level memory map describing how a BinaryView is loaded into memory. More...

Detailed Description

MemoryMap provides access to the system-level memory map describing how a BinaryView is loaded into memory.

Note
Architecture: This API-side MemoryMap class is a proxy that accesses the BinaryView's current MemoryMap state through the core API. The proxy provides a simple mutable interface: when you call modification operations (AddMemoryRegion, RemoveMemoryRegion, etc.), the proxy automatically accesses the updated MemoryMap. Internally, the core uses immutable copy-on-write data structures, but the proxy abstracts this away.

When you access a BinaryView's MemoryMap, you always see the current state. For lock-free access during analysis, AnalysisContext provides memory layout query methods (IsValidOffset, IsOffsetReadable, GetStart, GetLength, etc.) that operate on an immutable snapshot of the MemoryMap cached when the analysis was initiated.

A MemoryMap can contain multiple, arbitrarily overlapping memory regions. When modified, address space segmentation is automatically managed. If multiple regions overlap, the most recently added region takes precedence by default.

Public Member Functions

 MemoryMap (BNBinaryView *view)
 ~MemoryMap ()=default
void SetLogicalMemoryMapEnabled (bool enabled)
bool IsActivated ()
 Returns true if this MemoryMap represents a parsed BinaryView with real segments.
bool AddBinaryMemoryRegion (const std::string &name, uint64_t start, Ref< BinaryView > source, uint32_t flags=0)
bool AddDataMemoryRegion (const std::string &name, uint64_t start, const DataBuffer &source, uint32_t flags=0)
bool AddRemoteMemoryRegion (const std::string &name, uint64_t start, FileAccessor *source, uint32_t flags=0)
bool AddUnbackedMemoryRegion (const std::string &name, uint64_t start, uint64_t length, uint32_t flags=0, uint8_t fill=0)
bool RemoveMemoryRegion (const std::string &name)
std::string GetActiveMemoryRegionAt (uint64_t addr)
uint32_t GetMemoryRegionFlags (const std::string &name)
bool SetMemoryRegionFlags (const std::string &name, uint32_t flags)
bool IsMemoryRegionEnabled (const std::string &name)
bool SetMemoryRegionEnabled (const std::string &name, bool enabled)
bool IsMemoryRegionRebaseable (const std::string &name)
bool SetMemoryRegionRebaseable (const std::string &name, bool rebaseable)
uint8_t GetMemoryRegionFill (const std::string &name)
bool SetMemoryRegionFill (const std::string &name, uint8_t fill)
std::string GetMemoryRegionDisplayName (const std::string &name)
bool SetMemoryRegionDisplayName (const std::string &name, const std::string &displayName)
bool IsMemoryRegionLocal (const std::string &name)
void Reset ()

Constructor & Destructor Documentation

◆ MemoryMap()

BinaryNinja::MemoryMap::MemoryMap ( BNBinaryView * view)
inline

◆ ~MemoryMap()

BinaryNinja::MemoryMap::~MemoryMap ( )
default

Member Function Documentation

◆ SetLogicalMemoryMapEnabled()

void BinaryNinja::MemoryMap::SetLogicalMemoryMapEnabled ( bool enabled)
inline

◆ IsActivated()

bool BinaryNinja::MemoryMap::IsActivated ( )
inline

Returns true if this MemoryMap represents a parsed BinaryView with real segments.

This is determined by whether the BinaryView has a parent view - parsed views (ELF, PE, Mach-O, etc.) have a parent Raw view, while Raw views have no parent.

Returns true for parsed BinaryViews (ELF, PE, Mach-O, etc.) with segments from binary format parsing. Returns false for Raw BinaryViews (flat file view with synthetic MemoryMap) or views that failed to parse segments.

Use this to gate features that require parsed binary structure (sections, imports, relocations, etc.). For basic analysis queries (GetStart, IsOffsetReadable, GetLength, etc.), use the MemoryMap directly regardless of activation state - all BinaryViews have a usable MemoryMap.

Returns
True if this is an activated (parsed) memory map, false otherwise

◆ AddBinaryMemoryRegion()

bool BinaryNinja::MemoryMap::AddBinaryMemoryRegion ( const std::string & name,
uint64_t start,
Ref< BinaryView > source,
uint32_t flags = 0 )
inline

◆ AddDataMemoryRegion()

bool BinaryNinja::MemoryMap::AddDataMemoryRegion ( const std::string & name,
uint64_t start,
const DataBuffer & source,
uint32_t flags = 0 )
inline

◆ AddRemoteMemoryRegion()

bool BinaryNinja::MemoryMap::AddRemoteMemoryRegion ( const std::string & name,
uint64_t start,
FileAccessor * source,
uint32_t flags = 0 )
inline

◆ AddUnbackedMemoryRegion()

bool BinaryNinja::MemoryMap::AddUnbackedMemoryRegion ( const std::string & name,
uint64_t start,
uint64_t length,
uint32_t flags = 0,
uint8_t fill = 0 )
inline

◆ RemoveMemoryRegion()

bool BinaryNinja::MemoryMap::RemoveMemoryRegion ( const std::string & name)
inline

◆ GetActiveMemoryRegionAt()

std::string BinaryNinja::MemoryMap::GetActiveMemoryRegionAt ( uint64_t addr)
inline

◆ GetMemoryRegionFlags()

uint32_t BinaryNinja::MemoryMap::GetMemoryRegionFlags ( const std::string & name)
inline

◆ SetMemoryRegionFlags()

bool BinaryNinja::MemoryMap::SetMemoryRegionFlags ( const std::string & name,
uint32_t flags )
inline

◆ IsMemoryRegionEnabled()

bool BinaryNinja::MemoryMap::IsMemoryRegionEnabled ( const std::string & name)
inline

◆ SetMemoryRegionEnabled()

bool BinaryNinja::MemoryMap::SetMemoryRegionEnabled ( const std::string & name,
bool enabled )
inline

◆ IsMemoryRegionRebaseable()

bool BinaryNinja::MemoryMap::IsMemoryRegionRebaseable ( const std::string & name)
inline

◆ SetMemoryRegionRebaseable()

bool BinaryNinja::MemoryMap::SetMemoryRegionRebaseable ( const std::string & name,
bool rebaseable )
inline

◆ GetMemoryRegionFill()

uint8_t BinaryNinja::MemoryMap::GetMemoryRegionFill ( const std::string & name)
inline

◆ SetMemoryRegionFill()

bool BinaryNinja::MemoryMap::SetMemoryRegionFill ( const std::string & name,
uint8_t fill )
inline

◆ GetMemoryRegionDisplayName()

std::string BinaryNinja::MemoryMap::GetMemoryRegionDisplayName ( const std::string & name)
inline

◆ SetMemoryRegionDisplayName()

bool BinaryNinja::MemoryMap::SetMemoryRegionDisplayName ( const std::string & name,
const std::string & displayName )
inline

◆ IsMemoryRegionLocal()

bool BinaryNinja::MemoryMap::IsMemoryRegionLocal ( const std::string & name)
inline

◆ Reset()

void BinaryNinja::MemoryMap::Reset ( )
inline