Exemple #1
0
 void Window_RequestNavigate(object sender, RequestNavigateEventArgs e)
 {
     if (e.Uri.Scheme == "resource") {
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         using (Stream s = typeof(App).Assembly.GetManifestResourceStream(typeof(dnSpy.StartUpClass), e.Uri.AbsolutePath)) {
             using (StreamReader r = new StreamReader(s)) {
                 string line;
                 while ((line = r.ReadLine()) != null) {
                     output.Write(line, TextTokenType.Text);
                     output.WriteLine();
                 }
             }
         }
         var textView = ILSpy.MainWindow.Instance.SafeActiveTextView;
         textView.ShowText(output);
         ILSpy.MainWindow.Instance.SetTitle(textView, e.Uri.AbsolutePath);
         e.Handled = true;
     }
 }
Exemple #2
0
 public void ShowText(AvalonEditTextOutput textOutput)
 {
     ActiveTabPage.ShowTextView(textView => textView.ShowText(textOutput));
 }
Exemple #3
0
 internal void ShowNodes(AvalonEditTextOutput output, TreeNodes.ILSpyTreeNode[] nodes, IHighlightingDefinition highlighting)
 {
     ActiveTabPage.ShowTextView(textView => textView.ShowNodes(output, nodes, highlighting));
 }
Exemple #4
0
        public static void Display(DecompilerTextView textView)
        {
            AvalonEditTextOutput output = new AvalonEditTextOutput();

            output.WriteLine(string.Format("dnSpy version {0}", currentVersion.ToString()), TextTokenType.Text);
            var decVer = typeof(ICSharpCode.Decompiler.Ast.AstBuilder).Assembly.GetName().Version;

            output.WriteLine(string.Format("ILSpy Decompiler version {0}.{1}.{2}", decVer.Major, decVer.Minor, decVer.Build), TextTokenType.Text);
            if (checkForUpdateCode)
            {
                output.AddUIElement(
                    delegate {
                    StackPanel stackPanel          = new StackPanel();
                    stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
                    stackPanel.Orientation         = Orientation.Horizontal;
                    if (latestAvailableVersion == null)
                    {
                        AddUpdateCheckButton(stackPanel, textView);
                    }
                    else
                    {
                        // we already retrieved the latest version sometime earlier
                        ShowAvailableVersion(latestAvailableVersion, stackPanel);
                    }
                    CheckBox checkBox       = new CheckBox();
                    checkBox.Margin         = new Thickness(4);
                    checkBox.Content        = "Automatically check for updates every week";
                    UpdateSettings settings = new UpdateSettings(ILSpySettings.Load());
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled")
                    {
                        Source = settings
                    });
                    return(new StackPanel {
                        Margin = new Thickness(0, 4, 0, 0),
                        Cursor = Cursors.Arrow,
                        Children = { stackPanel, checkBox }
                    });
                });
            }
            if (checkForUpdateCode)
            {
                output.WriteLine();
            }
            foreach (var plugin in App.CompositionContainer.GetExportedValues <IAboutPageAddition>())
            {
                plugin.Write(output);
            }
            output.WriteLine();
            using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt")) {
                using (StreamReader r = new StreamReader(s)) {
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        output.WriteLine(line, TextTokenType.Text);
                    }
                }
            }
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("COPYING", "resource:COPYING"));
            textView.ShowText(output);
            MainWindow.Instance.SetTitle(textView, "About");

            //reset icon bar
            textView.manager.Bookmarks.Clear();
        }
