REFACTOR: All refactor in DiscImageChef.Decoders.

This commit is contained in:
2017-12-22 02:04:18 +00:00
parent 7f829422a8
commit 49144eeb01
148 changed files with 2606 additions and 1939 deletions

View File

@@ -31,10 +31,14 @@
// ****************************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class CID
{
public byte Manufacturer;
@@ -46,18 +50,18 @@ namespace DiscImageChef.Decoders.SecureDigital
public byte CRC;
}
public partial class Decoders
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static CID DecodeCID(uint[] response)
{
if(response == null) return null;
if(response.Length != 4) return null;
if(response?.Length != 4) return null;
byte[] data = new byte[16];
byte[] tmp;
tmp = BitConverter.GetBytes(response[0]);
byte[] tmp = BitConverter.GetBytes(response[0]);
Array.Copy(tmp, 0, data, 0, 4);
tmp = BitConverter.GetBytes(response[1]);
Array.Copy(tmp, 0, data, 4, 4);
@@ -71,24 +75,22 @@ namespace DiscImageChef.Decoders.SecureDigital
public static CID DecodeCID(byte[] response)
{
if(response == null) return null;
if(response?.Length != 16) return null;
if(response.Length != 16) return null;
byte[] tmp;
CID cid = new CID();
cid.Manufacturer = response[0];
tmp = new byte[2];
CID cid = new CID
{
Manufacturer = response[0],
ProductRevision = response[8],
ProductSerialNumber = BitConverter.ToUInt32(response, 9),
ManufacturingDate = (ushort)(((response[13] & 0x0F) << 4) + response[14]),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
byte[] tmp = new byte[2];
Array.Copy(response, 1, tmp, 0, 2);
cid.ApplicationID = StringHandlers.CToString(tmp);
tmp = new byte[5];
Array.Copy(response, 3, tmp, 0, 5);
cid.ProductName = StringHandlers.CToString(tmp);
cid.ProductRevision = response[8];
cid.ProductSerialNumber = BitConverter.ToUInt32(response, 9);
cid.ManufacturingDate = (ushort)(((response[13] & 0x0F) << 4) + response[14]);
cid.CRC = (byte)((response[15] & 0xFE) >> 1);
return cid;
}

View File

@@ -31,10 +31,14 @@
// ****************************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class CSD
{
public byte Structure;
@@ -68,18 +72,17 @@ namespace DiscImageChef.Decoders.SecureDigital
public byte CRC;
}
public partial class Decoders
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static CSD DecodeCSD(uint[] response)
{
if(response == null) return null;
if(response.Length != 4) return null;
if(response?.Length != 4) return null;
byte[] data = new byte[16];
byte[] tmp;
tmp = BitConverter.GetBytes(response[0]);
byte[] tmp = BitConverter.GetBytes(response[0]);
Array.Copy(tmp, 0, data, 0, 4);
tmp = BitConverter.GetBytes(response[1]);
Array.Copy(tmp, 0, data, 4, 4);
@@ -93,22 +96,35 @@ namespace DiscImageChef.Decoders.SecureDigital
public static CSD DecodeCSD(byte[] response)
{
if(response == null) return null;
if(response?.Length != 16) return null;
if(response.Length != 16) return null;
CSD csd = new CSD
{
Structure = (byte)((response[0] & 0xC0) >> 6),
TAAC = response[1],
NSAC = response[2],
Speed = response[3],
Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4)),
ReadBlockLength = (byte)(response[5] & 0x0F),
ReadsPartialBlocks = (response[6] & 0x80) == 0x80,
WriteMisalignment = (response[6] & 0x40) == 0x40,
ReadMisalignment = (response[6] & 0x20) == 0x20,
DSRImplemented = (response[6] & 0x10) == 0x10,
EraseBlockEnable = (response[10] & 0x40) == 0x40,
EraseSectorSize = (byte)(((response[10] & 0x3F) << 1) + ((response[11] & 0x80) >> 7)),
WriteProtectGroupSize = (byte)(response[11] & 0x7F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
FileFormatGroup = (response[14] & 0x80) == 0x80,
Copy = (response[14] & 0x40) == 0x40,
PermanentWriteProtect = (response[14] & 0x20) == 0x20,
TemporaryWriteProtect = (response[14] & 0x10) == 0x10,
FileFormat = (byte)((response[14] & 0x0C) >> 2),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
CSD csd = new CSD();
csd.Structure = (byte)((response[0] & 0xC0) >> 6);
csd.TAAC = response[1];
csd.NSAC = response[2];
csd.Speed = response[3];
csd.Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4));
csd.ReadBlockLength = (byte)(response[5] & 0x0F);
csd.ReadsPartialBlocks = (response[6] & 0x80) == 0x80;
csd.WriteMisalignment = (response[6] & 0x40) == 0x40;
csd.ReadMisalignment = (response[6] & 0x20) == 0x20;
csd.DSRImplemented = (response[6] & 0x10) == 0x10;
if(csd.Structure == 0)
{
csd.Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6));
@@ -119,19 +135,6 @@ namespace DiscImageChef.Decoders.SecureDigital
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
}
else csd.Size = (uint)(((response[7] & 0x3F) << 16) + (response[8] << 8) + response[9]);
csd.EraseBlockEnable = (response[10] & 0x40) == 0x40;
csd.EraseSectorSize = (byte)(((response[10] & 0x3F) << 1) + ((response[11] & 0x80) >> 7));
csd.WriteProtectGroupSize = (byte)(response[11] & 0x7F);
csd.WriteProtectGroupEnable = (response[12] & 0x80) == 0x80;
csd.WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2);
csd.WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6));
csd.WritesPartialBlocks = (response[13] & 0x20) == 0x20;
csd.FileFormatGroup = (response[14] & 0x80) == 0x80;
csd.Copy = (response[14] & 0x40) == 0x40;
csd.PermanentWriteProtect = (response[14] & 0x20) == 0x20;
csd.TemporaryWriteProtect = (response[14] & 0x10) == 0x10;
csd.FileFormat = (byte)((response[14] & 0x0C) >> 2);
csd.CRC = (byte)((response[15] & 0xFE) >> 1);
return csd;
}

