Check whether the section contains the address provided.
(self, rva)
| 1252 | ) |
| 1253 | |
| 1254 | def contains_rva(self, rva): |
| 1255 | """Check whether the section contains the address provided.""" |
| 1256 | |
| 1257 | # speedup |
| 1258 | if self.section_min_addr is not None and self.section_max_addr is not None: |
| 1259 | return self.section_min_addr <= rva < self.section_max_addr |
| 1260 | |
| 1261 | VirtualAddress_adj = self.get_VirtualAddress_adj() |
| 1262 | # Check if the SizeOfRawData is realistic. If it's bigger than the size of |
| 1263 | # the whole PE file minus the start address of the section it could be |
| 1264 | # either truncated or the SizeOfRawData contains a misleading value. |
| 1265 | # In either of those cases we take the VirtualSize |
| 1266 | # |
| 1267 | if len(self.pe.__data__) - self.get_PointerToRawData_adj() < self.SizeOfRawData: |
| 1268 | # PECOFF documentation v8 says: |
| 1269 | # VirtualSize: The total size of the section when loaded into memory. |
| 1270 | # If this value is greater than SizeOfRawData, the section is zero-padded. |
| 1271 | # This field is valid only for executable images and should be set to zero |
| 1272 | # for object files. |
| 1273 | # |
| 1274 | size = self.Misc_VirtualSize |
| 1275 | else: |
| 1276 | size = max(self.SizeOfRawData, self.Misc_VirtualSize) |
| 1277 | |
| 1278 | # Check whether there's any section after the current one that starts before |
| 1279 | # the calculated end for the current one. If so, cut the current section's size |
| 1280 | # to fit in the range up to where the next section starts. |
| 1281 | if ( |
| 1282 | self.next_section_virtual_address is not None |
| 1283 | and self.next_section_virtual_address > self.VirtualAddress |
| 1284 | and VirtualAddress_adj + size > self.next_section_virtual_address |
| 1285 | ): |
| 1286 | size = self.next_section_virtual_address - VirtualAddress_adj |
| 1287 | |
| 1288 | self.section_min_addr = VirtualAddress_adj |
| 1289 | self.section_max_addr = VirtualAddress_adj + size |
| 1290 | return VirtualAddress_adj <= rva < VirtualAddress_adj + size |
| 1291 | |
| 1292 | def contains(self, rva): |
| 1293 | return self.contains_rva(rva) |
no test coverage detected