From faab567391ddee9951e85975e9621cc66c128dcb Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sun, 4 Aug 2019 22:06:13 -0400 Subject: add total_bytes, highest_address, and lowest_address to native functions (in API only for now, will be moved into the core later) --- python/function.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'python/function.py') diff --git a/python/function.py b/python/function.py index 58565838..1ac95fb6 100644 --- a/python/function.py +++ b/python/function.py @@ -845,9 +845,29 @@ class Function(object): @property def start(self): - """Function start (read-only)""" + """Function start address (read-only)""" return core.BNGetFunctionStart(self.handle) + @property + def size(self): + """This property is not implemented as its implementation is not well defined. Use `.total_bytes` or `.highest_address-.lowest_address` instead""" + raise NotImplementedError("Intentionally unimplemented--use .total_bytes or .highest_address-.lowest_address.") + + @property + def total_bytes(self): + """Total bytes of a function calculated by summing each basic_block. Because basic blocks can overlap and have gaps between them this may or may not be equivalent to a .size property.""" + return sum(map(len, self)) + + @property + def highest_address(self): + "The highest virtual address in a function.""" + return max(self, key=lambda block:block.end).end + + @property + def lowest_address(self): + """The lowest virtual address in a function.""" + return min(self, key=lambda block:block.start).start + @property def symbol(self): """Function symbol(read-only)""" -- cgit v1.3.1