internal PeImage(Memory <byte> imageBytes) { using var peReader = new PEReader(new MemoryStream(imageBytes.ToArray())); BaseRelocationDirectory = new BaseRelocationDirectory(peReader.PEHeaders, imageBytes); DelayImportDirectory = new DelayImportDirectory(peReader.PEHeaders, imageBytes); ExportDirectory = new ExportDirectory(peReader.PEHeaders, imageBytes); Headers = peReader.PEHeaders; ImportDirectory = new ImportDirectory(peReader.PEHeaders, imageBytes); LoadConfigDirectory = new LoadConfigDirectory(peReader.PEHeaders, imageBytes); var debugDirectoryEntries = peReader.ReadDebugDirectory(); if (debugDirectoryEntries.Any(entry => entry.Type == DebugDirectoryEntryType.CodeView)) { var codeViewEntry = debugDirectoryEntries.First(entry => entry.Type == DebugDirectoryEntryType.CodeView); PdbData = peReader.ReadCodeViewDebugDirectoryData(codeViewEntry); } TlsDirectory = new TlsDirectory(peReader.PEHeaders, imageBytes); ValidatePeImage(); }
internal PeImage(Memory <byte> imageBytes) { using var peReader = new PEReader(imageBytes.ToArray().ToImmutableArray()); if (peReader.PEHeaders.PEHeader is null || !peReader.PEHeaders.IsDll) { throw new BadImageFormatException("The provided file was not a valid DLL"); } ExportDirectory = new ExportDirectory(peReader.PEHeaders, imageBytes); Headers = peReader.PEHeaders; ImportDirectory = new ImportDirectory(peReader.PEHeaders, imageBytes); LoadConfigDirectory = new LoadConfigDirectory(peReader.PEHeaders, imageBytes); RelocationDirectory = new RelocationDirectory(peReader.PEHeaders, imageBytes); ResourceDirectory = new ResourceDirectory(peReader.PEHeaders, imageBytes); TlsDirectory = new TlsDirectory(peReader.PEHeaders, imageBytes); }
internal PeImage(Memory <byte> imageBuffer) { using var peReader = new PEReader(new MemoryStream(imageBuffer.ToArray())); BaseRelocationDirectory = new BaseRelocationDirectory(peReader.PEHeaders, imageBuffer); DelayImportDirectory = new DelayImportDirectory(peReader.PEHeaders, imageBuffer); ExportDirectory = new ExportDirectory(peReader.PEHeaders, imageBuffer); Headers = peReader.PEHeaders; ImportDirectory = new ImportDirectory(peReader.PEHeaders, imageBuffer); LoadConfigDirectory = new LoadConfigDirectory(peReader.PEHeaders, imageBuffer); TlsDirectory = new TlsDirectory(peReader.PEHeaders, imageBuffer); ValidatePeImage(); }