Browse Source

Add TestPlugin.

pull/129/head
Daniel Grunwald 14 years ago
parent
commit
5c7d679c52
  1. 20
      ILSpy.sln
  2. 12
      ILSpy/AssemblyList.cs
  3. 1
      ILSpy/ILSpy.csproj
  4. 9
      ILSpy/Images/Images.cs
  5. 8
      ILSpy/MainWindow.xaml.cs
  6. 2
      ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessNode.cs
  7. 2
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs
  8. 2
      ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs
  9. 2
      ILSpy/TreeNodes/Analyzer/AnalyzerMethodOverridesTreeNode.cs
  10. 4
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  11. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  12. BIN
      TestPlugin/Clear.png
  13. 60
      TestPlugin/CustomLanguage.cs
  14. 29
      TestPlugin/MainMenuCommand.cs
  15. 31
      TestPlugin/Properties/AssemblyInfo.cs
  16. 25
      TestPlugin/Readme.txt
  17. 98
      TestPlugin/TestPlugin.csproj
  18. 2
      doc/Command Line.txt

20
ILSpy.sln

@ -1,7 +1,12 @@ @@ -1,7 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.1.7126
# SharpDevelop 4.0.1.7146
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"
ProjectSection(SolutionItems) = postProject
doc\Command Line.txt = doc\Command Line.txt
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy", "ILSpy\ILSpy.csproj", "{1E85EFF9-E370-4683-83E4-8A3D063FF791}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "SharpTreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}"
@ -16,10 +21,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "N @@ -16,10 +21,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "N
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler.Tests", "ICSharpCode.Decompiler\Tests\ICSharpCode.Decompiler.Tests.csproj", "{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"
ProjectSection(SolutionItems) = postProject
doc\Command Line.txt = doc\Command Line.txt
EndProjectSection
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPlugin", "TestPlugin\TestPlugin.csproj", "{F32EBCC8-0E53-4421-867E-05B3D6E10C70}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -85,6 +87,14 @@ Global @@ -85,6 +87,14 @@ Global
{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Release|Any CPU.Build.0 = Release|x86
{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Release|x86.ActiveCfg = Release|x86
{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Release|x86.Build.0 = Release|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Debug|Any CPU.Build.0 = Debug|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Debug|Any CPU.ActiveCfg = Debug|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Debug|x86.Build.0 = Debug|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Debug|x86.ActiveCfg = Debug|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Release|Any CPU.Build.0 = Release|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Release|Any CPU.ActiveCfg = Release|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Release|x86.Build.0 = Release|x86
{F32EBCC8-0E53-4421-867E-05B3D6E10C70}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

12
ILSpy/AssemblyList.cs

@ -130,8 +130,18 @@ namespace ICSharpCode.ILSpy @@ -130,8 +130,18 @@ namespace ICSharpCode.ILSpy
}
var newAsm = new LoadedAssembly(this, file);
this.assemblies.Add(newAsm);
lock (assemblies) {
this.assemblies.Add(newAsm);
}
return newAsm;
}
public void Unload(LoadedAssembly assembly)
{
App.Current.Dispatcher.VerifyAccess();
lock (assemblies) {
assemblies.Remove(assembly);
}
}
}
}

1
ILSpy/ILSpy.csproj

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<ApplicationIcon>Images\ILSpy.ico</ApplicationIcon>
<RunCodeAnalysis>False</RunCodeAnalysis>
<StartArguments>/separate</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>

9
ILSpy/Images/Images.cs

