bool ReadPEFileLevelData() //^ requires this.ReaderState >= ReaderState.Initialized; { MemoryReader memReader = new MemoryReader(this.BinaryDocumentMemoryBlock.Pointer, this.BinaryDocumentMemoryBlock.Length); if (memReader.RemainingBytes < PEFileConstants.BasicPEHeaderSize) { this.ErrorContainer.AddBinaryError(0, MetadataReaderErrorKind.FileSizeTooSmall); return false; } // Look for DOS Signature "MZ" ushort dosSig = memReader.PeekUInt16(0); if (dosSig != PEFileConstants.DosSignature) { this.ErrorContainer.AddBinaryError(0, MetadataReaderErrorKind.DosHeader); return false; } // Skip the DOS Header int ntHeaderOffset = memReader.PeekInt32(PEFileConstants.PESignatureOffsetLocation); if (!memReader.SeekOffset(ntHeaderOffset)) { this.ErrorContainer.AddBinaryError(memReader.Offset, MetadataReaderErrorKind.FileSizeTooSmall); return false; } // Look for PESignature "PE\0\0" uint NTSignature = memReader.ReadUInt32(); if (NTSignature != PEFileConstants.PESignature) { this.ErrorContainer.AddBinaryError(memReader.Offset - sizeof(uint), MetadataReaderErrorKind.PESignature); return false; } // Read the COFF Header if (!this.ReadCOFFFileHeader(ref memReader)) { return false; } // Read the magic to determine if its PE or PE+ PEMagic magic = (PEMagic)memReader.PeekUInt16(0); switch (magic) { case PEMagic.PEMagic32: if ( !this.ReadOptionalHeaderStandardFields32(ref memReader) || !this.ReadOptionalHeaderNTAdditionalFields32(ref memReader) ) { return false; } break; case PEMagic.PEMagic64: if ( !this.ReadOptionalHeaderStandardFields64(ref memReader) || !this.ReadOptionalHeaderNTAdditionalFields64(ref memReader) ) { return false; } break; default: this.ErrorContainer.AddBinaryError(memReader.Offset, MetadataReaderErrorKind.UnknownPEMagic); return false; } if (!this.ReadOptionalHeaderDirectoryEntries(ref memReader)) { return false; } if (!this.ReadSectionHeaders(ref memReader)) { return false; } this.ReaderState = ReaderState.PEFile; this.Win32ResourceMemoryReader = new MemoryReader(this.DirectoryToMemoryBlock(this.OptionalHeaderDirectoryEntries.ResourceTableDirectory)); return true; }