From 74361e5a39cb3d356a93de66a32ca893bcc15496 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 22 Jul 2024 15:16:10 -0400 Subject: Add ability to modify segment flags via MemoryMap API. --- binaryninjaapi.h | 15 +++++++++++++++ binaryninjacore.h | 5 ++++- python/binaryview.py | 9 +++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index e0fbfb50..a6e433a3 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -6764,6 +6764,16 @@ namespace BinaryNinja { return result; } + uint32_t GetMemoryRegionFlags(const std::string& name) + { + return BNGetMemoryRegionFlags(m_object, name.c_str()); + } + + bool SetMemoryRegionFlags(const std::string& name, uint32_t flags) + { + return BNSetMemoryRegionFlags(m_object, name.c_str(), flags); + } + bool IsMemoryRegionEnabled(const std::string& name) { return BNIsMemoryRegionEnabled(m_object, name.c_str()); @@ -6784,6 +6794,11 @@ namespace BinaryNinja { return BNSetMemoryRegionRebaseable(m_object, name.c_str(), rebaseable); } + uint8_t GetMemoryRegionFill(const std::string& name) + { + return BNGetMemoryRegionFill(m_object, name.c_str()); + } + bool SetMemoryRegionFill(const std::string& name, uint8_t fill) { return BNSetMemoryRegionFill(m_object, name.c_str(), fill); diff --git a/binaryninjacore.h b/binaryninjacore.h index cc9f2019..a55c6ff0 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,7 +37,7 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 67 +#define BN_CURRENT_CORE_ABI_VERSION 68 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and @@ -3776,10 +3776,13 @@ extern "C" BINARYNINJACOREAPI bool BNAddRemoteMemoryRegion(BNBinaryView* view, const char* name, uint64_t start, BNFileAccessor* accessor, uint32_t flags); BINARYNINJACOREAPI bool BNRemoveMemoryRegion(BNBinaryView* view, const char* name); BINARYNINJACOREAPI char* BNGetActiveMemoryRegionAt(BNBinaryView* view, uint64_t addr); + BINARYNINJACOREAPI uint32_t BNGetMemoryRegionFlags(BNBinaryView* view, const char* name); + BINARYNINJACOREAPI bool BNSetMemoryRegionFlags(BNBinaryView* view, const char* name, uint32_t flags); BINARYNINJACOREAPI bool BNIsMemoryRegionEnabled(BNBinaryView* view, const char* name); BINARYNINJACOREAPI bool BNSetMemoryRegionEnabled(BNBinaryView* view, const char* name, bool enable); BINARYNINJACOREAPI bool BNIsMemoryRegionRebaseable(BNBinaryView* view, const char* name); BINARYNINJACOREAPI bool BNSetMemoryRegionRebaseable(BNBinaryView* view, const char* name, bool rebaseable); + BINARYNINJACOREAPI uint8_t BNGetMemoryRegionFill(BNBinaryView* view, const char* name); BINARYNINJACOREAPI bool BNSetMemoryRegionFill(BNBinaryView* view, const char* name, uint8_t fill); BINARYNINJACOREAPI void BNResetMemoryMap(BNBinaryView* view); diff --git a/python/binaryview.py b/python/binaryview.py index f1d5ff79..9f47005b 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2263,6 +2263,12 @@ class MemoryMap: def get_active_memory_region_at(self, addr: int) -> str: return core.BNGetActiveMemoryRegionAt(self.handle, addr) + def get_memory_region_flags(self, name: str) -> SegmentFlag: + return SegmentFlag(core.BNGetMemoryRegionFlags(self.handle, name)) + + def set_memory_region_flags(self, name: str, flags: SegmentFlag) -> bool: + return core.BNSetMemoryRegionFlags(self.handle, name, flags) + def is_memory_region_enabled(self, name: str) -> bool: return core.BNIsMemoryRegionEnabled(self.handle, name) @@ -2275,6 +2281,9 @@ class MemoryMap: def set_memory_region_rebaseable(self, name: str, rebaseable: bool = True) -> bool: return core.BNSetMemoryRegionRebaseable(self.handle, name, rebaseable) + def get_memory_region_fill(self, name: str) -> int: + return core.BNGetMemoryRegionFill(self.handle, name) + def set_memory_region_fill(self, name: str, fill: int) -> bool: return core.BNSetMemoryRegionFill(self.handle, name, fill) -- cgit v1.3.1