View File

@@ -31,10 +31,16 @@
// ****************************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnassignedField.Global")]
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class OCR
{
public bool PowerUp;
@@ -53,37 +59,34 @@ namespace DiscImageChef.Decoders.SecureDigital
public bool LowPower;
}
public partial class Decoders
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static OCR DecodeOCR(uint response)
{
OCR ocr = new OCR();
ocr.PowerUp = (response & 0x80000000) == 0x80000000;
ocr.CCS = (response & 0x40000000) == 0x40000000;
ocr.PowerUp = (response & 0x20000000) == 0x20000000;
ocr.OneEight = (response & 0x01000000) == 0x01000000;
ocr.ThreeFive = (response & 0x00800000) == 0x00800000;
ocr.ThreeFour = (response & 0x00400000) == 0x00400000;
ocr.ThreeThree = (response & 0x00200000) == 0x00200000;
ocr.ThreeTwo = (response & 0x00100000) == 0x00100000;
ocr.ThreeOne = (response & 0x00080000) == 0x00080000;
ocr.ThreeZero = (response & 0x00040000) == 0x00040000;
ocr.TwoNine = (response & 0x00020000) == 0x00020000;
ocr.TwoEight = (response & 0x00010000) == 0x00010000;
ocr.TwoSeven = (response & 0x00008000) == 0x00008000;
ocr.LowPower = (response & 0x00000080) == 0x00000080;
return ocr;
return new OCR
{
PowerUp = (response & 0x80000000) == 0x80000000,
CCS = (response & 0x40000000) == 0x40000000,
UHS = (response & 0x20000000) == 0x20000000,
OneEight = (response & 0x01000000) == 0x01000000,
ThreeFive = (response & 0x00800000) == 0x00800000,
ThreeFour = (response & 0x00400000) == 0x00400000,
ThreeThree = (response & 0x00200000) == 0x00200000,
ThreeTwo = (response & 0x00100000) == 0x00100000,
ThreeOne = (response & 0x00080000) == 0x00080000,
ThreeZero = (response & 0x00040000) == 0x00040000,
TwoNine = (response & 0x00020000) == 0x00020000,
TwoEight = (response & 0x00010000) == 0x00010000,
TwoSeven = (response & 0x00008000) == 0x00008000,
LowPower = (response & 0x00000080) == 0x00000080
};
}
public static OCR DecodeOCR(byte[] response)
{
if(response == null) return null;
if(response.Length != 4) return null;
return DecodeOCR(BitConverter.ToUInt32(response, 0));
return response?.Length != 4 ? null : DecodeOCR(BitConverter.ToUInt32(response, 0));
}
public static string PrettifyOCR(OCR ocr)

