elf_getident, elf_getphnum, elf_getshnum, elf_getshstrndx - retrieve ELF header data
cc [ flag ... ] file ... -lelf [ library ... ] #include <libelf.h> char * elf_getident(Elf *elf, size_t *dst);
int elf_getphnum(Elf *elf, size_t *dst);
int elf_getshnum(Elf *elf, size_t *dst);
int elf_getshstrndx(Elf *elf, size_t *dst);
As elf(3ELF) explains, ELF provides a framework for various classes of files, where basic objects might have 32 or 64 bits. To accommodate these differences, without forcing the larger sizes on smaller machines, the initial bytes in an ELF file hold identification information common to all file classes. The e_ident of every ELF header has EI_NIDENT bytes with interpretations described in the following table.
e_ident Index | Value | Purpose |
EI_MAG0 | ||
EI_MAG1 | ||
EI_MAG2 | ||
EI_MAG3 | ||
EI_CLASS | ||
EI_DATA | ||
EI_VERSION | ||
7-15 |
Other kinds of files might have identification data, though they would not conform to e_ident. See elf_kind(3ELF) for information on other kinds of files.
The elf_getident() function returns a pointer to the initial bytes of the file. If the library recognizes the file, a conversion from the file image to the memory image can occur. The identification bytes are guaranteed to be unmodified, though the size of the unmodified area depends on the file type. If the dst argument is non-null, the library stores the number of identification bytes in the location to which dst points. If no data are present, elf is NULL, or an error occurs, the return value is a null pointer, with 0 stored through dst, if dst is non-null.
The elf_getphnum() function obtains the number of program headers recorded in the ELF file. The number of sections in a file is typically recorded in the e_phnum field of the ELF header. A file that requires the ELF extended program header records the value PN_XNUM in the e_phnum field and records the number of sections in the sh_info field of section header 0. See USAGE. The dst argument points to the location where the number of sections is stored. If elf is NULL or an error occurs, elf_getphnum() returns 0.
The elf_getshnum() function obtains the number of sections recorded in the ELF file. The number of sections in a file is typically recorded in the e_shnum field of the ELF header. A file that requires ELF extended section records the value 0 in the e_shnum field and records the number of sections in the sh_size field of section header 0. See USAGE. The dst argument points to the location where the number of sections is stored. If a call to elf_newscn(3ELF) that uses the same elf descriptor is performed, the value obtained by elf_getshnum() is valid only after a successful call to elf_update(3ELF). If elf is NULL or an error occurs, elf_getshnum() returns 0.
The elf_getshstrndx() function obtains the section index of the string table associated with the section headers in the ELF file. The section header string table index is typically recorded in the e_shstrndx field of the ELF header. A file that requires ELF extended section records the value SHN_XINDEX in the e_shstrndx field and records the string table index in the sh_link field of section header 0. See USAGE. The dst argument points to the location where the section header string table index is stored. If elf is NULL or an error occurs, elf_getshstrndx() returns 0.
ELF extended sections allow an ELF file to contain more than 0xff00 (SHN_LORESERVE) section. ELF extended program headers allow an ELF file to contain 0xffff (PN_XNUM) or more program headers. See the Linker and Libraries Guide for more information.
Upon successful completion, elf_getident(), elf_getphnum(), elf_getshnum(), and elf_getshstrndx() functions return 1. Otherwise, they return 0.
See attributes(5) for descriptions of the following attributes:
|
elf(3ELF), elf32_getehdr(3ELF), elf_begin(3ELF), elf_kind(3ELF), elf_newscn(3ELF), elf_rawfile(3ELF), elf_update(3ELF), libelf(3LIB), attributes(5)
Linker and Libraries Guide
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |