Ctrl-Alt-Del snatcher

Area:    Quik_Bas
  Msg:    #534
 Date:    06-16-92 06:26 (Public) 
 From:    Steve Gartrell           
 To:      All                      
 Subject: Ctrl-Alt-Del snatcher
'NOWARM.BAS follows:
DECLARE SUB SetVect ()
DECLARE SUB RestVect ()
'
'BIG FAT NOTE:  Observe the sequence of calls.  SetVect first,
'THEN ON UEVENT.  When done, UEVENT OFF _first_, then RestVect.
'Even in the event handler.  If you wish to tinker with this
'('cuz you don't believe me) don't complain when your INT 09h
'vector points to where a PDS handler used to be.  This works
'for stand alone executables in both QB and PDS.  Can be made
'into a QLB and compiled/linked in either QB or PDS.  Works
'inside the PDS environment.  Will LOCK YOUR SYSTEM up if
'you attempt to run it in inside the QB environment.  Tested
'on a Tandy 1000TX (Phoenix BIOS) and a USAFlex 80386 (AMI BIOS).
'Released to the public domain this 15th day of June, 1992
'by Stephen K. Gartrell.

SetVect
ON UEVENT GOSUB RebootHandler
UEVENT ON

CLS
'Text print loop here so you can try the reboot handler!!!
DO
   PRINT "I would like to remind you that even ";
   PRINT "cereal puts up with a few flakes...|-}"
LOOP WHILE INKEY$ <> "q"

UEVENT OFF
RestVect

END

RebootHandler:

VIEW PRINT 4 TO 7
CLS 2
LOCATE 5, 10
PRINT "WARNING!!  Rebooting now will result in loss of all data prior";
LOCATE 6, 10
PRINT " to saving to disk!!!  Continue with rebooting process? (y) ? ";
DO: ans$ = UCASE$(INKEY$): LOOP UNTIL LEN(ans$)
IF ans$ = "Y" THEN
   RESET
   UEVENT OFF
   RestVect
   CLS 2
   LOCATE 5, 17
   PRINT "Please press the CTRL-ALT-DEL key sequence again.";
   DO: LOOP UNTIL LEN(INKEY$)
END IF
VIEW PRINT
RETURN

;;CALTDEL.ASM released to public domain this 15th
;;day of June, 1992 by Stephen K. Gartrell.  Uses
;;a bunch of registers, but protects all of them.
;;USAGE: SetVect installs CTRL-ALT-DEL bypass with
;;OPTIONAL call to QB/PDS UEVENT flag setter
;;SETUEVENT.  RestVect restores routing to whatever
;;key handler PDS/QB was using at the time of the
;;SetVect call.  That is an important detail; think
;;about it.  More than one keyhandler _may_ be used
;;by PDS/QB, particularly when doing lots of event
;;handling routines.  If SetUevent and the UEVENT
;;routines are not used, then some complexity is
;;eliminated at the risk of annoying a user.

               .MODEL  MEDIUM, basic

               .CODE

               PUBLIC  BASIC restvect, setvect


NoSoftBoot      PROC FAR
 EXTRN   SetUevent:PROC    ;; REMOVE if no UEVENT processing

        jmp     SHORT @F

Old09Int        dd      90909090h       ;; Storage for
                                        ;;  offset and seg
                                        ;;  of old 09h int

@@:     push    bp
        push    ax
        push    es
        push    bx
        pushf
        in      al, 60h         ;; Check keyboard for delete key
        cmp     al, 53h
        jne     SHORT skip      ;; Ain't-back to key handler
        mov     bx, 0
        mov     es, bx
        mov     bx, 417h
        mov     al, es:[bx]
        and     al, 0Ch
        cmp     al, 0Ch         ;; Check for CTRL and ALT pressed
        je      SHORT noboot            ;; Uh-oh....


skip:   popf
        pop     bx
        pop     es
        pop     ax
        pop     bp
        jmp     cs:Old09Int

noboot: in      al, 61h         ;; Get control word
        mov     ah, al          ;; Save it
        or      al, 80h         ;; Set keyboard bit
        out     61h, al         ;; Ack delete key
        xchg    ah, al          ;; Original control word back
        out     61h, al         ;; restore control word

        mov     al, 20h         ;; Tell interrupt controller
        out     20h, al         ;;  false alarm, go back to sleep!
        push    es              ;; REMOVE if no UEVENT processing
        push    dx              ;; REMOVE if no UEVENT processing
        push    cx              ;; REMOVE if no UEVENT processing
        call    SetUevent       ;;Set user event flag, so you 
                                ;; REMOVE if no UEVENT processing
        pop     cx              ;; REMOVE if no UEVENT processing
        pop     dx              ;; REMOVE if no UEVENT processing
        pop     es              ;; REMOVE if no UEVENT processing

        popf
        sti
        pop     bx
        pop     es
        pop     ax
        pop     bp
        iret

NoSoftBoot      ENDP

setvect PROC FAR
        push    bp
        push    ax
        push    bx
        push    dx
        push    ds
        push    es
        pushf
@@:     mov     ax, 0100h               ;; Flush the keyboard
        int     16h                     ;;   buffer before
        jz      @F                      ;;   changing the 09h
        xor     ax, ax                  ;;   interrupt vector
        int     16h
        jmp     @B
@@:     mov     ax, 3509h                     ;; Load Get vector
        int     21h                           ;;  DOS interrupt
        mov     WORD PTR cs:Old09Int, bx      ;; Save the offset
        mov     WORD PTR cs:Old09Int +2, es   ;; Save the segment
        push    cs                            ;; Code seg to DS
        pop     ds
        lea     dx, NoSoftBoot          ;; Get handler offset
        mov     ax, 2509h               ;; Load set handler
        int     21h                     ;;  DOS interrupt
        popf
        pop     es
        pop     ds
        pop     dx
        pop     bx
        pop     ax
        pop     bp
        ret
setvect         ENDP

restvect PROC FAR
        push    bp
        push    ax
        push    bx
        push    ds
        lds     dx, cs:Old09Int       ;; Restore original
                                      ;;  key handler by
        mov     ax, 2509h             ;;  calling DOS set
        int     21h                   ;;  vector function
        pop     ds
        pop     bx
        pop     ax
        pop     bp
        ret
restvect        ENDP


  END




--- DB B1073/071082
 * Origin: RadioLink! Columbus, OH (614)766-2162 HST/DS (1:226/140)

Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET