Google Analytics

Wednesday, March 12, 2014

.Net Reactor and WiX

Okay, here's the situation: ("My parents went away on a week's vacation...") I need to obfuscate the code of a project I am working on using .Net Reactor. The project is in .Net (obviously) and we're using VS 2012 and WiX 3.7 to create the installer. Obfuscating code with .Net Reactor is relatively simple as well as powerful. In a side-by-side comparison with dotfuscator we found that Reactor did a better job particularly in control flow obfuscation than its more expensive counterpart. The issue before me is getting WiX to do this obfuscation before creating the installer.

Actually the project is broken up into several solutions, a client and several services that get packaged together. Obfuscating the initial project, the client, was relatively straightforward. First I created a .Net Reactor project specifying the protection options, settings, and files I wanted to obfuscate. I added that project file to my solution as a resource to copy into the output directory. The solution builds a number of projects including some shared libraries, so it was just easiest to copy the project into the output directory and run it from there. I edited the wixproj file (in VisualStudio you can right-click the project file and select 'Edit Project File') and overwrote the BeforeBuild target as such:


 

The .Net Reactor command-line help here, http://www.eziriz.com/help/source/command_line.htm, is useful, though if you are using the project file as I am, most of the settings will come from it. I added the -q[uiet] flag to keep Reactor's notification window from popping up. I should note here that by default a Reactor project will have \_secured\ as the Target File setting. That setting results in each obfuscated assembly being tucked away neatly in its own directory, which I would then have to pick through to pack back into the installer. To remedy this, I just had the obfuscated files overwrite the originals by removing the subdirectory of the Target File:
\. That has worked pretty well for me except that I need to be sure to rebuild the VS solution before building the WiX installer each time, else Reactor finds the previously obfuscated file and chokes.

For each of the services then I built a Reactor project and added multiple elements to the BeforeBuild of the wixproj that builds that installer. I also had to separately build a few other DLLs where I needed to have a lower level of obfuscation. It was simple just to create their own separate Reactor project and execute them in the BeforeBuild as well.

No comments: