code_junkie

Reading Unformatted Data

Nov 10th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. HANDLE drive = CreateFile(_T("\.PhysicalDrive0"), GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
  2. // error handling
  3. DWORD br = 0;
  4. DISK_GEOMETRY dg;
  5. DeviceIOControl(drive, IOCTL_DISK_GET_DRIVE_GEOMETRY, 0, 0, &dg, sizeof(dg), &br, 0);
  6. //
  7. LARGE_INTEGER pos;
  8. pos.QuadPart = static_cast<LONGLONG>(sectorToRead) * dg.BytesPerSector;
  9. SetFilePointerEx(drive, pos, 0, FILE_BEGIN);
  10. const bool success = ReadFile(drive, sectorData, dg.BytesPerSector, &br) && br == dg.BytesPerSector;
  11. //
  12. CloseHandle(drive);
  13.  
  14. DRIVE_LAYOUT_INFORMATION_EX dl;
  15. DeviceIOControl(drive, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, 0, 0, &dl, sizeof(dl), &br, 0);
  16. if(dl.PartitionStyle == PARTITION_STYLE_RAW)
  17. {
  18. // found correct disk
  19. }
Add Comment
Please, Sign In to add comment