GELF_XLATETOF(3) | Library Functions Manual | GELF_XLATETOF(3) |
elf32_xlate
,
elf64_xlate
, gelf_xlate
— translate data between files and memory
library “libelf”
#include
<libelf.h>
Elf_Data *
elf32_xlatetof
(Elf_Data
*dst, Elf_Data
*src, unsigned int
file_encoding);
Elf_Data *
elf32_xlatetom
(Elf_Data
*dst, Elf_Data
*src, unsigned int
file_encoding);
Elf_Data *
elf64_xlatetof
(Elf_Data
*dst, Elf_Data
*src, unsigned int
file_encoding);
Elf_Data *
elf64_xlatetom
(Elf_Data
*dst, Elf_Data
*src, unsigned int
file_encoding);
#include
<gelf.h>
Elf_Data *
gelf_xlatetof
(Elf *elf,
Elf_Data *dst, Elf_Data *src,
unsigned int file_encoding);
Elf_Data *
gelf_xlatetom
(Elf *elf,
Elf_Data *dst, Elf_Data *src,
unsigned int file_encoding);
These functions translate between the file and memory representations of ELF data structures. The in-memory representation of an ELF data structure would conform to the byte ordering and data alignment restrictions dictated by the host processor. As described in elf(3), the file representation of this data structure could use a different byte ordering from that of the host, or could use a different layout within the file.
Functions
elf32_xlatetom
(),
elf64_xlatetom
(),
and gelf_xlatetom
() translate data from file
representations to native, in-memory representations. Functions
elf32_xlatetof
(),
elf64_xlatetof
(),
and gelf_xlatetof
() translate data from in-memory
representations to file representations.
Argument src denotes an Elf_Data descriptor describing the source to be translated. The following elements of the descriptor need to be set before invoking these functions:
EV_CURRENT
is
supported.Argument dst describes the destination buffer. The following elements of the Elf_Data descriptor need to be set before invoking these functions:
EV_CURRENT
is supported.These translations routines allow the source and destination buffers to coincide, in which case an in-place translation will be done if the destination is large enough to hold the translated data. Other kinds of overlap between the source and destination buffers are not permitted.
On successful completion of the translation request the following fields of the dst descriptor would be modified:
Argument file_encoding specifies the encoding in which the file objects are represented. It must be one of:
ELFDATANONE
ELFDATA2LSB
ELFDATA2MSB
The functions
gelf_xlatetof
()
and
gelf_xlatetom
()
select the appropriate translation scheme based on the properties of
argument elf.
These functions return argument dst if successful, or NULL in case of an error.
To translate a GElf_Rel structure to its LSB file representation use:
Elf_Data dst, src; GElf_Rel rel; Elf *e; e = ...; /* See elf_begin(3). */ /* Set up the 'src' descriptor. */ memset(&src, 0, sizeof src); src.d_buf = &rel; src.d_size = sizeof(rel); src.d_type = ELF_T_REL; src.d_version = EV_CURRENT; /* Set up the 'dst' descriptor. */ memset(&dst, 0, sizeof dst); dst.d_buf = filebuf; dst.d_size = gelf_fsize(e, ELF_T_REL, 1, EV_CURRENT); dst.d_version = EV_CURRENT; if (gelf_xlatetof(e, &dst, &src, ELFDATA2LSB) == NULL) { printf("error: %s", elf_errmsg(0)); }
These functions may fail with the following errors:
ELF_E_ARGUMENT
]ELF_E_ARGUMENT
]ELF_E_ARGUMENT
]ELFDATANONE
, ELFDATA2LSB
or ELFDATA2MSB
.ELF_E_ARGUMENT
]ELF_E_DATA
]ELF_E_DATA
]ELF_E_DATA
]ELF_E_DATA
]ELF_E_DATA
]ELF_E_UNIMPL
]ELF_E_UNIMPL
]ELF_E_VERSION
]October 11, 2018 | OpenBSD-current |