summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-06-07 10:24:10 -0400
committerKyleMiles <krm504@nyu.edu>2023-06-07 10:35:22 -0400
commit42ae4876178a7f8b3b6b9574ad88e7e0948111f0 (patch)
tree0da7f7ceafa179dae50b4d1acae7fec830d7afdf /python
parent1e0369f2e89f1696e68b24bf703bc74c61baefbb (diff)
variable.py : Add 'offset_to_next_variable' convenience function
Diffstat (limited to 'python')
-rw-r--r--python/variable.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/python/variable.py b/python/variable.py
index 2ab0a9fe..1ea4728e 100644
--- a/python/variable.py
+++ b/python/variable.py
@@ -834,6 +834,20 @@ class Variable(CoreVariable):
core.BNSetFunctionVariableDeadStoreElimination(self._function.handle, self.to_BNVariable(), value)
@property
+ def offset_to_next_variable(self) -> Optional[int]:
+ """returns number of bytes to the next variable on the stack"""
+ if self.source_type != VariableSourceType.StackVariableSourceType:
+ return None
+
+ for i, var in enumerate(self._function.stack_layout):
+ if var == self:
+ if i+1 < len(self._function.stack_layout):
+ return abs(self.storage - self._function.stack_layout[i+1].storage)
+ else:
+ return abs(self.storage)
+ return None
+
+ @property
def function(self) -> 'binaryninja.function.Function':
"""returns the source Function object which this variable belongs to"""
return self._function