forked from dnSpy/dnSpy
-
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated decompiler submodule and added ILAst stepper
- Loading branch information
1 parent
2331f12
commit 34e0666
Showing
8 changed files
with
376 additions
and
22 deletions.
There are no files selected for viewing
Submodule ICSharpCode.Decompiler
updated
5 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Extensions/ILSpy.Decompiler/dnSpy.Decompiler.ILSpy.Core/ILAst/StepperConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright (C) 2023 ElektroKill | ||
This file is part of dnSpy | ||
dnSpy is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
dnSpy is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with dnSpy. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
|
||
#if DEBUG | ||
namespace dnSpy.Decompiler.ILSpy.Core.ILAst { | ||
public static class StepperConstants { | ||
public static readonly Guid ToolWindowGuid = new Guid("38FBE664-81E4-4456-961D-37CFB7A9FB8E"); | ||
public static readonly Guid TreeViewGuid = new Guid("D3707DFF-3728-4B4D-BB81-A9D85793FD65"); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
Extensions/ILSpy.Decompiler/dnSpy.Decompiler.ILSpy/ILAst/ILAstStepperToolWindowContent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
Copyright (C) 2023 ElektroKill | ||
This file is part of dnSpy | ||
dnSpy is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
dnSpy is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with dnSpy. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using dnSpy.Contracts.Controls; | ||
using dnSpy.Contracts.Decompiler; | ||
using dnSpy.Contracts.Documents; | ||
using dnSpy.Contracts.Documents.Tabs; | ||
using dnSpy.Contracts.ToolWindows; | ||
using dnSpy.Contracts.ToolWindows.App; | ||
using dnSpy.Contracts.TreeView; | ||
using dnSpy.Contracts.TreeView.Text; | ||
using dnSpy.Decompiler.ILSpy.Core.ILAst; | ||
using dnSpy.Decompiler.ILSpy.Core.Settings; | ||
using ICSharpCode.Decompiler.IL.Transforms; | ||
|
||
#if DEBUG | ||
namespace dnSpy.Decompiler.ILSpy.ILAst { | ||
[Export(typeof(IToolWindowContentProvider))] | ||
sealed class AnalyzerToolWindowContentProvider : IToolWindowContentProvider { | ||
readonly IDecompilerService decompilerService; | ||
readonly IDocumentTabService documentTabService; | ||
readonly ITreeViewService treeViewService; | ||
readonly ITreeViewNodeTextElementProvider treeViewNodeTextElementProvider; | ||
|
||
public ILAstStepperToolWindowContent DocumentTreeViewWindowContent => analyzerToolWindowContent ??= new ILAstStepperToolWindowContent(decompilerService, documentTabService, treeViewService, treeViewNodeTextElementProvider); | ||
ILAstStepperToolWindowContent? analyzerToolWindowContent; | ||
|
||
[ImportingConstructor] | ||
AnalyzerToolWindowContentProvider(IDecompilerService decompilerService, IDocumentTabService documentTabService, ITreeViewService treeViewService, ITreeViewNodeTextElementProvider treeViewNodeTextElementProvider) { | ||
this.decompilerService = decompilerService; | ||
this.documentTabService = documentTabService; | ||
this.treeViewService = treeViewService; | ||
this.treeViewNodeTextElementProvider = treeViewNodeTextElementProvider; | ||
} | ||
|
||
public IEnumerable<ToolWindowContentInfo> ContentInfos { | ||
get { yield return new ToolWindowContentInfo(StepperConstants.ToolWindowGuid); } | ||
} | ||
|
||
public ToolWindowContent? GetOrCreate(Guid guid) => guid == StepperConstants.ToolWindowGuid ? DocumentTreeViewWindowContent : null; | ||
} | ||
|
||
sealed class ILAstStepperToolWindowContent : ToolWindowContent, IFocusable, IStepperTreeNodeDataContext { | ||
readonly IDecompilerService decompilerService; | ||
readonly IDocumentTabService documentTabService; | ||
readonly ITreeViewNodeTextElementProvider treeViewNodeTextElementProvider; | ||
readonly ITreeView treeView; | ||
ILAstDecompiler? decompiler; | ||
|
||
public override object UIObject => treeView.UIObject; | ||
public override IInputElement? FocusedElement => null; | ||
public override FrameworkElement ZoomElement => treeView.UIObject; | ||
public override Guid Guid => StepperConstants.ToolWindowGuid; | ||
public override string Title => "ILAst Stepper"; | ||
public bool CanFocus => true; | ||
public ITreeView TreeView => treeView; | ||
public ITreeViewNodeTextElementProvider TreeViewNodeTextElementProvider => treeViewNodeTextElementProvider; | ||
public Stepper.Node? CurrentState { get; private set; } | ||
|
||
public ILAstStepperToolWindowContent(IDecompilerService decompilerService, IDocumentTabService documentTabService, ITreeViewService treeViewService, ITreeViewNodeTextElementProvider treeViewNodeTextElementProvider) { | ||
this.decompilerService = decompilerService; | ||
this.documentTabService = documentTabService; | ||
this.treeViewNodeTextElementProvider = treeViewNodeTextElementProvider; | ||
decompilerService.DecompilerChanged += DecompilerService_DecompilerChanged; | ||
|
||
var options = new TreeViewOptions { | ||
CanDragAndDrop = false, | ||
SelectionMode = SelectionMode.Single, | ||
}; | ||
treeView = treeViewService.Create(StepperConstants.TreeViewGuid, options); | ||
treeView.UIObject.Padding = new Thickness(0, 2, 0, 2); | ||
treeView.UIObject.BorderThickness = new Thickness(1); | ||
|
||
OnDecompilerSelected(decompilerService.Decompiler); | ||
} | ||
|
||
void DecompilerService_DecompilerChanged(object? sender, EventArgs e) => | ||
OnDecompilerSelected(decompilerService.Decompiler); | ||
|
||
void OnDecompilerSelected(IDecompiler newDecompiler) { | ||
if (decompiler is not null) | ||
decompiler.StepperUpdated -= ILAstStepperUpdated; | ||
decompiler = newDecompiler as ILAstDecompiler; | ||
if (decompiler is not null) | ||
decompiler.StepperUpdated += ILAstStepperUpdated; | ||
else { | ||
CurrentState = null; | ||
treeView.UIObject.Dispatcher.Invoke(() => treeView.Root.Children.Clear()); | ||
} | ||
} | ||
|
||
void ILAstStepperUpdated(object? sender, EventArgs e) { | ||
if (decompiler is null) | ||
return; | ||
|
||
CurrentState = null; | ||
|
||
treeView.UIObject.Dispatcher.Invoke(() => { | ||
treeView.Root.Children.Clear(); | ||
for (var i = 0; i < decompiler.Stepper.Steps.Count; i++) | ||
treeView.Root.AddChild(treeView.Create(new StepperNodeTreeNodeData(this, decompiler.Stepper.Steps[i]))); | ||
}); | ||
} | ||
|
||
public void ShowStateAfter(Stepper.Node node) { | ||
CurrentState = node; | ||
SetNewStepLimit(node.EndStep); | ||
RefreshTabs(); | ||
treeView.RefreshAllNodes(); | ||
} | ||
|
||
void SetNewStepLimit(int stepLimit) { | ||
if (decompiler is not null && decompiler.Settings is ILAstDecompilerSettings settings) | ||
settings.StepLimit = stepLimit; | ||
} | ||
|
||
void RefreshTabs() { | ||
var toRefresh = new HashSet<IDocumentTab>(); | ||
foreach (var tab in documentTabService.VisibleFirstTabs) { | ||
var decomp = (tab.Content as IDecompilerTabContent)?.Decompiler; | ||
if (decomp is not null && decomp == decompiler) | ||
toRefresh.Add(tab); | ||
} | ||
documentTabService.Refresh(toRefresh.ToArray()); | ||
} | ||
|
||
public void Focus() => treeView.Focus(); | ||
} | ||
} | ||
#endif |
33 changes: 33 additions & 0 deletions
33
Extensions/ILSpy.Decompiler/dnSpy.Decompiler.ILSpy/ILAst/IStepperTreeNodeDataContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright (C) 2023 ElektroKill | ||
This file is part of dnSpy | ||
dnSpy is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
dnSpy is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with dnSpy. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using dnSpy.Contracts.TreeView; | ||
using dnSpy.Contracts.TreeView.Text; | ||
using ICSharpCode.Decompiler.IL.Transforms; | ||
|
||
#if DEBUG | ||
namespace dnSpy.Decompiler.ILSpy.ILAst { | ||
interface IStepperTreeNodeDataContext { | ||
ITreeView TreeView { get; } | ||
ITreeViewNodeTextElementProvider TreeViewNodeTextElementProvider { get; } | ||
Stepper.Node? CurrentState { get; } | ||
void ShowStateAfter(Stepper.Node node); | ||
} | ||
} | ||
#endif |
34 changes: 34 additions & 0 deletions
34
Extensions/ILSpy.Decompiler/dnSpy.Decompiler.ILSpy/ILAst/ShowStepperToolWindowLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright (C) 2023 ElektroKill | ||
This file is part of dnSpy | ||
dnSpy is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
dnSpy is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with dnSpy. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System.ComponentModel.Composition; | ||
using dnSpy.Contracts.Extension; | ||
using dnSpy.Contracts.ToolWindows.App; | ||
using dnSpy.Decompiler.ILSpy.Core.ILAst; | ||
|
||
#if DEBUG | ||
namespace dnSpy.Decompiler.ILSpy.ILAst { | ||
[ExportAutoLoaded] | ||
sealed class ShowStepperToolWindowLoader : IAutoLoaded { | ||
[ImportingConstructor] | ||
public ShowStepperToolWindowLoader(IDsToolWindowService toolWindowService) => | ||
toolWindowService.Show(StepperConstants.ToolWindowGuid); | ||
} | ||
} | ||
#endif |
Oops, something went wrong.