Int 31h TSR (MSDOS in21h) to show everytime a message before a com/exe started

Viewed 47

I would like teach a TSR function (Memory resident) that embedded in int 21h (MSDOS) to show every time texts when you start another application (com/exe). "MY Text do Show when a program started after me"

Ex:
User type mkdir
I would to show everytime when DOS start a program my text < from my application
“Sytaxerror” < from MSDOS
´´´

This code is resident and (I am very sure) it work. This code is between int 21h from MSDOS and the operation to the secondary function over this function that MSDOS make.
ex: MSDOS (int21h) start a com/exe file > my function code bottom > mirror every command from MSDos > MSDOS normally
My question is only, how I get a text output (I will replace in future with other functions too) before the application started with MSDOS.

ex:

MSDOS start a COM/EXE > my function botton /TSR (31h) > output a text "MY Text do Show when a program started$" > this text show before every startet com/exe. My code in bottom is between INT 21h primary and secondary. ´´´

I question is only, I insert this code:

 mov dx offset MyText5
 mov ah, 09h
 int 21h

I would like show this text every time when MSDOS start a COM/EXE Ex: User type mkdir I would to show everytime when DOS start a program < from my application “Sytaxerror” < MSDOS

code    segment 
        assume cs:code,ds:code
        org   100h             
start:
     mov dx offset MyText5 ; I would to show everytime when DOS start a program$”
     mov ah, 09h
     int 21h

     jmp  instalar            ;Jump to the installation
                              ;routine.

;We put the original Int21 address in this variable.
old_21    dd   2

new_21:

;Here's the routine which hooks Int 21.

     jmp  cs:[old_21]              ;Jump to the original int.

instalar:

;Obtain the original Int 21 Vector
     mov  ax, 3521h
     int  21h
     mov  word ptr old_21, bx 
     mov  word ptr old_21+2, es    

;Set the new Int 21 vector.
        mov     ax,2521h          
        push cs
        pop  ds
        mov     dx, offset new_21
        int     21h

;Now it's resident
     mov  ah, 31h
     mov  dx, 30d    ;<--------- Number of paragraphs(16 bytes)   
     int  21h        ;leave resident.    

     JMP DataJump
     yText5 db "MY Text do Show when a program started$"
     DataJump:

code    ends
end  start
´´´
1 Answers

DOS has the EXEC function 4Bh that executes a program under the control of another program. Your hook into int 21h could keep a lookout for the function number AX=4B00h and if it comes by display the appropriate message right before chaining to the original int 21h.

new_21:
        cmp     ax, 4B00h
        jne     OLD

        push    ds                  ; (1)
        push    cs
        pop     ds
        mov     dx offset MyText5
        mov     ah, 09h
        int     21h
        pop     ds                  ; (1)

OLD:    jmp     cs:[old_21]         ; Jump to the original int.

Sometimes an EXEC operation can fail and then the above code would have displayed the message prematurely! So a better approach would be to first let DOS do the work and then inspect the carry flag for success. The code is more involved because the DOS function 4Bh does destroy SS:SP along with all the other registers except CS:IP.

new_21:
        cmp     ax, 4B00h
        jne     OLD

        mov     cs:[saveSPSS], sp
        mov     cs:[saveSPSS+2], ss
        pushf
        call    cs:[old_21]         ; Call to the original int (returns with IRET)
        mov     ss, cs:[saveSPSS+2] ; \  `lss sp, cs:[saveSPSS]`
        mov     sp, cs:[saveSPSS]   ; /
        jc      ERR

        push    cs
        pop     ds
        mov     dx offset MyText5
        mov     ah, 09h
        int     21h

        mov     bp, sp
        and     byte ptr [bp+4], -2 ; Clear CF
        iret


ERR:    mov     bp, sp
        or      byte ptr [bp+4], 1  ; Set CF
        iret

OLD:    jmp     cs:[old_21]         ; Jump to the original int.
Related