ELF_GETIDENT(3)
π elf_getident(3) π
okay bestie, welcome to the Libelf Programmer's Manual β¨ this one's short and sweet and honestly kinda iconic β it's the page about peeking at your ELF file's identification bytes, aka the little 16-byte vibe check at the very top of every ELF header. no cap.
πΈ NAME πΈ
elf_getident β return the ELF identification bytes π¦
β¨ SYNOPSIS β¨
#include <libelf.h>
char * elf_getident("Elf *elf", size_t *nbytes );
(yes the quotes are literally in there, we don't question it, we just vibe π )
π DESCRIPTION π
So the elf_getident() function hands you back a pointer to the 16-byte ELF identification array from the ELF header of the descriptor elf you passed in. it's giving "show me your ID" but for binaries π³β¨
That identification data starts with the magic number \177ELF and then rolls through the class, data encoding, ELF version, OS ABI, and ABI version fields. it corresponds to the first EI_NIDENT bytes of the ELF header, and you can also get at it through the e_ident field of either Elf32_Ehdr or Elf64_Ehdr. same bytes, different door πͺβ¨
If elf is a valid descriptor for an ELF object, the function returns a pointer to the internal buffer holding the header's identification bytes. and listen β that buffer is owned by the library. do not modify it, do not free it, do not touch it, bestie, it is NOT yours π it's a look-don't-touch situation fr fr.
If nbytes is not NULL, the function sets it to EI_NIDENT (16) β that's the length in bytes of the returned identifier. cute, consistent, always 16. π
π PARAMETERS π
elfβ pointer to anElfdescriptor referring to a valid ELF object. If the descriptor does not represent an ELF object file (it'sNULL, orelf_kind()is notELF_K_ELF),NULLgets returned. no ELF, no entry π«nbytesβ optional pointer to asize_tvariable. If it's non-NULL, it gets set to the length of the returned buffer (alwaysEI_NIDENTon success,0on failure). so on success you get 16, on failure you get 0, and them's the rules β¨
π₯ RETURN VALUE π₯
Returns a pointer to the internal 16-byte e_ident buffer on success, and NULL on failure. and here's the quirky part β it does not set elf_errno. so don't go checking elf_errno expecting answers, it simply did not leave a note π
That buffer is indexed using the EI_CLASS, EI_DATA, EI_VERSION, EI_OSABI, and EI_ABIVERSION macros found in elf.h. also see elf(5) for the lore π
π SEE ALSO π
π§ ATTRIBUTES π§
elf_getident()β Thread safety:MT-Safeβ so yes, you and your besties can all call it at the same time, it's chill π«Ά
π REPORTING BUGS π
found a bug? spill it to <elfutils-devel@sourceware.org> or drop it at https://sourceware.org/bugzilla/. we listen, we fix, we slay ππ
okay that's the whole page!! this was brought to you by Libelf, dated 2025-06-30, and filed under ELF_GETIDENT(3) β go read your bytes, main character πβ¨π¦π
π¦ where this page comes from
- alpine 3.23: elfutils-doc 0.194-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- alpine 3.24: elfutils-doc 0.195-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- arch rolling: libelf 0.196-1
- arch rolling: libelf 0.197-1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 10: elfutils-libelf-devel 0.197-1.el10 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.194-5.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.194-5.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- nixos 26.05: elfutils 0.194
- nixpkgs unstable: elfutils 0.195
- ubuntu resolute: libelf-dev 0.194-4 Β· GPL-3.0-or-later
- ubuntu stonking: libelf-dev 0.196-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms