對於一個項目,我想直接從DOS調用第一個硬盤上的MBR。我編寫了一個小型彙編程序,可以在0:7c00h的內存中加載MBR,並且可以遠程跳到它。我已將我的util安裝在(DOS)可啓動軟盤上。我試圖啓動的磁盤(HD0,0x80)上有一個TrueCrypt啓動加載器。當我在這個設置中運行該工具時,它會顯示TrueCrypt屏幕,但輸入密碼後會使系統崩潰。當我在一臺普通的WinXP機器上運行我的小巧工具(w00t.com)時,它似乎馬上崩潰。從DOS引導的MBR
顯然我忘記了BIOS通常所做的一些關鍵性的東西,我的猜測是一些微不足道的東西。有更好的裸機DOS和BIOS經驗的人能幫助我嗎?
繼承人我的代碼:
.MODEL tiny
.386
_TEXT SEGMENT USE16
INCLUDE BootDefs.i
ORG 100h
start:
; http://vxheavens.com/lib/vbw05.html
; Before DOS has booted the BIOS stores the amount of usable lower memory
; in a word located at 0:413h in memory. We going to erase this value because
; we have booted dos before loading the bootsector, and dos is fat (and ugly).
; fake free memory
;push ds
;push 0
;pop ds
;mov ax, TC_BOOT_LOADER_SEGMENT/1024 * 16 + TC_BOOT_MEMORY_REQUIRED
;mov word ptr ds:[413h], ax ;ax = memory in K
;pop ds
;lea si, memory_patched_msg
;call print
;mov ax, cs
mov ax, 0
mov es, ax
; read first sector to es:7c00h (== cs:7c00)
mov dl, 80h
mov cl, 1
mov al, 1
mov bx, 7c00h ;load sector to es:bx
call read_sectors
lea si, mbr_loaded_msg
call print
lea si, jmp_to_mbr_msg
call print
;Set BIOS default values in environment
cli
mov dl, 80h ;(drive C)
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0ffffh
sti
push es
push 7c00h
retf ;Jump to MBR code at 0:7c00h
; Print string
print:
xor bx, bx
mov ah, 0eh
cld
@@: lodsb
test al, al
jz print_end
int 10h
jmp @B
print_end:
ret
; Read sectors of the first cylinder
read_sectors:
mov ch, 0 ; Cylinder
mov dh, 0 ; Head
; DL = drive number passed from BIOS
mov ah, 2
int 13h
jnc read_ok
lea si, disk_error_msg
call print
read_ok:
ret
memory_patched_msg db 'Memory patched', 13, 10, 7, 0
mbr_loaded_msg db 'MBR loaded', 13, 10, 7, 0
jmp_to_mbr_msg db 'Jumping to MBR code', 13, 10, 7, 0
disk_error_msg db 'Disk error', 13, 10, 7, 0
_TEXT ENDS
END start
這確實是一個COM文件,所以這是個爲什麼它在100H ORGed。就像其他任何.com文件一樣。它將MBR加載到mem並跳轉到。 正如你可以在我最初的問題中看到的那樣,它實際上完成了這項工作:TrueCrypt引導程序開始並顯示正確的屏幕。所以加載和跳躍的作品。 只有在那之後,電腦纔會凍結。有些東西一定是錯的,也許環境設置不正確? – Rogier 2010-04-14 22:16:08
如果磁盤上的TrueCrypt引導加載程序實際上指望使用普通的.com文件,那麼ORG 100h應該不成問題。否則,我認爲這是一個錯誤。 - 其次,在Windows XP下執行時,程序崩潰並不奇怪。當計算機第一次啓動時,CPU處於實模式(8086模擬),引導加載程序期望這一點。一旦Windows XP啓動後,CPU將永遠不會回到實模式。 DOS程序可能會在所謂的虛擬8086模式下執行(如果我記得名稱正確),並且引導加載程序將不能在該CPU模式下工作。 – stakx 2010-04-15 06:29:25
不,即使將bootloader加載到地址0:7c00,在Windows(XP)中也無法使用此實用程序。你不能直接從窗口訪問磁盤,你不能只在內存中尋找機會。 但請閱讀我的問題,我從軟盤(映像)運行的工具,即它在DOS,16位實模式下運行。此外其實部分已經部分完成了工作;啓動TC Bootloader GETS並顯示「Welcome to TC,請輸入passsword」屏幕。只有在它之後,它纔會發生。 Ergo在BIOS通常設置的環境中一定有問題。 – Rogier 2010-04-15 07:10:26