How to use Dotfuscator in Visual Studio

By FoxLearn 9/18/2024 1:42:15 AM   13.16K
Dotfuscator is a tool for .NET applications that provides obfuscation to protect your code from reverse engineering and tampering, it helps protect your .net application.

How to use Dotfuscator in Visual Studio

Obfuscation is a technique that provides the ability to seamlessly rename the symbols in assemblies as well as other tricks to foil decompilers. Through this post you will learn how to use Dotfuscator in Visual Studio 2017, 2019, 2022

After completing the Dotfuscator installation, open your Visual Studio and select Tools =>PreEmptive Protection - Dotfuscator

dotfuscator visual studio

Clicking Ok button.

dotfuscator community edition registration

Entering your information, then click Submit button.

dotfuscator download

Clicking Download Now button.

dotfuscator registration

Enter your confirmation code. You can find it in the email when completing registration.

I'll create a new Console Application project, then make a simple c# example as shown below.

// dotfuscator visual studio
class Program
{
    static void Main(string[] args)
    {
        // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
        int limit = 77;
        string connectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        for (int i = 1; i <= limit; i++)
        {
            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                if (cn.State == System.Data.ConnectionState.Closed)
                    cn.Open();
                using (SqlCommand cmd = new SqlCommand($"select ProductName from Products where ProductID={i}", cn))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                            Console.WriteLine(string.Format("{0}: {1}\n", i, reader.GetString(0)));
                    }
                }
            }
        }
        Console.ReadKey();
    }
}

Opening your App.config file, then add a connection string as shown below.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <connectionStrings>
    <add name="cn" connectionString="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123@qaz;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

You should modify your connection string based on your sql account and database. I'm using Northwind database to play demo.

The c# code above allows you to connect to sql server, then retrieve products data from the products table in your Northwind database.

To release your application, you should change from Debug to Release mode, then rebuild your project.

Opening your Visual Studio and select Tools =>PreEmptive Protection - Dotfuscator

preemptive dotfuscator ce

Selecting Input item, then click Add button => Select your executable in the release directory => Click Build button.

c# dotfuscator

After completing the build, you will see detailed information below the screen

You will find the file ofuscator in the Dotfuscated folder located in the Release folder.

c# ofuscator

If you use the dnspy ​​tool to view the executable file, you might find that your file is decompiled.

dnspy

DNSpy is a popular open-source .NET assembly browser and decompiler. It's a powerful tool for .NET developers and security researchers, providing capabilities for reverse engineering, debugging, and analyzing .NET applications.

Here are some of its key features:

  1. Decompilation: DNSpy can decompile .NET assemblies into C# or Visual Basic code, allowing users to analyze and understand the logic of compiled .NET applications.

  2. Assembly Editing: It provides the ability to modify .NET assemblies directly within the tool, including editing IL code, renaming classes/methods/fields, and more.

  3. Debugging Support: DNSpy allows users to debug .NET assemblies by attaching to running processes or opening them directly. It provides features such as breakpoints, stepping through code, inspecting variables, etc.

  4. Assembly Analysis: DNSpy provides various analysis tools to inspect .NET assemblies, including metadata, resources, types, methods, and more.

  5. Plugin System: DNSpy supports a plugin system, allowing users to extend its functionality with custom plugins.

  6. Cross-Platform: DNSpy is cross-platform and can run on Windows, macOS, and Linux operating systems.

  7. Integration: It integrates with other tools commonly used in the .NET development ecosystem, such as Visual Studio and .NET Reflector.