Exemple #5
0
        public static void Display(DecompilerTextView textView)
        {
            AvalonEditTextOutput output = new AvalonEditTextOutput()
            {
                Title            = Resources.About,
                EnableHyperlinks = true
            };

            output.WriteLine(Resources.ILSpyVersion + RevisionClass.FullVersion);

            string prodVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(Uri).Assembly.Location).ProductVersion;

            output.WriteLine(Resources.NETFrameworkVersion + prodVersion);

            if (StorePackageHelper.HasPackageIdentity)
            {
                output.WriteLine($"Package Name: {StorePackageHelper.GetPackageFamilyName()}");
            }
            else
            {            // if we're running in an MSIX, updates work differently
                output.AddUIElement(
                    delegate {
                    StackPanel stackPanel          = new StackPanel();
                    stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
                    stackPanel.Orientation         = Orientation.Horizontal;
                    if (latestAvailableVersion == null)
                    {
                        AddUpdateCheckButton(stackPanel, textView);
                    }
                    else
                    {
                        // we already retrieved the latest version sometime earlier
                        ShowAvailableVersion(latestAvailableVersion, stackPanel);
                    }
                    CheckBox checkBox       = new CheckBox();
                    checkBox.Margin         = new Thickness(4);
                    checkBox.Content        = Resources.AutomaticallyCheckUpdatesEveryWeek;
                    UpdateSettings settings = new UpdateSettings(ILSpySettings.Load());
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled")
                    {
                        Source = settings
                    });
                    return(new StackPanel {
                        Margin = new Thickness(0, 4, 0, 0),
                        Cursor = Cursors.Arrow,
                        Children = { stackPanel, checkBox }
                    });
                });
                output.WriteLine();
            }

            foreach (var plugin in App.ExportProvider.GetExportedValues <IAboutPageAddition>())
            {
                plugin.Write(output);
            }
            output.WriteLine();
            output.Address = new Uri("resource://AboutPage");
            using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), Resources.ILSpyAboutPageTxt))
            {
                using (StreamReader r = new StreamReader(s))
                {
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        output.WriteLine(line);
                    }
                }
            }
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("third-party notices", "resource:third-party-notices.txt"));
            textView.ShowText(output);
        }
Exemple #6
0
 void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
 {
     if (args.NavigateTo != null)
     {
         bool found = false;
         if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal))
         {
             string namespaceName = args.NavigateTo.Substring(2);
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
                 if (asmNode != null)
                 {
                     NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
                     if (nsNode != null)
                     {
                         found = true;
                         SelectNode(nsNode);
                         break;
                     }
                 }
             }
         }
         else
         {
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 ModuleDefinition def = asm.ModuleDefinition;
                 if (def != null)
                 {
                     MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo);
                     if (mr != null)
                     {
                         found = true;
                         JumpToReference(mr);
                         break;
                     }
                 }
             }
         }
         if (!found)
         {
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo));
             decompilerTextView.ShowText(output);
         }
     }
     else if (commandLineLoadedAssemblies.Count == 1)
     {
         // NavigateTo == null and an assembly was given on the command-line:
         // Select the newly loaded assembly
         JumpToReference(commandLineLoadedAssemblies[0].ModuleDefinition);
     }
     if (args.Search != null)
     {
         SearchPane.Instance.SearchTerm = args.Search;
         SearchPane.Instance.Show();
     }
     if (!string.IsNullOrEmpty(args.SaveDirectory))
     {
         foreach (var x in commandLineLoadedAssemblies)
         {
             x.ContinueWhenLoaded((Task <ModuleDefinition> moduleTask) => {
                 OnExportAssembly(moduleTask, args.SaveDirectory);
             }, TaskScheduler.FromCurrentSynchronizationContext());
         }
     }
     commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
 }
 private static void AddIcon(AvalonEditTextOutput output, BitmapFrame frame)
 {
     output.AddUIElement(() => new Image {
         Source = frame
     });
 }
Exemple #8
0
 private void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
 {
     if (nugetPackagesToLoad.Count > 0)
     {
         LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false);
         nugetPackagesToLoad.Clear();
     }
     if (args.NavigateTo != null)
     {
         bool found = false;
         if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal))
         {
             string namespaceName = args.NavigateTo.Substring(2);
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
                 if (asmNode != null)
                 {
                     NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
                     if (nsNode != null)
                     {
                         found = true;
                         SelectNode(nsNode);
                         break;
                     }
                 }
             }
         }
         else
         {
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 ModuleDefinition def = asm.GetModuleDefinitionOrNull();
                 if (def != null)
                 {
                     MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo);
                     if (mr != null)
                     {
                         found = true;
                         JumpToReference(mr);
                         break;
                     }
                 }
             }
         }
         if (!found)
         {
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo));
             decompilerTextView.ShowText(output);
         }
     }
     else if (commandLineLoadedAssemblies.Count == 1)
     {
         // NavigateTo == null and an assembly was given on the command-line:
         // Select the newly loaded assembly
         JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionOrNull());
     }
     if (args.Search != null)
     {
         SearchPane.Instance.SearchTerm = args.Search;
         SearchPane.Instance.Show();
     }
     commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
 }
