Esempio n. 1
0
        private IEnumerable <ELFProgramSegment> ReadSegments()
        {
            Header.IsProgramHeaderCountReasonable.CheckThrowing();
            IsHeaderProgramHeaderOffsetValid.CheckThrowing();
            IsHeaderProgramHeaderEntrySizeValid.CheckThrowing();

            // Calculate the loadBias. It is usually just the base address except for some executable modules.
            ulong loadBias = _position;

            if (loadBias > 0)
            {
                for (uint i = 0; i < Header.ProgramHeaderCount; i++)
                {
                    ulong            programHeaderOffset = _position + Header.ProgramHeaderOffset + i * Header.ProgramHeaderEntrySize;
                    ELFProgramHeader header = DataSourceReader.Read <ELFProgramHeader>(programHeaderOffset);
                    if (header.Type == ELFProgramHeaderType.Load && header.FileOffset == 0)
                    {
                        loadBias -= header.VirtualAddress;
                    }
                }
            }

            // Build the program segments
            List <ELFProgramSegment> segments = new List <ELFProgramSegment>();

            for (uint i = 0; i < Header.ProgramHeaderCount; i++)
            {
                ulong programHeaderOffset = _position + Header.ProgramHeaderOffset + i * Header.ProgramHeaderEntrySize;
                segments.Add(new ELFProgramSegment(DataSourceReader, loadBias, programHeaderOffset, _isDataSourceVirtualAddressSpace));
            }
            return(segments);
        }
Esempio n. 2
0
        private IEnumerable <ELFSegment> ReadSegments()
        {
            Header.IsProgramHeaderCountReasonable.CheckThrowing();
            IsHeaderProgramHeaderOffsetValid.CheckThrowing();
            IsHeaderProgramHeaderEntrySizeValid.CheckThrowing();
            List <ELFSegment> segments = new List <ELFSegment>();

            for (uint i = 0; i < Header.ProgramHeaderCount; i++)
            {
                segments.Add(new ELFSegment(DataSourceReader, _position,
                                            _position + Header.ProgramHeaderOffset + i * Header.ProgramHeaderEntrySize, _isDataSourceVirtualAddressSpace));
            }
            return(segments);
        }