Make your code harder to read
Obfy protects compiled .NET assemblies and C# source. Add a DLL, an EXE or a whole solution, pick a level, and it writes a protected copy with its names scrambled, its strings encrypted and its control flow rewired. The app and the command line leave your originals alone, unless you choose the input’s own folder as the output. The Visual Studio extension replaces the project’s build output.
Try it here
Pick a level or flip a switch, and what Obfy writes changes. Press Obfuscate to run it again: a new run draws new random names, new numbers and a new key.
This is a small copy of Obfy’s source mode, working on one fixed sample in your browser. On a compiled assembly Obfy does this to the code itself, and a decompiler decides how it reads.
The live copy needs JavaScript. Without it, here is one Standard run.
Level
Techniques
Source mode keeps the namespace. On an assembly Obfy renames that too.
XOR here. The app’s default is AES-256.
Here, every method that qualifies. At Aggressive the app picks about four in five.
Obfy has thirteen more techniques. They work on compiled assemblies, so there is nothing to show for them here.
Your code
using System; namespace Shop.Orders { public class OrderService { private decimal limit = 500m; private decimal total; public decimal CalculateTotal(Order order) { if (order == null) throw new ArgumentException("Order not found"); total = order.Price * order.Quantity; if (total > limit) Reject(order); Save(order); return total; } void Reject(Order order) => Console.WriteLine("Over the limit"); void Save(Order order) => Console.WriteLine("Saved " + order.Id); } public record Order(string Id, decimal Price, int Quantity); }
What Obfy writes
Click an encrypted string to read it anyway.
using System; namespace Shop.Orders { public class _O1l { private decimal _ΙIι1 = 500m; private decimal _Ιι0101; public decimal _OIIIO(_I1ιι1Ι _ιIıιO) { if (_ιIıιO == null) throw new ArgumentException(global::Obfy.Runtime.__ObfyStringDecryptor.Decrypt("0DxLNDnlF6zMBDsiQH9IjU2P6KqgGsZsdAzPdk9D")); _Ιι0101 = _ιIıιO._001Iı1 * _ιIıιO._ιl0ι; if (_Ιι0101 > _ΙIι1) _IΙıII0(_ιIıιO); _ιΙı0OO(_ιIıιO); return _Ιι0101; } void _IΙıII0(_I1ιι1Ι _ΙıΙ11) => Console.WriteLine(global::Obfy.Runtime.__ObfyStringDecryptor.Decrypt("0DxPNDjlAKyeBG8iRn9CjRmPpKqvGsRsaAzVdg==")); void _ιΙı0OO(_I1ιι1Ι _ΙIOl) => Console.WriteLine(global::Obfy.Runtime.__ObfyStringDecryptor.Decrypt("zDxYNCvlF6zaBDsi") + _ΙIOl._ΙIıl); } public record _I1ιι1Ι(string _ΙIıl, decimal _001Iı1, int _ιl0ι); } namespace Obfy.Runtime { internal static class __ObfyStringDecryptor { private static readonly byte[] _key = global::System.Convert.FromBase64String("nzw5NF3lcqy+BBsiLn8njTmPyKrGGqlsAQyhditD0Bw="); internal static string Decrypt(string encrypted) { if (string.IsNullOrEmpty(encrypted)) return encrypted; var data = global::System.Convert.FromBase64String(encrypted); var result = new byte[data.Length]; for (int i = 0; i < data.Length; i++) result[i] = (byte)(data[i] ^ _key[i % _key.Length]); var chars = new char[result.Length / 2]; for (int i = 0; i < chars.Length; i++) chars[i] = (char)(result[i * 2] | (result[(i * 2) + 1] << 8)); return new string(chars); } } }
Read with the key from the helper class below it. The key ships in the output, which is why obfuscation is not confidentiality.
Symbol map
Obfy can write this map from each original to its new name, to read stack traces from the protected build. Keep it private.
Nothing was renamed, so there is no map.
{
"NamedType:Shop.Orders.OrderService": "_O\u200D1\uFEFF\uFEFFl",
"Field:Shop.Orders.OrderService.limit": "_\u200C\u200C\u0399I\u03B9\u200C\u20601",
"Field:Shop.Orders.OrderService.total": "_\u0399\u03B9\uFEFF0101",
"Method:Shop.Orders.OrderService.CalculateTotal(Shop.Orders.Order)": "_O\u200CI\u200C\u200BIIO\u200D\u2060",
"Parameter:Shop.Orders.OrderService.CalculateTotal(Shop.Orders.Order).order": "_\u200B\u03B9I\u0131\u2060\u03B9O",
"Method:Shop.Orders.OrderService.Reject(Shop.Orders.Order)": "_I\u0399\u0131\u200CI\u200BI0",
"Parameter:Shop.Orders.OrderService.Reject(Shop.Orders.Order).order": "_\u200B\u0399\u0131\u03991\uFEFF\u200D1",
"Method:Shop.Orders.OrderService.Save(Shop.Orders.Order)": "_\u03B9\u0399\u01310OO\u200D\u200D\u200D\u200B",
"Parameter:Shop.Orders.OrderService.Save(Shop.Orders.Order).order": "_\u0399IO\uFEFFl\u2060\u200C\u200D",
"NamedType:Shop.Orders.Order": "_I1\u03B9\u03B91\u200C\u0399",
"Parameter:Shop.Orders.Order.Order(string, decimal, int).Id": "_\u0399I\u0131\uFEFFl",
"Property:Shop.Orders.Order.Id": "_\u0399I\u0131\uFEFFl",
"Parameter:Shop.Orders.Order.Order(string, decimal, int).Price": "_00\uFEFF\u200C1\u2060I\u01311",
"Property:Shop.Orders.Order.Price": "_00\uFEFF\u200C1\u2060I\u01311",
"Parameter:Shop.Orders.Order.Order(string, decimal, int).Quantity": "_\u03B9\uFEFF\uFEFFl0\u03B9",
"Property:Shop.Orders.Order.Quantity": "_\u03B9\uFEFF\uFEFFl0\u03B9"
}
Standard · 13 names renamed · 3 strings encrypted
Ctrl+EnterThat was Obfy, more or less. On your own assemblies it works on the compiled code, with thirteen more techniques.
Get it from the Microsoft Store
What it does
Obfy is for developers who ship compiled .NET to machines they do not control: a desktop app, a library, a plugin, a game. It makes decompiled code slower and less pleasant to read. It does not make it unreadable, and the note further down says why.
Assemblies and source
Protects compiled assemblies with dnlib, and C# source files with Roslyn. Source protection covers string encryption, control flow and symbol renaming.
Four levels
Minimal renames symbols and nothing else. Standard, the default, adds string encryption and metadata removal. Aggressive turns most protections on. Custom is yours to set.
Whole solutions
Hand it a solution or a project and it works out the outputs. Assemblies protected together are renamed as one closed set, so what they share keeps one name.
Merge
Fold several assemblies into one before protecting them, and make the merged types internal.
A symbol map
Optionally write a map from the new short names back to the originals, to read stack traces from the protected build. Keep it private.
Reports
An HTML or JSON report with counts, the size before and after, timings and warnings.
One config file
obfy.json holds every setting. obfy config generate writes one, and obfy config wizard asks you through it.
Fits a build
Call obfy from MSBuild or GitHub Actions on the assembly you built. Visual Studio can obfuscate after every build.
Platform profiles
Profiles for NativeAOT, Unity IL2CPP and Blazor WebAssembly switch off the protections that cannot work there and keep your stored settings. MAUI has a recipe that keeps XAML working.
Nothing sent anywhere
No account and no telemetry. Obfy reads and writes the files you pick, and its logs stay on your PC. The code is MIT-licensed, on GitHub. The privacy policy has the details.
The app
The Windows app is one window with a sidebar: Files, Protection, Results and a Guide on F1. Protection holds the level cards and a page for every technique. A bar along the bottom starts the run, and says why it cannot start when it cannot.
Three ways to use it
They all use the same engine and read the same obfy.json. The Visual Studio extension calls the obfy command, so install that too.
The desktop app
For Windows. Drop in files, a solution or a project and press Obfuscate, or Ctrl+Enter. It needs the WebView2 runtime.
The command line
obfy is a .NET tool. Its tests run on Windows and on Linux in CI, so it works on a build server too. macOS is untested. The Store app installs it as well.
Visual Studio 2022
Right-click a project and choose Obfuscate, or turn on obfuscation after every build. Settings are kept per project. You build the extension from the repository and install the VSIX. It is not on the Visual Studio Marketplace, and no release carries it.
On the command line
obfy MyApp.dll -o output/ obfy MyApp.sln -o out/ obfy MyApp.dll -l aggressive -o output/ obfy MyApp.dll -c obfy.json -o output/ --report report.html obfy App.dll Lib.dll --merge -o output/ obfy config wizard -o obfy.json
What it does to your code
Each technique is a switch of its own, and the level you pick chooses a set of them. They run in a fixed order.
Names and structure
- Symbol renaming. Types, methods, fields, properties, events, namespaces and parameters get meaningless names. A library’s public API can be left alone.
- Control flow. Basic blocks go behind a state-machine dispatcher, opaque predicates, or both.
- Reference proxy. Calls to code in the same module go through proxy methods.
- Virtualization. Eligible methods run on a bytecode interpreter. Off at every level, and some methods are skipped.
What is stored
- String encryption. String literals are encrypted, with XOR or AES-256.
- Constant encryption. The same for int, long, float and double constants.
- Resource encryption. Embedded resources are encrypted and decrypted as they are read.
- Method encryption. Method bodies are encrypted in the file, each with its own key. Windows only.
At run time
- Anti-debug. Detects an attached debugger. Its Windows-specific checks do nothing on other systems.
- Anti-dump. Wipes the PE headers in memory and patches the dump call in its own process. Windows only. A dumper outside the process is unaffected.
- Anti-tamper. Checks the assembly’s integrity when it loads.
- Anti-decompiler. Junk types and methods, and optional decoy attributes, clutter what a decompiler shows.
Around the assembly
- Metadata removal. Strips debug information and custom attributes.
- Watermark. Embeds a customer or build id as an attribute. Opt-in.
- Dependency embedding. Packs the DLLs next to yours into it as resources. Opt-in.
- Native packing. Replaces the managed file with a native win-x64 host, and keeps your code as ciphertext in an overlay. Opt-in, and set in the config file.
Aggressive turns on most of these, with control flow at intensity 80, and method encryption on Windows. Virtualization, packing, watermark and dependency embedding are opt-in: no level turns them on. Method encryption, anti-dump and native packing work only in a program that runs on Windows.
Solutions and closed sets
The desktop app takes a .sln or .slnx file, or a .csproj, .vbproj or .fsproj project, and expands it into the outputs it builds. A row it skips says why. The command line takes a solution too.
When two or more assemblies are included, they are protected as a closed set: renamed together, so a type that two of them share keeps one name in both. Merge folds them into a single assembly instead. In the app, an empty output folder writes one file as name.obfuscated.dll next to the input, and a closed set to an obfy-out folder next to the first.
What obfuscation will not do
Obfuscation raises the cost of reverse engineering. It is not confidentiality. The key for string, constant, resource and method encryption is in the assembly Obfy writes, so anyone who can run it or inspect it can recover what it protects: XOR trivially, AES-256 with a little more effort. Packing hides the managed file on disk, and its key is in the overlay. Virtualization is a deterrent, not a lock.
So do not put real secrets, such as API keys, tokens or credentials, in an assembly and rely on Obfy to keep them there. Test the protected build before you ship it, the aggressive level most of all.
Getting it
Obfy is free. The Microsoft Store has the desktop app, adds the obfy command to your PATH and keeps both up to date. On a build server or on Linux, install the command-line tool with .NET.
Desktop app and command line, from the Store
winget install --id 9NNLPK835QM4 --source msstoreCommand line only, as a .NET tool
dotnet tool install --global Obfy- The desktop app · Windows 10 or later · x64
- The WebView2 runtime, part of current Windows; the installer includes it
- The command line · the .NET 10 SDK or runtime. Tested on Windows and Linux, not on macOS
- One obfy on your PATH · the Store app and the .NET tool both add the command, so use one of them
- Licence · MIT, with the source on GitHub
- Help · Report a problem on GitHub, or read the guide