From e9a35074bb068e4d71d0f60c520128b245edac48 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Wed, 22 Sep 2021 11:30:45 -0400 Subject: Add __contains__ for Function, Section, Segment, BasicBlock and BinaryView Addresses issue binaryninja-api#1113 --- python/binaryview.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'python/binaryview.py') 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() -- cgit v1.3.1