Override default INT 9h

前端 未结 2 2118
北恋
北恋 2021-01-29 02:02

I\'m trying to override the default interruption when a key is pressed. Here is my code : I don\'t understand why it doesn\'t work, it works with others INT numbers (43h for exa

2条回答
  •  天命终不由人
    2021-01-29 02:07

    I'll try and answer this again - in a somewhat long-winded fashion.

    Before Windows became prevalent, DOS ruled the computer. In order to extend its functionality, people used to write TSR (terminate and stay resident) programs; these programs would hook various interrupt functions (such as the clock and the keyboard), terminate and then stay resident in memory. As a result, when the given interrupt occurred, the resident code of these utilities would handle the interrupt, possibly calling the original interrupt handler.

    Such programs would have a structure composed of two sections: the transient part and the resident part. The transient part would be the code which would run when the program was invoked from the command line; this would check whether the resident part had already been installed. If the resident part had been installed, the program would simply exit, but if this was the first invocation, the program would first save the address of the current interrupt handler, then install its own code as the new interrupt handler and then make a special DOS call which would leave the handler code in memory.

    The code which you have shown is part of the transient program where the new interrupt handler is installed into the interrupt table. This code should only ever run once and is certainly not part of the new interrupt handler itself.

    TSR programs became obsolete when the use of Windows became widespread. In a sense, every program run under Windows is a TSR program, and what was the keyboard interrupt handler code now becomes a keyboard event which is handled (in Delphi, for example) in an 'OnKeyPress' function.

    The following code changes the interrupt table

    mov ax, 2509h
    mov dx, offset kb_handler
    int 21h
    

    The code which begins at the address *kb_handler* is the actual interrupt handler.

    What you are doing is repeatedly setting the address of the interrupt handler as opposed to handling the interrupt. Your above code should be run only once when the program itself is installed; the interrupt handler code will be called many times.

    I hope that this makes things clearer.

    What you haven't written is why you are doing this.

提交回复
热议问题