PDA

View Full Version : Masking CTRL-ALT-DEL and ^C Interrupts



Unregistered
12-18-2001, 07:16 PM
Hi, I was just wondering how to mask the interrupts for CTRL-ALT-DEL and ^C for a DOS BOX under windows?

Thanks =)

VirtualAce
12-19-2001, 09:11 AM
The only one that uses an interrupt is break. The best way to trap for these is to write a keyboard handler. There are several posts on this board related to this topic so I'll not write reams of text here. Check the board as this topic is all over it multiple times in multiple places.

VirtualAce
01-10-2002, 07:24 AM
I misled you a bit with my info. For Ctrl^C just write an int23h interrupt handler either in asm or C.




//Use (...) for C++ and (void) for C.

void interrupt (*oldbreakhandler)(...)=NULL;


void interrupt breakhandler(...)
{
//Do something
//You can just disable this by putting nothing here
//This would translate to an IRET in asm
//Turning off CTRL-C, though, is probably not what you want
//to do while building your code.

//Example:
//Uninstall any other int handlers we have installed
//Free memory
uninstallbreakhandler();
oldbreakhandler(); //Pass the int onto the orig int 23h handler

//Will terminate, but cleans up prior to terminating
}

void installbreakhandler(void)
{
disable();
//Save old handler
oldbreakhandler=getvect(0x23);
//Install our handler
setvect(0x23,breakhandler);
enable();
}

void uninstallbreakhandler(void)
{
//Restore the int vector table
disable();
setvect(0x23,oldbreakhandler);
enable();
}



DOS does not restore the int vector table if you have patched interrupts and pressed CTRL-C midway in your program. This thrashes the interrupt chain for the vectors you have patched. You would have to reboot to run your code again. The above method will allow you to press CTRL-C for debugging and will properly restore the int vector table so you can run your code again w/o having to reboot.

In a commercial build you would probably just put an IRET in the int23h handler. You will also want to patch int24h which is DOS's Critical Error Handler - not very friendly at all. Your version should help the user determine what the heck happened and why DOS failed or a DOS call failed.

Yoshi
01-10-2002, 06:52 PM
Ctrl + C's ASCI code is 3

As for the Invincible breakout... You can't in Windows because it will bring up the close prog dialog.

VirtualAce
01-10-2002, 07:30 PM
This is for DOS, since this is the DOS programming board.