Example #1
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("ImageFileViewer");

            using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
            {
                var source = new BitmapImage();
                source.BeginInit();
                source.CacheOption  = BitmapCacheOption.OnLoad;
                source.StreamSource = stream;
                source.EndInit();

                var image = new Image
                {
                    Source = source,
                    Width  = source.Width,
                    Height = source.Height,
                };

                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = image
                });
            }
        }
Example #2
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
            {
                // don't display file bigger than 1MB
                if (stream.Length > 1024 * 1024)
                {
                    return("** This file is too big to view inline. ***");
                }

                var rtf = new RichTextBox
                {
                    IsReadOnly                    = true,
                    BorderThickness               = new System.Windows.Thickness(0),
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
                };
                rtf.Document.MinPageWidth = 800;

                var range = new TextRange(rtf.Document.ContentStart, rtf.Document.ContentEnd);
                range.Load(stream, System.Windows.DataFormats.Rtf);

                return(rtf);
            }
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            AssemblyDebugDataViewModel?data = null;

            // Get the PE file, exe or dll that matches
            var filename = Path.GetFileNameWithoutExtension(selectedFile.Name);
            var pe       = peerFiles.FirstOrDefault(pc => pc.Path != selectedFile.Path &&
                                                    Path.GetFileNameWithoutExtension(pc.Name) !.Equals(filename, StringComparison.OrdinalIgnoreCase) &&
                                                    (".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                                     ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase)));

            Stream?peStream = null;

            try
            {
                if (pe != null) // we have a matching file
                {
                    peStream = StreamUtility.MakeSeekable(pe.GetStream(), true);
                }


                // This might throw an exception because we don't know if it's a full PDB or portable
                // Try anyway in case it succeeds as a ppdb
                try
                {
                    using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
                    {
                        data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));
                    }

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = new Controls.PdbFileViewer
                        {
                            DataContext = data
                        }
                    });
                }
                catch (ArgumentNullException)
                {
                }
            }
            finally
            {
                peStream?.Dispose();
            }

            return(new TextBlock()
            {
                Text = "Full PDB files rquired the EXE or DLL to be alongside."
            });
        }
Example #4
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            AssemblyDebugDataViewModel?data = null;

            // Get the PE file, exe or dll that matches
            var pe = peerFiles.FirstOrDefault(pc => ".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".winmd".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase));

#pragma warning disable CA2000 // Dispose objects before losing scope -- ReadDebugData will dispose
            Stream?peStream = null;

            if (pe != null) // we have a matching file
            {
                peStream = StreamUtility.MakeSeekable(pe.GetStream(), true);
            }


            // This might throw an exception because we don't know if it's a full PDB or portable
            // Try anyway in case it succeeds as a ppdb
            try
            {
                var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true);
                data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));


                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = new Controls.PdbFileViewer
                    {
                        DataContext = data
                    }
                });
            }
            catch (ArgumentNullException)
            {
            }
#pragma warning restore CA2000 // Dispose objects before losing scope
            return(new TextBlock()
            {
                Text = "Full PDB files requires the EXE or DLL to be alongside."
            });
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            var tempFile = Path.GetTempFileName();

            try
            {
                using (var str = selectedFile.GetStream())
                    using (var fileStream = File.OpenWrite(tempFile))
                    {
                        str.CopyTo(fileStream);
                    }

                var assemblyMetadata = AssemblyMetadataReader.ReadMetaData(tempFile);
                AssemblyDebugDataViewModel debugDataViewModel = null;
                if (assemblyMetadata.DebugData != null)
                {
                    debugDataViewModel = new AssemblyDebugDataViewModel(assemblyMetadata.DebugData);
                }

                // No debug data to display
                if (assemblyMetadata != null && debugDataViewModel == null)
                {
                    var orderedAssemblyDataEntries = assemblyMetadata.GetMetadataEntriesOrderedByImportance();

                    var grid = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries);

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = grid,
                    });
                }
                else if (assemblyMetadata != null && debugDataViewModel != null)
                {
                    var orderedAssemblyDataEntries = assemblyMetadata.GetMetadataEntriesOrderedByImportance();

                    // Tab control with two pages
                    var tc = new TabControl()
                    {
                        Items =
                        {
                            new TabItem
                            {
                                Header  = "Assembly Attributes",
                                Content = new ScrollViewer()
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries)
                                }
                            },
                            new TabItem
                            {
                                Header  = "Embedded PDB Data",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbFileViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            }
                        }
                    };

                    return(tc);
                }
            }
            catch { }
            finally
            {
                if (File.Exists(tempFile))
                {
                    try
                    {
                        File.Delete(tempFile);
                    }
                    catch
                    {
                    }
                }
            }

            return(new Grid());
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("AssemblyFileViewer");



            try
            {
                using var str      = selectedFile.GetStream();
                using var tempFile = new TemporaryFile(str);

                var debugData        = (selectedFile as PackageFile)?.DebugData;
                var assemblyMetadata = AssemblyMetadataReader.ReadMetaData(tempFile.FileName);

                if (debugData == null)
                {
                    if (assemblyMetadata?.DebugData.HasDebugInfo == true)
                    {
                        debugData = assemblyMetadata.DebugData;
                    }
                }

                AssemblyDebugDataViewModel?debugDataViewModel = null;

                if (debugData != null)
                {
                    debugDataViewModel = new AssemblyDebugDataViewModel(Task.FromResult(debugData));
                }

                // No debug data to display
                if (assemblyMetadata != null && debugDataViewModel == null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    var grid = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries);

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = grid,
                    });
                }
                else if (assemblyMetadata != null && debugDataViewModel != null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    // Tab control with three pages
                    var tc = new TabControl()
                    {
                        Items =
                        {
                            new TabItem
                            {
                                Header  = "Assembly Attributes",
                                Content = new ScrollViewer()
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries)
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Info",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbInfoViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Sources",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbSourcesViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            }
                        }
                    };

                    return(tc);
                }
            }
            catch { }

            return(new Grid());
        }
