diff options
| author | Josh F <josh@vector35.com> | 2022-07-06 13:40:52 -0400 |
|---|---|---|
| committer | Josh F <josh@vector35.com> | 2022-07-18 16:13:50 -0400 |
| commit | 11458f3160e9c82d3e0f48b7013d952b729ec38b (patch) | |
| tree | 4c2165c208fa9542a2c744b7a3f94be52877315e /python | |
| parent | c3362d1ffb2c581c0647a1e9f480b98e7976fe25 (diff) | |
Memory map sidebar widget + segment/section notifications
Diffstat (limited to 'python')
| -rw-r--r-- | python/binaryview.py | 78 | ||||
| -rw-r--r-- | python/examples/notification_callbacks.py | 18 |
2 files changed, 96 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index fbbba6f9..61123621 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -210,6 +210,23 @@ class BinaryDataNotification: def type_field_ref_changed(self, view: 'BinaryView', name: '_types.QualifiedName', offset: int) -> None: pass + def segment_added(self, view: 'BinaryView', segment: 'Segment') -> None: + pass + + def segment_updated(self, view: 'BinaryView', segment: 'Segment') -> None: + pass + + def segment_removed(self, view: 'BinaryView', segment: 'Segment') -> None: + pass + + def section_added(self, view: 'BinaryView', section: 'Section') -> None: + pass + + def section_updated(self, view: 'BinaryView', section: 'Section') -> None: + pass + + def section_removed(self, view: 'BinaryView', section: 'Section') -> None: + pass class StringReference: _decodings = { @@ -439,6 +456,13 @@ class BinaryDataNotificationCallbacks: self._cb.typeUndefined = self._cb.typeUndefined.__class__(self._type_undefined) self._cb.typeReferenceChanged = self._cb.typeReferenceChanged.__class__(self._type_ref_changed) self._cb.typeFieldReferenceChanged = self._cb.typeFieldReferenceChanged.__class__(self._type_field_ref_changed) + self._cb.segmentAdded = self._cb.segmentAdded.__class__(self._segment_added) + self._cb.segmentUpdated = self._cb.segmentUpdated.__class__(self._segment_updated) + self._cb.segmentRemoved = self._cb.segmentRemoved.__class__(self._segment_removed) + self._cb.sectionAdded = self._cb.sectionAdded.__class__(self._section_added) + self._cb.sectionUpdated = self._cb.sectionUpdated.__class__(self._section_updated) + self._cb.sectionRemoved = self._cb.sectionRemoved.__class__(self._section_removed) + def _register(self) -> None: core.BNRegisterDataNotification(self._view.handle, self._cb) @@ -658,6 +682,60 @@ class BinaryDataNotificationCallbacks: except: log_error(traceback.format_exc()) + def _segment_added(self, ctxt, view: core.BNBinaryView, segment_obj: core.BNSegment) -> None: + try: + segment_handle = core.BNNewSegmentReference(segment_obj) + assert segment_handle is not None, "core.BNNewSegmentReference returned None" + result = Segment(segment_handle) + self._notify.segment_added(self._view, result) + except: + log_error(traceback.format_exc()) + + def _segment_updated(self, ctxt, view: core.BNBinaryView, segment_obj: core.BNSegment) -> None: + try: + segment_handle = core.BNNewSegmentReference(segment_obj) + assert segment_handle is not None, "core.BNNewSegmentReference returned None" + result = Segment(segment_handle) + self._notify.segment_updated(self._view, result) + except: + log_error(traceback.format_exc()) + + def _segment_removed(self, ctxt, view: core.BNBinaryView, segment_obj: core.BNSegment) -> None: + try: + segment_handle = core.BNNewSegmentReference(segment_obj) + assert segment_handle is not None, "core.BNNewSegmentReference returned None" + result = Segment(segment_handle) + self._notify.segment_removed(self._view, result) + except: + log_error(traceback.format_exc()) + + def _section_added(self, ctxt, view: core.BNBinaryView, section_obj: core.BNSection) -> None: + try: + section_handle = core.BNNewSectionReference(section_obj) + assert section_handle is not None, "core.BNNewSectionReference returned None" + result = Section(section_handle) + self._notify.section_added(self._view, result) + except: + log_error(traceback.format_exc()) + + def _section_updated(self, ctxt, view: core.BNBinaryView, section_obj: core.BNSection) -> None: + try: + section_handle = core.BNNewSectionReference(section_obj) + assert section_handle is not None, "core.BNNewSectionReference returned None" + result = Section(section_handle) + self._notify.section_updated(self._view, result) + except: + log_error(traceback.format_exc()) + + def _section_removed(self, ctxt, view: core.BNBinaryView, section_obj: core.BNSection) -> None: + try: + section_handle = core.BNNewSectionReference(section_obj) + assert section_handle is not None, "core.BNNewSectionReference returned None" + result = Section(section_handle) + self._notify.section_removed(self._view, result) + except: + log_error(traceback.format_exc()) + @property def view(self) -> 'BinaryView': return self._view diff --git a/python/examples/notification_callbacks.py b/python/examples/notification_callbacks.py index 24d798de..47282884 100644 --- a/python/examples/notification_callbacks.py +++ b/python/examples/notification_callbacks.py @@ -107,5 +107,23 @@ class DemoNotification(BinaryDataNotification): def type_field_ref_changed(self, *args): log.log_info(inspect.stack()[0][3] + str(args)) + def segment_added(self, *args): + log.log_info(inspect.stack()[0][3] + str(args)) + + def segment_updated(self, *args): + log.log_info(inspect.stack()[0][3] + str(args)) + + def segment_removed(self, *args): + log.log_info(inspect.stack()[0][3] + str(args)) + + def section_added(self, *args): + log.log_info(inspect.stack()[0][3] + str(args)) + + def section_updated(self, *args): + log.log_info(inspect.stack()[0][3] + str(args)) + + def section_removed(self, *args): + log.log_info(inspect.stack()[0][3] + str(args)) + PluginCommand.register("Register Notification", "", reg_notif) |
