I'm trying to alter my interrupt table to take over the keyboard i开发者_如何学运维nterrupt. My end goal is to write my new interrupt routine, copy myself into RAM and make the real-mode interrupt table point to me.
I have found random sample code online but it is missing explanations on how to get the address of the original interrupt. They simply have variables in their place, and how to put itself into memory.
So my question is how do I figure out or print to my screen the real mode interrupt table?
And/OR if someone has any good code examples of doing this to either disable certain keys or beep on certain keys I'd really appreciate it.
Thanks!
In 16-bit real mode, the interrupt table starts at address 0, with 256 4 byte entries. Each of the 256 interrupt vectors gets a 4 byte address (segment + offset) in that table.
http://en.wikipedia.org/wiki/Interrupt_descriptor_table has some more detail.
If your program is running under DOS, you can (and probably should) use the DOS-provided API:
MOV AH,35H ; function 35H is Get Vector
MOV Al,9 ; slot in IDT for keyboard interrupt
INT 21H ; call DOS, contents of old vector in ES:BX (save them somewhere)
.
.
MOV AH,25H ; function 25H is Set Vector
MOV AL,9
PUSH CS ; the new vector is passed in DS:DX, so copy CS to DS
POP DS : (assuming your new handler is in the same seg as other code)
MOV DX,NewHandler
INT 21H
精彩评论