Debugging decompiled .NET sources

Recently I decided to purchase the N2 Elite as I'm unable to get all the amiibo's out there to use with my Nintendo Switch to get extra's in some of the games I own. The N2 Elite comes with a tool called 'USB Manager Application'. As I hook up the RFID reader and fire up the application, all seems to be in working order. But when i try to load some dump files, the images seem to be broken or not found as I get a big questionmark where the image should be. Everything else works fine but the images don't. The more I load, the more questionmarks I get. It's starting to irritate me.

Maybe I can figure out the problem, so I take a closer look at the application and it's assemblies. As it turns out, they are .NET assemblies so I could possibly decompile and debug them.

Prerequisites

Step 1: Decompiling the assemblies

Decompiling an assembly works best on assemblies that aren't obfuscated by any tool. As it turns out, they weren't when I tried to load them into dotPeek.

Now where to begin? I start looking around in the executable assembly, which seems to be a windows forms application, and I find a method called ShowN2EliteBanks. As I look at the decompiled source, this function most likely has something to do with showing the images that are missing. I would like to put a breakpoint at the beginning of the function and see what goes on there on runtime.

Step 2: Fire up the symbol server

As I do not possess the source code, I can't simply run the application using Visual Studio, set a breakpoint and start debugging. This is where the dotPeek symbol server comes in handy. What the symbol server in dotPeek actually does is provide symbol files for the assemblies we decompiled in the previous step. The symbol files can obviously be used for debugging purposes. The dotPeek symbol server runs on http://localhost:33417 by default. I doublecheck the settings and fire up the symbol server.

Step 2: Configure Visual Studio

To use the symbols provided by the dotPeek symbol server in Visual Studio, we need to add it. Fire up Visual Studio, navigate to Tools -> Options -> Debugging -> Symbols and add the dotPeek symbol server.

Now, we want to debug code that is not ours. This is disabled by default within Visual Studio. To enable this feature, navigate to Tools -> Options -> Debugging -> General and untick Enable Just My Code.

Step 3: Attach the debugger

Because we can't run any source code, I start up the application and hook up the Visual Studio debugger to the running process.

Step 4: Creating a breakpoint

But now what? How am I supposed to set a breakpoint when I don't have any source code available? You can add a New Function Breakpoint by pressing crtl + b or by navigating to Debug -> New Breakpoint -> New Function Breakpoint. I put in the name of the function I found in Step 1 and click OK.

Step 5: Live debugging

I push some buttons in the application hoping it will trigger the function, and suddenly BOOM.

The breakpoint was hit! Now I'm able to do some debugging as I normally would.

Recap

The problem turned out to be an instance of ResourceManager that was null in the libamiibo assembly supplied with the application. After some further investigation, I found libamiibo to be open source. So I cloned the repository from github, recompiled the source code, updated the assemblies and fixed the problem.