ELF_RAWDATA(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_RAWDATA πŸ’…

okay bestie, welcome to elf_rawdata β€” it lives in the Libelf Programmer's Manual and it is literally the "give me the section exactly as it sat on disk, no glow-up, no filter" function πŸŽ€


🌸 SYNOPSIS 🌸

#include <libelf.h>

Elf_Data *elf_rawdata(Elf_Scn *scn, Elf_Data *data);

πŸ’– DESCRIPTION πŸ’–

so. elf_rawdata() hands you back a pointer to an Elf_Data structure, and inside that structure is the unprocessed (raw) contents of the section that scn is pointing at. no cap.

and when we say raw, we mean raw raw β€” this view is the exact on-disk binary layout of the ELF file, with zero modifications made for endianness or memory alignment. it's the section in its natural habitat, before anyone touched it πŸ¦‹

if you actually want the data translated into the in-memory format, that's a different function, babe β€” go use elf_getdata(3). that's the one that does the translation. this one does not. periodt.

now, the data parameter, and this matters:

  • if data is NULL, the raw data of the section is returned.
  • if data is not NULL and raw data has not been initialized, the call fails. 😭

compressed sections? bestie, listen. for compressed sections (i.e., ones with the SHF_COMPRESSED flag), the returned Elf_Data contains the compressed form, and its d_type is ELF_T_CHDR. it does not unzip anything for you, it's just handing you the compressed vibe as-is.

for sections of type SHT_NOBITS, the d_buf pointer is NULL. no buffer, no drama.

⚠️ important, and I need you to hear me on this one: the Elf_Data * returned by this function and its d_buf are owned by libelf and should not be freed. they're only valid until elf_end(3) is called on the Elf descriptor associated with scn. so don't free them, don't hoard them, don't keep them past elf_end. that's it, that's the rule πŸ’€

🫢 PARAMETERS 🫢

  • scn β€” a section descriptor returned from elf_getscn(3) or elf_nextscn(3). and if it's NULL? then this function returns NULL. it's giving "you get nothing, respectfully" πŸ™ˆ
  • data β€” must be NULL on the initial invocation. any other use is not supported. that's not me being mean, that's just the facts πŸ’…

πŸ‘‘ RETURN VALUE πŸ‘‘

it returns a pointer to an Elf_Data descriptor describing the raw contents of the section. if something goes wrong, NULL is returned and elf_errno is set. so like, always check your elf_errno, bestie, that's the whole plot twist 🌈


πŸ”₯ SEE ALSO πŸ”₯


⭐ ATTRIBUTES ⭐

  • Interface: elf_rawdata()
  • Attribute: Thread safety
  • Value: MT-Safe

(yes bestie, it's MT-Safe. multi-threaded and unbothered. main character energy fr fr ✨)


πŸ› REPORTING BUGS πŸ›

found a bug? don't gatekeep it, report it to <elfutils-devel@sourceware.org> or over at https://sourceware.org/bugzilla/. the maintainers will literally be obsessed with you for it πŸ“


and that's the whole page, bestie!! this was Libelf, dated 2025-06-30 β€” go forth, read your raw section bytes, and do not free that pointer. iykyk πŸ’œπŸ§š

πŸ“¦ where this page comes from