XLL File packing - obfuscation

387 views
Skip to first unread message

Xavier Aymé - Mauchand

unread,
Nov 22, 2019, 10:57:04 AM11/22/19
to Excel-DNA
Hi!

I'd like to make things a bit more complicated for reverse-engineering an XLL plug in. 

I know from this post that the XLL format is a small protection by itself, but once you know that the plug in has been built upon Excel-DNA, it's quite easy to unpack it using Caio Proiete Tool (it works like a charm, thanks !) ), and to decompile the business DLL. I've tried it and I can read the code as if I was in my IDE! 

So I'd like to obfuscate the DLL containing the core logic, and repack the XLL file. 

Problem is : I've found a tool to unpack but nothing to repack :-D Is there any way of performing such an operation? With a dedicated tool or by modyfying slightly how Excel DNA works (waiting for the DLL to be obfuscated before packing?) 

Thanks and regards!

Govert van Drimmelen

unread,
Nov 22, 2019, 10:59:47 AM11/22/19
to exce...@googlegroups.com

Hi Xavier.

 

The Excel-DNA packing tool (ExcelDnaPack.exe) is part of the Excel-DNA project here, and can be downloaded from here:

https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution

 

Then you can re-pack your obfuscated assembly using the command-line tool.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/085e89ae-bed9-49c2-bce6-0e55786c7ae2%40googlegroups.com.

Caio Proiete

unread,
Nov 22, 2019, 1:27:33 PM11/22/19
to exce...@googlegroups.com
Hi Xavier,

You shouldn't have to unpack and then repack everything... Instead, I'd suggest you disable the default packing first, by setting RunExcelDnaPack to `false` in your `ExcelDna.Build.props` file, and then in the PostBuild event, you can call the tool you're using to obfuscate the assemblies, and finally call ExcelDnaPack.exe to pack everything (once).

The tool that performs the packing (ExcelDnaPack.exe) comes with the NuGet package that you installed (ExcelDna.AddIn), so you just need to reference it from your PostBuild event... Usually it is $(ProjectDir)..\..\packages\ExcelDna.AddIn.{Version-of-ExcelDna}\tools\ExcelDnaPack.exe

image.png

If you want to take it to the next level and do everything via MSBuild, you can write a .targets build script that hooks into the build process by executing in between the targets `ExcelDnaBuild` and `ExcelDnaPack` to do the obfuscation. Your target would look something like:

<Target Name="ObfuscateMyDLLs" DependsOnTargets="ExcelDnaBuild" BeforeTargets="ExcelDnaPack">
   <!-- // Call tool to Obfuscate assemblies ... -->
</Target>

You might want to check how the ExcelDnaPack target works as I'd yours would probably be similar.

Thanks,



--

Xavier Aymé - Mauchand

unread,
Nov 24, 2019, 7:06:54 PM11/24/19
to Excel-DNA
Hi @Govert and @Caio, 

Thanks to both of you for your quick answers. I used Babel NET for obfuscation, in between the DLL generation and the DNA packing process as you suggested, and it ran super smoothly.

For the record : the obfuscation worked fine as long as I didn't activate "Anti-Reflection Protection" option. As soon as I turned this option on, Excel got trouble loading resources (warning message at startup). But, I tried to decompile my plug in, and I found that even without this option, the code is messed enough to discourage anyone trying to retro-engineer it. 

Best!

Xavier

Caio Proiete

unread,
Nov 26, 2019, 10:21:55 AM11/26/19
to exce...@googlegroups.com
Hi Xavier, that's good news!

Excel-DNA uses Reflection to locate the types in the assembly (e.g. classes that implement IExcelAddIn, classes that inherit from Ribbon, etc.), and to instantiate them, so by having this "Anti-Reflection protection", you're effectively blocking the Excel-DNA add-in loader from being able to load your add-in, which causes the issues you mentioned.

Cheers,
Caio Proiete


--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages