home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH20 / NORESET.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-07-24  |  4.1 KB  |  184 lines

  1. ; NORESET.ASM
  2. ;
  3. ; A short TSR that patches the int 9 interrupt and intercepts the
  4. ; ctrl-alt-del keystroke sequence.
  5. ;
  6. ; Note that this code does not patch into int 2Fh (multiplex interrupt)
  7. ; nor can you remove this code from memory except by rebooting.
  8. ; If you want to be able to do these two things (as well as check for
  9. ; a previous installation), see the chapter on resident programs.  Such
  10. ; code was omitted from this program because of length constraints.
  11. ;
  12. ;
  13. ; cseg and EndResident must occur before the standard library segments!
  14.  
  15. cseg        segment    para public 'code'
  16. OldInt9        dword    ?
  17. cseg        ends
  18.  
  19. ; Marker segment, to find the end of the resident section.
  20.  
  21. EndResident    segment    para public 'Resident'
  22. EndResident    ends
  23.  
  24.         .xlist
  25.         include     stdlib.a
  26.         includelib    stdlib.lib
  27.         .list
  28.  
  29.  
  30. DelScanCode    equ    53h
  31.  
  32. ; Bits for the various modifier keys
  33.  
  34. CtrlBit        equ    4
  35. AltBit        equ    8
  36.  
  37.  
  38. KbdFlags    equ    <byte ptr ds:[17h]>
  39.  
  40.  
  41.  
  42. cseg        segment    para public 'code'
  43.         assume    ds:nothing
  44.  
  45.  
  46. ; SetCmd-    Sends the command byte in the AL register to the 8042
  47. ;        keyboard microcontroller chip (command register at
  48. ;        port 64h).
  49.  
  50. SetCmd        proc    near
  51.         push    cx
  52.         push    ax        ;Save command value.
  53.         cli            ;Critical region, no ints now.
  54.  
  55. ; Wait until the 8042 is done processing the current command.
  56.  
  57.         xor    cx, cx        ;Allow 65,536 times thru loop.
  58. Wait4Empty:    in    al, 64h        ;Read keyboard status register.
  59.         test    al, 10b        ;Input buffer full?
  60.         loopnz    Wait4Empty    ;If so, wait until empty.
  61.  
  62. ; Okay, send the command to the 8042:
  63.  
  64.         pop    ax        ;Retrieve command.
  65.         out    64h, al
  66.         sti            ;Okay, ints can happen again.
  67.         pop    cx
  68.         ret
  69. SetCmd        endp
  70.  
  71.  
  72. ; MyInt9-    Interrupt service routine for the keyboard hardware
  73. ;        interrupt.  Tests to see if the user has pressed a
  74. ;        DEL key.  If not, it passes control on to the original
  75. ;        int 9 handler. If so, it first checks to see if the
  76. ;        alt and ctrl keys are currently down; if not, it passes
  77. ;        control to the original handler.  Otherwise it eats the
  78. ;        scan code and doesn't pass the DEL through.
  79.  
  80. MyInt9        proc    far
  81.         push    ds
  82.         push    ax
  83.         push    cx
  84.  
  85.         mov    ax, 40h
  86.         mov    ds, ax
  87.  
  88.         mov    al, 0ADh        ;Disable keyboard
  89.         call    SetCmd
  90.         cli                ;Disable interrupts.
  91.         xor    cx, cx
  92. Wait4Data:    in    al, 64h            ;Read kbd status port.
  93.         test    al, 10b            ;Data in buffer?
  94.         loopz    Wait4Data        ;Wait until data available.
  95.  
  96.         in    al, 60h            ;Get keyboard data.
  97.         cmp    al, DelScanCode        ;Is it the delete key?
  98.         jne    OrigInt9
  99.         mov    al, KbdFlags        ;Okay, we've got DEL, is
  100.         and    al, AltBit or CtrlBit    ; ctrl+alt down too?
  101.         cmp    al, AltBit or CtrlBit
  102.         jne    OrigInt9
  103.  
  104. ; If ctrl+alt+DEL is down, just eat the DEL code and don't pass it through.
  105.  
  106.         mov    al, 0AEh        ;Reenable the keyboard
  107.         call    SetCmd
  108.  
  109.         mov    al, 20h            ;Send EOI (end of interrupt)
  110.         out    20h, al            ; to the 8259A PIC.
  111.         pop    cx
  112.         pop    ax
  113.         pop    ds
  114.         iret
  115.  
  116. ; If ctrl and alt aren't both down, pass DEL on to the original INT 9
  117. ; handler routine.
  118.  
  119. OrigInt9:    mov    al, 0AEh        ;Reenable the keyboard
  120.         call    SetCmd
  121.  
  122.         pop    cx
  123.         pop    ax
  124.         pop    ds
  125.         jmp    cs:OldInt9
  126. MyInt9        endp
  127.  
  128.  
  129.  
  130. Main        proc
  131.         assume    ds:cseg
  132.  
  133.         mov    ax, cseg
  134.         mov    ds, ax
  135.  
  136.         print
  137.         byte    "Ctrl-Alt-Del Filter",cr,lf
  138.         byte    "Installing....",cr,lf,0
  139.  
  140. ; Patch into the INT 9 interrupt vector.  Note that the
  141. ; statements above have made cseg the current data segment,
  142. ; so we can store the old INT 9 value directly into
  143. ; the OldInt9 variable.
  144.  
  145.         cli                ;Turn off interrupts!
  146.         mov    ax, 0
  147.         mov    es, ax
  148.         mov    ax, es:[9*4]
  149.         mov    word ptr OldInt9, ax
  150.         mov     ax, es:[9*4 + 2]
  151.         mov    word ptr OldInt9+2, ax
  152.         mov    es:[9*4], offset MyInt9
  153.         mov    es:[9*4+2], cs
  154.         sti                ;Okay, ints back on.
  155.  
  156.  
  157. ; We're hooked up, the only thing that remains is to terminate and
  158. ; stay resident.
  159.  
  160.         print
  161.         byte    "Installed.",cr,lf,0
  162.  
  163.         mov    ah, 62h            ;Get this program's PSP
  164.         int    21h            ; value.
  165.  
  166.         mov    dx, EndResident        ;Compute size of program.
  167.         sub    dx, bx
  168.         mov    ax, 3100h        ;DOS TSR command.
  169.         int    21h
  170. Main        endp
  171. cseg        ends
  172.  
  173. sseg        segment    para stack 'stack'
  174. stk        db    1024 dup ("stack   ")
  175. sseg        ends
  176.  
  177. zzzzzzseg    segment    para public 'zzzzzz'
  178. LastBytes    db    16 dup (?)
  179. zzzzzzseg    ends
  180.         end    Main
  181.  
  182.  
  183.  
  184.