ddn.elf.file
ELF file reading infrastructure.
This module provides core functionality for reading and parsing ELF files, supporting both file-backed and memory-backed access with lazy loading and caching for efficient operation.
Types 4
ELF file reader with lazy loading and caching.
This struct provides access to ELF file data, supporting both file-backed and memory-backed sources. It implements lazy loading of sections and segments with caching for efficient access.
const(ubyte)[] _databool _ownedtypes.ElfClass _classio.ElfEndian _endiangelf.FileHeader _ehdrbool _ehdrCachedconst(gelf.FileHeader) getEhdr()Get the GELF file header.elf32.FileHeader getEhdr32()Get the ELF32 file header.elf64.FileHeader getEhdr64()Get the ELF64 file header.auto getSectionHeaders()Get a range for iterating over section headers.auto getProgramHeaders()Get a range for iterating over program headers.void _detectMetadata()Detect ELF metadata (class and endianness) from data.void _loadEhdr()Load and cache the ELF header.this()Default constructor - creates an empty ElfFile.this(const(ubyte)[] data)Constructor from byte array (non-owned reference).this(ubyte[] data)Constructor from owned byte array (takes ownership).this(string path)Constructor from file path.~thisDestructor - releases owned data.Section range for ElfFile.
Provides input range interface for iterating over sections.
@property auto front()Get the current section header.void popFront()Advance to the next section.this(ElfFile file, io.StructRange!(gelf.SectionHeader) headerRange)Constructor.Program range for ElfFile.
Provides input range interface for iterating over program headers.
@property auto front()Get the current program header.void popFront()Advance to the next program header.this(ElfFile file, io.StructRange!(gelf.ProgramHeader) headerRange)Constructor.Builder for creating ELF files from scratch.
This class provides a fluent API for constructing ELF files with full control over sections, segments, symbols, and other ELF structures.
types.ElfClass _classio.ElfEndian _endiantypes.ElfType _typetypes.ElfMachine _machineulong _entryuint _flagsstrtab.StringTableBuilder _shstrtabstrtab.StringTableBuilder _strtabstrtab.StringTableBuilder _dynstrSectionEntry[] _sectionsSegmentEntry[] _segmentsSymbolEntry[] _symbolsuint _phnumElfBuilder create(types.ElfClass class_, io.ElfEndian endian)Create a new ELF builder with the specified class and endianness.ElfBuilder setFileType(types.ElfType type)Set the ELF file type (relocatable, executable, shared object, etc.).ElfBuilder setMachine(types.ElfMachine machine)Set the target machine architecture.ElfBuilder setEntryPoint(ulong entry)Set the entry point address.ElfBuilder setFlags(uint flags)Set processor-specific flags.uint addSection(string name, uint type, ulong flags, const(ubyte)[] data = null,
uint link = 0, uint info = 0, ulong addralign = 1, ulong entsize = 0)Add a section to the ELF file.uint addSegment(uint type, uint flags, uint[] sections, ulong alignment = 0x1000)Add a segment (program header) to the ELF file.ElfBuilder addSymbol(string name, uint sectionIndex, uint binding, uint type,
ulong value = 0, ulong size = 0)Add a symbol to the symbol table.ubyte[] build()Build the ELF file and return the raw byte array.void write(string path)Build the ELF file and write it to a file.uint getSectionCount()Get the number of sections.uint getSegmentCount()Get the number of segments.void updateSectionData(uint index, const(ubyte)[] data)Update the data of an existing section.void removeSegmentAt(uint index)Remove a segment at the specified index.this()Private constructor to ensure factory method usage.SectionEntrySegmentEntrySymbolEntryFunctions 12
bool isElfFile(const(ubyte)[] data) pure nothrow @nogc @safeCheck if the given data represents a valid ELF file.types.ElfClass getElfClass(const(ubyte)[] data)Get the ELF class (32-bit or 64-bit) from ELF data.void writeFileHeader32(ubyte[] data, ref const elf32.FileHeader ehdr, io.ElfEndian endian)Write ELF32 file header with endianness handling.void writeFileHeader64(ubyte[] data, ref const elf64.FileHeader ehdr, io.ElfEndian endian)Write ELF64 file header with endianness handling.void writeSectionHeader32(ubyte[] data, size_t pos, ref const elf32.SectionHeader shdr, io.ElfEndian endian)Write ELF32 section header with endianness handling.void writeSectionHeader64(ubyte[] data, size_t pos, ref const elf64.SectionHeader shdr, io.ElfEndian endian)Write ELF64 section header with endianness handling.void writeProgramHeader32(ubyte[] data, size_t pos, ref const elf32.ProgramHeader phdr, io.ElfEndian endian)Write ELF32 program header with endianness handling.void writeProgramHeader64(ubyte[] data, size_t pos, ref const elf64.ProgramHeader phdr, io.ElfEndian endian)Write ELF64 program header with endianness handling.