C# ConfuserEX Not working with embedded .dlls

834 views Asked by At

I'm using Costura.Fody which allows users to embed dependencies as resources. In my case its embedding a .dll to my .exe... The problem is when I try to use ConfuserEX afterwards to prevent decompiling it comes up with this error:

[ERROR] Failed to resolve dependency of 'Program.exe'.
Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Siticone.Desktop.UI, Version=2.0.9.0, Culture=neutral, PublicKeyToken=422d444a8a9fa6db
   at dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, IAssembly assembly, ModuleDef sourceModule) in E:\Source\Public\Confuser2\dnlib\src\DotNet\IAssemblyResolver.cs:line 113
   at Confuser.Core.ConfuserEngine.Inspection(ConfuserContext context) in e:\Source\Public\Confuser2\Confuser.Core\ConfuserEngine.cs:line 264

How do I embed my .dlls and prevent decompiling?

1

There are 1 answers

0
Avi On

Your problem lies with the fact that Costura will delete your dll's.

See the following Question to fix your problem: Cannot use Costura.Fody with ConfuserEx

Make sure that when obfuscating, the dll's are in the same directory as your executable.


If you want to obfuscate the dependencies themselves, such as a custom library you have made, you will have to do a bit more.

Personally I've done it by directly referecing the dll's I use and obfuscating them in the prebuild events of my main project.

I created 2 bat-scripts, 1 for building my dependencies/libraries and 1 to obfuscate them afterwards.

My prebuilds events:

cd %cd%\..\..\..\..\
call dependency_builder.bat
if $(ConfigurationName) == Release (
call dependency_obfuscator.bat
)

"dependency_builder.bat" simply builds all my dependencies using the msbuild CLI, while "dependency_obfuscator.bat" obfuscates them using the ConfuserEx2 CLI.

Its quite tedious, but for now this is the best I was able to come up with to also obfuscate the dependencies.

Hope this helps :)