summaryrefslogtreecommitdiff
path: root/python/binaryview.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2021-09-22 11:30:45 -0400
committerPeter LaFosse <peter@vector35.com>2021-09-22 11:31:32 -0400
commite9a35074bb068e4d71d0f60c520128b245edac48 (patch)
treecd5c37a9139dcfd2623925a2dab07b4673e57a47 /python/binaryview.py
parente8f1068684236e5805e511b9abfd83888f05a1f9 (diff)
Add __contains__ for Function, Section, Segment, BasicBlock and BinaryView
Addresses issue binaryninja-api#1113
Diffstat (limited to 'python/binaryview.py')
-rw-r--r--python/binaryview.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 12f886fd..ef559d8b 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -978,6 +978,9 @@ class Segment:
def __hash__(self):
return hash(ctypes.addressof(self.handle.contents))
+ def __contains__(self, i:int):
+ return i >= self.start and i < self.end
+
@property
def start(self) -> int:
return core.BNSegmentGetStart(self.handle)
@@ -1073,6 +1076,9 @@ class Section:
def __hash__(self):
return hash(ctypes.addressof(self.handle.contents))
+ def __contains__(self, i:int):
+ return i >= self.start and i < self.end
+
@property
def name(self) -> str:
return core.BNSectionGetName(self.handle)
@@ -1493,6 +1499,12 @@ class BinaryView:
else:
raise IndexError("index out of range")
+ def __contains__(self, i:int):
+ for s in self.segments:
+ if i in s:
+ return True
+ return False
+
@classmethod
def register(cls) -> None:
binaryninja._init_plugins()