Last active
September 6, 2022 17:05
-
-
Save cyco130/bb5bb852c1ebe2d17577ff66576564a0 to your computer and use it in GitHub Desktop.
TSR to report MSDOS version differently (8.0), in NASM syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bits 16 | |
cpu 8086 | |
org 0100h | |
section .data | |
SInstalled: db "DOSVER is allready installed.",0ah,0dh | |
section .text | |
; Jump to main program entry | |
jmp Main | |
; ------------------------------------ | |
; The actual interrupt handler routine | |
; It's at the very beginning to save memory | |
; ------------------------------------- | |
Int21Handler: | |
; Is it GetVersion? | |
cmp ah,30h | |
jne GoInt21 | |
; Yes, is it installation check? | |
cmp bx,'DO' | |
jne NotCheck | |
cmp cx,'SV' | |
jne NoCheck | |
cmp dx,'ER' | |
jne NotCheck | |
; Installation check, report that we're here | |
mov ax,0200h ; DOSVER version 2.0 | |
mov bx,'IS' | |
mov cx,'HE' | |
mov dx,'RE' | |
NotCheck: | |
pushf ; Simulate interrupt | |
call GoInt21 ; Call original handler | |
mov ax,0800h ; Overwrite with version 8.0 | |
iret | |
; Here's some self modifying code magic | |
GoInt21: | |
db 0eah ; JMP instruction | |
OldIntOfs: | |
dw 0 ; Patched at runtime | |
OldIntSeg: | |
dw 0 ; Patched at runtime | |
FirstUnused: | |
; ------------------------------------ | |
; Type the string at DS:SI to the screen | |
; ------------------------------------- | |
TypeStr: | |
mov al,[si] | |
cmp al,0dh | |
je Return | |
mov ah,0eh | |
mov bh,0 | |
mov bl,7 | |
int 10h | |
inc si | |
jmp TypeStr | |
Return: | |
retn | |
; ------------------------------------ | |
; Main entry point | |
; ------------------------------------- | |
Main: | |
; Release environment block | |
mov ax,[002ch] | |
jz noenv | |
mov es,ax | |
mov ah,49h | |
int 21h | |
noenv: | |
; Installation check | |
mov ah,30h | |
mov bx,'DO' | |
mov cx,'SV' | |
mov dx,'ER' | |
int 21h | |
cmp bx,'IS' | |
jne NotInstalled | |
cmp cx,'HE' | |
jne NotInstalled | |
cmp dx,'RE' | |
jne NotInstalled | |
; Allready installed, type the message and exit | |
mov si,SInstalled | |
jmp TypeStr | |
; ------------------------------------ | |
; Not installed, so install our handler and terminate (but stay resident) | |
; ------------------------------------- | |
NotInstalled: | |
; Save old int 21h vector | |
mov ax,3521h ; get interrupt vector 21h | |
int 21h | |
mov [OldIntOfs],bx ; store offset | |
push es | |
pop ax | |
mov [OldIntSeg],ax ; store segment | |
; Install new vector | |
mov ax,2521h ; set interrupt vector 21h | |
mov dx,Int21Handler | |
int 21h | |
; Terminate and stay resident | |
mov dx,FirstUnused ; We can release the memory after this part | |
int 27h | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment