Hi! I've instaled on my box WinXP and Win98, but i've lost a file named BootSect.DOS that is located
on the root of the drive. And from the informations that i've this file is the boot sector of Win98.
The current MBR of the drive is the one of WinXP OS. Since i've another box on my house with Win98
OS only, i've the idea to create a bootsector "dumper". This is my first program coded to be used on
MS-DOS, so don't blame me if it is like shit. Soo first i try to use INT 13h,2:


MOV AH,02h
MOV AL,01h
MOV CX,1
MOV DH,0
MOV DL,1000000b ;harddrive num is 0 (C:)
MOV BX,OFFSET BootSector
INT 13h
JC _Error2

Acording with Ralph INT list: "under Windows95, a volume must be locked (see INT 21/AX==440Dh/CX=084Bh)
in order to perform direct accesses such as INT 13h reads writes."
The INT 21h,440Dh uses a few tables, but there is no another method??

I don't know if there is some port that can do it, coz i don't have any port list file explaning
something about the port and is number...
I've tried all the methods (that i know about them) to get MBR of a HD without success. The only thing
that i could do was get the boot sector of a diskette on drive a. And yes i've tryed all the methods
on MS-DOS not DOS on Windows ambient.
BOOTSEC.ZIP... (example from m$) i've downloaded but when i try to build it i got 3 errors. It uses
the same method that my first try (see on source code).

Remeber that my main objective, is to read the MBR (or boot sector) of a HardDrive, in a way
soo i can write it on a file.

Thanks!

Regards, jean (Coder7345)

PS: sorry my bad english...


;########### Source code start, i use TASM 5.0 to compile it #########
;########### tasm xxxx | tlink /t xxxx #########

.MODEL TINY
; .STACK 100h
; .286
.code
MAIN SEGMENT
ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
ORG 100h
Start:

; Reset Disk System (if i do this, INT 21,7305 returns error, else it don't,
; but the BootSection goes empty...)

MOV AX,440Dh
MOV CX,084Bh
INT 13h

;----- 1st Try
MOV AX,0201h
MOV CX,00000001b ;Sector number (1-...) & High two bits of cylinder
MOV DH,0 ;Head number
MOV DL,1000000b ;Drive (80h=HD1,...)
MOV BX,OFFSET BootSector ;data buffer
INT 13h ;DISK READ SECTOR(S) INTO MEMORY
JC _Error2

;----- 2nd Try
; MOV CX,-1 ; must be
; MOV AL,2 ;DriveNumber (0=A, 1=B, 2=C)
; LEA BX,dio ;Disk I/O packet (DS)
; LEA DI,BootSector
; MOV bso,DI ;Save
; INT 25h ;ABSOLUTE DISK READ (32M-2047M hard-disk partition)
; JC _Error2

;----- 3th Try
; MOV AX,7305h
; MOV CX,0FFFFh ;must be
; MOV DL,02h ;drive number (0=default, 1=a, 2=b,...)
; MOV SI,0 ;read/write mode flags
; LEA BX,dio
; LEA DI,BootSector
; MOV bso,DI
; INT 21h ;Win95 - FAT32 - Extended Absolute Disk Read/Write
; JC _Error2

; Create file

MOV AH,03Ch
MOV CX,000h
MOV DX,OFFSET BootFile
INT 21h ; Create File using Handle
JC _Error ; Error ocurred

; Write BootSector to file

MOV DI,AX ;Save file handle so we can close it later

MOV BX,AX
MOV AH,40h
MOV CX,200h
MOV DX,OFFSET BootSector
INT 21h

MOV BX,DI
MOV AX,3E00h
INT 21h

Exit: INT 20h

_Error:
MOV AH,09h
MOV DX,OFFSET Error
INT 21h
MOV AH,00h
INT 21h

_Error2:
MOV AH,09h
MOV DX,OFFSET Error2
INT 21h
MOV AH,00h
INT 21h


Error db "Error$",0
Error2 db "Error on INT !$"
dio dd 1
dw 1
dw 0
bso dw 0 ;OFFSET BootSector
BootFile db "bootfile.bin",0
BootSector db 200h dup(0)
MAIN ENDS
END Start
Posted on 2002-01-03 17:35:42 by coder
Try looking at this thread, it might help:
http://www.asmcommunity.net/board/index.php?topic=1936&highlight=flat+thunk

