mirror of https://github.com/icsharpcode/ILSpy.git
18 changed files with 290 additions and 25 deletions
After Width: | Height: | Size: 1.1 KiB |
@ -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()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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.*")] |
@ -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 |
||||||
|
|
@ -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> |
Loading…
Reference in new issue