ELF_RAWFILE(3)
β¨ ELF_RAWFILE(3) β¨
okay bestie, welcome to the libelf programmer's manual π this one's short and sweet and honestly kind of iconic.
πΈ NAME πΈ
elf_rawfile β grab a pointer to the entire raw ELF file image π¦
π SYNOPSIS π
#include <libelf.h>
char *elf_rawfile(Elf *elf, size_t *ptr);
π DESCRIPTION π
so like. elf_rawfile() hands you back a pointer to the whole entire contents of the ELF file that elf is representing. not a section, not a segment, the whole thing. it's unprocessed data too β it starts at the ELF header and runs allll the way to the final byte. the full meal, no cap π
here's the tea on where that pointer actually comes from:
- if the ELF descriptor was opened from memory, or the file has already been memory-mapped or fully read, you just get a pointer to the internal buffer. easy peasy.
- if the ELF data hasn't been read or mapped yet? it gets loaded on demand, bestie. it'll show up when you need it β¨
and if ptr is non-NULL, the total size in bytes of the raw file gets stashed in *ptr. so you always know how much you're working with π
β οΈ okay this part is IMPORTANT: the buffer you get back is read-only and it's managed internally by libelf. do NOT modify it, do NOT free it. that's not your buffer, that's libelf's buffer, hands off π
π«Ά PARAMETERS π«Ά
elfβ a handle you already got fromelf_begin(3). the main character of this whole operation πptrβ if it's not NULL, it receives the size in bytes of the ELF file. if you pass NULL, that's fine too, you just don't get the size π
β RETURN VALUE β
returns a pointer to the start of the ELF file data. if things go wrong, you get NULL back β and if ptr was non-NULL, *ptr gets set to 0. sad girl hours but at least it's consistent π
π₯ SEE ALSO π₯
π ATTRIBUTES π
- Interface:
elf_rawfile() - Attribute: Thread safety
- Value:
MT-Safe
so yeah, she's thread safe. go off π
π§ REPORTING BUGS π§
found a bug? don't just sit there, tell someone! report it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/ πβ¨
that's the whole page bestie, go forth and read your raw files π¦π
signing off β Libelf, dated 2025-06-30 π
π¦ 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