Skip to content

Instantly share code, notes, and snippets.

@WideWord
Created May 17, 2015 18:11
Show Gist options
  • Save WideWord/77f89441b902fdfaa788 to your computer and use it in GitHub Desktop.
Save WideWord/77f89441b902fdfaa788 to your computer and use it in GitHub Desktop.
org 100h
jmp init
resident_begin:
handler_09:
pusha
push ds
mov dx, cs
mov ds, dx
push 40h
pop ds
mov ax, [17h]
and ax, 0h
cmp ax, 0h
jne .no_ast
mov ah, 02h
mov dl, '*'
int 21h
.no_ast:
pop ds
popa
jmp dword [cs:original_handler_09]
.reboot:
mov ax, 0040h
mov ds, ax
mov WORD [0072h], 1234h ; Sets warm boot
jmp 0F000h:0FFF0h ; Jump to reset code
original_handler_09 dw 0
original_handler_09_seg dw 0
handler_2F:
cmp ah, 0D3h
jne .next
cmp al, 01h
je .selfremove
mov al, 0FFh
iret
.selfremove:
pusha
push es
push ds
mov ax, 3509h
int 21h
cmp bx, handler_09
jne .cant_uninstall
push cs
pop dx
push es
pop ax
cmp ax, dx
jne .cant_uninstall
mov ax, 352Fh
int 21h
cmp bx, handler_2F
jne .cant_uninstall
push cs
pop dx
push es
pop ax
cmp ax, dx
jne .cant_uninstall
mov ax, 2509h
mov dx, [cs:original_handler_09_seg]
mov ds, dx
mov dx, [cs:original_handler_09]
int 21h
mov ax, 252Fh
push word [cs:original_handler_2F_seg]
pop ds
mov dx, [cs:original_handler_2F]
int 21h
mov ah, 49h
push cs
pop es
int 21h
pop ds
pop es
popa
mov al, 11h
iret
.cant_uninstall:
mov al, 10h
iret
.next:
jmp dword [cs:original_handler_2F]
original_handler_2F dw 0
original_handler_2F_seg dw 0
resident_end:
init:
cmp byte [82h], 'u'
je uninstal_request
mov ax, 0D300h
int 2Fh
cmp al, 0
je install
mov ah, 09h
mov dx, .already_installed_str
int 21h
ret
.already_installed_str db "Already installed.$"
install:
cli
mov ax, 3509h
int 21h
mov [original_handler_09_seg], es
mov [original_handler_09], bx
mov ax, 352Fh
int 21h
mov [original_handler_2F_seg], es
mov [original_handler_2F], bx
mov ax, 2509h
mov dx, handler_09
int 21h
mov ax, 252Fh
mov dx, handler_2F
int 21h
sti
mov ah, 09h
mov dx, .installed_str
int 21h
mov cx, cs
mov dx, resident_end
int 27h
ret
.installed_str db "Installed.$"
uninstal_request:
mov ax, 0D300h
int 2Fh
cmp al, 0
jne .not_installed_over
mov ah, 09h
mov dx, .not_installed_str
int 21h
ret
.not_installed_str db "Not installed.$"
.not_installed_over:
mov ax, 0D301h
int 2Fh
cmp al, 11h
jne .ok_over
mov ah, 09h
mov dx, .uninstalled_str
int 21h
ret
.uninstalled_str db "Uninstalled.$"
.ok_over:
mov ah, 09h
mov dx, .cant_uninstall_str
int 21h
ret
.cant_uninstall_str db "Cannot uninstall.$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment