PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
elf64_get_string.c
Go to the documentation of this file.
1#include "common/elf.h"
2
3const char* elf64_get_string(const Elf64_File* elf, Elf64_Xword strTabIndex, Elf64_Off offset)
4{
5 if (elf == NULL)
6 {
7 return NULL;
8 }
9
10 Elf64_Ehdr* header = (Elf64_Ehdr*)elf->header;
11 if (strTabIndex >= header->e_shnum)
12 {
13 return NULL;
14 }
15
16 Elf64_Shdr* strtabHdr = ELF64_GET_SHDR(elf, strTabIndex);
17 if (strtabHdr->sh_type != SHT_STRTAB)
18 {
19 return NULL;
20 }
21
22 if (offset >= strtabHdr->sh_size)
23 {
24 return NULL;
25 }
26
27 char* strTable = (char*)ELF64_AT_OFFSET(elf, strtabHdr->sh_offset);
28 return &strTable[offset];
29}
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.
#define ELF64_AT_OFFSET(elf, offset)
Get a pointer to a location in the ELF file at the given offset.
Definition elf.h:814
uint64_t Elf64_Xword
ELF64 Unsigned long integer.
Definition elf.h:60
uint64_t Elf64_Off
ELF64 Unsigned file offset.
Definition elf.h:36
#define ELF64_GET_SHDR(elf, index)
Get the section header at the given index from an ELF file.
Definition elf.h:805
@ SHT_STRTAB
Contains a string table.
Definition elf.h:492
#define NULL
Pointer error value.
Definition NULL.h:23
ELF64 Header.
Definition elf.h:95
Elf64_Half e_shnum
Definition elf.h:114
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_type
Section type.
Definition elf.h:470
Elf64_Xword sh_size
Section size in bytes.
Definition elf.h:474
Elf64_Off sh_offset
Section's file offset in bytes.
Definition elf.h:473