Exemple #9
0
 void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
 {
     if (nugetPackagesToLoad.Count > 0)
     {
         LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false);
         nugetPackagesToLoad.Clear();
     }
     if (args.NavigateTo != null)
     {
         bool found = false;
         if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal))
         {
             string namespaceName = args.NavigateTo.Substring(2);
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
                 if (asmNode != null)
                 {
                     NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
                     if (nsNode != null)
                     {
                         found = true;
                         SelectNode(nsNode);
                         break;
                     }
                 }
             }
         }
         else
         {
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 var def = asm.GetPEFileOrNull();
                 if (def != null)
                 {
                     var compilation = new SimpleCompilation(def, MinimalCorlib.Instance);
                     var mr          = IdStringProvider.FindEntity(args.NavigateTo, new SimpleTypeResolveContext(compilation));
                     if (mr != null)
                     {
                         found = true;
                         // Defer JumpToReference call to allow an assembly that was loaded while
                         // resolving a type-forwarder in FindMemberByKey to appear in the assembly list.
                         Dispatcher.BeginInvoke(new Action(() => JumpToReference(mr)), DispatcherPriority.Loaded);
                         break;
                     }
                 }
             }
         }
         if (!found)
         {
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo));
             decompilerTextView.ShowText(output);
         }
     }
     else if (commandLineLoadedAssemblies.Count == 1)
     {
         // NavigateTo == null and an assembly was given on the command-line:
         // Select the newly loaded assembly
         JumpToReference(commandLineLoadedAssemblies[0].GetPEFileOrNull());
     }
     if (args.Search != null)
     {
         SearchPane.Instance.SearchTerm = args.Search;
         SearchPane.Instance.Show();
     }
     commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
 }
Exemple #10
0
        async Task <AvalonEditTextOutput> CreateSolution(IEnumerable <LoadedAssembly> assemblies, Language language, CancellationToken ct)
        {
            var result = new AvalonEditTextOutput();

            var duplicates = new HashSet <string>();

            if (assemblies.Any(asm => !duplicates.Add(asm.ShortName)))
            {
                result.WriteLine("Duplicate assembly names selected, cannot generate a solution.");
                return(result);
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                // Explicitly create an enumerable partitioner here to avoid Parallel.ForEach's special cases for lists,
                // as those seem to use static partitioning which is inefficient if assemblies take differently
                // long to decompile.
                await Task.Run(() => Parallel.ForEach(Partitioner.Create(assemblies),
                                                      new ParallelOptions {
                    MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = ct
                },
                                                      n => WriteProject(n, language, solutionDirectory, ct)))
                .ConfigureAwait(false);

                if (projects.Count == 0)
                {
                    result.WriteLine();
                    result.WriteLine("Solution could not be created, because none of the selected assemblies could be decompiled into a project.");
                }
                else
                {
                    await Task.Run(() => SolutionCreator.WriteSolutionFile(solutionFilePath, projects))
                    .ConfigureAwait(false);
                }
            }
            catch (AggregateException ae)
            {
                if (ae.Flatten().InnerExceptions.All(e => e is OperationCanceledException))
                {
                    result.WriteLine();
                    result.WriteLine("Generation was cancelled.");
                    return(result);
                }

                result.WriteLine();
                result.WriteLine("Failed to generate the Visual Studio Solution. Errors:");
                ae.Handle(e => {
                    result.WriteLine(e.Message);
                    return(true);
                });

                return(result);
            }

            foreach (var item in statusOutput)
            {
                result.WriteLine(item);
            }

            if (statusOutput.Count == 0)
            {
                result.WriteLine("Successfully decompiled the following assemblies into Visual Studio projects:");
                foreach (var item in assemblies.Select(n => n.Text.ToString()))
                {
                    result.WriteLine(item);
                }

                result.WriteLine();

                if (assemblies.Count() == projects.Count)
                {
                    result.WriteLine("Created the Visual Studio Solution file.");
                }

                result.WriteLine();
                result.WriteLine("Elapsed time: " + stopwatch.Elapsed.TotalSeconds.ToString("F1") + " seconds.");
                result.WriteLine();
                result.AddButton(null, "Open Explorer", delegate { Process.Start("explorer", "/select,\"" + solutionFilePath + "\""); });
            }

            return(result);
        }
