0

I am able to obfuscate a .dll in my visual studio solution upon running it. enter image description here

The problem is that I have no idea how this can be done upon publishing the application into an .exe. Because the source code of the dll inside the published exe can still be seen with a de-obfuscator.

Could someone help me out please? Thanks in advance.

  • How do you create the exe? – PMF Nov 15 '21 at 11:22
  • I create the exe by using the publishing funtion inside Visual Studio 2022. I am using the "produce single file" option. But unchecking this changes nothing. – Andreas Damen Nov 15 '21 at 11:38
  • _"Because the source code of the dll inside the published exe can still be seen with a de-obfuscator."_ - with enough determination, you'll _always_ be able to deobfuscate to some extend. If that code is _so_ critical to you, consider making it a cloud API. – Fildor Nov 15 '21 at 12:20
  • I know that, but thats just how it is. A cloud api would be an expensive option in this case. The software makes calls to a service allowing a max of 1200 calls per minute. each client makes about 600 calls a minute, meaning only 2 instances could be used at a time. More than 2 people use this software. This is why obfuscation is in my eyes the best option – Andreas Damen Nov 15 '21 at 12:32
  • Are you sure the obfuscation also runs when you do a publish? You might also have a problem in your build settings. – PMF Nov 15 '21 at 12:35
  • It does run, it creates an obfuscated version of the Projectname.dll in a seperate folder. The problem is that i dont know how to do it for the actual file itself. Because it does not allow me to change that file on build – Andreas Damen Nov 15 '21 at 12:42

1 Answers1

2

I just found the solution. By installing Obfuscar Global Tool and adding the following code to my .csproj file.

<Target Name="Obfuscation" AfterTargets="AfterCompile">
    <Message Text="Obfuscating" Importance="high" />
    <!--Optional to log a message.-->
    <Exec Command="obfuscar.console obfuscar.xml" />
        <!--Assuming you have installed Obfuscar.GlobalTool(attpsifluww.nuget.org/packages/Obfuscar.GlobalTool). -->
    <Exec Command="COPY $(ProjectDir)$(IntermediateOutputPath)Protected\$(TargetFileName) $(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</Target>

This allowed me to change the dll file on publish.

Thanks everyone for helping me solve this. I really appreciate it!

Rahul
  • 2,431
  • 3
  • 35
  • 77
  • If you find the solution, you could click '✔' to mark it as an answer to change its status to Answered. It will also help others to solve a similar issue. See also [stackoverflow.com/help/why-vote](https://stackoverflow.com/help/why-vote) – Jiale Xue - MSFT Nov 23 '21 at 10:01
  • Glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Jiale Xue - MSFT Nov 25 '21 at 08:52