ddn.elf.segments

ELF program header (segment) handling functionality.

This module provides utilities for reading and manipulating ELF program headers (segments). Segments contain information about how the program is loaded into memory.

Types 4

Represents an ELF segment (program header).

This struct provides lazy access to segment information.

Fields
ElfFile _file
size_t _index
bool _headerLoaded
const(ubyte)[] _data
bool _dataLoaded
Methods
void _loadHeader()Load the program header from the ELF file.
void _loadData()Load the segment data from the ELF file.
size_t index() pure nothrow @nogc @safe constGet the segment index.
gelf.ProgramHeader getHeader()Get the program header for this segment.
types.SegmentType getType()Get the segment type.
types.SegmentFlags getFlags()Get the segment flags.
const(ubyte)[] getData()Get the segment data from the file.
ulong getFileOffset()Get the segment's file offset.
ulong getVirtualAddress()Get the segment's virtual address.
ulong getPhysicalAddress()Get the segment's physical address.
ulong getFileSize()Get the segment's size in the file.
ulong getMemorySize()Get the segment's size in memory.
ulong getAlignment()Get the segment's alignment.
bool isLoadable()Check if this segment is loadable (PT_LOAD).
bool isDynamic()Check if this segment contains dynamic linking information.
bool isInterpreter()Check if this segment contains the interpreter path.
bool isReadable()Check if this segment is readable.
bool isWritable()Check if this segment is writable.
bool isExecutable()Check if this segment is executable.
Constructors
this(ElfFile file, size_t index)Constructor.

Range for iterating over segments of a specific type.

Note

This range does not implement full InputRange interface

because it cannot create valid ElfSegment instances without access to the ElfFile. Use getSegmentByIndex() instead.

Fields
size_t[] _originalIndices
size_t _currentIndex
ElfFile _file
Methods
bool empty() pure nothrow @nogc @safe constChecks if the range is empty.
ElfSegment front()Get the current segment.
void popFront()Advances to the next segment of the target type.
typeof(this) save()Saves the current state of the range.
Constructors
this(types.SegmentType type, gelf.ProgramHeader[] headers, size_t[] originalIndices, size_t currentIndex, ElfFile file)Constructor for creating a saved copy of the range.
this(ElfFile file, types.SegmentType type)Constructor for creating a range that filters segments by type.

Range for iterating over all segments.

Note

This range does not implement full InputRange interface

because it cannot create valid ElfSegment instances without access to the ElfFile. Use getSegmentByIndex() instead.

Fields
size_t _currentIndex
size_t _totalSegments
ElfFile _file
Methods
typeof(this) save()Save the current state of the range.
bool empty() pure nothrow @nogc @safe constCheck if the range is empty.
ElfSegment front()Get the current segment.
void popFront()Advance to the next segment.
Constructors
this(size_t currentIndex, size_t totalSegments, ElfFile file)Private constructor with state.
this(ElfFile file)Constructor for iterating all segments.

Builder for creating ELF program headers (segments).

This struct allows incremental construction of a program header table.

Fields
gelf.ProgramHeader[] _segments
Methods
ProgramHeaderBuilder create()Create a new empty program header builder.
size_t addSegment(types.SegmentType type, types.SegmentFlags flags, ulong offset, ulong vaddr, ulong paddr, ulong fileSize, ulong memSize, ulong alignment)Add a segment to the program header table.
size_t count() pure nothrow @nogc @safe constGet the number of segments.
gelf.ProgramHeader getSegment(size_t index)Get a segment by index.
ubyte[] build()Build the final program header table byte array.
void clear()Clear all segments from the builder.
Constructors
this(gelf.ProgramHeader[] segments)Private constructor with segment array.

Functions 6

fnsize_t getSegmentCount(ElfFile file)Get the number of program headers (segments) in an ELF file.
fnSegmentRange getSegments(ElfFile file)Get a range for iterating over all segments in an ELF file.
fnElfSegment getSegmentByIndex(ElfFile file, size_t index)Get a segment by its index.
fnSegmentTypeRange getSegmentsByType(ElfFile file, types.SegmentType type)Get a range for iterating over segments of a specific type.
fnSegmentTypeRange getLoadableSegments(ElfFile file)Get a range for iterating over loadable segments (PT_LOAD).
fnSegmentTypeRange getSegmentsContainingSection(ElfFile file, ElfSection section)Get segments that contain a specific section.