MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / get_rva_from_offset

Method get_rva_from_offset

pythonmemorymodule/pefile.py:5908–5937  ·  view source on GitHub ↗

Get the RVA corresponding to this file offset.

(self, offset)

Source from the content-addressed store, hash-verified

5906 return s.get_data(rva, length)
5907
5908 def get_rva_from_offset(self, offset):
5909 """Get the RVA corresponding to this file offset."""
5910
5911 s = self.get_section_by_offset(offset)
5912 if not s:
5913 if self.sections:
5914 lowest_rva = min(
5915 [
5916 self.adjust_SectionAlignment(
5917 s.VirtualAddress,
5918 self.OPTIONAL_HEADER.SectionAlignment,
5919 self.OPTIONAL_HEADER.FileAlignment,
5920 )
5921 for s in self.sections
5922 ]
5923 )
5924 if offset < lowest_rva:
5925 # We will assume that the offset lies within the headers, or
5926 # at least points before where the earliest section starts
5927 # and we will simply return the offset as the RVA
5928 #
5929 # The case illustrating this behavior can be found at:
5930 # http://corkami.blogspot.com/2010/01/hey-hey-hey-whats-in-your-head.html
5931 # where the import table is not contained by any section
5932 # hence the RVA needs to be resolved to a raw offset
5933 return offset
5934 return None
5935 else:
5936 return offset
5937 return s.get_rva_from_offset(offset)
5938
5939 def get_offset_from_rva(self, rva):
5940 """Get the file offset corresponding to this RVA.

Callers 2

parse_importsMethod · 0.95
__setattr__Method · 0.45

Calls 2

get_section_by_offsetMethod · 0.95

Tested by

no test coverage detected