ELF\_RAWFILE(3) Libelf Programmer's Manual ELF\_RAWFILE(3)

# [NAME](#NAME)

elf\_rawfile - Retrieve a pointer to the entire raw ELF file image

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
char *elf_rawfile(Elf *elf, size_t *ptr);
```

# [DESCRIPTION](#DESCRIPTION)

The **elf\_rawfile**() function returns a pointer to the entire contents of the ELF file represented by *elf*. This data is unprocessed and includes everything from the ELF header to the final byte.

If the ELF descriptor was opened from memory or the file has already been memory-mapped or fully read, this function returns a pointer to the internal buffer.

If the ELF data has not yet been read or mapped, it is loaded on demand.

If *ptr* is non-NULL, the total size in bytes of the raw file is stored in *\*ptr*.

The returned buffer is read-only and managed internally by libelf. The application must not modify or free it.

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

A handle previously returned by [**elf\_begin**(3)](/man/os/elfutils/elf_begin.3)**.**

[*ptr*](#ptr)

If not **NULL**, receives the size in bytes of the ELF file.

# [RETURN VALUE](#RETURN_VALUE)

Returns a pointer to the start of the ELF file data. On failure, **NULL** is returned and *\*ptr* (if non-NULL) is set to 0.

# [SEE ALSO](#SEE_ALSO)

[**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** elf\_rawfile () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;elfutils-devel@sourceware.org&gt; or https://sourceware.org/bugzilla/.

2025-06-30 Libelf

---

Document: elf_rawfile(3) from elfutils 0.197-r0 (Chainguard OS)
Source: https://sourceware.org/git/elfutils.git
