User Tools

Site Tools


solaris:elf_strptr.3elf

elf_strptr


NAME

elf_strptr - make a string pointer

SYNOPSIS

cc [ flag … ] file-lelf [ library … ]
#include <libelf.h>

char *elf_strptr(Elf *elf, size_t section, size_t offset);

DESCRIPTION

The elf_strptr() function converts a string section offset to a string pointer. elf identifies the file in which the string section resides, and section identifies the section table index for the strings. elf_strptr() normally returns a pointer to a string, but it returns a null pointer when elf is null, section is invalid or is not a section of type SHT_STRTAB, the section data cannot be obtained, offset is invalid, or an error occurs.

EXAMPLES

Example 1 A sample program of calling elf_strptr() function.

A prototype for retrieving section names appears below. The file header specifies the section name string table in the e_shstrndx member. The following code loops through the sections, printing their names.

/* handle the error */
if 1) == 0) {

return;

}
ndx = ehdr→e_shstrndx;
scn = 0;
while 2) != 0) {

char *name = 0;
if 3) != 0)

name = elf_strptr(elf, ndx, (size_t)shdr→sh_name);

printf(“’%s’\n”, name? name: “(null)”);

}

ATTRIBUTES

See attributes(7) for descriptions of the following attributes:

SEE ALSO

elf(3ELF), elf32_getshdr(3ELF), elf32_xlatetof(3ELF), elf_getdata(3ELF), libelf(3LIB), attributes(7)

NOTES

When applied to a compressed string table section, elf_strptr() will return pointers to uncompressed strings, without causing the string table section to be uncompressed.

A program may call elf_getdata() to retrieve an entire string table section. For some applications, that would be both more efficient and more convenient than using elf_strptr().


1)
ehdr = elf32_getehdr(elf
2)
scn = elf_nextscn(elf, scn
3)
shdr = elf32_getshdr(scn
solaris/elf_strptr.3elf.txt · Last modified: 2023/07/19 08:57 by A User Not Logged in