Fetch the PE file sections. The sections will be readily available in the "sections" attribute. Its attributes will contain all the section information plus "data" a buffer containing the section's data. The "Characteristics" member will be processed and attributes
(self, offset)
| 3368 | return |
| 3369 | |
| 3370 | def parse_sections(self, offset): |
| 3371 | """Fetch the PE file sections. |
| 3372 | |
| 3373 | The sections will be readily available in the "sections" attribute. |
| 3374 | Its attributes will contain all the section information plus "data" |
| 3375 | a buffer containing the section's data. |
| 3376 | |
| 3377 | The "Characteristics" member will be processed and attributes |
| 3378 | representing the section characteristics (with the 'IMAGE_SCN_' |
| 3379 | string trimmed from the constant's names) will be added to the |
| 3380 | section instance. |
| 3381 | |
| 3382 | Refer to the SectionStructure class for additional info. |
| 3383 | """ |
| 3384 | |
| 3385 | self.sections = [] |
| 3386 | MAX_SIMULTANEOUS_ERRORS = 3 |
| 3387 | for i in range(self.FILE_HEADER.NumberOfSections): |
| 3388 | if i >= MAX_SECTIONS: |
| 3389 | self.__warnings.append( |
| 3390 | "Too many sections {0} (>={1})".format( |
| 3391 | self.FILE_HEADER.NumberOfSections, MAX_SECTIONS |
| 3392 | ) |
| 3393 | ) |
| 3394 | break |
| 3395 | simultaneous_errors = 0 |
| 3396 | section = SectionStructure(self.__IMAGE_SECTION_HEADER_format__, pe=self) |
| 3397 | if not section: |
| 3398 | break |
| 3399 | section_offset = offset + section.sizeof() * i |
| 3400 | section.set_file_offset(section_offset) |
| 3401 | section_data = self.__data__[ |
| 3402 | section_offset : section_offset + section.sizeof() |
| 3403 | ] |
| 3404 | # Check if the section is all nulls and stop if so. |
| 3405 | if count_zeroes(section_data) == section.sizeof(): |
| 3406 | self.__warnings.append(f"Invalid section {i}. Contents are null-bytes.") |
| 3407 | break |
| 3408 | if not section_data: |
| 3409 | self.__warnings.append( |
| 3410 | f"Invalid section {i}. No data in the file (is this corkami's " |
| 3411 | "virtsectblXP?)." |
| 3412 | ) |
| 3413 | break |
| 3414 | section.__unpack__(section_data) |
| 3415 | self.__structures__.append(section) |
| 3416 | |
| 3417 | if section.SizeOfRawData + section.PointerToRawData > len(self.__data__): |
| 3418 | simultaneous_errors += 1 |
| 3419 | self.__warnings.append( |
| 3420 | f"Error parsing section {i}. SizeOfRawData is larger than file." |
| 3421 | ) |
| 3422 | |
| 3423 | if self.adjust_FileAlignment( |
| 3424 | section.PointerToRawData, self.OPTIONAL_HEADER.FileAlignment |
| 3425 | ) > len(self.__data__): |
| 3426 | simultaneous_errors += 1 |
| 3427 | self.__warnings.append( |
no test coverage detected