Under NT kernels, you can get harddrive access in a very convenient
way - through CreateFile. You can open devices like \\.\PHYSICALDRIVE0
or \\.\C: - this makes it very very easy to extract boot sectors :).
Posted on 2002-01-03 18:50:41 by f0dder
i heard alot about DPMI services in windows but how to
use them? i wanted to write the same prog, too... it would
be nice if it's written win32_compatible without vxd's or dll's.
Posted on 2002-01-04 03:17:26 by mob
I only think you can use the DPMI services from 9x, and that does
have a bit hacky feel to it. As a lot of 9x stuff ;). And on NT kernels,
the createfile method works like a charm (haven't tested writing
yet, but I can't see why it wouldn't work when you have admin privileges).
Posted on 2002-01-04 03:23:39 by f0dder
don't worry it works nice on NT... 'think it's a great loss
that this is not win32 compatible :(
Posted on 2002-01-04 03:41:59 by mob
It *is* win32 compatible - too bad win9x isn't :).
Posted on 2002-01-04 03:47:56 by f0dder
I never looked at it carefully but i heard somewhere that DeviceIOControl can be useful to do those things under 9x

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/hardware/devio_89ph.asp

may be a start.

*EDIT*

I've just seen that DeviceIOControl need an handle from CreateFile... so the problem seems to be the same :(
Posted on 2002-01-04 04:44:23 by JCP
coder7345,

here we go:

the attached program i wrote read the MBR, but work only on 95/98.
It need a 16 bit dll, where i call DPMI int31h to emulate int13h service42 (read sectors as LBA) that i've also coded.

Use Tools>EditSector to see how it works.

It's not finished yet but, let me know if could be useful.
On my site you'll find a tutorial about the method i've used. I've posted also the code, if you need i can send the complete project.

Bye B7
Posted on 2002-01-04 07:48:29 by Bit7
ok, lets begin...

f0dder, i forget to talk about portability, in this progy i don't care it it is to work on DOS or on Win9x, it work? cool... but anyway it is a interesting way! ;)

mob, i never heard anything about DPMI services... u know something about them?

readiosys, deviceIOControl... ummm (coz of that handle....)

Bit7, i've not test that progy yet but when i try it i tell u something. About your tutor, i'ven't read it yet to, i take a quick look on it, and from what i see it uses Int 13h service 42h (large disk reading), and i try it to on my DOS proggy (i've forggoten to put that method/try) without success. But maybe i found the problem with this source code. Thanks for it :)

god coding times...

jean/coder7345
Posted on 2002-01-04 17:30:42 by Unregistered
If you want, I made a prog that activate a partition, it reads in the mbr with int13, it checks if it's correct, then it can update it and write in the mbr with int13 too. But under W98 or/and W95 (don't remember) it is protected, you can't write in the mbr directly, you have to reboot to DOS mode and then execute your exe.

There is also winhex that can write in the mbr and it shows you how the mbr works. But it's a shareware ;) . You can go to : http://www.winhex.com
Posted on 2002-01-06 03:47:37 by Vom-bonjour:-()
I believe you can get int13 disk access under 9x if you do a "lock"
before launching your app. I know there's a way to do the lock
programatically (I've seen an app that does it), and this information
is probably in Ralph Brown's interrupt list. Again, this is 9x only, and
would only work from a dos app.
Posted on 2002-01-06 03:55:54 by f0dder
f0dder, i know what is the INT to lock but i don't know (for now) how to use it. It is INT 25 i think. I go try to use it to lock and next i try to read the MBR.

Vom-bonjour, if the prog u have can read the mbr of a HD... ok it will help me if u let me see the source. Long time ago i've downloaded that prog (winhex) but i don't know that it could read mbrs.... i will check it.

regards, jean (coder7345)
Posted on 2002-01-06 16:04:54 by coder
Vom-bonjour writing such thing in dos is easy but
in windows you can't use the normal way coz you're
in protected mode... well, a win32 compatible way to
do this would be really great.

hm elicz wrote a prog that uses VWIN32 to access MBR
but i don't know if it's the same as DPMI... the prog is
called absdisk9xII and it's in his export\trash2.zip.
Posted on 2002-01-07 03:10:57 by mob
vwin32 code would also be 9x-only if I'm not mistaken. You probably
can't create a universal version, so just do GetVersion checks. Use
whatever is cleanest on 9x, and the wonderful clean CreateFile
under NT kernels (with proper checks for the administrative rights
required to do this - or at least handle CreateFile returning INVALID_HANDLE_VALUE ;) ).
Posted on 2002-01-07 04:59:34 by f0dder
Well it seems that i've found the problem on my INT 13h call.
It was a segment register problem, since it is my first DOS app
i don't have care about segment registers, but i think that
this one is not commly used (ES). The interrupt gets the buffer
address with ES:BX. Btw f0dder, i try to use "Lock" ints, in
Windows9x it works as it works without it, on DOS.... let me
check...ummm... nop... under DOS it "cannot" lock the HD. The INT
return an error. WinHex is a kinda strange program, since it
don't use any private VxD or DLL. Bit7 your program works fine
but when i save the file to my HD it save the text inside the
EDITBOX not the real HEX bytez of the sector :)

On WinXP the INTs to read/write directly to HD does work.
At least on DOS programs. A private VxD sould resolve this
problem (with an ExE loader with GUI look of curse).
Label Iczelion's VxD tut is a very close way, than the VxD
will be. If some one is writing a sector reader... by me
i write a VxD to work on Win9x platforms, and for WinNT
i will use the method that f0dder tell:

CreateFile("\\.\C:",....)
something like this, check MSDN.

My DOS COM source is here coz someone can need it to learn
something or even maybe fix is HD MBR problem... :)
(151 bytes... i think it could be smaller, without error
messages it is +/- 55 bytes)

I've writen a mbr writer to, since is not such difrence.

cyas, Jean/Coder7345
Posted on 2002-01-08 09:55:01 by coder