@ -78,10 +78,13 @@ namespace ICSharpCode.ILSpy @@ -78,10 +78,13 @@ namespace ICSharpCode.ILSpy
public static BitmapImage LoadImage(object part, string icon)
{
Uri uri;
if (part.GetType().Assembly == typeof(Images).Assembly)
var assembly = part.GetType().Assembly;
if (assembly == typeof(Images).Assembly) {
uri = new Uri("pack://application:,,,/" + icon);
else
throw new NotImplementedException();
} else {
var name = assembly.GetName();
uri = new Uri("pack://application:,,,/" + name.Name + ";v" + name.Version + ";component/" + icon);
}
BitmapImage image = new BitmapImage(uri);
image.Freeze();
return image;

8
ILSpy/MainWindow.xaml.cs

@ -209,6 +209,10 @@ namespace ICSharpCode.ILSpy @@ -209,6 +209,10 @@ namespace ICSharpCode.ILSpy
}
#endregion
public AssemblyList CurrentAssemblyList {
get { return assemblyList; }
}
List<LoadedAssembly> commandLineLoadedAssemblies = new List<LoadedAssembly>();
bool HandleCommandLineArguments(CommandLineArguments args)
@ -371,10 +375,6 @@ namespace ICSharpCode.ILSpy @@ -371,10 +375,6 @@ namespace ICSharpCode.ILSpy
assemblyListTreeNode.FilterSettings = sessionSettings.FilterSettings.Clone();
}
internal AssemblyList AssemblyList {
get { return assemblyList; }
}
internal AssemblyListTreeNode AssemblyListTreeNode {
get { return assemblyListTreeNode; }
}

2
ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessNode.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{
return FindReferences(MainWindow.Instance.AssemblyList.GetAssemblies(), ct);
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
}
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)

2
ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs

@ -67,7 +67,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -67,7 +67,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{
return FindReferences(MainWindow.Instance.AssemblyList.GetAssemblies(), ct);
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
}
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)

2
ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{
return FindReferences(MainWindow.Instance.AssemblyList.GetAssemblies(), ct);
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
}
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)

2
ILSpy/TreeNodes/Analyzer/AnalyzerMethodOverridesTreeNode.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -55,7 +55,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{
return FindReferences(MainWindow.Instance.AssemblyList.GetAssemblies(), ct);
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
}
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)

4
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -161,9 +161,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -161,9 +161,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void DeleteCore()
{
lock (assembly.AssemblyList.assemblies) {
assembly.AssemblyList.assemblies.Remove(assembly);
}
assembly.AssemblyList.Unload(assembly);
}
internal const string DataFormat = "ILSpyAssemblies";

8
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs

@ -383,7 +383,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -383,7 +383,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Clones the whole subtree starting at this AST node.
/// </summary>
/// <remarks>Annotations are copied over to the new nodes; and any annotations implementating ICloneable will be cloned.</remarks>
/// <remarks>Annotations are copied over to the new nodes; and any annotations implementing ICloneable will be cloned.</remarks>
public AstNode Clone()
{
AstNode copy = (AstNode)MemberwiseClone();
@ -401,9 +401,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -401,9 +401,9 @@ namespace ICSharpCode.NRefactory.CSharp
}
// Finally, clone the annotation, if necessary
ICloneable annotations = copy.annotations as ICloneable; // read from copy (for thread-safety)
if (annotations != null)
copy.annotations = annotations.Clone();
ICloneable copiedAnnotations = copy.annotations as ICloneable; // read from copy (for thread-safety)
if (copiedAnnotations != null)
copy.annotations = copiedAnnotations.Clone();
return copy;
}

BIN
TestPlugin/Clear.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

60
TestPlugin/CustomLanguage.cs

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
// 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.Controls;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Ast;
using ICSharpCode.ILSpy;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
namespace TestPlugin
{
/// <summary>
/// Adds a new language to the decompiler.
/// </summary>
[Export(typeof(Language))]
public class CustomLanguage : Language
{
public override string Name {
get {
return "Custom";
}
}
public override string FileExtension {
get {
// used in 'Save As' dialog
return ".txt";
}
}
// There are several methods available to override; in this sample, we deal with methods only
public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
{
if (method.Body != null) {
output.WriteLine("Size of method: {0} bytes", method.Body.CodeSize);
ISmartTextOutput smartOutput = output as ISmartTextOutput;
if (smartOutput != null) {
// when writing to the text view (but not when writing to a file), we can even add UI elements such as buttons:
smartOutput.AddButton(null, "Click me!", (sender, e) => (sender as Button).Content = "I was clicked!");
smartOutput.WriteLine();
}
// ICSharpCode.Decompiler.Ast.AstBuilder can be used to decompile to C#
AstBuilder b = new AstBuilder(new DecompilerContext(method.Module) {
Settings = options.DecompilerSettings,
CurrentType = method.DeclaringType
});
b.AddMethod(method);
b.RunTransformations();
output.WriteLine("Decompiled AST has {0} nodes", b.CompilationUnit.DescendantsAndSelf.Count());
}
}
}
}

