首页  编辑  

绝对磁盘读取

Tags: /超级猛料/Hardware.硬件相关/驱动器相关/   Date Created:

读、写Win2K的分区表

给你个读的例子,写的没敢试验,因为我只有一个HD.[:D]

procedure TForm1.Button1Click(Sender: TObject);

var  hFile:THandle ;

    bytesread:DWORD;

    buf: array[0..511] of char ;

    Security: TSecurityAttributes;

begin

hFile:=CreateFile('\\.\PhysicalDrive0',GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, nil ,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);

 if hFile=INVALID_HANDLE_VALUE then

 begin

   ShowMessage('No file exists yet.' );

   Exit;

 end;

 if not  ReadFile(hFile, buf, sizeof(buf), bytesread, nil) then showmessage('Error');

end;

*****************

我曾经用C++ BUILDER 编写如下的程序来读区物理磁盘的绝对扇区,对软盘可用,但对硬盘不管用

不知问题出在哪里,请各位指教:

void __fastcall TForm1::Button1Click(TObject *Sender)

{

       DWORD w;

       int v;

       hDevice=CreateFile("\\\\.\\VWIN32",GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,

       NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

       if(hDevice!=NULL)

       {  w=1;

          w=w<<8;

          v=0x80;

          reg.reg_EAX=0x440D;

          reg.reg_EBX=v|w;

          reg.reg_ECX=0x084B;

          reg.reg_EDX=1;

          reg.reg_Flags=0x0001;

         fresult=DeviceIoControl(hDevice,VWIN32_DIOC_DOS_IOCTL,?,sizeof(reg),?,sizeof(reg),&cb1,0);

          if(!fresult||(reg.reg_Flags & 0x0001))

             ShowMessage("Fail1");

          reg.reg_EAX=0x0201; //读硬盘的0面0柱面1扇区,数量为一扇区.

          reg.reg_EBX=(DWORD)&boot; //定义为 BYTE boot[512];

          reg.reg_ECX=0x0001;//

          reg.reg_EDX=v;

          reg.reg_Flags=0x0001;

          fresult=DeviceIoControl(hDevice,VWIN32_DIOC_DOS_INT13,?,sizeof(reg),?,sizeof(reg),&cb1,0);

          if(!fresult||(reg.reg_Flags & 0x0001))

             ShowMessage("Fail2");

          Edit2->Text=AnsiString(boot[StrToInt(Edit1->Text)]);

          reg.reg_EAX=0x440d;

          reg.reg_EBX=v;

          reg.reg_ECX=0x086b;

          reg.reg_Flags=0x0001;

          DeviceIoControl(hDevice,VWIN32_DIOC_DOS_IOCTL,?,sizeof(reg),?,sizeof(reg),&cb1,0);

          if(!fresult||(reg.reg_Flags & 0x0001))

             ShowMessage("Fail3");

       }

}