Get data chunk from a section. Allows to query data from the section by passing the addresses where the PE file would be loaded by default. It is then possible to retrieve code and data by their real addresses as they would be if loaded. Note that sections o
(self, start=None, length=None, ignore_padding=False)
| 1177 | return self.VirtualAddress_adj |
| 1178 | |
| 1179 | def get_data(self, start=None, length=None, ignore_padding=False): |
| 1180 | """Get data chunk from a section. |
| 1181 | |
| 1182 | Allows to query data from the section by passing the |
| 1183 | addresses where the PE file would be loaded by default. |
| 1184 | It is then possible to retrieve code and data by their real |
| 1185 | addresses as they would be if loaded. |
| 1186 | |
| 1187 | Note that sections on disk can include padding that would |
| 1188 | not be loaded to memory. That is the case if `section.SizeOfRawData` |
| 1189 | is greater than `section.Misc_VirtualSize`, and that means |
| 1190 | that data past `section.Misc_VirtualSize` is padding. |
| 1191 | In case you are not interested in this padding, passing |
| 1192 | `ignore_padding=True` will truncate the result in order |
| 1193 | not to return the padding (if any). |
| 1194 | |
| 1195 | Returns bytes() under Python 3.x and set() under Python 2.7 |
| 1196 | """ |
| 1197 | |
| 1198 | if start is None: |
| 1199 | offset = self.get_PointerToRawData_adj() |
| 1200 | else: |
| 1201 | offset = ( |
| 1202 | start - self.get_VirtualAddress_adj() |
| 1203 | ) + self.get_PointerToRawData_adj() |
| 1204 | |
| 1205 | if length is not None: |
| 1206 | end = offset + length |
| 1207 | else: |
| 1208 | end = offset + self.SizeOfRawData |
| 1209 | |
| 1210 | if ignore_padding: |
| 1211 | end = min(end, offset + self.Misc_VirtualSize) |
| 1212 | |
| 1213 | # PointerToRawData is not adjusted here as we might want to read any possible |
| 1214 | # extra bytes that might get cut off by aligning the start (and hence cutting |
| 1215 | # something off the end) |
| 1216 | if end > self.PointerToRawData + self.SizeOfRawData: |
| 1217 | end = self.PointerToRawData + self.SizeOfRawData |
| 1218 | return self.pe.__data__[offset:end] |
| 1219 | |
| 1220 | def __setattr__(self, name, val): |
| 1221 |
no test coverage detected