mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: All refactor in DiscImageChef.Decoders.
This commit is contained in:
@@ -31,10 +31,15 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscImageChef.Decoders.MMC
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "UnassignedField.Global")]
|
||||
public class CID
|
||||
{
|
||||
public byte Manufacturer;
|
||||
@@ -47,18 +52,18 @@ namespace DiscImageChef.Decoders.MMC
|
||||
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);
|
||||
@@ -72,22 +77,20 @@ namespace DiscImageChef.Decoders.MMC
|
||||
|
||||
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];
|
||||
cid.DeviceType = (byte)(response[1] & 0x03);
|
||||
tmp = new byte[6];
|
||||
CID cid = new CID
|
||||
{
|
||||
Manufacturer = response[0],
|
||||
DeviceType = (byte)(response[1] & 0x03),
|
||||
ProductRevision = response[9],
|
||||
ProductSerialNumber = BitConverter.ToUInt32(response, 10),
|
||||
ManufacturingDate = response[14],
|
||||
CRC = (byte)((response[15] & 0xFE) >> 1)
|
||||
};
|
||||
byte[] tmp = new byte[6];
|
||||
Array.Copy(response, 3, tmp, 0, 6);
|
||||
cid.ProductName = StringHandlers.CToString(tmp);
|
||||
cid.ProductRevision = response[9];
|
||||
cid.ProductSerialNumber = BitConverter.ToUInt32(response, 10);
|
||||
cid.ManufacturingDate = response[14];
|
||||
cid.CRC = (byte)((response[15] & 0xFE) >> 1);
|
||||
|
||||
return cid;
|
||||
}
|
||||
|
||||
@@ -31,10 +31,15 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscImageChef.Decoders.MMC
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
|
||||
public class CSD
|
||||
{
|
||||
public byte Structure;
|
||||
@@ -72,18 +77,18 @@ namespace DiscImageChef.Decoders.MMC
|
||||
public byte CRC;
|
||||
}
|
||||
|
||||
public partial class Decoders
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[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);
|
||||
@@ -97,47 +102,44 @@ namespace DiscImageChef.Decoders.MMC
|
||||
|
||||
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();
|
||||
|
||||
csd.Structure = (byte)((response[0] & 0xC0) >> 6);
|
||||
csd.Version = (byte)((response[0] & 0x3C) >> 2);
|
||||
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;
|
||||
csd.Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6));
|
||||
csd.ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3);
|
||||
csd.ReadCurrentAtVddMax = (byte)(response[8] & 0x07);
|
||||
csd.WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5);
|
||||
csd.WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2);
|
||||
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
|
||||
csd.EraseGroupSize = (byte)((response[10] & 0x7C) >> 2);
|
||||
csd.EraseGroupSizeMultiplier = (byte)(((response[10] & 0x03) << 3) + ((response[11] & 0xE0) >> 5));
|
||||
csd.WriteProtectGroupSize = (byte)(response[11] & 0x1F);
|
||||
csd.WriteProtectGroupEnable = (response[12] & 0x80) == 0x80;
|
||||
csd.DefaultECC = (byte)((response[12] & 0x60) >> 5);
|
||||
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.ContentProtection = (response[13] & 0x01) == 0x01;
|
||||
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.ECC = (byte)(response[14] & 0x03);
|
||||
csd.CRC = (byte)((response[15] & 0xFE) >> 1);
|
||||
|
||||
return csd;
|
||||
return new CSD
|
||||
{
|
||||
Structure = (byte)((response[0] & 0xC0) >> 6),
|
||||
Version = (byte)((response[0] & 0x3C) >> 2),
|
||||
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,
|
||||
Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6)),
|
||||
ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3),
|
||||
ReadCurrentAtVddMax = (byte)(response[8] & 0x07),
|
||||
WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5),
|
||||
WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2),
|
||||
SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7)),
|
||||
EraseGroupSize = (byte)((response[10] & 0x7C) >> 2),
|
||||
EraseGroupSizeMultiplier = (byte)(((response[10] & 0x03) << 3) + ((response[11] & 0xE0) >> 5)),
|
||||
WriteProtectGroupSize = (byte)(response[11] & 0x1F),
|
||||
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
|
||||
DefaultECC = (byte)((response[12] & 0x60) >> 5),
|
||||
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
|
||||
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
|
||||
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
|
||||
ContentProtection = (response[13] & 0x01) == 0x01,
|
||||
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),
|
||||
ECC = (byte)(response[14] & 0x03),
|
||||
CRC = (byte)((response[15] & 0xFE) >> 1)
|
||||
};
|
||||
}
|
||||
|
||||
public static string PrettifyCSD(CSD csd)
|
||||
|
||||
@@ -31,11 +31,16 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscImageChef.Decoders.MMC
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "UnassignedField.Global")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class ExtendedCSD
|
||||
{
|
||||
@@ -197,7 +202,10 @@ namespace DiscImageChef.Decoders.MMC
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)] public byte[] Reserved18;
|
||||
}
|
||||
|
||||
public partial class Decoders
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public static partial class Decoders
|
||||
{
|
||||
public static ExtendedCSD DecodeExtendedCSD(byte[] response)
|
||||
{
|
||||
|
||||
@@ -31,10 +31,15 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscImageChef.Decoders.MMC
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
|
||||
public class OCR
|
||||
{
|
||||
public bool PowerUp;
|
||||
@@ -58,42 +63,40 @@ namespace DiscImageChef.Decoders.MMC
|
||||
public bool OneSix;
|
||||
}
|
||||
|
||||
public partial class Decoders
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[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.AccessMode = (byte)((response & 0x60000000) >> 29);
|
||||
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.TwoSix = (response & 0x00004000) == 0x00004000;
|
||||
ocr.TwoFive = (response & 0x00002000) == 0x00002000;
|
||||
ocr.TwoFour = (response & 0x00001000) == 0x00001000;
|
||||
ocr.TwoThree = (response & 0x00000800) == 0x00000800;
|
||||
ocr.TwoTwo = (response & 0x00000400) == 0x00000400;
|
||||
ocr.TwoOne = (response & 0x00000200) == 0x00000200;
|
||||
ocr.TwoZero = (response & 0x00000100) == 0x00000100;
|
||||
ocr.OneSix = (response & 0x00000080) == 0x00000080;
|
||||
|
||||
return ocr;
|
||||
return new OCR
|
||||
{
|
||||
PowerUp = (response & 0x80000000) == 0x80000000,
|
||||
AccessMode = (byte)((response & 0x60000000) >> 29),
|
||||
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,
|
||||
TwoSix = (response & 0x00004000) == 0x00004000,
|
||||
TwoFive = (response & 0x00002000) == 0x00002000,
|
||||
TwoFour = (response & 0x00001000) == 0x00001000,
|
||||
TwoThree = (response & 0x00000800) == 0x00000800,
|
||||
TwoTwo = (response & 0x00000400) == 0x00000400,
|
||||
TwoOne = (response & 0x00000200) == 0x00000200,
|
||||
TwoZero = (response & 0x00000100) == 0x00000100,
|
||||
OneSix = (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)
|
||||
|
||||
@@ -34,12 +34,12 @@ namespace DiscImageChef.Decoders.MMC
|
||||
{
|
||||
public static class VendorString
|
||||
{
|
||||
public static string Prettify(byte MMCVendorID)
|
||||
public static string Prettify(byte mmcVendorId)
|
||||
{
|
||||
switch(MMCVendorID)
|
||||
switch(mmcVendorId)
|
||||
{
|
||||
case 0x15: return "Samsung";
|
||||
default: return $"Unknown manufacturer ID 0x{MMCVendorID:X2}";
|
||||
default: return $"Unknown manufacturer ID 0x{mmcVendorId:X2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user