| 349 | } |
| 350 | |
| 351 | std::vector<NoteData> |
| 352 | getNoteData(Elf* elf, Elf64_Word note_type, Elf_Type note_data_type) |
| 353 | { |
| 354 | LOG(DEBUG) << "Searching for NOTE segments of type " << note_type; |
| 355 | size_t n_program_headers; |
| 356 | if (elf_getphdrnum(elf, &n_program_headers) < 0) { |
| 357 | LOG(ERROR) << "Cannot determine number of program headers in the ELF file"; |
| 358 | return {}; |
| 359 | } |
| 360 | |
| 361 | // We have to look through the program header to find the note sections. |
| 362 | // Note that there can be more than one. |
| 363 | for (size_t program_header_idx = 0; program_header_idx < n_program_headers; ++program_header_idx) { |
| 364 | GElf_Phdr mem; |
| 365 | const GElf_Phdr* program_header = gelf_getphdr(elf, program_header_idx, &mem); |
| 366 | |
| 367 | if (program_header == nullptr || program_header->p_type != PT_NOTE) { |
| 368 | continue; |
| 369 | } |
| 370 | LOG(DEBUG) << "Program header of type PT_NOTE found with offset " << std::hex << std::showbase |
| 371 | << program_header->p_offset; |
| 372 | Elf_Data* data = elf_getdata_rawchunk( |
| 373 | elf, |
| 374 | program_header->p_offset, |
| 375 | program_header->p_filesz, |
| 376 | ELF_T_NHDR); |
| 377 | |
| 378 | if (data == nullptr) { |
| 379 | LOG(WARNING) << "Invalid data in NOTE section at " << std::showbase << std::hex |
| 380 | << program_header->p_offset; |
| 381 | continue; |
| 382 | } |
| 383 | |
| 384 | LOG(DEBUG) << "Fetching data from NOTE segments of type " << note_type |
| 385 | << " in program header with offset " << std::hex << std::showbase |
| 386 | << program_header->p_offset; |
| 387 | return getDataFromNoteSection(elf, note_type, note_data_type, program_header, data); |
| 388 | } |
| 389 | LOG(ERROR) << "Failed to locate a program header of type PT_NOTE in the core file"; |
| 390 | return {}; |
| 391 | } |
| 392 | |
| 393 | bool |
| 394 | getSectionInfo(const std::string& filename, const std::string& section_name, SectionInfo* result) |
no test coverage detected