Get the offset of data appended to the file and not contained within the area described in the headers.
(self)
| 7300 | return False |
| 7301 | |
| 7302 | def get_overlay_data_start_offset(self): |
| 7303 | """Get the offset of data appended to the file and not contained within |
| 7304 | the area described in the headers.""" |
| 7305 | |
| 7306 | largest_offset_and_size = (0, 0) |
| 7307 | |
| 7308 | def update_if_sum_is_larger_and_within_file( |
| 7309 | offset_and_size, file_size=len(self.__data__) |
| 7310 | ): |
| 7311 | if sum(offset_and_size) <= file_size and sum(offset_and_size) > sum( |
| 7312 | largest_offset_and_size |
| 7313 | ): |
| 7314 | return offset_and_size |
| 7315 | return largest_offset_and_size |
| 7316 | |
| 7317 | if hasattr(self, "OPTIONAL_HEADER"): |
| 7318 | largest_offset_and_size = update_if_sum_is_larger_and_within_file( |
| 7319 | ( |
| 7320 | self.OPTIONAL_HEADER.get_file_offset(), |
| 7321 | self.FILE_HEADER.SizeOfOptionalHeader, |
| 7322 | ) |
| 7323 | ) |
| 7324 | |
| 7325 | for section in self.sections: |
| 7326 | largest_offset_and_size = update_if_sum_is_larger_and_within_file( |
| 7327 | (section.PointerToRawData, section.SizeOfRawData) |
| 7328 | ) |
| 7329 | |
| 7330 | skip_directories = [DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_SECURITY"]] |
| 7331 | |
| 7332 | for idx, directory in enumerate(self.OPTIONAL_HEADER.DATA_DIRECTORY): |
| 7333 | if idx in skip_directories: |
| 7334 | continue |
| 7335 | try: |
| 7336 | largest_offset_and_size = update_if_sum_is_larger_and_within_file( |
| 7337 | (self.get_offset_from_rva(directory.VirtualAddress), directory.Size) |
| 7338 | ) |
| 7339 | # Ignore directories with RVA out of file |
| 7340 | except PEFormatError: |
| 7341 | continue |
| 7342 | |
| 7343 | if len(self.__data__) > sum(largest_offset_and_size): |
| 7344 | return sum(largest_offset_and_size) |
| 7345 | |
| 7346 | return None |
| 7347 | |
| 7348 | def get_overlay(self): |
| 7349 | """Get the data appended to the file and not contained within the area described |
no test coverage detected