From 42ae4876178a7f8b3b6b9574ad88e7e0948111f0 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Wed, 7 Jun 2023 10:24:10 -0400 Subject: variable.py : Add 'offset_to_next_variable' convenience function --- python/variable.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'python/variable.py') diff --git a/python/variable.py b/python/variable.py index 2ab0a9fe..1ea4728e 100644 --- a/python/variable.py +++ b/python/variable.py @@ -833,6 +833,20 @@ class Variable(CoreVariable): def dead_store_elimination(self, value): 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""" -- cgit v1.3.1