Exemple #11
0
        async void NavigateOnLaunch(string navigateTo, string[] activeTreeViewPath, ILSpySettings spySettings, List <LoadedAssembly> relevantAssemblies)
        {
            var initialSelection = treeView.SelectedItem;

            if (navigateTo != null)
            {
                bool found = false;
                if (navigateTo.StartsWith("N:", StringComparison.Ordinal))
                {
                    string namespaceName = navigateTo.Substring(2);
                    foreach (LoadedAssembly asm in relevantAssemblies)
                    {
                        AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
                        if (asmNode != null)
                        {
                            // FindNamespaceNode() blocks the UI if the assembly is not yet loaded,
                            // so use an async wait instead.
                            await asm.GetPEFileAsync().Catch <Exception>(ex => { });

                            NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
                            if (nsNode != null)
                            {
                                found = true;
                                if (treeView.SelectedItem == initialSelection)
                                {
                                    SelectNode(nsNode);
                                }
                                break;
                            }
                        }
                    }
                }
                else if (navigateTo == "none")
                {
                    // Don't navigate anywhere; start empty.
                    // Used by ILSpy VS addin, it'll send us the real location to navigate to via IPC.
                    found = true;
                }
                else
                {
                    IEntity mr = await Task.Run(() => FindEntityInRelevantAssemblies(navigateTo, relevantAssemblies));

                    if (mr != null && mr.ParentModule.PEFile != null)
                    {
                        found = true;
                        if (treeView.SelectedItem == initialSelection)
                        {
                            JumpToReference(mr);
                        }
                    }
                }
                if (!found && treeView.SelectedItem == initialSelection)
                {
                    AvalonEditTextOutput output = new AvalonEditTextOutput();
                    output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", navigateTo));
                    DockWorkspace.Instance.ShowText(output);
                }
            }
            else if (relevantAssemblies.Count == 1)
            {
                // NavigateTo == null and an assembly was given on the command-line:
                // Select the newly loaded assembly
                AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]);
                if (asmNode != null && treeView.SelectedItem == initialSelection)
                {
                    SelectNode(asmNode);
                }
            }
            else if (spySettings != null)
            {
                SharpTreeNode node = null;
                if (activeTreeViewPath?.Length > 0)
                {
                    foreach (var asm in assemblyList.GetAssemblies())
                    {
                        if (asm.FileName == activeTreeViewPath[0])
                        {
                            // FindNodeByPath() blocks the UI if the assembly is not yet loaded,
                            // so use an async wait instead.
                            await asm.GetPEFileAsync().Catch <Exception>(ex => { });
                        }
                    }
                    node = FindNodeByPath(activeTreeViewPath, true);
                }
                if (treeView.SelectedItem == initialSelection)
                {
                    if (node != null)
                    {
                        SelectNode(node);

                        // only if not showing the about page, perform the update check:
                        await ShowMessageIfUpdatesAvailableAsync(spySettings);
                    }
                    else
                    {
                        AboutPage.Display(DockWorkspace.Instance.GetTextView());
                    }
                }
            }
        }
Exemple #12
0
        public static void Display(DecompilerTextView textView)
        {
            AvalonEditTextOutput output = new AvalonEditTextOutput()
            {
                EnableHyperlinks = true
            };

            output.WriteLine(Resources.ILSpyVersion + RevisionClass.FullVersion);
            if (WindowsVersionHelper.HasPackageIdentity)
            {
                output.WriteLine($"Package Name: {WindowsVersionHelper.GetPackageFamilyName()}");
            }
            else                // if we're running in an MSIX, updates work differently
            {
                output.AddUIElement(
                    delegate {
                    StackPanel stackPanel          = new StackPanel();
                    stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
                    stackPanel.Orientation         = Orientation.Horizontal;
                    if (latestAvailableVersion == null)
                    {
                        AddUpdateCheckButton(stackPanel, textView);
                    }
                    else
                    {
                        // we already retrieved the latest version sometime earlier
                        ShowAvailableVersion(latestAvailableVersion, stackPanel);
                    }
                    CheckBox checkBox       = new CheckBox();
                    checkBox.Margin         = new Thickness(4);
                    checkBox.Content        = Resources.AutomaticallyCheckUpdatesEveryWeek;
                    UpdateSettings settings = new UpdateSettings(ILSpySettings.Load());
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled")
                    {
                        Source = settings
                    });
                    return(new StackPanel {
                        Margin = new Thickness(0, 4, 0, 0),
                        Cursor = Cursors.Arrow,
                        Children = { stackPanel, checkBox }
                    });
                });
                output.WriteLine();
            }

            foreach (var plugin in App.ExportProvider.GetExportedValues <IAboutPageAddition>())
            {
                plugin.Write(output);
            }
            output.WriteLine();
            using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt")) {
                using (StreamReader r = new StreamReader(s)) {
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        output.WriteLine(line);
                    }
                }
            }
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MS-PL", "resource:MS-PL.txt"));
            textView.ShowText(output);
        }