Example #7
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("AssemblyFileViewer");

            try
            {
                using var str      = selectedFile.GetStream();
                using var tempFile = new TemporaryFile(str);

                var debugData        = (selectedFile as PackageFile)?.DebugData;
                var assemblyMetadata = AssemblyMetadataReader.ReadMetaData(tempFile.FileName);

                if (debugData == null)
                {
                    if (assemblyMetadata?.DebugData.HasDebugInfo == true)
                    {
                        debugData = assemblyMetadata.DebugData;
                    }
                }

                AssemblyDebugDataViewModel?debugDataViewModel = null;

                if (debugData != null)
                {
                    debugDataViewModel = new AssemblyDebugDataViewModel(Task.FromResult(debugData));
                }

#if !HAS_UNO
                // No debug data to display
                if (assemblyMetadata != null && debugDataViewModel == null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    var grid = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries);

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = grid,
                    });
                }
                else if (assemblyMetadata != null && debugDataViewModel != null)
                {
                    var orderedAssemblyDataEntries = GetMetadataEntriesOrderedByImportance(assemblyMetadata);

                    // Tab control with three pages
                    var tc = new TabControl()
                    {
#if HAS_UNO
                        IsAddTabButtonVisible = false,
                        TabItems =
#else
                        Items =
#endif
                        {
                            new TabItem
                            {
                                Header  = "Assembly Attributes",
                                Content = new ScrollViewer()
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = CreateAssemblyMetadataGrid(orderedAssemblyDataEntries)
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Info",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbInfoViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            },
                            new TabItem
                            {
                                Header  = "PDB Sources",
                                Content = new ScrollViewer
                                {
                                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                    Content = new Controls.PdbSourcesViewer
                                    {
                                        DataContext = debugDataViewModel
                                    }
                                }
                            }
                        }
                    };

                    return(tc);
                }
#else
                // returning UIElement from here works.
                // however due to performance issues, we are just
                // returning the datacontext and letting the xaml to handle the view.
                // also, the ui layout is vastely different compared to the #if-block above
                return(new AssemblyFileContent()
                {
                    Metadata = assemblyMetadata
                               ?.SelectOrDefault(GetMetadataEntriesOrderedByImportance)
                               .ToArray(),
                    DebugData = debugDataViewModel,
                });
#endif
            }
            catch (Exception e)
            {
#if HAS_UNO
                this.Log().Error("Failed to generate view", e);
#endif
            }

#if !HAS_UNO
            return(new Grid());
#else
            // the empty object is needed for branching via type-checking
            return(new AssemblyFileContent());
#endif
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            // Get the PE file, exe or dll that matches
            var pe = peerFiles.FirstOrDefault(pc => ".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".winmd".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase));

#pragma warning disable CA2000 // Dispose objects before losing scope -- ReadDebugData will dispose
            var peStream = pe != null
                ? StreamUtility.MakeSeekable(pe.GetStream(), true)
                : null;

            // This might throw an exception because we don't know if it's a full PDB or portable
            // Try anyway in case it succeeds as a ppdb
            try
            {
                var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true);
                var data   = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));

#if !HAS_UNO
                // Tab control with two pages
                var tc = new TabControl()
                {
                    Items =
                    {
                        new TabItem
                        {
                            Header  = "PDB Info",
                            Content = new ScrollViewer
                            {
                                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                Content = new Controls.PdbInfoViewer
                                {
                                    DataContext = data
                                }
                            }
                        },
                        new TabItem
                        {
                            Header  = "PDB Sources",
                            Content = new ScrollViewer
                            {
                                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                Content = new Controls.PdbSourcesViewer
                                {
                                    DataContext = data
                                }
                            }
                        }
                    }
                };

                return(tc);
#else
                // returning UIElement from here works.
                // however due to performance issues, we are just
                // returning the datacontext and letting the xaml to handle the view.
                // also, the ui layout is vastely different compared to the #if-block above
                return(new AssemblyFileViewer.AssemblyFileContent()
                {
                    Metadata = null,
                    DebugData = data,
                });
#endif
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
#if HAS_UNO
                this.Log().Error("Failed to generate view", e);
#endif
            }

#pragma warning restore CA2000 // Dispose objects before losing scope
            return(new TextBlock()
            {
                Text = "Full PDB files requires the EXE or DLL to be alongside."
            });
        }