* Find data. */
| 259 | * Find data. |
| 260 | */ |
| 261 | static uint8_t *findPEData(const Binary *B, uint32_t addr) |
| 262 | { |
| 263 | if (addr == 0x0) |
| 264 | return nullptr; |
| 265 | PIMAGE_FILE_HEADER file_hdr = B->pe.file_hdr; |
| 266 | PIMAGE_SECTION_HEADER shdr = B->pe.shdr; |
| 267 | for (uint16_t i = 0; i < file_hdr->NumberOfSections; i++) |
| 268 | { |
| 269 | if (addr >= shdr[i].VirtualAddress && |
| 270 | addr < shdr[i].VirtualAddress + shdr[i].VirtualSize) |
| 271 | { |
| 272 | uint32_t offset = shdr[i].PointerToRawData + |
| 273 | (addr - shdr[i].VirtualAddress); |
| 274 | return B->patched.bytes + offset; |
| 275 | } |
| 276 | } |
| 277 | return nullptr; |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | * Emit the (modified) PE executable. |