PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
elf64_get_section_name.c
Go to the documentation of this file.
1#include "common/elf.h"
2
3const char* elf64_get_section_name(const Elf64_File* elf, const Elf64_Shdr* section)
4{
5 if (elf == NULL || section == NULL)
6 {
7 return NULL;
8 }
9
10 Elf64_Ehdr* header = (Elf64_Ehdr*)elf->header;
11
12 uint64_t shstrndx = header->e_shstrndx;
13 if (shstrndx == SHN_XINDEX)
14 {
15 Elf64_Shdr* firstShdr = ELF64_GET_SHDR(elf, 0);
16 shstrndx = firstShdr->sh_link;
17 }
18
19 return elf64_get_string(elf, shstrndx, section->sh_name);
20}
const char * elf64_get_string(const Elf64_File *elf, Elf64_Xword strTabIndex, Elf64_Off offset)
Get a string from the string table section at the given offset.
const char * elf64_get_section_name(const Elf64_File *elf, const Elf64_Shdr *section)
Get the name of a section.
#define ELF64_GET_SHDR(elf, index)
Get the section header at the given index from an ELF file.
Definition elf.h:805
@ SHN_XINDEX
Indicates that the actual index is too large to fit and is stored elsewhere.
Definition elf.h:454
#define NULL
Pointer error value.
Definition NULL.h:23
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
ELF64 Header.
Definition elf.h:95
Elf64_Half e_shstrndx
Definition elf.h:123
ELF File Helper structure.
Definition elf.h:781
Elf64_Ehdr * header
The data in the file, pointed to the start of the ELF header.
Definition elf.h:782
ELF64 Section Header.
Definition elf.h:468
Elf64_Word sh_name
Index of the section name in the string table.
Definition elf.h:469
Elf64_Word sh_link
Definition elf.h:475