diff options
| -rw-r--r-- | python/binaryview.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 5594b066..5a63248f 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -3197,7 +3197,7 @@ class BinaryView: _handle = core.BNCreateCustomBinaryView(self.__class__.name, file_metadata.handle, _parent_view, self._cb) assert _handle is not None - self.handle = _handle + self._handle = _handle self._notifications = {} self._parse_only = False self._preload_limit = 5 @@ -3210,9 +3210,9 @@ class BinaryView: for i in self._notifications.values(): i._unregister() self._notifications.clear() - if self.handle is not None: - core.BNFreeBinaryView(self.handle) - self.handle = None + if self._handle is not None: + core.BNFreeBinaryView(self._handle) + self._handle = None def __enter__(self) -> 'BinaryView': return self @@ -3225,6 +3225,8 @@ class BinaryView: self._cleanup() def __repr__(self): + if self._handle is None: + return "<BinaryView: disposed>" start = self.start length = self.length if start != 0: @@ -3240,6 +3242,12 @@ class BinaryView: def length(self): return int(core.BNGetViewLength(self.handle)) + @property + def handle(self): + if self._handle is None: + raise ReferenceError("BinaryView has been disposed") + return self._handle + def __bool__(self): return True |
