PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
elf64_get_symbol_by_index.c
Go to the documentation of this file.
1#include "common/elf.h"
2
4{
5 if (elf == NULL)
6 {
7 return NULL;
8 }
9
10 if (elf->symtab == NULL)
11 {
12 return NULL;
13 }
14
15 uint64_t symCount = elf->symtab->sh_size / elf->symtab->sh_entsize;
16 if (symbolIndex >= symCount)
17 {
18 return NULL;
19 }
20
21 void* symTableBase = ELF64_AT_OFFSET(elf, elf->symtab->sh_offset);
22 return (Elf64_Sym*)((uintptr_t)symTableBase + (symbolIndex * elf->symtab->sh_entsize));
23}
#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
Elf64_Sym * elf64_get_symbol_by_index(const Elf64_File *elf, Elf64_Xword symbolIndex)
Get a symbol by its index from the symbol table.
#define NULL
Pointer error value.
Definition NULL.h:23
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
ELF File Helper structure.
Definition elf.h:781
Elf64_Shdr * symtab
The symbol table section, or NULL if not found.
Definition elf.h:784
Elf64_Xword sh_entsize
Definition elf.h:479
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
ELF64 Symbol Table Entry.
Definition elf.h:543