public void Parse(BinaryReader reader) { m_dosHeader = DosHeader.Parse(reader); int dosStubSize = (int)(m_dosHeader.CoffHeaderOffset - reader.BaseStream.Position); m_dosStubBytes = reader.ReadBytes(dosStubSize); m_coffHeader = CoffHeader.Parse(reader); m_peHeaderOffset = (uint)reader.BaseStream.Position; m_peHeader = PEHeader.Parse(reader); for (int i = 0; i < m_coffHeader.NumberOfSections; i++) { m_sectionHeaders.Add(PESectionHeader.Parse(reader)); } int fillerSize = (int)(m_sectionHeaders[0].PointerToRawData - reader.BaseStream.Position); m_filler = reader.ReadBytes(fillerSize); for (int i = 0; i < m_coffHeader.NumberOfSections; i++) { byte[] sectionBytes = reader.ReadBytes((int)m_sectionHeaders[i].SizeOfRawData); m_sections.Add(sectionBytes); } int remainingByteCount = (int)(reader.BaseStream.Length - reader.BaseStream.Position); m_remainingBytes = reader.ReadBytes(remainingByteCount); // file ends here // Parse Import Directory: PEDataDirectory importDirectoryEntry = m_peHeader.DataDirectories[(int)DataDirectoryName.Import]; if (importDirectoryEntry.VirtualAddress > 0) { uint importDirectoryFileOffset = GetOffsetFromRVA(importDirectoryEntry.VirtualAddress); reader.BaseStream.Seek(importDirectoryFileOffset, SeekOrigin.Begin); m_importDirectory = ImportDirectory.Parse(reader); } }