ddn.elf.io

Low-level binary I/O utilities for ELF structures.

This module provides endianness-aware reading and writing functions for ELF structures. It supports both little-endian and big-endian formats.

Types 2

enumElfEndian : ubyte

Endianness enumeration for ELF files.

ELF files can be either little-endian or big-endian, independent of host system's native endianness. These values match the ELF specification.

LITTLE = 1Little-endian byte order (least significant byte first)
BIG = 2Big-endian byte order (most significant byte first)
structStructRange(T)

Input range for iterating over packed structs in a byte array.

This range provides lazy iteration over packed structs stored in a byte array.

Fields
private const(ubyte)[] data
private size_t offset
private ElfEndian endian
Methods
bool empty() pure nothrow @nogc @safe constCheck if the range is empty.
T front() constGet the current struct in the range.
void popFront()Advance to the next struct in the range.
typeof(this) save() @propertySave the current state of the range.
size_t currentOffset() pure nothrow @nogc @safe constGet the current offset in the range.
void restore(size_t state) pure nothrow @nogc @safeRestore the range to a previously saved position.
Constructors
this(const(ubyte)[] data, size_t offset, ElfEndian endian)Private constructor with explicit offset for save/restore.
this(const(ubyte)[] data, ElfEndian endian)Construct a struct range from byte data.

Functions 16

fnElfEndian getElfEndian(ubyte dataEncoding) pure nothrow @nogc @safeGet the ELF endianness from the ELF data encoding field.
fnubyte getElfDataEncoding(ElfEndian endian) pure nothrow @nogc @safeGet the ELF data encoding value from an ELF endianness.
fnbool isNativeEndian(ElfEndian fileEndian) pure nothrow @nogc @safeCheck if a file endianness matches the native system endianness.
fnT swapBytes(T)(T value) if (isIntegral!T) pure nothrow @nogc @safeSwap bytes of an integral value.
fnT toNative(T)(T value, ElfEndian fileEndian) if (isIntegral!T) pure nothrow @nogc @safeConvert a value from file endianness to native endianness.
fnT fromNative(T)(T value, ElfEndian fileEndian) if (isIntegral!T) pure nothrow @nogc @safeConvert a value from native endianness to file endianness.
fnT readValue(T)(const(ubyte)[] data, size_t offset, ElfEndian fileEndian) if (isIntegral!T)Read a value from a byte array at a specified offset.
fnubyte[] writeValue(T)(T value, ElfEndian fileEndian) if (isIntegral!T)Write a value to a byte array.
fnT readStruct(T)(const(ubyte)[] data, size_t offset, ElfEndian fileEndian)Read a packed struct from a byte array.
fnubyte[] writeStruct(T)(T value, ElfEndian fileEndian)Write a packed struct to a byte array.
fnT[] readArray(T)(const(ubyte)[] data, size_t offset, size_t count, ElfEndian fileEndian)Read an array of structs from a byte array.
fnubyte[] writeArray(T)(T[] values, ElfEndian fileEndian)Write an array of structs to a byte array.
fnbool isElfMagic(const(ubyte)[] data) pure nothrow @nogc @safeCheck if a byte array starts with the ELF magic number.
fnstring readString(const(ubyte)[] data, size_t offset)Read a null-terminated string from a byte array.
fnstring[] readStringTable(const(ubyte)[] data)Read a string table from a byte array.
fnStructRange!T iterateStructs(T)(const(ubyte)[] data, ElfEndian endian) pure nothrow @nogc @safeCreate a range for iterating over packed structs in a byte array.