29
TestPlugin/MainMenuCommand.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
// 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 ICSharpCode.ILSpy;
namespace TestPlugin
{
// Menu: menu into which the item is added
// MenuIcon: optional, icon to use for the menu item. Must be embedded as "Resource" (WPF-style resource) in the same assembly as the command type.
// Header: text on the menu item
// MenuCategory: optional, used for grouping related menu items together. A separator is added between different groups.
// MenuOrder: controls the order in which the items appear (items are sorted by this value)
[ExportMainMenuCommand(Menu = "_File", MenuIcon = "Clear.png", Header = "_Clear List", MenuCategory = "Open", MenuOrder = 1.5)]
// ToolTip: the tool tip
// ToolbarIcon: The icon. Must be embedded as "Resource" (WPF-style resource) in the same assembly as the command type.
// ToolbarCategory: optional, used for grouping related toolbar items together. A separator is added between different groups.
// ToolbarOrder: controls the order in which the items appear (items are sorted by this value)
[ExportToolbarCommand(ToolTip = "Clears the current assembly list", ToolbarIcon = "Clear.png", ToolbarCategory = "Open", ToolbarOrder = 1.5)]
public class UnloadAllAssembliesCommand : SimpleCommand
{
public override void Execute(object parameter)
{
foreach (var loadedAssembly in MainWindow.Instance.CurrentAssemblyList.GetAssemblies()) {
loadedAssembly.AssemblyList.Unload(loadedAssembly);
}
}
}
}

31
TestPlugin/Properties/AssemblyInfo.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TestPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestPlugin")]
[assembly: AssemblyCopyright("Copyright 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

25
TestPlugin/Readme.txt

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
ILSpy uses MEF (Managed Extensibility Framework) for plugins.
Plugins must be placed in the same directory as ILSpy.exe, and must be called "*.Plugin.dll".
To write a plugin, you need to add a reference to ILSpy.exe and to System.ComponentModel.Composition.
Depending on what your plugin is doing, you might also need references to the other libraries shipping with ILSpy.
Plugins work by exporting types for certain extension points.
Here is a list of extension points:
Adding another language:
[Export(typeof(Language))]
public class CustomLanguage : Language
This adds an additional language to the combobox in the toolbar.
The language has to implement its own decompiler (all the way from IL), but it can also re-use
the ICSharpCode.Decompiler library to decompile to C#, and then translate the C# code to the target language.
---
Adding an entry to the main menu:
[ExportMainMenuCommand(Menu = "_File", Header = "_Clear List", MenuCategory = "Open", MenuOrder = 1.5)]
public class UnloadAllAssembliesCommand : SimpleCommand

98
TestPlugin/TestPlugin.csproj

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{F32EBCC8-0E53-4421-867E-05B3D6E10C70}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>TestPlugin</RootNamespace>
<AssemblyName>Test.Plugin</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<StartArguments>/separate</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<StartAction>Program</StartAction>
<StartProgram>bin\Debug\ILSpy.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
<StartAction>Program</StartAction>
<StartProgram>bin\Release\ILSpy.exe</StartProgram>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomLanguage.cs" />
<Compile Include="MainMenuCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Resource Include="Clear.png" />
<None Include="Readme.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj">
<Project>{984CC812-9470-4A13-AFF9-CC44068D666C}</Project>
<Name>ICSharpCode.Decompiler</Name>
</ProjectReference>
<ProjectReference Include="..\ILSpy\ILSpy.csproj">
<Project>{1E85EFF9-E370-4683-83E4-8A3D063FF791}</Project>
<Name>ILSpy</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

2
doc/Command Line.txt

@ -10,7 +10,7 @@ Available options: @@ -10,7 +10,7 @@ Available options:
/separate Start up a separate ILSpy instance even if it is already running.
/noActivate Do not activate the existing ILSpy instance. This option has no effec
/noActivate Do not activate the existing ILSpy instance. This option has no effect
if a new ILSpy instance is being started.
/list:listname Specifies the name of the assembly list that is loaded initially.

Loading…
Cancel
Save