Many developers are still not aware that Portable Executable (PE) files can be decompiled to readable source code. Before learning how to prevent or make it hard for the decompilers to reverse engineer the source code, we need to understand a few basics concepts.
What is a Portable Executable File?
When source code is complied, it generates a Portable Executable (PE) file. Portable Executable (PE) is either a DLL or an EXE. PE file contains MSIL (Microsoft Intermediate Language) and Metadata. MSIL is ultimately converted by CLR into the native code which a processor can understand. Metadata contains assemble information like Assembly Name, Version, Culture and Public Key.
How Can We Get Source Code from DLL or EXE?
Yes, we can get the source code from DLL or EXE. To demonstrate this, let's create a simple application first.
Open Visual Studio, create a new project and select console based application.
Add some sample code into the Program.cs:
internal class Program
private static void Main(string args)
public static string PublicMethod()
return "Public Method";
private static string PrivateMethod()
return "Private Method";
Now build the application, an EXE will be generated in the bin/debug folder:
Now let's try to get the source code from the EXE file. For the first, open Visual Studio command prompt.
ildasm and hit enter. IL DASM is MSIL Disassembler. It basically has an ability to read Intermediate Language.
IL DASM will open, now open the EXE file we created.
As we can see, IL DASM disassembles the EXE and lots of useful information can be retrieved, though it does not provide the original source code completely, a lot can be interpreted. The easy way to reverse engineer and get the exact source code there are decompilers available in the market for free such as Telerik JustDecompile and Jet Brains dotPeek through which we can convert the Intermediate Language into the original source code.
As we can see in the above screenshot when we open the EXE with Telerik JustDecompile, we are able to see the original source code, this can lead to piracy and ultimately you can lose your profits.
How to Prevent EXE and DLL from Getting Decompiled?
The process of protecting the EXE and DLL from getting decompiled into the original source code is called Obfuscation. There are a lot of paid and free software available to Obfuscate the .NET assemblies, Dotfucator from PreEmptive Solutions is one of the popular ones and their community edition is free and included with Visual Studio. If you are interested in buying other version, check out this comparison. The Dofuscator community edition has limited features and the professional edition is very expensive. So instead of gaining profits by protecting them from reverse engineering, we will end up spending a lot on Obfuscation.
One of the best alternate utility for obfuscating is ConfuserEx - it is a completely free and opensource. You can ConfuserEx download from here.
After downloading, extract the zip into a folder and then run ConfuserEx.exe.
Drag and drop the EXE you want to protect on the ConfuserEx or you can manually select Base Directory, Output Directory and add the DDL or EXE.
Once you have done setting up the directories and adding DLL or EXE, go to the Settings tab in
ConfuserEx. You can either add rules to Gobal settings or set individually for each DLL or EXE.
Click on “+” button, you will see “true” under Rules. Now click on edit rule (button below “-”).
On clicking edit rule, a new window will appear as shown below. Click on “
You can select different ways of adding levels of protection. If you want to learn Obfuscation in depth, check out this article.
Select only with “Anti IL Dasm” and “Anti Tamper”, that is enough for making it hard enough to reverse engineer for the decompilers.
After you click on Done, go to Protect tab and click on Protect button.
You can find the protected DLL or EXE in the output directory selected.
Test the EXE or DLL generated by
ConfusedEx and check if it is working as usual. Now try to decompile it with a decompiler.
As we can see, the confused DLL or EXE which gets generated by
ConfuserEx cannot be decompiled any more.