private void ReadProgramHeaders() { if (Layout.SizeOfProgramHeaderEntry == 0) { if (_programHeaderCount > 0) { Diagnostics.Error(DiagnosticId.ELF_ERR_InvalidZeroProgramHeaderTableEntrySize, $"Unable to read program header table as the size of program header entry ({nameof(ElfNative.Elf32_Ehdr.e_phentsize)}) == 0 in the Elf Header"); } return; } for (int i = 0; i < _programHeaderCount; i++) { var offset = Layout.OffsetOfProgramHeaderTable + (ulong)i * Layout.SizeOfProgramHeaderEntry; if (offset >= (ulong)Stream.Length) { Diagnostics.Error(DiagnosticId.ELF_ERR_InvalidProgramHeaderStreamOffset, $"Unable to read program header [{i}] as its offset {offset} is out of bounds"); break; } // Seek to the header position Stream.Position = (long)offset; var segment = (ObjectFile.FileClass == ElfFileClass.Is32) ? ReadProgramHeader32(i) : ReadProgramHeader64(i); ObjectFile.AddSegment(segment); } }