mirror of https://github.com/icsharpcode/ILSpy.git
73 changed files with 1223 additions and 758 deletions
@ -0,0 +1,122 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel.Composition; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
using ICSharpCode.ILSpy.TextView; |
||||||
|
using ICSharpCode.ILSpy.TreeNodes; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy |
||||||
|
{ |
||||||
|
[ExportMainMenuCommand(Menu = "_File", Header = "E_xit", MenuOrder = 99999, MenuCategory = "Exit")] |
||||||
|
sealed class ExitCommand : SimpleCommand |
||||||
|
{ |
||||||
|
public override void Execute(object parameter) |
||||||
|
{ |
||||||
|
MainWindow.Instance.Close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[ExportToolbarCommand(ToolTip = "Back", ToolbarIcon = "Images/Back.png", ToolbarCategory = "Navigation", ToolbarOrder = 0)] |
||||||
|
sealed class BrowseBackCommand : CommandWrapper { |
||||||
|
public BrowseBackCommand() : base(NavigationCommands.BrowseBack) {} |
||||||
|
} |
||||||
|
|
||||||
|
[ExportToolbarCommand(ToolTip = "Forward", ToolbarIcon = "Images/Forward.png", ToolbarCategory = "Navigation", ToolbarOrder = 1)] |
||||||
|
sealed class BrowseForwardCommand : CommandWrapper { |
||||||
|
public BrowseForwardCommand() : base(NavigationCommands.BrowseForward) {} |
||||||
|
} |
||||||
|
|
||||||
|
[ExportToolbarCommand(ToolTip = "Open", ToolbarIcon = "Images/Open.png", ToolbarCategory = "Open", ToolbarOrder = 0)] |
||||||
|
[ExportMainMenuCommand(Menu = "_File", MenuIcon = "Images/Open.png", MenuCategory = "Open", MenuOrder = 0)] |
||||||
|
sealed class OpenCommand : CommandWrapper { |
||||||
|
public OpenCommand() : base(ApplicationCommands.Open) {} |
||||||
|
} |
||||||
|
|
||||||
|
[ExportMainMenuCommand(Menu = "_File", Header = "Open from _GAC", MenuCategory = "Open", MenuOrder = 1)] |
||||||
|
sealed class OpenFromGacCommand : SimpleCommand |
||||||
|
{ |
||||||
|
public override void Execute(object parameter) |
||||||
|
{ |
||||||
|
OpenFromGacDialog dlg = new OpenFromGacDialog(); |
||||||
|
dlg.Owner = MainWindow.Instance; |
||||||
|
if (dlg.ShowDialog() == true) { |
||||||
|
MainWindow.Instance.OpenFiles(dlg.SelectedFileNames); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[ExportToolbarCommand(ToolTip = "Reload all assemblies", ToolbarIcon = "Images/Refresh.png", ToolbarCategory = "Open", ToolbarOrder = 2)] |
||||||
|
[ExportMainMenuCommand(Menu = "_File", Header = "Reload", MenuIcon = "Images/Refresh.png", MenuCategory = "Open", MenuOrder = 2)] |
||||||
|
sealed class RefreshCommand : CommandWrapper { |
||||||
|
public RefreshCommand() : base(NavigationCommands.Refresh) {} |
||||||
|
} |
||||||
|
|
||||||
|
[ExportMainMenuCommand(Menu = "_File", Header = "_Save Code...", MenuIcon = "Images/SaveFile.png", MenuCategory = "Save", MenuOrder = 0)] |
||||||
|
sealed class SaveCommand : SimpleCommand |
||||||
|
{ |
||||||
|
public override void Execute(object parameter) |
||||||
|
{ |
||||||
|
MainWindow mainWindow = MainWindow.Instance; |
||||||
|
if (mainWindow.SelectedNodes.Count() == 1) { |
||||||
|
if (mainWindow.SelectedNodes.Single().Save(mainWindow.TextView)) |
||||||
|
return; |
||||||
|
} |
||||||
|
mainWindow.TextView.SaveToDisk(mainWindow.CurrentLanguage, |
||||||
|
mainWindow.SelectedNodes, |
||||||
|
new DecompilationOptions() { FullDecompilation = true }); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class CommandWrapper : ICommand |
||||||
|
{ |
||||||
|
ICommand wrappedCommand; |
||||||
|
|
||||||
|
public CommandWrapper(ICommand wrappedCommand) |
||||||
|
{ |
||||||
|
this.wrappedCommand = wrappedCommand; |
||||||
|
} |
||||||
|
|
||||||
|
public static ICommand Unwrap(ICommand command) |
||||||
|
{ |
||||||
|
CommandWrapper w = command as CommandWrapper; |
||||||
|
if (w != null) |
||||||
|
return w.wrappedCommand; |
||||||
|
else |
||||||
|
return command; |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler CanExecuteChanged { |
||||||
|
add { wrappedCommand.CanExecuteChanged += value; } |
||||||
|
remove { wrappedCommand.CanExecuteChanged -= value; } |
||||||
|
} |
||||||
|
|
||||||
|
public void Execute(object parameter) |
||||||
|
{ |
||||||
|
wrappedCommand.Execute(parameter); |
||||||
|
} |
||||||
|
|
||||||
|
public bool CanExecute(object parameter) |
||||||
|
{ |
||||||
|
return wrappedCommand.CanExecute(parameter); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public abstract class SimpleCommand : ICommand |
||||||
|
{ |
||||||
|
public event EventHandler CanExecuteChanged { |
||||||
|
add { CommandManager.RequerySuggested += value; } |
||||||
|
remove { CommandManager.RequerySuggested -= value; } |
||||||
|
} |
||||||
|
|
||||||
|
public abstract void Execute(object parameter); |
||||||
|
|
||||||
|
public virtual bool CanExecute(object parameter) |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,56 +0,0 @@ |
|||||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Windows.Input; |
|
||||||
|
|
||||||
namespace ICSharpCode.ILSpy.Commands |
|
||||||
{ |
|
||||||
public static class RoutedUICommands |
|
||||||
{ |
|
||||||
static RoutedUICommands() |
|
||||||
{ |
|
||||||
AttachToProcess = new RoutedUICommand("Attach to running process...", "AttachToProcess", typeof(RoutedUICommands)); |
|
||||||
DetachFromProcess = new RoutedUICommand("Detach from process...", "DetachFromProcess", typeof(RoutedUICommands)); |
|
||||||
ContinueDebugging = new RoutedUICommand("Continue debugging", "ContinueDebugging", typeof(RoutedUICommands)); |
|
||||||
StepInto = new RoutedUICommand("Step into", "StepInto", typeof(RoutedUICommands)); |
|
||||||
StepOver = new RoutedUICommand("Step over", "StepOver", typeof(RoutedUICommands)); |
|
||||||
StepOut = new RoutedUICommand("Step out", "StepOut", typeof(RoutedUICommands)); |
|
||||||
|
|
||||||
RemoveAllBreakpoint = new RoutedUICommand("Remove all breakpoints", "RemoveAllBreakpoint", typeof(RoutedUICommands)); |
|
||||||
|
|
||||||
DebugExecutable = new RoutedUICommand("Debug an executable", "DebugExecutable", typeof(RoutedUICommands)); |
|
||||||
} |
|
||||||
|
|
||||||
public static RoutedUICommand AttachToProcess { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand DetachFromProcess { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand ContinueDebugging { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand StepInto { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand StepOver { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand StepOut { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand RemoveAllBreakpoint { get; private set; } |
|
||||||
|
|
||||||
public static RoutedUICommand DebugExecutable { get; private set; } |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,63 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel.Composition; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy |
||||||
|
{ |
||||||
|
#region Toolbar
|
||||||
|
public interface IToolbarCommandMetadata |
||||||
|
{ |
||||||
|
string ToolbarIcon { get; } |
||||||
|
string ToolTip { get; } |
||||||
|
string ToolbarCategory { get; } |
||||||
|
|
||||||
|
double ToolbarOrder { get; } |
||||||
|
} |
||||||
|
|
||||||
|
[MetadataAttribute] |
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] |
||||||
|
public class ExportToolbarCommandAttribute : ExportAttribute |
||||||
|
{ |
||||||
|
public ExportToolbarCommandAttribute() |
||||||
|
: base("ToolbarCommand", typeof(ICommand)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public string ToolTip { get; set; } |
||||||
|
public string ToolbarIcon { get; set; } |
||||||
|
public string ToolbarCategory { get; set; } |
||||||
|
public double ToolbarOrder { get; set; } |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Main Menu
|
||||||
|
public interface IMainMenuCommandMetadata |
||||||
|
{ |
||||||
|
string MenuIcon { get; } |
||||||
|
string Header { get; } |
||||||
|
string Menu { get; } |
||||||
|
string MenuCategory { get; } |
||||||
|
|
||||||
|
double MenuOrder { get; } |
||||||
|
} |
||||||
|
|
||||||
|
[MetadataAttribute] |
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] |
||||||
|
public class ExportMainMenuCommandAttribute : ExportAttribute |
||||||
|
{ |
||||||
|
public ExportMainMenuCommandAttribute() |
||||||
|
: base("MainMenuCommand", typeof(ICommand)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public string MenuIcon { get; set; } |
||||||
|
public string Header { get; set; } |
||||||
|
public string Menu { get; set; } |
||||||
|
public string MenuCategory { get; set; } |
||||||
|
public double MenuOrder { get; set; } |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
@ -0,0 +1,174 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.ComponentModel.Composition; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Resources; |
||||||
|
using System.Text; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Threading; |
||||||
|
using ICSharpCode.AvalonEdit.Highlighting; |
||||||
|
using ICSharpCode.AvalonEdit.Utils; |
||||||
|
using ICSharpCode.Decompiler; |
||||||
|
using ICSharpCode.ILSpy.TextView; |
||||||
|
using Microsoft.Win32; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.TreeNodes |
||||||
|
{ |
||||||
|
public class ResourceTreeNode : ILSpyTreeNode |
||||||
|
{ |
||||||
|
Resource r; |
||||||
|
|
||||||
|
public ResourceTreeNode(Resource r) |
||||||
|
{ |
||||||
|
if (r == null) |
||||||
|
throw new ArgumentNullException("r"); |
||||||
|
this.r = r; |
||||||
|
} |
||||||
|
|
||||||
|
public Resource Resource { |
||||||
|
get { return r; } |
||||||
|
} |
||||||
|
|
||||||
|
public override object Text { |
||||||
|
get { return r.Name; } |
||||||
|
} |
||||||
|
|
||||||
|
public override object Icon { |
||||||
|
get { return Images.Resource; } |
||||||
|
} |
||||||
|
|
||||||
|
public override FilterResult Filter(FilterSettings settings) |
||||||
|
{ |
||||||
|
if (!settings.ShowInternalApi && (r.Attributes & ManifestResourceAttributes.VisibilityMask) == ManifestResourceAttributes.Private) |
||||||
|
return FilterResult.Hidden; |
||||||
|
if (settings.SearchTermMatches(r.Name)) |
||||||
|
return FilterResult.Match; |
||||||
|
else |
||||||
|
return FilterResult.Hidden; |
||||||
|
} |
||||||
|
|
||||||
|
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) |
||||||
|
{ |
||||||
|
language.WriteCommentLine(output, string.Format("{0} ({1}, {2})", r.Name, r.ResourceType, r.Attributes)); |
||||||
|
|
||||||
|
ISmartTextOutput smartOutput = output as ISmartTextOutput; |
||||||
|
if (smartOutput != null && r is EmbeddedResource) { |
||||||
|
smartOutput.AddButton(Images.Save, "Save", delegate { Save(null); }); |
||||||
|
output.WriteLine(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
internal override bool View(DecompilerTextView textView) |
||||||
|
{ |
||||||
|
EmbeddedResource er = r as EmbeddedResource; |
||||||
|
if (er != null) { |
||||||
|
Stream s = er.GetResourceStream(); |
||||||
|
if (s != null && s.Length < DecompilerTextView.DefaultOutputLengthLimit) { |
||||||
|
s.Position = 0; |
||||||
|
FileType type = GuessFileType.DetectFileType(s); |
||||||
|
if (type != FileType.Binary) { |
||||||
|
s.Position = 0; |
||||||
|
AvalonEditTextOutput output = new AvalonEditTextOutput(); |
||||||
|
output.Write(FileReader.OpenStream(s, Encoding.UTF8).ReadToEnd()); |
||||||
|
string ext; |
||||||
|
if (type == FileType.Xml) |
||||||
|
ext = ".xml"; |
||||||
|
else |
||||||
|
ext = Path.GetExtension(DecompilerTextView.CleanUpName(er.Name)); |
||||||
|
textView.Show(output, HighlightingManager.Instance.GetDefinitionByExtension(ext)); |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public override bool Save(TextView.DecompilerTextView textView) |
||||||
|
{ |
||||||
|
EmbeddedResource er = r as EmbeddedResource; |
||||||
|
if (er != null) { |
||||||
|
SaveFileDialog dlg = new SaveFileDialog(); |
||||||
|
dlg.FileName = DecompilerTextView.CleanUpName(er.Name); |
||||||
|
if (dlg.ShowDialog() == true) { |
||||||
|
Stream s = er.GetResourceStream(); |
||||||
|
s.Position = 0; |
||||||
|
using (var fs = dlg.OpenFile()) { |
||||||
|
s.CopyTo(fs); |
||||||
|
} |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public static ILSpyTreeNode Create(Resource resource) |
||||||
|
{ |
||||||
|
ILSpyTreeNode result = null; |
||||||
|
foreach (var factory in App.CompositionContainer.GetExportedValues<IResourceNodeFactory>()) { |
||||||
|
result = factory.CreateNode(resource); |
||||||
|
if (result != null) |
||||||
|
break; |
||||||
|
} |
||||||
|
return result ?? new ResourceTreeNode(resource); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This interface allows plugins to create custom nodes for resources.
|
||||||
|
/// </summary>
|
||||||
|
public interface IResourceNodeFactory |
||||||
|
{ |
||||||
|
ILSpyTreeNode CreateNode(Resource resource); |
||||||
|
ILSpyTreeNode CreateNode(string key, Stream data); |
||||||
|
} |
||||||
|
|
||||||
|
[Export(typeof(IResourceNodeFactory))] |
||||||
|
sealed class ResourcesFileTreeNodeFactory : IResourceNodeFactory |
||||||
|
{ |
||||||
|
public ILSpyTreeNode CreateNode(Resource resource) |
||||||
|
{ |
||||||
|
EmbeddedResource er = resource as EmbeddedResource; |
||||||
|
if (er != null && er.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) { |
||||||
|
return new ResourcesFileTreeNode(er); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public ILSpyTreeNode CreateNode(string key, Stream data) |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
sealed class ResourcesFileTreeNode : ResourceTreeNode |
||||||
|
{ |
||||||
|
public ResourcesFileTreeNode(EmbeddedResource er) : base(er) |
||||||
|
{ |
||||||
|
this.LazyLoading = true; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void LoadChildren() |
||||||
|
{ |
||||||
|
EmbeddedResource er = this.Resource as EmbeddedResource; |
||||||
|
if (er != null) { |
||||||
|
Stream s = er.GetResourceStream(); |
||||||
|
s.Position = 0; |
||||||
|
ResourceReader reader; |
||||||
|
try { |
||||||
|
reader = new ResourceReader(s); |
||||||
|
} catch (ArgumentException) { |
||||||
|
return; |
||||||
|
} |
||||||
|
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) { |
||||||
|
if (entry.Value is Stream) |
||||||
|
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), (Stream)entry.Value)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue