DEV Community

Cover image for How to view .Net application source code and hiding it [Updated]
Tawanda Nyahuye
Tawanda Nyahuye

Posted on • Edited on

How to view .Net application source code and hiding it [Updated]

Have you ever liked an application to the point that you want to view its source code? Well, I have been there. For .Net executable files and libraries such as DLL files, viewing the source code is a piece of cake as long as the code is not obfuscated by the developer. In this article, we are going to view the source code of a .Net DLL file as well as obfuscating it.

The process of viewing the source code of an executable file is the same.

To create a DLL you can check this article of mine

Viewing source code using JetBrains dotPeek

JetBrains dotPeek decompiles an executable file or DLL/.exe file written using .Net to their equivalent C# code.

Installing dotPeek

  • Download JetBrains dotPeek from JetBrains
  • Run the setup and install the free .Net decompiler and assembly tools.

Decompiling the code

  1. Open dotPeek
  2. File -> Open -> navigate to your project -> select your .DLL/.exe file
  3. Your project will be listed in the projects on our dotPeek under Assembly Explorer
  4. Click your project and find the classes to view the source code

My file is called MyCalculator.dll and below is the source code
Alt Text

Obfuscating the source code

For more obfuscating tools both open source and paid versions check this NuGet obfuscator article

In this article, I'm using two .Net Obfuscation tools ArmDot and Eazfuscator. ArmDot works on both Windows and Linux. You can check a full article where I cover using Armdot in full detail.

To demonstrate the tools, I will be using a simple C# calculator DLL I wrote some time ago.

NB: ArmDot and Eazfuscator.NET are not free software but both have free trials.

Obfuscating With ArmDot

  1. Open your application in Visual Studio
  2. Right Click Project -> Manage Nuget Packages
  3. Under Browse Section -> Search for ArmDot
  4. Install ArmDot.Client and ArmDot.Engine.MSBuildTasks Install ArmDot Nuget packages
  5. Add ArmDot Metadata Annotation to your classes that you want to obfuscate
using System;

namespace MyCalculator
{
    [ArmDot.Client.VirtualizeCode] //ArmDot Annotation
    public class Calculator
    {
      //class code goes here
    }
}

Enter fullscreen mode Exit fullscreen mode
  1. Add the MSBuildTask to your project file .csproj
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
    <ItemGroup>
        <Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
    </ItemGroup>
    <ArmDot.Engine.MSBuildTasks.ObfuscateTask
        Inputs="@(Assemblies)"
        ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
        SkipAlreadyObfuscatedAssemblies="true"/>
</Target>
Enter fullscreen mode Exit fullscreen mode

If you open and check your .exe/.DLL file using dotPeek you will notice that your source code is now obfuscated.

ArmDot Obfuscated code

Obfuscating With Eazfuscator.NET

  1. Open your application in Visual Studio
  2. Change your project from debug mode to Release mode Alt Text
  3. Open Eazfuscator.NET then drag and drop your project from solution explorer to protect it Alt Text
  4. Rebuild your project and click reload all

If you open and check your .exe/.DLL file using dotPeek you will notice that your source code is now obfuscated.

Disclaimer: I am not affiliated with Softanics (ArmDot) or Gapotchenko (Eazfuscator.NET). This article is for educational purposes.

Top comments (0)