Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:
- int 21h ; Preserve all other info
- mov ax,0800h ; 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
Add Comment
Please, Sign In to add comment