summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-11-28 11:13:08 -0800
committerMark Rowe <mark@vector35.com>2025-12-08 13:21:58 -0800
commit540fca65afaff35343a938b86596b21f2e16b48d (patch)
treef84da14232124ab1829f4051de2794b304355827 /binaryninjaapi.h
parentdaede114cfacf4cd68ed0a9f67c829b8b16da961 (diff)
Introduce an RAII type for managing bulk symbol modifications
Fixes https://github.com/Vector35/binaryninja-api/issues/7666. Correctly managing the state of bulk symbol modifications via `BeginBulkModifySymbols` / `EndBulkModifySymbols` is error-prone in the face of exceptions and early returns. Leaking a bulk symbol modification can leave the view in a state where no further changes to symbols will be applied. All users of the C++ API are encouraged to move from `BeginBulkModifySymbols` / `EndBulkModifySymbols` to the new `BulkSymbolModification` class.
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 9cef3ee0..55aa96ca 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -6869,7 +6869,24 @@ namespace BinaryNinja {
*/
bool IsApplyingDebugInfo() const;
+ /*! Begin an operation that may potentially modify many symbols
+
+ When performing bulk symbol modifications, surrounding the modifications with
+ \c BeginBulkModifySymbols and \c EndBulkModifySymbols will defer some work until
+ the end of the operation, improving performance.
+
+ \deprecated Prefer \c BulkSymbolModification for bulk symbol modifications.
+ */
void BeginBulkModifySymbols();
+
+ /*! Finish an operation that potentially modified many symbols
+
+ When performing bulk symbol modifications, surrounding the modifications with
+ \c BeginBulkModifySymbols and \c EndBulkModifySymbols will defer some work until
+ the end of the operation, improving performance.
+
+ \deprecated Prefer \c BulkSymbolModification for bulk symbol modifications.
+ */
void EndBulkModifySymbols();
/*! Add a new TagType to this binaryview
@@ -8300,6 +8317,54 @@ namespace BinaryNinja {
}
};
+ /*! An RAII helper for use when modifying symbols in bulk.
+
+ \ingroup binaryview
+
+ When modifying many symbols, it is more efficient to wrap the modifications
+ in a \c BulkSymbolModification object. This will defer some processing until
+ all bulk modifications are complete.
+
+ While a bulk modification is active, some API calls may not reflect (or may
+ only partially reflect) any symbol changes made until all bulk modifications
+ are complete.
+
+ The bulk modification will be active for the lifetime of the
+ \c BulkSymbolModification object. It can be ended early via the \c End method,
+ if needed.
+ */
+ class BulkSymbolModification
+ {
+ public:
+ BulkSymbolModification(Ref<BinaryView> view)
+ : m_view(std::move(view))
+ {
+ m_view->BeginBulkModifySymbols();
+ }
+
+ ~BulkSymbolModification()
+ {
+ if (m_view)
+ m_view->EndBulkModifySymbols();
+ }
+
+ /*! End this bulk modification early. */
+ void End()
+ {
+ m_view->EndBulkModifySymbols();
+ m_view = nullptr;
+ }
+
+ // Move-only.
+ BulkSymbolModification(const BulkSymbolModification&) = delete;
+ BulkSymbolModification& operator=(const BulkSymbolModification&) = delete;
+ BulkSymbolModification(BulkSymbolModification&&) = default;
+ BulkSymbolModification& operator=(BulkSymbolModification&&) = default;
+
+ private:
+ Ref<BinaryView> m_view;
+ };
+
/*!
\ingroup binaryview
*/