dotPeek Encoding

Mykhailo Antonishyn
4 min readNov 1, 2022

--

Introduction

Programming does not all go down to writing a few lines of code in order to build the desired application. Nowadays, structures are built with various tools that are either easier to use or provide more flexibility. When it comes to coding, dotPeek from JetBrains aims to provide a user friendly environment for decompiling .NET assemblies to C# code. dotPeek is a free-of-charge standalone tool based on ReSharper’s bundled decompiler. It can reliably decompile any .NET assembly into equivalent C# or IL code. The main advantages of dotPeek are the quality of decompilation, ease of loading and managing .NET assemblies. In addition, dotPeek offers numerous search, navigation and coding features borrowed from ReSharper. As a free application dotPeek has a well-deserved place in the JetBrains product line.

Main features:

  1. decompiling .NET assemblies to C# source code

To display decompiled code, dotPeek uses most of the features familiar to Microsoft Visual Studio users: opening decompiled files in separate tabs, syntax highlighting, folding code blocks, line numbering, and much more.

2. Fast and comfortable loading of .NET assemblies and their conversion to Microsoft Visual Studio projects

dotPeek supports several different assembly file formats: .dll, .exe, .zip, .vsix, .nupkg, and .winmd, allowing you to create collections of assemblies, save them, and switch between them.You will be able to load assemblies directly from Windows Explorer and from the Global Assembly Cache. It also provides browsing and loading related assemblies. If you want to not only examine the assembly, but also make changes to it, dotPeek will allow you to convert and save it to a Microsoft Visual Studio project and thus continue working with the assembly source code.

3. Instant search and navigation

dotPeek borrows many features from ReSharper. These include contextual and context-independent navigation, search for usages, and various ways to view hierarchies and code structures. It provides a extensive set of functionality for navigating and searching loaded and linked assemblies, including .NET Framework assemblies. You only need to press a few keys to search for any assembly, type, or type member. From any symbol in decompiled code, you can instantly jump to base and derived symbols, usages, implementations, and overrides. The Find Usages action helps you find all methods, properties, local variables, and other entities that use the character you are looking for. In the Find Results window, you can group, navigate, and jump to search results in the code view. dotPeek indexes all assemblies in the assembly list and all assemblies they reference, and lets you instantly jump to specific code. For example, the Go to Everything action lets you find the assembly, namespace, type, type member, or recently opened file you want. One of dotPeek’s most convenient navigation features is the transition from the exception stack trace to the code of the methods that called it.

4. Loading the source code and debug third party code

dotPeek can recognize local source code from PDB files and retrieve code from source servers such as the Microsoft Reference Source Center or SymbolSource. Also, dotPeek can act as a symbol server and provide the Visual Studio debugger with the information it needs to debug an assembly. Below is an example of using dotPeek.

The solution consists of one project, written by using the C # language. The project contains the class named Print, which is placed in a separate file. Also, in the Program class, the ShowText() method is written to display some text. Comments have been added to each method.

Class Print code:

The Program class code:

The result of the program execution:

Now let’s see how dotPeek decompiles this assembly.

When uploading the exe file to dotPeek, we get the source code of the project, including comments to the methods. Moreover, the names of variables, classes and methods are exactly the same as the original code.

Also, in the main window of the program, you can get acquainted with the IL code.

To summarize, dotPeek does an excellent job to get the source code and even form a full-fledged Microsoft Visual Studio project, provides the ability to conveniently navigate through the result and recognize local source code based on PDB files.

Author: Yevhenii Nahirniak, Senior C# developer, one.nobilus@gmail.com

--

--

Mykhailo Antonishyn

I work in information and cyber security. I regularly share my experience and knowledge in my blog.