diff options
| -rw-r--r-- | binaryninjaapi.h | 44 | ||||
| -rw-r--r-- | binaryninjacore.h | 6 | ||||
| -rw-r--r-- | binaryview.cpp | 30 | ||||
| -rw-r--r-- | python/binaryview.py | 56 |
4 files changed, 128 insertions, 8 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 3207b1da..2de2aa63 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -6488,6 +6488,44 @@ namespace BinaryNinja { */ MemoryMap* GetMemoryMap() { return m_memoryMap.get(); } + /*! Begin a bulk segment addition operation. + + This function prepares the `BinaryView` for bulk addition of both auto and user-defined segments. + During the bulk operation, segments can be added using `AddAutoSegment`, `AddAutoSegments`, + `AddUserSegment`, or `AddUserSegments` without immediately triggering the MemoryMap update process. + The queued segments will not take effect until `EndBulkAddSegments` is called. + + \sa EndBulkAddSegments + \sa CancelBulkAddSegments + */ + void BeginBulkAddSegments(); + + /*! Finalize and apply all queued segments (auto and user) added during a bulk segment addition operation. + + This function commits all segments that were queued since the last call to `BeginBulkAddSegments`. + The MemoryMap update process is executed at this point, applying all changes in one batch for + improved performance. + + \note This function must be called after `BeginBulkAddSegments` to apply the queued segments. + + \sa BeginBulkAddSegments + \sa CancelBulkAddSegments + */ + void EndBulkAddSegments(); + + /*! Cancel a bulk segment addition operation. + + This function discards all auto and user segments that were queued since the last call to + `BeginBulkAddSegments` without applying them. It allows you to abandon the changes in case + they are no longer needed. + + \note If no bulk operation is in progress, calling this function has no effect. + + \sa BeginBulkAddSegments + \sa EndBulkAddSegments + */ + void CancelBulkAddSegments(); + /*! Add an analysis segment that specifies how data from the raw file is mapped into a virtual address space Note that the segment added may have different size attributes than requested @@ -6527,6 +6565,12 @@ namespace BinaryNinja { */ void AddUserSegment(uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags); + /*! Creates user-defined segments that specify how data from the raw file is mapped into a virtual address space + + \param segments Segments to add to the BinaryView + */ + void AddUserSegments(const std::vector<BNSegmentInfo>& segments); + /*! Removes a user-defined segment from th current segment mapping \param start Virtual address of the start of the segment diff --git a/binaryninjacore.h b/binaryninjacore.h index 7836f254..ff1f3241 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 82 +#define BN_CURRENT_CORE_ABI_VERSION 83 // 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 @@ -4146,10 +4146,14 @@ extern "C" BINARYNINJACOREAPI bool BNSearch(BNBinaryView* view, const char* query, void* context, bool (*callback)(void*, uint64_t, BNDataBuffer*)); BINARYNINJACOREAPI bool BNPerformSearch(const char* query, const uint8_t* buffer, size_t size, bool(*callback)(void*, size_t, size_t), void* context); + BINARYNINJACOREAPI void BNBeginBulkAddSegments(BNBinaryView* view); + BINARYNINJACOREAPI void BNEndBulkAddSegments(BNBinaryView* view); + BINARYNINJACOREAPI void BNCancelBulkAddSegments(BNBinaryView* view); BINARYNINJACOREAPI void BNAddAutoSegment(BNBinaryView* view, uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags); BINARYNINJACOREAPI void BNAddAutoSegments(BNBinaryView* view, const BNSegmentInfo* segmentInfo, size_t count); BINARYNINJACOREAPI void BNRemoveAutoSegment(BNBinaryView* view, uint64_t start, uint64_t length); BINARYNINJACOREAPI void BNAddUserSegment(BNBinaryView* view, uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags); + BINARYNINJACOREAPI void BNAddUserSegments(BNBinaryView* view, const BNSegmentInfo* segmentInfo, size_t count); BINARYNINJACOREAPI void BNRemoveUserSegment(BNBinaryView* view, uint64_t start, uint64_t length); BINARYNINJACOREAPI BNSegment** BNGetSegments(BNBinaryView* view, size_t* count); BINARYNINJACOREAPI void BNFreeSegmentList(BNSegment** segments, size_t count); diff --git a/binaryview.cpp b/binaryview.cpp index 32aff542..d88c4548 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -4726,8 +4726,25 @@ bool BinaryView::GetAddressInput(uint64_t& result, const string& prompt, const s } -void BinaryView::AddAutoSegment( - uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags) +void BinaryView::BeginBulkAddSegments() +{ + BNBeginBulkAddSegments(m_object); +} + + +void BinaryView::EndBulkAddSegments() +{ + BNEndBulkAddSegments(m_object); +} + + +void BinaryView::CancelBulkAddSegments() +{ + BNCancelBulkAddSegments(m_object); +} + + +void BinaryView::AddAutoSegment(uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags) { BNAddAutoSegment(m_object, start, length, dataOffset, dataLength, flags); } @@ -4745,13 +4762,18 @@ void BinaryView::RemoveAutoSegment(uint64_t start, uint64_t length) } -void BinaryView::AddUserSegment( - uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags) +void BinaryView::AddUserSegment(uint64_t start, uint64_t length, uint64_t dataOffset, uint64_t dataLength, uint32_t flags) { BNAddUserSegment(m_object, start, length, dataOffset, dataLength, flags); } +void BinaryView::AddUserSegments(const vector<BNSegmentInfo>& segments) +{ + BNAddUserSegments(m_object, segments.data(), segments.size()); +} + + void BinaryView::RemoveUserSegment(uint64_t start, uint64_t length) { BNRemoveUserSegment(m_object, start, length); diff --git a/python/binaryview.py b/python/binaryview.py index 110f4646..c1e21298 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -9080,6 +9080,45 @@ to a the type "tagRECT" found in the typelibrary "winX64common" return None return value.value + def begin_bulk_add_segments(self) -> None: + """ + ``begin_bulk_add_segments`` Begins a bulk segment addition operation. + + This function prepares the `BinaryView` for bulk addition of both auto and user-defined segments. + During the bulk operation, segments can be added using `add_auto_segment` or similar functions + without immediately triggering the MemoryMap update process. The queued segments will not take + effect until `end_bulk_add_segments` is called. + """ + core.BNBeginBulkAddSegments(self.handle) + + + def end_bulk_add_segments(self) -> None: + """ + ``end_bulk_add_segments`` Finalizes and applies all queued segments (auto and user) + added during a bulk segment addition operation. + + This function commits all segments that were queued since the last call to `begin_bulk_add_segments`. + The MemoryMap update process is executed at this point, applying all changes in one batch for + improved performance. + + Note: This function must be called after `begin_bulk_add_segments` to apply the queued segments. + """ + core.BNEndBulkAddSegments(self.handle) + + + def cancel_bulk_add_segments(self) -> None: + """ + ``cancel_bulk_add_segments`` Cancels a bulk segment addition operation. + + This function discards all auto and user segments that were queued since the last call to + `begin_bulk_add_segments` without applying them. It allows you to abandon the changes in case + they are no longer needed. + + Note: If no bulk operation is in progress, calling this function has no effect. + """ + core.BNCancelBulkAddSegments(self.handle) + + def add_auto_segment(self, start: int, length: int, data_offset: int, data_length: int, flags: SegmentFlag) -> None: """ ``add_auto_segment`` Adds an analysis segment that specifies how data from the raw file is mapped into a virtual address space @@ -9092,10 +9131,11 @@ to a the type "tagRECT" found in the typelibrary "winX64common" """ ``add_auto_segments`` Adds analysis segments that specify how data from the raw file is mapped into a virtual address space - Note that the segments added may have different size attributes than requested + :param List[core.BNSegmentInfo] segments: list of segments to add + :rtype: None """ - segment_arr = (core.BNSegmentInfo * len(segments))(*segments) - core.BNAddAutoSegments(self.handle, segment_arr, len(segments)) + segment_list = (core.BNSegmentInfo * len(segments))(*segments) + core.BNAddAutoSegments(self.handle, segment_list, len(segments)) def remove_auto_segment(self, start: int, length: int = 0) -> None: """ @@ -9123,6 +9163,16 @@ to a the type "tagRECT" found in the typelibrary "winX64common" """ core.BNAddUserSegment(self.handle, start, length, data_offset, data_length, flags) + def add_user_segments(self, segments: List[core.BNSegmentInfo]) -> None: + """ + ``add_user_segments`` Adds user-defined segments that specify how data from the raw file is mapped into a virtual address space + + :param List[core.BNSegmentInfo] segments: list of segments to add + :rtype: None + """ + segment_list = (core.BNSegmentInfo * len(segments))(*segments) + core.BNAddUserSegments(self.handle, segment_list, len(segments)) + def remove_user_segment(self, start: int, length: int = 0) -> None: """ ``remove_user_segment`` Removes a user-defined segment from the current segment mapping. This method removes the most recently added 'user' segment that either matches the specified start address or contains it. |
