assembly Int 31 h TSR(MSDOS in 21 h),每次在com/exe启动前显示消息

wfsdck30  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(203)

我想教一个TSR函数(内存驻留),嵌入在int 21 h(MSDOS)显示每次文本,当你启动另一个应用程序(com/exe).“我的文本做显示当一个程序在我之后启动”

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启动一个COM/EXE〉我的函数bottom/TSR(31 h)〉输出一个文本“我的文本做显示当一个程序启动$”〉这个文本显示在每一个startet com/exe之前。我的代码在底部是INT 21 h之间的主要和次要。
我的问题只是,我插入这段代码:

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

我希望每次MSDOS启动COM/EXE Ex时显示此文本:用户类型mkdir我会显示每次当DOS启动程序〈从我的应用程序“语法错误”〈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
´´´
vof42yt1

vof42yt11#

DOS有一个EXEC函数4 Bh,它在另一个程序的控制下执行一个程序。你进入int 21h的钩子可以监视函数号AX=4B00h,如果它来了,在链接到原来的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.

有时EXEC操作会失败,然后上面的代码会过早地显示消息!所以一个更好的方法是首先让DOS做这项工作,然后检查进位标志是否成功。代码更复杂,因为DOS函数4 Bh确实会破坏SS:SP沿着除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.

相关问题