Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model tiny
  2. .code
  3. org 100h
  4.  
  5. start:
  6.   call read_args
  7.   jmp methods
  8.  
  9. ; resident
  10. handler proc far
  11.     cmp al, 0
  12.     jne handler_cmd
  13.     mov ax, 'DS'
  14.   mov bx, cs
  15.     iret
  16.   ; command to handler
  17.     handler_cmd:
  18.     cmp al, 1
  19.     je uninstall_handler
  20.     cmp al, 2
  21.     je kill_2fh
  22.     iret
  23.     uninstall_handler:
  24.     push ds ; backup
  25.     push 0
  26.     pop ds
  27.     mov ax, cs
  28.     cmp ax, word ptr ds:[2fh*4 + 2]
  29.     jne uninstall_failed
  30.     pop ds ; restore
  31.     jmp kill_2fh
  32.   uninstall_failed:
  33.     mov al, 'F'
  34.     pop ds ; restore
  35.     iret
  36.     kill_2fh:
  37.     push es ; s
  38.     push ds ; a
  39.     push ax ; v
  40.     push dx ; e
  41.   ; restore old handler
  42.   mov   ax, 252fh
  43.     mov dx, word ptr cs:[old_2fh]
  44.     mov ds, word ptr cs:[old_2fh + 2]
  45.     int 21h
  46.   ; free allocated
  47.     mov es, cs:2ch
  48.     mov ah, 49h
  49.     int 21h
  50.     push cs
  51.     pop es
  52.     mov ah, 49h
  53.     int 21h
  54.   ; restore
  55.   pop   dx
  56.     pop ax
  57.     pop ds
  58.     pop es
  59.     iret
  60. handler endp
  61.  
  62. write_addr proc
  63.   mov ax, ds
  64.   mov es, ax
  65.   mov di, dx
  66.   mov cl, 12
  67. mov_loop:
  68.   mov ax, bx
  69.   shr ax, cl
  70.   and ax, 0fh
  71.   cmp ax, 0ah
  72.   jl digit
  73.   add ax, 07h
  74. digit:
  75.   add ax, 30h
  76.   stosb
  77.   sub cl, 04h
  78.   jns mov_loop
  79.   ret
  80. write_addr endp
  81.  
  82. read_args proc
  83.   mov si, 81h
  84.   xor dx, dx
  85.   read:
  86.   lodsb
  87.   lea bx, letters
  88.   xlat
  89.   lea bx, automaton
  90.   add al, dh
  91.   xlat
  92.   cmp al, 09h
  93.   jge end_args
  94.   mov ah, 09h
  95.   mul ah
  96.   mov dh, al
  97.   jmp read
  98.   end_args:
  99.   ret
  100. read_args endp
  101.  
  102. methods:
  103. cmp al, 09h
  104. je help
  105. cmp al, 0ch
  106. je install
  107. cmp al, 0ah
  108. je kill
  109. cmp al, 0bh
  110. je state
  111. cmp al, 0dh
  112. je rm_handler
  113. jmp usage
  114.  
  115. install:
  116.   mov ax, 0
  117.   int 2fh
  118.   cmp ax, 'DS'
  119.   je installed_already
  120.   ; get vector 2f
  121.   mov   ax, 352fh
  122.   int   21h
  123.   mov   [old_2fh], bx
  124.   mov   [old_2fh + 2], es
  125.   ; set handler
  126.   mov   ah, 25h
  127.   lea   dx, handler
  128.   int   21h
  129.   lea   dx, write_addr
  130.   int   27h
  131. jmp no_errors
  132.  
  133. kill:
  134.   mov ax, 0
  135.   int 2fh
  136.   cmp ax, 'DS'
  137.   jne not_installed
  138.   mov al, 2
  139.   int 2fh
  140. jmp no_errors
  141.  
  142. state:
  143.   mov ax, 0
  144.   int 2fh
  145.   cmp ax, 'DS'
  146.   jne not_installed
  147.   lea dx, place_msg
  148.   call write_addr
  149.   lea dx, inmem_msg
  150. jmp output
  151.  
  152. rm_handler:
  153.   mov ax, 0
  154.   int 2fh
  155.   cmp ax, 'DS'
  156.   jne not_installed
  157.   mov al, 1
  158.   int 2fh
  159.   cmp al, 'F'
  160.   je not_in_top
  161. jmp no_errors
  162.  
  163. ; outputs
  164. help:
  165.   lea dx, full_help
  166.   jmp output
  167. usage:
  168.   lea dx, tiny_help
  169.   jmp output
  170. installed_already:
  171.   lea dx, sorry_msg
  172.   jmp output
  173. not_installed:
  174.   lea dx, not_inmem
  175.   jmp output
  176. not_in_top:
  177.   lea dx, enot_last
  178.   jmp output
  179. no_errors:
  180.   lea dx, ok_messag
  181. output:
  182.   mov ax, 0900h
  183.   int 21h
  184.   ret
  185.  
  186.     old_2fh   dw ?, ?
  187.     tiny_help db 10, 'I did anything. Try call me with -h', 10, '$'
  188.     full_help db 10, 'Use:  resident_evil [-h i k s u]', 10, 10
  189.               db ' -h   show how to use this useless program (This message)', 10
  190.               db ' -i   inject me to memory       -u   purge me from memory', 10
  191.               db ' -k   kill me without mercy     -s   show how I am living', 10, '$'
  192.     sorry_msg db 'Sorry, I am sleeping in memory', '$'
  193.     inmem_msg db 'I am in memory: '
  194.     place_msg dd ?
  195.               db '$'
  196.     not_inmem db 'I am not in memory', '$'
  197.     enot_last db 'Sorry, I am not last', '$'
  198.     ok_messag db 'Everything went smoothly', '$'
  199.  
  200.     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)
  201.  
  202.     automaton db 0, 0, 0, 0, 0, 0, 1,  15, 0
  203.               db 2, 0, 0, 0, 0, 0, 1,  15, 0
  204.               db 0, 3, 4, 5, 6, 7, 1,  15, 0
  205.               db 0, 0, 0, 0, 0, 0, 9,  9,  0
  206.               db 0, 0, 0, 0, 0, 0, 10, 10, 0
  207.               db 0, 0, 0, 0, 0, 0, 11, 11, 0
  208.               db 0, 0, 0, 0, 0, 0, 12, 12, 0
  209.               db 0, 0, 0, 0, 0, 0, 13, 13, 0
  210.  
  211. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement