ELF_GETDATA_RAWCHUNK(3)
β¨ ELF_GETDATA_RAWCHUNK(3) β¨
okay so bestie, welcome to the Libelf Programmer's Manual π this one's the page for elf_getdata_rawchunk, and ngl it's lowkey one of the most useful little gremlins in the whole libelf family. let's get into it π«Ά
πΈ NAME πΈ
elf_getdata_rawchunk β create a raw data descriptor from a file offset
π SYNOPSIS π
#include <libelf.h>
Elf_Data * elf_getdata_rawchunk("Elf *elf", int64_t offset , size_t size , Elf_Type type );
π¦ DESCRIPTION π¦
so the way that elf_getdata_rawchunk() works is it hands you back an Elf_Data descriptor that points at a raw region of the ELF file. like, it starts at the file offset you gave it and spans size bytes. this is literally the move for grabbing arbitrary byte ranges in the ELF file that might not line up with any section or any segment. no section? no segment? doesn't matter bestie, we ball π
the Elf_Data you get back has its d_buf properly aligned for the type you asked for. slay.
here's the tea on byte order: if the file's byte order matches the host, and the alignment permits it, the raw data comes back as-is. but if the file's byte order is different, the buffer gets converted into native byte order and aligned so you can access it directly. so basically this behaves like elf_getdata(), and not like elf_rawdata(). meaning: the contents of the return value's d_buf are a decoded representation. periodt.
β οΈ and now the important part, bestie: the returned data is not associated with any section or update mechanism. it will not be included in any output written byelf_update(3). it's also owned by libelf, and it stays valid untilelf_end()is called onelf. don't free it yourself, don't be that girl π
π PARAMETERS π
elfβ a pointer to anElfdescriptor representing the ELF file. your main character β¨offsetβ the starting file offset, in bytes. this one has to lie within the bounds of the file. no sneaking past the edge, okay? π«sizeβ how many bytes to include in the data chunk, starting atoffset.typeβ anElf_Typeenumeration value that tells libelf how you intend to interpret the data. the values include:ELF_T_BYTEβ raw bytes. just vibes, no interpretation πELF_T_ADDR,ELF_T_OFF,ELF_T_HALF,ELF_T_WORD,ELF_T_XWORD,ELF_T_SWORD,ELF_T_SXWORDβ integer and pointer types.ELF_T_EHDR,ELF_T_SHDR,ELF_T_PHDRβ ELF file headers, section headers, and program headers.ELF_T_SYM,ELF_T_DYN,ELF_T_REL,ELF_T_RELA,ELF_T_RELRβ symbols and relocations.ELF_T_NHDR,ELF_T_CHDR,ELF_T_NHDR8β ELF note headers and compressed data headers.ELF_T_VDEF,ELF_T_VDAUX,ELF_T_VNEED,ELF_T_VNAUXβ versioning structures.ELF_T_SYMINFO,ELF_T_MOVE,ELF_T_LIBβ other ELF metadata.ELF_T_GNUHASHβ GNU-style hash table.ELF_T_AUXVβ auxiliary vectors.
π₯ RETURN VALUE π₯
on success you get a pointer to an Elf_Data descriptor. iconic. π
if any arguments are invalid, or if memory allocation fails, or if file reading fails, you get NULL. and an error code gets set, which you can grab with elf_errmsg(). so check that, bestie, don't just sit there wondering π
also cute detail: the result is cached and shared between repeated calls using the same arguments. so call it twice with the same args and you're getting the same thing back. efficient queen π
π SEE ALSO π
elf(3), elf_errmsg(3), elf_getdata(3), elf_getscn(3), elf_rawdata(3), libelf(3), elf(5)
β ATTRIBUTES β
no tables here, just the facts, and the fact is:
- Interface:
elf_getdata_rawchunk()- Attribute: Thread safety
- Value:
MT-Safe
so yeah, thread-safe, go off π§
π REPORTING BUGS π
found a bug? don't gatekeep it, report it to <elfutils-devel@sourceware.org> or at https://sourceware.org/bugzilla/. the devs wanna know fr fr π«Ά
πΈ HISTORY πΈ
elf_getdata_rawchunk first appeared in elfutils 0.130.
β οΈ and heads up: this function is an elfutils libelf extension and may not be available in other libelf implementations. so if you're porting your code around, vibe check your libelf first, iykyk.
okay that's the whole page, bestie, you're fully caught up π this was the Libelf manual, dated 2025-06-30, and yeah, the page is literally called ELF_GETDATA_RAWCHUNK(3) β go forth and read your raw chunks, no cap πβ¨
π¦ 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