Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model tiny
- .code
- org 100h
- start:
- call read_args
- jmp methods
- ; resident
- handler proc far
- cmp al, 0
- jne handler_cmd
- mov ax, 'DS'
- mov bx, cs
- iret
- ; command to handler
- handler_cmd:
- cmp al, 1
- je uninstall_handler
- cmp al, 2
- je kill_2fh
- iret
- uninstall_handler:
- push ds ; backup
- push 0
- pop ds
- mov ax, cs
- cmp ax, word ptr ds:[2fh*4 + 2]
- jne uninstall_failed
- pop ds ; restore
- jmp kill_2fh
- uninstall_failed:
- mov al, 'F'
- pop ds ; restore
- iret
- kill_2fh:
- push es ; s
- push ds ; a
- push ax ; v
- push dx ; e
- ; restore old handler
- mov ax, 252fh
- mov dx, word ptr cs:[old_2fh]
- mov ds, word ptr cs:[old_2fh + 2]
- int 21h
- ; free allocated
- mov es, cs:2ch
- mov ah, 49h
- int 21h
- push cs
- pop es
- mov ah, 49h
- int 21h
- ; restore
- pop dx
- pop ax
- pop ds
- pop es
- iret
- handler endp
- write_addr proc
- mov ax, ds
- mov es, ax
- mov di, dx
- mov cl, 12
- mov_loop:
- mov ax, bx
- shr ax, cl
- and ax, 0fh
- cmp ax, 0ah
- jl digit
- add ax, 07h
- digit:
- add ax, 30h
- stosb
- sub cl, 04h
- jns mov_loop
- ret
- write_addr endp
- read_args proc
- mov si, 81h
- xor dx, dx
- read:
- lodsb
- lea bx, letters
- xlat
- lea bx, automaton
- add al, dh
- xlat
- cmp al, 09h
- jge end_args
- mov ah, 09h
- mul ah
- mov dh, al
- jmp read
- end_args:
- ret
- read_args endp
- methods:
- cmp al, 09h
- je help
- cmp al, 0ch
- je install
- cmp al, 0ah
- je kill
- cmp al, 0bh
- je state
- cmp al, 0dh
- je rm_handler
- jmp usage
- install:
- mov ax, 0
- int 2fh
- cmp ax, 'DS'
- je installed_already
- ; get vector 2f
- mov ax, 352fh
- int 21h
- mov [old_2fh], bx
- mov [old_2fh + 2], es
- ; set handler
- mov ah, 25h
- lea dx, handler
- int 21h
- lea dx, write_addr
- int 27h
- jmp no_errors
- kill:
- mov ax, 0
- int 2fh
- cmp ax, 'DS'
- jne not_installed
- mov al, 2
- int 2fh
- jmp no_errors
- state:
- mov ax, 0
- int 2fh
- cmp ax, 'DS'
- jne not_installed
- lea dx, place_msg
- call write_addr
- lea dx, inmem_msg
- jmp output
- rm_handler:
- mov ax, 0
- int 2fh
- cmp ax, 'DS'
- jne not_installed
- mov al, 1
- int 2fh
- cmp al, 'F'
- je not_in_top
- jmp no_errors
- ; outputs
- help:
- lea dx, full_help
- jmp output
- usage:
- lea dx, tiny_help
- jmp output
- installed_already:
- lea dx, sorry_msg
- jmp output
- not_installed:
- lea dx, not_inmem
- jmp output
- not_in_top:
- lea dx, enot_last
- jmp output
- no_errors:
- lea dx, ok_messag
- output:
- mov ax, 0900h
- int 21h
- ret
- old_2fh dw ?, ?
- tiny_help db 10, 'I did anything. Try call me with -h', 10, '$'
- full_help db 10, 'Use: resident_evil [-h i k s u]', 10, 10
- db ' -h show how to use this useless program (This message)', 10
- db ' -i inject me to memory -u purge me from memory', 10
- db ' -k kill me without mercy -s show how I am living', 10, '$'
- sorry_msg db 'Sorry, I am sleeping in memory', '$'
- inmem_msg db 'I am in memory: '
- place_msg dd ?
- db '$'
- not_inmem db 'I am not in memory', '$'
- enot_last db 'Sorry, I am not last', '$'
- ok_messag db 'Everything went smoothly', '$'
- letters db 13 dup(8), 7, 18 dup(8), 6, 12 dup(8), 0, 58 dup(8), 1, 4, 8, 2, 7 dup(8), 3, 8, 5, 10 dup(8)
- automaton db 0, 0, 0, 0, 0, 0, 1, 15, 0
- db 2, 0, 0, 0, 0, 0, 1, 15, 0
- db 0, 3, 4, 5, 6, 7, 1, 15, 0
- db 0, 0, 0, 0, 0, 0, 9, 9, 0
- db 0, 0, 0, 0, 0, 0, 10, 10, 0
- db 0, 0, 0, 0, 0, 0, 11, 11, 0
- db 0, 0, 0, 0, 0, 0, 12, 12, 0
- db 0, 0, 0, 0, 0, 0, 13, 13, 0
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement