ELF_RAWFILE(3)

πŸ“¦
version 0.197 Β· 2 versions
, in alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

✨ 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 from elf_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