View File

@@ -31,10 +31,15 @@
// ****************************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class SCR
{
public byte Structure;
@@ -50,18 +55,17 @@ namespace DiscImageChef.Decoders.SecureDigital
public byte[] ManufacturerReserved;
}
public partial class Decoders
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static partial class Decoders
{
public static SCR DecodeSCR(uint[] response)
{
if(response == null) return null;
if(response.Length != 2) return null;
if(response?.Length != 2) return null;
byte[] data = new byte[8];
byte[] tmp;
tmp = BitConverter.GetBytes(response[0]);
byte[] tmp = BitConverter.GetBytes(response[0]);
Array.Copy(tmp, 0, data, 0, 4);
tmp = BitConverter.GetBytes(response[1]);
Array.Copy(tmp, 0, data, 4, 4);
@@ -71,22 +75,22 @@ namespace DiscImageChef.Decoders.SecureDigital
public static SCR DecodeSCR(byte[] response)
{
if(response == null) return null;
if(response?.Length != 8) return null;
if(response.Length != 8) return null;
SCR scr = new SCR();
scr.Structure = (byte)((response[0] & 0xF0) >> 4);
scr.Spec = (byte)(response[0] & 0x0F);
scr.DataStatusAfterErase = (response[1] & 0x80) == 0x80;
scr.Security = (byte)((response[1] & 0x70) >> 4);
scr.BusWidth = (byte)(response[1] & 0x0F);
scr.Spec3 = (response[2] & 0x80) == 0x80;
scr.ExtendedSecurity = (byte)((response[2] & 0x78) >> 3);
scr.Spec4 = (response[2] & 0x04) == 0x04;
scr.SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6));
scr.CommandSupport = (byte)(response[3] & 0x0F);
scr.ManufacturerReserved = new byte[4];
SCR scr = new SCR
{
Structure = (byte)((response[0] & 0xF0) >> 4),
Spec = (byte)(response[0] & 0x0F),
DataStatusAfterErase = (response[1] & 0x80) == 0x80,
Security = (byte)((response[1] & 0x70) >> 4),
BusWidth = (byte)(response[1] & 0x0F),
Spec3 = (response[2] & 0x80) == 0x80,
ExtendedSecurity = (byte)((response[2] & 0x78) >> 3),
Spec4 = (response[2] & 0x04) == 0x04,
SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)),
CommandSupport = (byte)(response[3] & 0x0F),
ManufacturerReserved = new byte[4]
};
Array.Copy(response, 4, scr.ManufacturerReserved, 0, 4);
return scr;

View File

@@ -34,12 +34,12 @@ namespace DiscImageChef.Decoders.SecureDigital
{
public static class VendorString
{
public static string Prettify(byte SDVendorID)
public static string Prettify(byte sdVendorId)
{
switch(SDVendorID)
switch(sdVendorId)
{
case 0xAA: return "QEMU";
default: return $"Unknown manufacturer ID 0x{SDVendorID:X2}";
default: return $"Unknown manufacturer ID 0x{sdVendorId:X2}";
}
}
}