Command-Not-Found on Windows

(Okay, not quite.)

After someposers started duplicating the functionality of the Ubuntu command-not-found package, I thought I may as well have a go on a sensible OS.

Unfortunately for me, it turns out that Windows CMD doesn't offer, as such, a function that's run when a command isn't found, so I had to add my own (everyone loves screenshots of text, right?):

My beautiful assembly defeating Ollydbg's highly competent analysis

For those of you who can't read my beautiful hand-coded assembler, when a command isn't found, my patched cmd.exe will now attempt to load "cnf.dll" from the system path, and pass the command-line to a function, imaginatively named cnf, in that dll.

Stage two, obviously, is to get some kind of useful reply...

// cl /Fecnf.dll /EHsc cnf.cpp /link /dll /dynamicbase /subsystem:console
#define UNICODE
#include <iostream>

extern "C" { __declspec(dllexport) void __stdcall cnf(const wchar_t*); }

using std::wcout; using std::endl;

void __stdcall cnf(const wchar_t* command)
    wcout << L"I'm sorry, it looks like you tried to call ``" << command << "'', but the command doesn't exist!" << endl << endl;
    wcout << L"Did you want to try /your mother/ instead?" << endl;

I started writing a loader that'd apply the patch on-the-fly/to all existing instances of cmd, but I kind of ran out of care (it should be safe, it's about a sixty-byte patch). If anyone can think of any actual applications of this...

Commenting is disabled for this post.

Read more of Faux' blog