(self, rva, size)
| 3876 | return LoadConfigData(struct=load_config_struct) |
| 3877 | |
| 3878 | def parse_relocations_directory(self, rva, size): |
| 3879 | """""" |
| 3880 | |
| 3881 | rlc_size = Structure(self.__IMAGE_BASE_RELOCATION_format__).sizeof() |
| 3882 | end = rva + size |
| 3883 | |
| 3884 | relocations = [] |
| 3885 | while rva < end: |
| 3886 | |
| 3887 | # OC Patch: |
| 3888 | # Malware that has bad RVA entries will cause an error. |
| 3889 | # Just continue on after an exception |
| 3890 | # |
| 3891 | try: |
| 3892 | rlc = self.__unpack_data__( |
| 3893 | self.__IMAGE_BASE_RELOCATION_format__, |
| 3894 | self.get_data(rva, rlc_size), |
| 3895 | file_offset=self.get_offset_from_rva(rva), |
| 3896 | ) |
| 3897 | except PEFormatError: |
| 3898 | self.__warnings.append( |
| 3899 | "Invalid relocation information. Can't read " |
| 3900 | "data at RVA: 0x%x" % rva |
| 3901 | ) |
| 3902 | rlc = None |
| 3903 | |
| 3904 | if not rlc: |
| 3905 | break |
| 3906 | |
| 3907 | # rlc.VirtualAddress must lie within the Image |
| 3908 | if rlc.VirtualAddress > self.OPTIONAL_HEADER.SizeOfImage: |
| 3909 | self.__warnings.append( |
| 3910 | "Invalid relocation information. VirtualAddress outside" |
| 3911 | " of Image: 0x%x" % rlc.VirtualAddress |
| 3912 | ) |
| 3913 | break |
| 3914 | |
| 3915 | # rlc.SizeOfBlock must be less or equal than the size of the image |
| 3916 | # (It's a rather loose sanity test) |
| 3917 | if rlc.SizeOfBlock > self.OPTIONAL_HEADER.SizeOfImage: |
| 3918 | self.__warnings.append( |
| 3919 | "Invalid relocation information. SizeOfBlock too large" |
| 3920 | ": %d" % rlc.SizeOfBlock |
| 3921 | ) |
| 3922 | break |
| 3923 | |
| 3924 | reloc_entries = self.parse_relocations( |
| 3925 | rva + rlc_size, rlc.VirtualAddress, rlc.SizeOfBlock - rlc_size |
| 3926 | ) |
| 3927 | |
| 3928 | relocations.append(BaseRelocationData(struct=rlc, entries=reloc_entries)) |
| 3929 | |
| 3930 | if not rlc.SizeOfBlock: |
| 3931 | break |
| 3932 | rva += rlc.SizeOfBlock |
| 3933 | |
| 3934 | return relocations |
| 3935 |
nothing calls this directly
no test coverage detected