diff --git a/DICUI.Library/Utilities/Drive.cs b/DICUI.Library/Utilities/Drive.cs
index 594a99cd..183539bd 100644
--- a/DICUI.Library/Utilities/Drive.cs
+++ b/DICUI.Library/Utilities/Drive.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Linq;
using DICUI.Data;
namespace DICUI.Utilities
@@ -61,5 +62,39 @@ namespace DICUI.Utilities
this.InternalDriveType = driveType;
this.DriveInfo = driveInfo;
}
+
+ ///
+ /// Read a sector from the given drive
+ ///
+ /// Sector number
+ /// Byte array representing the sector, null on error
+ public byte[] ReadSector(long sector)
+ {
+ // Missing drive leter is not supported
+ if (string.IsNullOrEmpty(DriveInfo?.Name))
+ return null;
+
+ // We don't support negative sectors
+ if (sector < 0)
+ return null;
+
+ // Get the starting point
+ int sectorSize = 2048;
+ long start = sector * sectorSize;
+
+ // Try to read the sector from the device
+ try
+ {
+ var fs = File.OpenRead(@"\\?\E:");
+ fs.Seek(start, SeekOrigin.Begin);
+ byte[] buffer = new byte[sectorSize];
+ fs.Read(buffer, 0, sectorSize);
+ return buffer;
+ }
+ catch
+ {
+ return null;
+ }
+ }
}
}