/// <inheritdoc /> protected override IList <IResourceEntry> GetEntries() { var result = new OwnedCollection <IResourceDirectory, IResourceEntry>(this); // Optimisation, check for invalid resource directory offset, and prevention of self loop: if (_namedEntries + _idEntries == 0 || _depth >= MaxDepth) { return(result); } uint baseRva = _peFile.OptionalHeader.DataDirectories[OptionalHeader.ResourceDirectoryIndex].VirtualAddress; // Create entries reader. uint entryListSize = (uint)((_namedEntries + _idEntries) * ResourceDirectoryEntry.EntrySize); var entriesReader = _peFile.CreateReaderAtFileOffset(_entriesOffset, entryListSize); for (int i = 0; i < _namedEntries + _idEntries; i++) { var rawEntry = new ResourceDirectoryEntry(_peFile, entriesReader); // Note: Even if creating the directory reader fails, we still want to include the directory entry // itself. In such a case, we expose the directory as an empty directory. This is why the // following statement is not used as a condition for an if statement. _peFile.TryCreateReaderAtRva(baseRva + rawEntry.DataOrSubDirOffset, out var entryReader); result.Add(rawEntry.IsSubDirectory ? (IResourceEntry) new SerializedResourceDirectory(_peFile, rawEntry, entryReader, _depth + 1) : new SerializedResourceData(_peFile, rawEntry, entryReader)); } return(result); }