/// <summary> /// Constructor /// </summary> /// <param name="reader">PE file reader pointing to the start of this section</param> /// <param name="verify">Verify sections</param> /// <exception cref="BadImageFormatException">Thrown if verification fails</exception> public PEInfo(ref DataReader reader, bool verify) { reader.Position = 0; imageDosHeader = new ImageDosHeader(ref reader, verify); if (verify && imageDosHeader.NTHeadersOffset == 0) { throw new BadImageFormatException("Invalid NT headers offset"); } reader.Position = imageDosHeader.NTHeadersOffset; imageNTHeaders = new ImageNTHeaders(ref reader, verify); reader.Position = (uint)imageNTHeaders.OptionalHeader.StartOffset + imageNTHeaders.FileHeader.SizeOfOptionalHeader; int numSections = imageNTHeaders.FileHeader.NumberOfSections; if (numSections > 0) { // Mono doesn't verify the section count var tempReader = reader; tempReader.Position += 0x14; uint firstSectionOffset = tempReader.ReadUInt32(); numSections = Math.Min(numSections, (int)((firstSectionOffset - reader.Position) / 0x28)); } imageSectionHeaders = new ImageSectionHeader[numSections]; for (int i = 0; i < imageSectionHeaders.Length; i++) { imageSectionHeaders[i] = new ImageSectionHeader(ref reader, verify); } }
/// <summary> /// Constructor /// </summary> /// <param name="reader">PE file reader pointing to the start of this section</param> /// <param name="verify">Verify sections</param> /// <exception cref="BadImageFormatException">Thrown if verification fails</exception> public PEInfo(IImageStream reader, bool verify) { reader.Position = 0; this.imageDosHeader = new ImageDosHeader(reader, verify); if (verify && this.imageDosHeader.NTHeadersOffset == 0) throw new BadImageFormatException("Invalid NT headers offset"); reader.Position = this.imageDosHeader.NTHeadersOffset; this.imageNTHeaders = new ImageNTHeaders(reader, verify); reader.Position = (long)this.imageNTHeaders.OptionalHeader.StartOffset + this.imageNTHeaders.FileHeader.SizeOfOptionalHeader; this.imageSectionHeaders = new ImageSectionHeader[this.imageNTHeaders.FileHeader.NumberOfSections]; for (int i = 0; i < this.imageSectionHeaders.Length; i++) this.imageSectionHeaders[i] = new ImageSectionHeader(reader, verify); }
/// <summary> /// Constructor /// </summary> /// <param name="reader">PE file reader pointing to the start of this section</param> /// <param name="verify">Verify sections</param> /// <exception cref="BadImageFormatException">Thrown if verification fails</exception> public PEInfo(IImageStream reader, bool verify) { reader.Position = 0; this.imageDosHeader = new ImageDosHeader(reader, verify); if (verify && this.imageDosHeader.NTHeadersOffset == 0) { throw new BadImageFormatException("Invalid NT headers offset"); } reader.Position = this.imageDosHeader.NTHeadersOffset; this.imageNTHeaders = new ImageNTHeaders(reader, verify); reader.Position = (long)this.imageNTHeaders.OptionalHeader.StartOffset + this.imageNTHeaders.FileHeader.SizeOfOptionalHeader; this.imageSectionHeaders = new ImageSectionHeader[this.imageNTHeaders.FileHeader.NumberOfSections]; for (int i = 0; i < this.imageSectionHeaders.Length; i++) { this.imageSectionHeaders[i] = new ImageSectionHeader(reader, verify); } }