February 14th 2008 06:34 am

Command-Not-Found on Windows

(Okay, not quite.)

After some posers 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…

3 Comments »

3 Responses to “Command-Not-Found on Windows”

  1. Sadiq on 17 Feb 2008 at 10:36 pm #

    Baby Ballmer is crying. (Or throwing chairs).

  2. icStatic on 07 May 2008 at 2:44 pm #

    ZOMG WIN!

    I can’t think of ANY practical use for this, but it involves binary patching, so it must be good, right?

  3. Faux’s Blog » Noelevate on 22 Dec 2008 at 12:17 am #

    [...] seems that, like some other things, as far as I can see, there’s no support for [...]

Trackback URI | Comments RSS

Leave a Reply

Anti-Spam Protection by WP-SpamFree

« | »