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
- Open dotPeek
- File -> Open -> navigate to your project -> select your .DLL/.exe file
- Your project will be listed in the projects on our dotPeek under
Assembly Explorer
- Click your project and find the classes to view the source code
My file is called MyCalculator.dll
and below is the source code
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
- Open your application in Visual Studio
- Right Click Project -> Manage Nuget Packages
- Under Browse Section -> Search for ArmDot
- Install
ArmDot.Client
andArmDot.Engine.MSBuildTasks
- 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
}
}
- 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>
If you open and check your .exe/.DLL file using dotPeek you will notice that your source code is now obfuscated.
Obfuscating With Eazfuscator.NET
- Open your application in Visual Studio
- Change your project from
debug
mode toRelease
mode - Open Eazfuscator.NET then drag and drop your project from solution explorer to protect it
- 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)