-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadDisk.cs
More file actions
31 lines (26 loc) · 901 Bytes
/
ReadDisk.cs
File metadata and controls
31 lines (26 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.IO;
public static class ReadDisk
{
public static byte[] Read(string driveLetter, int sectorNumber)
{
int sectorSize = 512; // Standardgröße eines Sektors
string drivePath = $@"\\.\{driveLetter}:";
try
{
using (FileStream fs = new FileStream(drivePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
byte[] buffer = new byte[sectorSize];
fs.Seek(sectorNumber * sectorSize, SeekOrigin.Begin);
fs.Read(buffer, 0, sectorSize);
// Return the sector data and raw bytes
return buffer;
}
} catch (Exception ex)
{
// System error message popup
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
}