public static PEStructure TryCreate(PEStructureProviderFactory peStructureProviderFactory, HexBufferFile file) { if (file.Properties.TryGetProperty(typeof(PEStructure), out PEStructure peStructure)) { return(peStructure); } var provider = peStructureProviderFactory.TryGetProvider(file); if (provider != null) { peStructure = new PEStructure(provider); } file.Properties.AddProperty(typeof(PEStructure), peStructure); return(peStructure); }
public override IEnumerable <TreeNodeData> CreateChildren() { Debug.Assert(TreeNode.Children.Count == 0 && weakDocListener == null); if (weakDocListener != null) { yield break; } var file = createBufferFile(); if (file == null) { yield break; } var peStructureProvider = peStructureProviderFactory.TryGetProvider(file); if (peStructureProvider == null) { yield break; } weakDocListener = new WeakDocumentListener(this, file.Buffer); yield return(new ImageDosHeaderNode(peStructureProvider.ImageDosHeader)); yield return(new ImageFileHeaderNode(peStructureProvider.ImageFileHeader)); if (peStructureProvider.ImageOptionalHeader is ImageOptionalHeader32VM) { yield return(new ImageOptionalHeader32Node((ImageOptionalHeader32VM)peStructureProvider.ImageOptionalHeader)); } else { yield return(new ImageOptionalHeader64Node((ImageOptionalHeader64VM)peStructureProvider.ImageOptionalHeader)); } for (int i = 0; i < peStructureProvider.Sections.Length; i++) { yield return(new ImageSectionHeaderNode(peStructureProvider.Sections[i], i)); } var cor20Hdr = ImageCor20HeaderNode.Create(peStructureProvider.ImageCor20Header); if (cor20Hdr != null) { yield return(cor20Hdr); } if (cor20Hdr != null && peStructureProvider.StorageSignature != null) { yield return(new StorageSignatureNode(peStructureProvider.StorageSignature)); yield return(new StorageHeaderNode(peStructureProvider.StorageHeader)); foreach (var storageStream in peStructureProvider.StorageStreams) { if (storageStream.HeapKind == DotNetHeapKind.Tables) { yield return(new TablesStorageStreamNode(storageStream, peStructureProvider.TablesStream)); } else { yield return(new StorageStreamNode(storageStream)); } } } }