diff options
| author | Peter LaFosse <peter@vector35.com> | 2021-09-06 11:38:59 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2021-09-06 11:46:44 -0400 |
| commit | 5a1f98b0e46d0077f777cb90e7d9d916c9186535 (patch) | |
| tree | f90bcc662dcf85fad1d2b5ef262568e5dc905d2e /python | |
| parent | a377529b29b43e35cce8763ec4077b329b218f43 (diff) | |
Fix some unnecessary checks for handle is not None in destructors
Diffstat (limited to 'python')
| -rw-r--r-- | python/callingconvention.py | 2 | ||||
| -rw-r--r-- | python/filemetadata.py | 2 | ||||
| -rw-r--r-- | python/flowgraph.py | 15 | ||||
| -rw-r--r-- | python/function.py | 2 | ||||
| -rw-r--r-- | python/highlevelil.py | 2 | ||||
| -rw-r--r-- | python/lowlevelil.py | 13 | ||||
| -rw-r--r-- | python/mediumlevelil.py | 2 | ||||
| -rw-r--r-- | python/platform.py | 2 | ||||
| -rw-r--r-- | python/settings.py | 2 | ||||
| -rw-r--r-- | python/workflow.py | 5 |
10 files changed, 23 insertions, 24 deletions
diff --git a/python/callingconvention.py b/python/callingconvention.py index 5b816e20..ff3e8ff6 100644 --- a/python/callingconvention.py +++ b/python/callingconvention.py @@ -166,7 +166,7 @@ class CallingConvention: self.confidence = confidence def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreeCallingConvention(self.handle) def __repr__(self): diff --git a/python/filemetadata.py b/python/filemetadata.py index 5a3e4d4e..f4cc75f3 100644 --- a/python/filemetadata.py +++ b/python/filemetadata.py @@ -263,14 +263,12 @@ class FileMetadata: @navigation.setter def navigation(self, value:NavigationHandler) -> None: - assert self.handle is not None value._register(self.handle) self._nav = value @property def session_data(self) -> Any: """Dictionary object where plugins can store arbitrary data associated with the file""" - assert self.handle is not None, "Attempting to set session_data when handle is None" handle = ctypes.cast(self.handle, ctypes.c_void_p) # type: ignore if handle.value not in FileMetadata._associated_data: obj = _FileMetadataAssociatedDataStore() diff --git a/python/flowgraph.py b/python/flowgraph.py index 922cc933..1d3d9504 100644 --- a/python/flowgraph.py +++ b/python/flowgraph.py @@ -21,6 +21,7 @@ import ctypes import threading import traceback +from typing import Optional # Binary Ninja components import binaryninja @@ -96,7 +97,7 @@ class FlowGraphNode: self._graph = FlowGraph(handle = core.BNGetFlowGraphNodeOwner(self.handle)) def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreeFlowGraphNode(self.handle) def __repr__(self): @@ -398,8 +399,9 @@ class FlowGraph: """ _registered_instances = [] - def __init__(self, handle = None): - if handle is None: + def __init__(self, handle:Optional[core.BNCustomFlowGraphHandle] = None): + _handle = handle + if _handle is None: self._ext_cb = core.BNCustomFlowGraph() self._ext_cb.context = 0 self._ext_cb.prepareForLayout = self._ext_cb.prepareForLayout.__class__(self._prepare_for_layout) @@ -408,9 +410,9 @@ class FlowGraph: self._ext_cb.update = self._ext_cb.update.__class__(self._update) self._ext_cb.externalRefTaken = self._ext_cb.externalRefTaken.__class__(self._external_ref_taken) self._ext_cb.externalRefReleased = self._ext_cb.externalRefReleased.__class__(self._external_ref_released) - handle = core.BNCreateCustomFlowGraph(self._ext_cb) - assert handle is not None - self.handle = handle + _handle = core.BNCreateCustomFlowGraph(self._ext_cb) + assert _handle is not None + self.handle = _handle def __del__(self): if core is not None: @@ -433,7 +435,6 @@ class FlowGraph: return not (self == other) def __hash__(self): - assert self.handle is not None return hash(ctypes.addressof(self.handle.contents)) def __setattr__(self, name, value): diff --git a/python/function.py b/python/function.py index 7df9aaaa..7d9a6d16 100644 --- a/python/function.py +++ b/python/function.py @@ -185,7 +185,7 @@ class Function: self._platform = None def __del__(self): - if self.handle is not None: + if core is not None: if self._advanced_analysis_requests > 0: core.BNReleaseAdvancedFunctionAnalysisDataMultiple(self.handle, self._advanced_analysis_requests) core.BNFreeFunction(self.handle) diff --git a/python/highlevelil.py b/python/highlevelil.py index 53678cce..570df465 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -2290,7 +2290,7 @@ class HighLevelILFunction: self.handle = _handle def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreeHighLevelILFunction(self.handle) def __repr__(self): diff --git a/python/lowlevelil.py b/python/lowlevelil.py index dd49f10a..48c39189 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -292,7 +292,10 @@ class CoreLowLevelILInstruction: @classmethod def from_BNLowLevelILInstruction(cls, instr:core.BNLowLevelILInstruction) -> 'CoreLowLevelILInstruction': - operands:OperandsType = tuple([ExpressionIndex(instr.operands[i]) for i in range(4)]) # type: ignore + operands:OperandsType = (ExpressionIndex(instr.operands[0]), + ExpressionIndex(instr.operands[1]), + ExpressionIndex(instr.operands[2]), + ExpressionIndex(instr.operands[3])) return cls(LowLevelILOperation(instr.operation), instr.size, instr.flags, instr.sourceOperand, operands, instr.address) @@ -2702,7 +2705,7 @@ class LowLevelILFunction: assert self._source_function is not None def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreeLowLevelILFunction(self.handle) def __repr__(self): @@ -2872,7 +2875,6 @@ class LowLevelILFunction: def registers(self) -> List[ILRegister]: """ List of registers used in this IL """ count = ctypes.c_ulonglong() - assert self.handle is not None, "LLIL Function handle is None" registers = core.BNGetLowLevelRegisters(self.handle, count) assert registers is not None, "core.BNGetLowLevelRegisters returned None" result = [] @@ -2918,7 +2920,6 @@ class LowLevelILFunction: return [] register_count = ctypes.c_ulonglong() - assert self.handle is not None, "LLIL Function handle is None" registers = core.BNGetLowLevelRegisters(self.handle, register_count) assert registers is not None, "core.BNGetLowLevelRegisters returned None" result = [] @@ -4406,8 +4407,8 @@ class LowLevelILFunction: :return: the label list expression :rtype: ExpressionIndex """ - label_list = (ctypes.POINTER(core.BNLowLevelILLabel) * len(labels))() # type: ignore - value_list = (ctypes.POINTER(ctypes.c_ulonglong) * len(labels))() # type: ignore + label_list = (ctypes.POINTER(core.BNLowLevelILLabel) * len(labels))() + value_list = (ctypes.POINTER(ctypes.c_ulonglong) * len(labels))() for i, (key, value) in enumerate(labels.items()): value_list[i] = key label_list[i] = value.handle diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index a9b3e39b..44e94937 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -2591,7 +2591,7 @@ class MediumLevelILFunction: self._source_function = _source_function def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreeMediumLevelILFunction(self.handle) def __repr__(self): diff --git a/python/platform.py b/python/platform.py index 279a80e1..13052e77 100644 --- a/python/platform.py +++ b/python/platform.py @@ -85,7 +85,7 @@ class Platform(metaclass=_PlatformMetaClass): return core.BNGetPlatformName(self.handle) def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreePlatform(self.handle) def __repr__(self): diff --git a/python/settings.py b/python/settings.py index b508e863..7297f157 100644 --- a/python/settings.py +++ b/python/settings.py @@ -137,7 +137,7 @@ class Settings: self.handle = _handle def __del__(self): - if self.handle is not Settings.default_handle and self.handle is not None: + if self.handle is not Settings.default_handle: core.BNFreeSettings(self.handle) def __eq__(self, other): diff --git a/python/workflow.py b/python/workflow.py index 1f909232..e1b1ad1f 100644 --- a/python/workflow.py +++ b/python/workflow.py @@ -57,8 +57,7 @@ class Activity(object): log_error(traceback.format_exc()) def __del__(self): - log_error("Activity DEL called!") - if self.handle is not None: + if core is not None: core.BNFreeActivity(self.handle) def __repr__(self): @@ -180,7 +179,7 @@ class Workflow(metaclass=_WorkflowMetaclass): self._name = core.BNGetWorkflowName(self.handle) def __del__(self): - if self.handle is not None: + if core is not None: core.BNFreeWorkflow(self.handle) def __len__(self): |
