Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read raw block from an USB storage device with Delphi?

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?

like image 435
ivarec Avatar asked Oct 19 '11 19:10

ivarec


People also ask

How to recover data from a RAW USB flash drive?

Steps to Recover Data from a RAW USB Flash Drive Another option is to make use of a data recovery tool like Disk Drill. This can be used to recover data in a variety of ways in a range of circumstances, including when a drive has gone RAW for some reason.

Can I read and write to a raw partition in Delphi?

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).

How do I know if my USB drive has turned raw?

#1 The most obvious symptom of a USB drive having turned RAW is that you will simply not be able to access any of the files you know are stored on it. If you look at the properties of the drive you are having problems with, you will see that the file system is RAW or – in some cases – the format may not be recognized at all.

What components do I need to run Delphi 2010?

You just need the first sector Physical Disk Access (may work for you) Raw Disk Access (may work for you) TDiskIO (too old, works only under w9x) Those components won't compile on Delphi 2010 (and probably all Delphis above 2009) and porting them is giving me a hard time.


2 Answers

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;
like image 171
opc0de Avatar answered Oct 05 '22 04:10

opc0de


Did you try RawDiskAccess component, source for Delphi 7 here

like image 29
Warren P Avatar answered Oct 05 '22 03:10

Warren P