From f3dce0828c95e11af1f7d23ca56be6037b86de3c Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 16 May 2025 19:59:05 +0200 Subject: Add `BNIsMemoryMapActivated` API So that users of the memory map API can know if a view has activated the memory map and adjust behavior accordingly. --- binaryninjaapi.h | 5 +++++ binaryninjacore.h | 1 + python/binaryview.py | 5 +++++ rust/src/binary_view/memory_map.rs | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index c911dc50..95c54095 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -7067,6 +7067,11 @@ namespace BinaryNinja { BNSetLogicalMemoryMapEnabled(m_object, enabled); } + bool IsActivated() + { + return BNIsMemoryMapActivated(m_object); + } + bool AddBinaryMemoryRegion(const std::string& name, uint64_t start, Ref source, uint32_t flags = 0) { return BNAddBinaryMemoryRegion(m_object, name.c_str(), start, source->GetObject(), flags); diff --git a/binaryninjacore.h b/binaryninjacore.h index 91e366f4..1cd87b37 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -4091,6 +4091,7 @@ extern "C" BINARYNINJACOREAPI char* BNGetBaseMemoryMapDescription(BNBinaryView* view); BINARYNINJACOREAPI char* BNGetMemoryMapDescription(BNBinaryView* view); BINARYNINJACOREAPI void BNSetLogicalMemoryMapEnabled(BNBinaryView* view, bool enabled); + BINARYNINJACOREAPI bool BNIsMemoryMapActivated(BNBinaryView* view); BINARYNINJACOREAPI bool BNAddBinaryMemoryRegion(BNBinaryView* view, const char* name, uint64_t start, BNBinaryView* data, uint32_t flags); BINARYNINJACOREAPI bool BNAddDataMemoryRegion(BNBinaryView* view, const char* name, uint64_t start, BNDataBuffer* data, uint32_t flags); BINARYNINJACOREAPI bool BNAddRemoteMemoryRegion(BNBinaryView* view, const char* name, uint64_t start, BNFileAccessor* accessor, uint32_t flags); diff --git a/python/binaryview.py b/python/binaryview.py index ccd4fba3..00188902 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2381,6 +2381,11 @@ class MemoryMap: """ core.BNSetLogicalMemoryMapEnabled(self.handle, enabled) + @property + def is_activated(self): + """Whether the memory map is activated for the associated view.""" + return core.BNIsMemoryMapActivated(self.handle) + def add_memory_region(self, name: str, start: int, source: Union['os.PathLike', str, bytes, bytearray, 'BinaryView', 'databuffer.DataBuffer', 'fileaccessor.FileAccessor'], flags: SegmentFlag = 0) -> bool: """ Adds a memory region to the memory map. Depending on the source parameter, the memory region is created as one of the following types: diff --git a/rust/src/binary_view/memory_map.rs b/rust/src/binary_view/memory_map.rs index 34ebd572..cedea26e 100644 --- a/rust/src/binary_view/memory_map.rs +++ b/rust/src/binary_view/memory_map.rs @@ -40,6 +40,11 @@ impl MemoryMap { unsafe { BNSetLogicalMemoryMapEnabled(self.view.handle, enabled) }; } + /// Whether the memory map is activated for the associated view. + pub fn is_activated(&self) -> bool { + unsafe { BNIsMemoryMapActivated(self.view.handle) } + } + pub fn add_binary_memory_region( &mut self, name: &str, -- cgit v1.3.1