summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/function.py4
-rw-r--r--python/lowlevelil.py4
-rw-r--r--python/mediumlevelil.py4
3 files changed, 9 insertions, 3 deletions
diff --git a/python/function.py b/python/function.py
index c860fced..9eac5728 100644
--- a/python/function.py
+++ b/python/function.py
@@ -769,8 +769,10 @@ class Function(object):
try:
if i < 0:
i = count.value + i
- if i < 0 or i >= count.value:
+ if i < -len(self.basic_blocks) or i >= count.value:
raise IndexError("index out of range")
+ if i < 0:
+ i = len(self.basic_blocks) + i
block = binaryninja.basicblock.BasicBlock(core.BNNewBasicBlockReference(blocks[i]), self._view)
return block
finally:
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 4d4ca2ec..87400b4d 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -1304,8 +1304,10 @@ class LowLevelILFunction(object):
# for backwards compatibility
if isinstance(i, LowLevelILInstruction):
return i
- if (i < 0) or (i >= len(self)):
+ if i < -len(self) or i >= len(self):
raise IndexError("index out of range")
+ if i < 0:
+ i = len(self) + i
return LowLevelILInstruction(self, core.BNGetLowLevelILIndexForInstruction(self.handle, i), i)
def __setitem__(self, i, j):
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index ef858f3b..ba352503 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -905,8 +905,10 @@ class MediumLevelILFunction(object):
# for backwards compatibility
if isinstance(i, MediumLevelILInstruction):
return i
- if (i < 0) or (i >= len(self)):
+ if i < -len(self) or i >= len(self):
raise IndexError("index out of range")
+ if i < 0:
+ i = len(self) + i
return MediumLevelILInstruction(self, core.BNGetMediumLevelILIndexForInstruction(self.handle, i), i)
def __setitem__(self, i, j):