Exemple #1
0
 public PEFile(DosHeader dosHeader, FileHeader fileHeader, OptionalHeader optionalHeader)
 {
     DosHeader      = dosHeader ?? throw new ArgumentNullException(nameof(dosHeader));
     FileHeader     = fileHeader ?? throw new ArgumentNullException(nameof(fileHeader));
     OptionalHeader = optionalHeader ?? throw new ArgumentNullException(nameof(optionalHeader));
     Sections       = new PESectionCollection(this);
 }
Exemple #2
0
        /// <inheritdoc />
        protected override IList <PESection> GetSections()
        {
            var result = new PESectionCollection(this);

            for (int i = 0; i < _sectionHeaders.Count; i++)
            {
                var header = _sectionHeaders[i];

                (ulong offset, uint size) = MappingMode switch
                {
                    PEMappingMode.Unmapped => (header.PointerToRawData, header.SizeOfRawData),
                    PEMappingMode.Mapped => (_reader.StartOffset + header.VirtualAddress, header.VirtualSize),
                    _ => throw new ArgumentOutOfRangeException()
                };

                _reader.Offset = offset;

                ISegment physicalContents = null;
                if (size > 0)
                {
                    physicalContents = DataSegment.FromReader(_reader, (int)size);
                }

                var virtualSegment = new VirtualSegment(physicalContents, header.VirtualSize);
                virtualSegment.UpdateOffsets(offset, header.VirtualAddress);
                result.Add(new PESection(header, virtualSegment));
            }

            return(result);
        }
    }