How to read raw block from an USB storage device w

2019-02-16 23:34发布

问题:

I'm dealing with an USB storage device that contains a proprietary file system. So, I need to read these device's 512 bytes blocks to implement a viewer for this filesystem.

How should I go about this? Is there some material on it using Delphi?

回答1:

I hate components so here is some code

 var 
    RawMBR : array [0..511] of byte;
    btsIO  : DWORD;
 begin
  hDevice := CreateFile('\\.\PHYSICALDRIVE1', GENERIC_READ,
      FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
    if hDevice <> INVALID_HANDLE_VALUE then
    begin
      SetFilePointer(hDevice,512 * 0,nil,FILE_BEGIN); // replace 0 with sector that you wish to read
      ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
      CloseHandle(hDevice);
    end;
  end;


回答2:

Did you try RawDiskAccess component, source for Delphi 7 here



回答3:

Read it just like any other disk when doing a raw read access. You just need the first sector

For Delphi you can look at:

http://www.torry.net/pages.php?id=253

Physical Disk Access (may work for you) Raw Disk Access (may work for you) TDiskIO (too old, works only under w9x)



回答4:

We have RawDisk product which provides read and write access to raw partitions under XP, Vista and Windows 7 (there exist certain security restrictions when using Windows API and RawDisk lets you bypass those restrictions). Code is available for all versions of Delphi from Delphi 5 to Delphi XE (XE2 support will be added in a couple of days).