diff --git a/DiscImageChef.Devices/Windows/ListDevices.cs b/DiscImageChef.Devices/Windows/ListDevices.cs index 16f0d3bee..c987ea6f0 100644 --- a/DiscImageChef.Devices/Windows/ListDevices.cs +++ b/DiscImageChef.Devices/Windows/ListDevices.cs @@ -41,6 +41,19 @@ namespace DiscImageChef.Devices.Windows { static class ListDevices { + internal static string HexStringToString(string hex) + { + StringBuilder result = new StringBuilder(); + const string hextable = "0123456789abcdef"; + + for (int i = 0; i < hex.Length / 2; i++) + { + result.Append((char)(16 * hextable.IndexOf(hex[2 * i]) + hextable.IndexOf(hex[2 * i + 1]))); + } + + return result.ToString(); + } + internal static DeviceInfo[] GetList() { List deviceIDs = new List(); @@ -130,11 +143,20 @@ namespace DiscImageChef.Devices.Windows info.Model = StringHandlers.CToString(descriptorB, Encoding.ASCII, start: (int)descriptor.ProductIdOffset); // TODO: Get serial number of SCSI and USB devices, probably also FireWire (untested) - if(descriptor.SerialNumberOffset > 0) + if (descriptor.SerialNumberOffset > 0) + { info.Serial = StringHandlers.CToString(descriptorB, Encoding.ASCII, start: (int)descriptor.SerialNumberOffset); + // fix any serial numbers that are returned as hex-strings + if (Array.TrueForAll(info.Serial.ToCharArray(), (char c) => "0123456789abcdef".IndexOf(c) >= 0) + && (info.Serial.Length == 40)) + { + info.Serial = HexStringToString(info.Serial).Trim(); + } + } + if(string.IsNullOrEmpty(info.Vendor) || info.Vendor == "ATA") { string[] pieces = info.Model.Split(' ');