* Data analysis pass: find potential code pointers in data. */
| 328 | * Data analysis pass: find potential code pointers in data. |
| 329 | */ |
| 330 | static void CFGDataAnalysis(const ELF *elf, bool pic, const Instr *Is, |
| 331 | size_t size, const std::set<intptr_t> &tables, Targets &targets) |
| 332 | { |
| 333 | // Gather relocation information: |
| 334 | const SectionInfo §ions = getELFSectionInfo(elf); |
| 335 | for (const auto &entry: sections) |
| 336 | { |
| 337 | const Elf64_Shdr *shdr = entry.second; |
| 338 | if (shdr->sh_type != SHT_RELA) |
| 339 | continue; |
| 340 | const uint8_t *sh_data = getELFData(elf) + shdr->sh_offset; |
| 341 | size_t sh_size = shdr->sh_size; |
| 342 | const Elf64_Rela *rela = (const Elf64_Rela *)sh_data; |
| 343 | const Elf64_Rela *rela_end = rela + sh_size / sizeof(Elf64_Rela); |
| 344 | for (; rela < rela_end; rela++) |
| 345 | { |
| 346 | if (ELF64_R_TYPE(rela->r_info) == R_X86_64_RELATIVE) |
| 347 | { |
| 348 | intptr_t target = (intptr_t)rela->r_addend; |
| 349 | DEBUG(targets, target, "Reloc : %p (F)", (void *)target); |
| 350 | addTarget(target, TARGET_INDIRECT | TARGET_FUNCTION, targets); |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | // Analyze each data section: |
| 356 | for (const auto &entry: sections) |
| 357 | CFGSectionAnalysis(elf, pic, entry.first, entry.second, Is, size, |
| 358 | tables, targets); |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Build the set of potential jump targets. |
no test coverage detected