diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2022-03-08 16:09:00 -0500 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2022-03-11 20:28:57 -0500 |
| commit | 4c88144acfbb58e29742e27949e5b02ef4c4108e (patch) | |
| tree | 44491ec556214084d9e3259453406256dd59b59b | |
| parent | 4cdb1af22efb7374470668919bb19795a64622fd (diff) | |
Add bulk symbol management API to improve performance when adding/removing large numbers of symbols
| -rw-r--r-- | binaryninjaapi.h | 3 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | binaryview.cpp | 12 | ||||
| -rw-r--r-- | python/binaryview.py | 20 |
4 files changed, 37 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index a58d42fe..e11b7d9f 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1930,6 +1930,9 @@ namespace BinaryNinja { void DefineImportedFunction(Ref<Symbol> importAddressSym, Ref<Function> func, Ref<Type> type = nullptr); + void BeginBulkModifySymbols(); + void EndBulkModifySymbols(); + void AddTagType(Ref<TagType> tagType); void RemoveTagType(Ref<TagType> tagType); Ref<TagType> GetTagType(const std::string& name); diff --git a/binaryninjacore.h b/binaryninjacore.h index 5687fcf2..c86b501e 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -4476,6 +4476,8 @@ extern "C" BNBinaryView* view, BNSymbol* importAddressSym, BNFunction* func, BNType* type); BINARYNINJACOREAPI BNSymbol* BNDefineAutoSymbolAndVariableOrFunction( BNBinaryView* view, BNPlatform* platform, BNSymbol* sym, BNType* type); + BINARYNINJACOREAPI void BNBeginBulkModifySymbols(BNBinaryView* view); + BINARYNINJACOREAPI void BNEndBulkModifySymbols(BNBinaryView* view); BINARYNINJACOREAPI BNDebugInfo* BNGetDebugInfo(BNBinaryView* view); BINARYNINJACOREAPI void BNApplyDebugInfo(BNBinaryView* view, BNDebugInfo* newDebugInfo); diff --git a/binaryview.cpp b/binaryview.cpp index 853e201a..ba812919 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -2411,6 +2411,18 @@ void BinaryView::DefineImportedFunction(Ref<Symbol> importAddressSym, Ref<Functi } +void BinaryView::BeginBulkModifySymbols() +{ + BNBeginBulkModifySymbols(m_object); +} + + +void BinaryView::EndBulkModifySymbols() +{ + BNEndBulkModifySymbols(m_object); +} + + void BinaryView::AddTagType(Ref<TagType> tagType) { BNAddTagType(m_object, tagType->GetObject()); diff --git a/python/binaryview.py b/python/binaryview.py index 9439af5e..37d85580 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -4774,6 +4774,26 @@ class BinaryView: self.handle, import_addr_sym.handle, func.handle, None if type is None else type.handle ) + def bulk_modify_symbols(self): + """ + ``bulk_modify_symbols`` returns a context manager that improves performance when adding or + removing a large number of symbols. Symbols added within the Python `with` keyword will + defer processing until the end of the block. Many symbol getter APIs will return stale + results inside the `with` block, so this function should only be used when symbol + queries are not needed at the same time as the modifications. + """ + class BulkModify: + def __init__(self, view: 'BinaryView'): + self._view = view + + def __enter__(self): + core.BNBeginBulkModifySymbols(self._view.handle) + + def __exit__(self, type, value, traceback): + core.BNEndBulkModifySymbols(self._view.handle) + + return BulkModify(self) + def create_tag_type(self, name: str, icon: str) -> 'TagType': """ ``create_tag_type`` creates a new Tag Type and adds it to the view |
