ILSpy
.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
Top Related Projects
.NET debugger and assembly editor
.NET deobfuscator and unpacker.
Reads and writes .NET assemblies and modules
NLog - Advanced and Structured Logging for Various .NET Platforms
Cecil is a library to inspect, modify and create .NET programs and libraries.
Quick Overview
ILSpy is an open-source .NET assembly browser and decompiler. It allows developers to inspect and analyze compiled .NET assemblies by decompiling them back into readable C# or Visual Basic code. ILSpy is widely used for reverse engineering, debugging, and learning purposes.
Pros
- Free and open-source, with a large community of contributors
- Supports decompilation of .NET assemblies to C# and Visual Basic
- Includes a powerful search functionality for finding types, members, and strings
- Offers a user-friendly GUI and a command-line interface for integration into other tools
Cons
- May not always produce perfectly accurate decompiled code, especially for complex or obfuscated assemblies
- Performance can be slower when decompiling large assemblies
- Limited support for some advanced language features or custom attributes
- Requires .NET Framework or .NET Core runtime to be installed
Getting Started
To use ILSpy:
- Download the latest release from the GitHub releases page.
- Extract the ZIP file to a folder of your choice.
- Run
ILSpy.exe
to launch the application. - Drag and drop a .NET assembly (DLL or EXE) into the ILSpy window, or use File > Open to browse for an assembly.
- Navigate the tree view to explore the decompiled code of the assembly.
For command-line usage:
ILSpy.Console.exe <assembly> -o <output-directory>
This will decompile the specified assembly and save the decompiled code to the output directory.
Competitor Comparisons
.NET debugger and assembly editor
Pros of dnSpy
- Advanced debugging capabilities, including edit-and-continue functionality
- More user-friendly interface with better syntax highlighting
- Faster decompilation for large assemblies
Cons of dnSpy
- No longer actively maintained (last commit in 2020)
- Limited support for newer .NET versions and features
- Fewer plugin options compared to ILSpy
Code Comparison
Both ILSpy and dnSpy use similar approaches for decompiling .NET assemblies. Here's a basic example of how they might decompile a simple method:
ILSpy:
public static int Add(int a, int b)
{
return a + b;
}
dnSpy:
public static int Add(int a, int b)
{
return a + b;
}
In this case, the output is identical. However, for more complex code, dnSpy often provides better formatting and more accurate representations of the original source code.
Summary
While dnSpy offers superior debugging features and a more polished user interface, its lack of recent updates may be a concern for users working with the latest .NET technologies. ILSpy, on the other hand, continues to be actively developed and supports a wider range of .NET versions and features. The choice between the two largely depends on specific use cases and the importance of ongoing maintenance.
.NET deobfuscator and unpacker.
Pros of de4dot
- Specialized in deobfuscation and cleaning of .NET assemblies
- More advanced obfuscation removal techniques
- Supports a wider range of obfuscators and protectors
Cons of de4dot
- Limited to deobfuscation tasks, not a full-featured decompiler
- Less user-friendly interface, primarily command-line based
- Requires more technical knowledge to use effectively
Code Comparison
de4dot:
var deobfuscator = new DeobfuscatorInfo();
var options = new DeobfuscatorOptions();
var assemblyResult = deobfuscator.Deobfuscate(assemblyPath, options);
ILSpy:
var decompiler = new CSharpDecompiler(assemblyPath, new DecompilerSettings());
var syntaxTree = decompiler.DecompileWholeModuleAsSingleFile();
Summary
de4dot is a specialized tool for deobfuscating .NET assemblies, offering advanced techniques for removing various obfuscation methods. It excels in cleaning protected code but has a steeper learning curve and limited functionality beyond deobfuscation.
ILSpy, on the other hand, is a more comprehensive .NET decompiler with a user-friendly interface. It provides a broader range of features for analyzing and exploring .NET assemblies but may not be as effective in handling heavily obfuscated code compared to de4dot.
Choose de4dot for focused deobfuscation tasks, especially with complex protections. Opt for ILSpy for general-purpose .NET assembly analysis and decompilation in a more accessible environment.
Reads and writes .NET assemblies and modules
Pros of dnlib
- Lightweight and focused library for reading, writing, and analyzing .NET assemblies
- Faster performance for specific tasks like reading and writing assemblies
- More flexible and customizable for low-level operations
Cons of dnlib
- Less user-friendly for beginners compared to ILSpy's GUI
- Narrower scope, focusing primarily on assembly manipulation rather than decompilation
- Requires more manual coding for complex operations
Code Comparison
ILSpy (decompiling a method):
var decompiler = new CSharpDecompiler(assemblyFileName, new DecompilerSettings());
var method = decompiler.DecompileType(new FullTypeName("Namespace.ClassName")).Methods.First();
Console.WriteLine(method.Body);
dnlib (reading a method):
using dnlib.DotNet;
var module = ModuleDefMD.Load(assemblyFileName);
var type = module.Find("Namespace.ClassName", false);
var method = type.FindMethod("MethodName");
Console.WriteLine(method.Body);
Both libraries serve different purposes: ILSpy is a full-featured decompiler with a GUI, while dnlib is a lower-level library for assembly manipulation. The choice depends on the specific requirements of your project.
NLog - Advanced and Structured Logging for Various .NET Platforms
Pros of NLog
- More focused on logging functionality, providing a wide range of logging targets and configurations
- Extensive documentation and community support for logging-specific use cases
- Highly customizable and flexible logging architecture
Cons of NLog
- Limited to logging functionality, unlike ILSpy's broader .NET analysis capabilities
- May have a steeper learning curve for complex logging scenarios
- Less suitable for reverse engineering or code analysis tasks
Code Comparison
NLog (logging configuration):
<nlog>
<targets>
<target name="file" type="File" fileName="log.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
</rules>
</nlog>
ILSpy (decompiled C# code):
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
While NLog focuses on configuring logging targets and rules, ILSpy is designed to decompile and analyze .NET assemblies. The code examples highlight their different purposes: NLog for logging configuration and ILSpy for code analysis and decompilation.
Cecil is a library to inspect, modify and create .NET programs and libraries.
Pros of Cecil
- More focused library for reading, writing, and manipulating .NET assemblies
- Lighter weight and potentially faster for specific assembly manipulation tasks
- Better suited for integration into other tools and libraries
Cons of Cecil
- Lacks a built-in GUI for easy visual inspection of assemblies
- More limited in scope compared to ILSpy's full decompilation capabilities
- Requires more manual coding to achieve complex decompilation tasks
Code Comparison
Cecil (reading an assembly):
using Mono.Cecil;
AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly("path/to/assembly.dll");
foreach (TypeDefinition type in assembly.MainModule.Types)
{
Console.WriteLine(type.FullName);
}
ILSpy (programmatic decompilation):
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;
var decompiler = new CSharpDecompiler("path/to/assembly.dll", new DecompilerSettings());
var syntaxTree = decompiler.DecompileWholeModuleAsSingleFile();
Console.WriteLine(syntaxTree.ToString());
Cecil is more focused on low-level assembly manipulation, while ILSpy provides a higher-level decompilation API. Cecil is better suited for tasks like modifying assemblies, while ILSpy excels at producing readable C# code from compiled assemblies.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ILSpy
ILSpy is the open-source .NET assembly browser and decompiler.
Download: latest release | latest CI build (master) | Microsoft Store (RTM versions only)
Decompiler Frontends
Aside from the WPF UI ILSpy (downloadable via Releases, see also plugins), the following other frontends are available:
- Visual Studio 2022 ships with decompilation support for F12 enabled by default (using our engine v8.1).
- In Visual Studio 2019, you have to manually enable F12 support. Go to Tools / Options / Text Editor / C# / Advanced and check "Enable navigation to decompiled source"
- C# for Visual Studio Code ships with decompilation support as well. To enable, activate the setting "Enable Decompilation Support".
- Our Visual Studio 2022 extension marketplace
- Our Visual Studio 2017/2019 extension marketplace
- Our Visual Studio Code Extension repository | marketplace
- Our Linux/Mac/Windows ILSpy UI based on Avalonia - check out https://github.com/icsharpcode/AvaloniaILSpy
- Our ICSharpCode.Decompiler NuGet for your own projects
- Our dotnet tool for Linux/Mac/Windows - check out ILSpyCmd in this repository
- Our Linux/Mac/Windows PowerShell cmdlets in this repository
Features
- Decompilation to C# (check out the language support status)
- Whole-project decompilation
- Search for types/methods/properties (learn about the options)
- Hyperlink-based type/method/property navigation
- Base/Derived types navigation, history
- Assembly metadata explorer (feature walkthrough)
- BAML to XAML decompiler
- ReadyToRun binary support for .NET Core (see the tutorial)
- Extensible via plugins
- Additional features in DEBUG builds (for the devs)
License
ILSpy is distributed under the MIT License. Please see the About doc for details, as well as third party notices for included open-source libraries.
How to build
Windows:
- Make sure Windows PowerShell (at least version) 5.0 or PowerShell 7+ is installed.
- Clone the ILSpy repository using git.
- Execute
git submodule update --init --recursive
to download the ILSpy-Tests submodule (used by some test cases). - Install Visual Studio (documented version: 17.8). You can install the necessary components in one of 3 ways:
- Follow Microsoft's instructions for importing a configuration, and import the .vsconfig file located at the root of the solution.
- Alternatively, you can open the ILSpy solution (ILSpy.sln) and Visual Studio will prompt you to install the missing components.
- Finally, you can manually install the necessary components via the Visual Studio Installer. The workloads/components are as follows:
- Workload ".NET Desktop Development". This workload includes the .NET Framework 4.8 SDK and the .NET Framework 4.7.2 targeting pack, as well as the .NET 8.0 SDK (ILSpy.csproj targets .NET 8.0, but we have net472 projects too). Note: The optional components of this workload are not required for ILSpy
- Workload "Visual Studio extension development" (ILSpy.sln contains a VS extension project) Note: The optional components of this workload are not required for ILSpy
- Individual Component "MSVC v143 - VS 2022 C++ x64/x86 build tools" (or similar)
- The VC++ toolset is optional; if present it is used for
editbin.exe
to modify the stack size used by ILSpy.exe from 1MB to 16MB, because the decompiler makes heavy use of recursion, where small stack sizes lead to problems in very complex methods.
- The VC++ toolset is optional; if present it is used for
- Open ILSpy.sln in Visual Studio.
- NuGet package restore will automatically download further dependencies
- Run project "ILSpy" for the ILSpy UI
- Use the Visual Studio "Test Explorer" to see/run the tests
- If you are only interested in a specific subset of ILSpy, you can also use
- ILSpy.Wpf.slnf: for the ILSpy WPF frontend
- ILSpy.XPlat.slnf: for the cross-platform CLI or PowerShell cmdlets
- ILSpy.AddIn.slnf: for the Visual Studio plugin
Note: Visual Studio includes a version of the .NET SDK that is managed by the Visual Studio installer - once you update, it may get upgraded too. Please note that ILSpy is only compatible with the .NET 8.0 SDK and Visual Studio will refuse to load some projects in the solution (and unit tests will fail). If this problem occurs, please manually install the .NET 8.0 SDK from here.
Unix / Mac:
- Make sure .NET 8.0 SDK is installed.
- Make sure PowerShell is installed (formerly known as PowerShell Core)
- Clone the repository using git.
- Execute
git submodule update --init --recursive
to download the ILSpy-Tests submodule (used by some test cases). - Use
dotnet build ILSpy.XPlat.slnf
to build the non-Windows flavors of ILSpy (.NET Core Global Tool and PowerShell Core).
How to contribute
- Report bugs
- If you want to contribute a pull request, please add https://github.com/icsharpcode/ILSpy/blob/master/BuildTools/pre-commit to your
.git/hooks
to prevent checking in code with wrong formatting. We use tabs and not spaces. The build server runs the same script, so any pull requests using wrong formatting will fail.
Current and past contributors.
Privacy Policy for ILSpy
ILSpy does not collect any personally identifiable information, nor does it send user files to 3rd party services. ILSpy does not use any APM (Application Performance Management) service to collect telemetry or metrics.
Top Related Projects
.NET debugger and assembly editor
.NET deobfuscator and unpacker.
Reads and writes .NET assemblies and modules
NLog - Advanced and Structured Logging for Various .NET Platforms
Cecil is a library to inspect, modify and create .NET programs and libraries.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot