summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorGalen Williamson <galen@vector35.com>2021-12-22 16:07:27 -0500
committerPeter LaFosse <peter@vector35.com>2022-01-04 09:07:06 -0500
commit82d4730da75b01e9521344b7497f2238bbdef18f (patch)
tree005860aa964e3a6d6e664f7a722bed36601ad71c /python
parent7271793243570e1a33b0f338cfd50a889d1780f9 (diff)
added BinaryView.get_data_offset_for_address to python API
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 3b6cb0da..3f3f1808 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -6864,7 +6864,7 @@ class BinaryView:
def get_address_for_data_offset(self, offset:int) -> Optional[int]:
"""
- ``get_address_for_data_offset`` returns the virtual address that maps to the specific file offset
+ ``get_address_for_data_offset`` returns the virtual address that maps to the specific file offset.
:param int offset: file offset
:return: the virtual address of the first segment that contains that file location
@@ -6875,6 +6875,23 @@ class BinaryView:
return None
return address.value
+ def get_data_offset_for_address(self, address:int) -> Optional[int]:
+ """
+ ``get_data_offset_for_address`` returns the file offset that maps to the given virtual address, if possible.
+
+ If `address` falls within a bss segment or an external segment, for example, no mapping is possible, and `None` will be returned.
+
+ :param int address: virtual address
+ :return: the file location that is mapped to the given virtual address, or None if no such mapping is possible
+ :rtype: Int
+ """
+ segment = self.get_segment_at(address)
+ if segment is not None and segment.start <= address < segment.end:
+ offset = address - segment.start
+ if offset < segment.data_length:
+ return offset + segment.data_offset
+ return None
+
def add_auto_section(self, name:str, start:int, length:int,
semantics:SectionSemantics = SectionSemantics.DefaultSectionSemantics, type:str = "",
align:int = 1, entry_size:int = 1, linked_section:str = "", info_section:str = "", info_data:int = 0) -> None: