0

members

Easy CBASIC Lesson 10 Decompiling code

of Acoptex.com in Csharp

CBASIC Learning C# basics

Tags: C#, Csharp, C# fundamentals, C# basics, JustCompile, .NET Reflector, ILSpy, dotPeek, CodeReflect, Refractor .NET, Dis #Net decompiler, Dotnet IL Editor, DILE

These lessons are designed to keep you engaged with the process of learning C# basics. Our main focus will be on learning C# basics. 

Lesson 10 C# Decompiling code

In this lesson we will show you how to decompile a code.

As a part of learning process sometimes programmers need to see the code of a module or program, which has not been written by them and with no source code available. The process, which generates source code from an existing executable binary file (.exe or .dll) is called decompiling. You may need to decompile code in the following cases:

  • check how a given algorithm is implemented and when no source code available;
  • want to see how to use certain API;
  • when no information how library works but you have the compiled code, which uses it;
  • you have lost our source code and you want to recover it. Code recovery through decompilation will result in lost variable names, comments, formatting, and others but you will get the source code.

Decompiling is done with the help of tools, which are not standard part of Visual Studio.

When you are wondering how a certain method works or how something is implemented in a given assembly, you can always rely on the decompiler to find out.

Let's check each of them.

The most popular .NET decompilers are:

  1. .NET Reflector (v6 free, commercial from v7);
  2. JustDecompile (free);
  3. ILSpy, git link here (free);
  4. dotPeek (free); 
  5. CodeReflect (free);
  6. Refractor .NET (free);
  7. Dis #net decompiler (commercial);
  8. DILE (free).

1. .NET Reflector

.NET Reflector is a class browser, decompiler and static analyzer for software created with .NET Framework.

On 1 February 2011 Red Gate announced that .NET Reflector would become a commercial product as of version 7, which was released on 14 March 2011. On 26 April 2011, due to community feedback Red Gate announced that they would continue to make .NET Reflector 6 available for free to existing users (while new users will have to pay for Reflector).

Features:

  • Decompile, browse, and analyze any .NET assembly to C#, VB.NET, or IL.
  • Use the standalone application to explore and navigate decompiled code.
  • Get results as you type and find what you're looking for easily.
  • Use your regular debugging techniques on any decompiled assemblies as if they were your own, using the Visual Studio debugger.
  • Generate .pdb files for decompiled assemblies and save them so you only need to enable debugging once for each assembly.
  • Assemblies decompile seamlessly in Visual Studio so source code is always available for your libraries.
  • Use F12 to “Go To Definition”, F9 to “Set Breakpoints”, and F11 to “Step Into” any decompiled code.
  • .NET Reflector supports C#7, .NET 4.7.2, and .NET Core and Standard.
  • .NET Reflector VSPro adds the Reflector Object Browser into Visual Studio. Use the tree view to navigate through code.

Installing the .NET Reflector

  1. Go to red-gate.com website and download the latest .NET Reflector version (14-day, fully functional free trial)
  2. When donload competed you will see file in Download folder.
    Click on this file with right mouse button and select Run as Administrator to start installation process.
    When donload competed you will see file ReflectorInstaller.exe in Download folder.
  3. Click on this file with right mouse button and select Run as Administrator to start installation process.
  4. Click on Continue button.
  5. Click on Accept button.
  6. Click on Install button. The installation process starts.
  7. Click on Finish button when instllation completed.

Using the .NET Reflector

 

  1. Go to Start and click on .Net reflector 10.1
  2. The program starts.
  3. Go to File->Open Assembly...
  4. Select the file to decompile and click on Open button.

2. JustDecompile

JustDecompile is the open-source .NET assembly browser and decompiler. 

Features:

  1. Fast decompiler;
  2. Open API for everyone to create extensions;
  3. Supports .NET 2.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, WinRT Metadata, C#5, APPX and WinMD;
  4. The code is easily searchable;
  5. Creates a Visual Studio project from a decompiled assembly;
  6. Integrates with JustCode and JustTrace.
  7. Switch easily between different methods and assemblies in one instance.
  8. Decompile referenced assemblies in a Visual Studio project. Supported Visual Studio versions: 2010, 2012, 2013, 2015 and 2017.
  9. Save resources from assemblies.
  10. Bookmark usages in loaded assemblies.
  11. Export code directly from the command prompt.
  12. Decompile an assembly after browsing to it in Windows Explorer.

Installing the JustDecompile

  1. Go to telerik.com website and download the latest version of JustDecompile.
  2. When donload competed you will see file in Download folder.
  3. Click on this file with right mouse button and select Run as Administrator to start installation process.
  4. Select product JustCompile and click on Next button.
  5. Select installation folder, tick on create shortcut and yes, I accept. Make sure that Visual studio integration->JustCompile->VisualStudio2017Support selected.
  6. Click on Next button.
  7. Create account, enter required details.
  8. Click on Install button.
  9. Click on Agree button. Installation process will start. You need an active internet connection as the setup will download additionally some data.
  10. After installation you will see this window.
  11. Close it. Installation completed successfully. You will see the JustCompile program shortcut on you Desktop.

Using the JustDecompile

After downloading and installing JustDecompile, you just need to point to your .exe (or perhaps your .dll), and if it was written using .Net (and isn't obfuscated), you should be able to see some details from the binary and browse the IL code.

  1. Double click on JustCompile shortcut on Desktop. The program will open.
  2. Select Open..->File(s)... Find the file and click on Open button.
  3. From here, you simply need to start exploring the binary, and the tools will decompile the IL code in the binaries back to your .Net language of choice (most tools support at least C# and Visual Basic.Net). The Telerik tool also has a 'search' tool where you can search for types, or do free text searches.

3. ILSpy

ILSpy is the open-source .NET assembly browser and decompiler. 

Features:

  1. Assembly browsing
  2. IL Disassembly
  3. Support C# 5.0 "async"
  4. Decompilation to C#
  5. Supports lambdas and 'yield return'
  6. Shows XML documentation
  7. Decompilation to VB
  8. Saving of resources
  9. Save decompiled assembly as .csproj
  10. Search for types/methods/properties (substring)
  11. Hyperlink-based type/method/property navigation
  12. Base/Derived types navigation
  13. Navigation history
  14. BAML to XAML decompiler
  15. Save Assembly as C# Project
  16. Find usage of field/method
  17. Extensible via plugins (MEF)
  18. Assembly Lists

Installing the ILSpy

1. You need to have Microsoft Visual Studio Community 2017 or 2019 installed with the following components: 

  • Workload ".NET Desktop Development";
  •  
  • .NET Framework 4.6.2 Targeting Pack (if the VS installer does not offer this option, install the .NET 4.6.2 developer pack separately); 
  • Individual Component "VC++ 2017 version 15.9 v14.16 latest v141 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.

 

2. Install the .NET Core SDK 2.2

3. Download Git for Windows and install. After installation start the Git GUI.

4. Click on Clone Existing Repository. Enter source location - https://github.com/icsharpcode/ILSpy , target directory - select any with browse. Do not create the folder, for example we have the path to the folder ILSpy , which will be on desktop. Click on Clone button. The repository will be cloned to the folder ILSpy.

Using the ILSpy

1. Open ILSpy.sln in Microsoft Visual Studio Community 2017 or 2019.

2. NuGet package restore will automatically download further dependencies.

3. Run project ILSpy for the ILSpy UI. Go to File->Open...

4. Select the file to decompile and click on Open button.

4. dotPeek

dotPeek is a free-of-charge standalone tool based on ReSharper's bundled decompiler. dotPeek can decompile any .NET assemblies into equivalent C# code and optionally show the underlying IL code. The decompiler supports multiple formats including libraries (.dll), executables (.exe), and Windows metadata files (.winmd).

As dotPeek is based on ReSharper's powerful code insight architecture, it lets you navigate decompiled assemblies in a contextual or context-insensitive ways, get a quick summary what's inside each decompiled file, set bookmarks and explore inheritance chains.

dotPeek provides tools to quickly grasp the structure of any given assembly, understand relationships between assemblies, as well as organize assemblies into discrete lists, which helps only focus on assemblies that you're interested for your current assignment.

Features:

  • Libraries, executables and more
  • View source code if available
  • Show or hide compiler-generated code
  • Explore running processes
  • View IL code in a separate view
  • View IL code as comments to decompiled C#
  • Use your preferred color theme
  • Find usages of any symbol
  • Highlight usages in code viewer
  • Explore current document
  • Jump to any code
  • Set bookmarks
  • Navigate contextually
  • Navigate class hierarchies
  • Explore inheritance chains
  • Manage assembly lists
  • Explore assembly contents
  • Explore assembly metadata
  • View dependencies between assemblies

Installing the dotPeek

  1. Go to jetbrains.com website and download the latest dotPeek version.
  2. When donload competed you will see file in Download folder.
    Click on this file with right mouse button and select Run as Administrator to start installation process.
    When donload competed you will see file JetBrains.dotPeek.2018.3.4.web.exe in Download folder.
  3. Click on this file with right mouse button and select Run as Administrator to start installation process.
  4. Make sure that I have read and I accept the license agreement tick box selected. Click on Next button.
  5. Click on Install button. The installation process starts.
  6. Click on Exit button when installation completed.

Using the dotPeek

  1. After the downloading open the JetBrains dotPeek. Go to Start and select JetBrains dotPeek 2018.3.4.
  2. Tick on I accept the terms... and click on OK button.
  3. Click on I accept button.
  4. Click on OK button.
  5. Click on OK button.
  6. The program will start. Go to File->Open...
  7. Select the file to decompile and click on Open.


5. CodeReflect

CodeReflect is a standalone decompiler for .NET and allows you to decompile compiled assemblies back to their original source code or as close to it as possible. .NET CodeReflect decompiles any .NET assembly to C#, VB.NET or MSIL

CodeReflect is designed to decompile .NET assemblies for the purpose of performance analysis, bug investigation, code familiarisation, validating obfuscation and debugging released code. It is not intended for reverse engineering copyrighted/obfuscated assemblies. 

CodeReflect is provided for FREE, and will always remain free as a gift back to the software development community.

Features:

  • Assembly class browsing
  • Decompile .NET code
  • MSIL disassembly view
  • Decompile C# code
  • Decompile VB.NET code
  • Extract embedded resources
  • Hyperlink based navigation
  • Assembly dependency list
  • .NET framework 1.0, 1.1, 2.0, 3.5 & 4.0 support
  • Decompile any .NET assembly that supports reflection
  • Commercially maintained

Installing the CodeReflect

  1. Go to devextras.com website and download the latest CodeReflect version.
  2. When donload competed you will see file in Download folder.
    Click on this file with right mouse button and select Run as Administrator to start installation process.
    When donload competed you will see file DevExtras.CodeReflect.1.08.zip in Download folder.
  3. You will need to unzip (you can use the free program 7Zip) files to folder (we made Code Reflect folder).

Using the Code Reflect

  1. Double click on CodeReflect.exe. The program opens. Select the file to decompile and click on Open button.

 

6. Refractor .NET

Refractor .NET assembly browser is free developer productivity tool designed to enable easy .NET assembly browsing and decompiling. The interface builds on years of experience in code analysis and development productiveness specially created for Skater .NET obfuscator, Rustemsoft's .NET code protection software. The .NET assembly browser and decompiler lets you explore and analyze without exertion compiled .NET assemblies, decompiling code with the simple click of a button.

.NET assembly browser and decompiler interface is a great tool for doing an in-depth examination of various types of assemblies and also for disassembling IL code towards a supported .NET languages C# and/or VB.

The free decompiler can be used to inspect, navigate, search, analyze, and browse the contents of a .NET component such as an assembly and translates the binary information to a human-readable form. By default .NET assembly browser and disassembler allows decompilation of .NET assemblies into C#, Visual Basic .NET, and Common Intermediate Language (IL). It can be used to effectively convert source code between C# and VB. It can also be used to find assembly dependencies, and even windows DLL dependencies.

To run free Refractor .NET assembly browser and decompiler .NET framework 4.x has to be installed.

Features:

  • Assembly browsing
  • Decompilation to IL
  • C# Disassembly
  • Visual Basic Disassembly
  • Shows XML contents
  • Shows XAML (BAML) scripts

Installing the Refractor .NET

  1. Go to skaterpro.net website and download the latest Refractor .NET version.
  2. When donload competed you will see file in Download folder.
    Click on this file with right mouse button and select Run as Administrator to start installation process.
    When donload competed you will see file Refractor.exe in Download folder.
  3. Click on this file with right mouse button and select Run as Administrator to start installation process.
  4. Click on Next button.
  5. Click on I Agree button.
  6. Click on Install button.
  7. Click on Finish button when installation completed.

Using the the Refractor .NET

  1. After the installation the program starts.
  2. Go to File->Open to open the file to decompile. Click on Open button.

7. Dis #Net com

Dis# (DisSharp) is a powerful tool to reverse engineer MSIL code into a human readable one. In addition to the support for a choice of programming languages and the latest .NET 2.0 innovations, it offers unique processing of metadata, name import from PDB files and documentation import from XML files, inline code editor and a host of other features. Their synergetic force results in amazingly accurate decompilation. 

Dis# trial is free .NET assembly browser and it allows full functional decompilation of 7 .NET Framework assemblies.  Dis# require .NET Framework 2.0 or higher. 

Dis# costs 399 USD for a single-user license. The company offers flexible pricing for bulk orders. Registered users are entitled to free life-time support and program updates. 

Features:

  • Support for C#, Visual Basic.NET, Delphi.NET and Chrome;
  • Support for .NET 2.0 (assembly formats, generics etc.);
  • Comfortable browsing and editing (inline editor, assembly browser);
  • Customizable code presentation ( full namespaces, decimal or hexadecimal constants, Unicode Chars, Type Detail, Single Statement Brace etc.);
  • Visual Studio compatible projects;
  • Code optimization and deobfuscation;
  • Unique code simplification system (Pseudo Assembler).

Installing the Dis #Net com

  1. Go to netdecompiler.com website and download the latest Dis #Net com version (demo).
  2. When donload competed you will see file in Download folder.
    Click on this file with right mouse button and select Run as Administrator to start installation process.
    When donload competed you will see file DisSharp.zip in Download folder.
  3. You will need to unzip (you can use the free program 7Zip) files to folder (we made Code Reflect folder).
  4. Click on setup.exe file with right mouse button and select Run as Administrator to start installation process.
  5. Click on Next button.
  6. Select I agree and click on Next button.
  7. Click on Next button.
  8. Click on Next button. The installation process starts.
  9. Click on Close button when installation completed.

Using the Dis #Net com

  1. Double click on shortcut on your PC/laptop Desktop.
  2. The program starts. Go to File->Load Assembly... to open the file to compile.
  3. Select the file to decompile and click on Open button.

8. Dotnet IL Editor

Dotnet IL Editor (DILE) allows disassembling and debugging .NET 1.0/1.1/2.0/3.0/3.5/4.0 applications without source code or .pdb files. It can debug even itself or the assemblies of the .NET Framework on IL level.

Installing the Dotnet IL Editor

  1. Go to website and download the latest Dotnet IL Editor version.
  2. When donload competed you will see file in Download folder.
    Click on this file with right mouse button and select Run as Administrator to start installation process.
    When donload competed you will see file dile_v0_2_13_x86.zip in Download folder.
  3. You will need to unzip (you can use the free program 7Zip) files to folder (we made Code Reflect folder).
  4. Double click on dile.exe file. The program starts.

Using the Dotnet IL Editor

  1. Go to File->New Project... type the Name and click on OK button.
  2. Go to Project->Add assembly...
  3. Select the file to decompile and click on Open button.
  4. Go to File->Save project. Type the File name and click on Save button.

 

Summary

Both .NET CodeReflect, ILSpy and JustDecompile can decompile to VB, IL and C# compared to dotPeek that only have support for C#. JustDecompile and ILSspy are the only tool that support to save the decompiled code as a visual studio project with can be very useful in some cases. What i really like with dotPeek is that it use normal Visual Studio shortcuts as for example F12 to got to declaration. A cool feature in JustDecompile is the integration with windows explorer context menu. ILSpy is the only one that can’t extract embedded resources but is on the other hand the only open source tool.

If you are going for simple but powerful decompiler and you can leave with only C# support we would recommend dotPeek. If you want that little extra as saving to Visual Studio project and windows explorer context menu integration, then JustDecompile is the product. The only drawback with JustDecompile is that you need to register to install it. JustDecompile puts labels outside scope of goto statements. If you prefer open source and can leave without possibility to extract embedded resources ILSpy is your tool. We can't really recommend .NET CodeReflect for any reasons when it's compared to the other tools.

Next -> CBASIC Lesson 11



Other projects of Acoptex.com
Easy Basics: Project 105a SIM900A GSM GPRS mini module of Acoptex.com in NANO 28-11-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 11-04-2019
Viewed: 483 times