Move to file scoped namespaces.

This commit is contained in:
2022-03-06 13:29:37 +00:00
parent c7178d94c6
commit 3b6091c02c
119 changed files with 38048 additions and 38172 deletions

View File

@@ -35,180 +35,179 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Helpers;
namespace Aaru.Decoders.MMC
namespace Aaru.Decoders.MMC;
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "UnassignedField.Global")]
public class CID
{
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "UnassignedField.Global")]
public class CID
public byte ApplicationID;
public byte CRC;
public byte DeviceType;
public byte Manufacturer;
public byte ManufacturingDate;
public string ProductName;
public byte ProductRevision;
public uint ProductSerialNumber;
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static CID DecodeCID(uint[] response)
{
public byte ApplicationID;
public byte CRC;
public byte DeviceType;
public byte Manufacturer;
public byte ManufacturingDate;
public string ProductName;
public byte ProductRevision;
public uint ProductSerialNumber;
if(response?.Length != 4)
return null;
byte[] data = new byte[16];
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);
tmp = BitConverter.GetBytes(response[2]);
Array.Copy(tmp, 0, data, 8, 4);
tmp = BitConverter.GetBytes(response[3]);
Array.Copy(tmp, 0, data, 12, 4);
return DecodeCID(data);
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
public static CID DecodeCID(byte[] response)
{
public static CID DecodeCID(uint[] response)
if(response?.Length != 16)
return null;
var cid = new CID
{
if(response?.Length != 4)
return null;
Manufacturer = response[0],
DeviceType = (byte)(response[1] & 0x03),
ProductRevision = response[9],
ProductSerialNumber = Swapping.Swap(BitConverter.ToUInt32(response, 10)),
ManufacturingDate = response[14],
CRC = (byte)((response[15] & 0xFE) >> 1)
};
byte[] data = new byte[16];
byte[] tmp = new byte[6];
Array.Copy(response, 3, tmp, 0, 6);
cid.ProductName = StringHandlers.CToString(tmp);
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);
tmp = BitConverter.GetBytes(response[2]);
Array.Copy(tmp, 0, data, 8, 4);
tmp = BitConverter.GetBytes(response[3]);
Array.Copy(tmp, 0, data, 12, 4);
return DecodeCID(data);
}
public static CID DecodeCID(byte[] response)
{
if(response?.Length != 16)
return null;
var cid = new CID
{
Manufacturer = response[0],
DeviceType = (byte)(response[1] & 0x03),
ProductRevision = response[9],
ProductSerialNumber = Swapping.Swap(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);
return cid;
}
public static string PrettifyCID(CID cid)
{
if(cid == null)
return null;
var sb = new StringBuilder();
sb.AppendLine("MultiMediaCard Device Identification Register:");
sb.AppendFormat("\tManufacturer: {0}", VendorString.Prettify(cid.Manufacturer)).AppendLine();
switch(cid.DeviceType)
{
case 0:
sb.AppendLine("\tRemovable device");
break;
case 1:
sb.AppendLine("\tBGA device");
break;
case 2:
sb.AppendLine("\tPOP device");
break;
}
sb.AppendFormat("\tApplication ID: {0}", cid.ApplicationID).AppendLine();
sb.AppendFormat("\tProduct name: {0}", cid.ProductName).AppendLine();
sb.AppendFormat("\tProduct revision: {0:X2}.{1:X2}", (cid.ProductRevision & 0xF0) >> 4,
cid.ProductRevision & 0x0F).AppendLine();
sb.AppendFormat("\tProduct serial number: {0}", cid.ProductSerialNumber).AppendLine();
string year = "";
switch(cid.ManufacturingDate & 0x0F)
{
case 0:
year = "1997 or 2013";
break;
case 1:
year = "1998 or 2014";
break;
case 2:
year = "1999 or 2015";
break;
case 3:
year = "2000 or 2016";
break;
case 4:
year = "2001 or 2017";
break;
case 5:
year = "2002 or 2018";
break;
case 6:
year = "2003 or 2019";
break;
case 7:
year = "2004 or 2020";
break;
case 8:
year = "2005 or 2021";
break;
case 9:
year = "2006 or 2022";
break;
case 10:
year = "2007 or 2023";
break;
case 11:
year = "2008 or 2024";
break;
case 12:
year = "2009 or 2025";
break;
case 13:
year = "2010";
break;
case 14:
year = "2011";
break;
case 15:
year = "2012";
break;
}
sb.AppendFormat("\tDevice manufactured month {0} of {1}", (cid.ManufacturingDate & 0xF0) >> 4, year).
AppendLine();
sb.AppendFormat("\tCID CRC: 0x{0:X2}", cid.CRC).AppendLine();
return sb.ToString();
}
public static string PrettifyCID(uint[] response) => PrettifyCID(DecodeCID(response));
public static string PrettifyCID(byte[] response) => PrettifyCID(DecodeCID(response));
return cid;
}
public static string PrettifyCID(CID cid)
{
if(cid == null)
return null;
var sb = new StringBuilder();
sb.AppendLine("MultiMediaCard Device Identification Register:");
sb.AppendFormat("\tManufacturer: {0}", VendorString.Prettify(cid.Manufacturer)).AppendLine();
switch(cid.DeviceType)
{
case 0:
sb.AppendLine("\tRemovable device");
break;
case 1:
sb.AppendLine("\tBGA device");
break;
case 2:
sb.AppendLine("\tPOP device");
break;
}
sb.AppendFormat("\tApplication ID: {0}", cid.ApplicationID).AppendLine();
sb.AppendFormat("\tProduct name: {0}", cid.ProductName).AppendLine();
sb.AppendFormat("\tProduct revision: {0:X2}.{1:X2}", (cid.ProductRevision & 0xF0) >> 4,
cid.ProductRevision & 0x0F).AppendLine();
sb.AppendFormat("\tProduct serial number: {0}", cid.ProductSerialNumber).AppendLine();
string year = "";
switch(cid.ManufacturingDate & 0x0F)
{
case 0:
year = "1997 or 2013";
break;
case 1:
year = "1998 or 2014";
break;
case 2:
year = "1999 or 2015";
break;
case 3:
year = "2000 or 2016";
break;
case 4:
year = "2001 or 2017";
break;
case 5:
year = "2002 or 2018";
break;
case 6:
year = "2003 or 2019";
break;
case 7:
year = "2004 or 2020";
break;
case 8:
year = "2005 or 2021";
break;
case 9:
year = "2006 or 2022";
break;
case 10:
year = "2007 or 2023";
break;
case 11:
year = "2008 or 2024";
break;
case 12:
year = "2009 or 2025";
break;
case 13:
year = "2010";
break;
case 14:
year = "2011";
break;
case 15:
year = "2012";
break;
}
sb.AppendFormat("\tDevice manufactured month {0} of {1}", (cid.ManufacturingDate & 0xF0) >> 4, year).
AppendLine();
sb.AppendFormat("\tCID CRC: 0x{0:X2}", cid.CRC).AppendLine();
return sb.ToString();
}
public static string PrettifyCID(uint[] response) => PrettifyCID(DecodeCID(response));
public static string PrettifyCID(byte[] response) => PrettifyCID(DecodeCID(response));
}

1209
MMC/CSD.cs

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -35,148 +35,147 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Helpers;
namespace Aaru.Decoders.MMC
namespace Aaru.Decoders.MMC;
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class OCR
{
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class OCR
public byte AccessMode;
public bool OneSix;
public bool PowerUp;
public bool ThreeFive;
public bool ThreeFour;
public bool ThreeOne;
public bool ThreeThree;
public bool ThreeTwo;
public bool ThreeZero;
public bool TwoEight;
public bool TwoFive;
public bool TwoFour;
public bool TwoNine;
public bool TwoOne;
public bool TwoSeven;
public bool TwoSix;
public bool TwoThree;
public bool TwoTwo;
public bool TwoZero;
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static OCR DecodeOCR(uint response)
{
public byte AccessMode;
public bool OneSix;
public bool PowerUp;
public bool ThreeFive;
public bool ThreeFour;
public bool ThreeOne;
public bool ThreeThree;
public bool ThreeTwo;
public bool ThreeZero;
public bool TwoEight;
public bool TwoFive;
public bool TwoFour;
public bool TwoNine;
public bool TwoOne;
public bool TwoSeven;
public bool TwoSix;
public bool TwoThree;
public bool TwoTwo;
public bool TwoZero;
response = Swapping.Swap(response);
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
};
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
public static OCR DecodeOCR(byte[] response) =>
response?.Length != 4 ? null : DecodeOCR(BitConverter.ToUInt32(response, 0));
public static string PrettifyOCR(OCR ocr)
{
public static OCR DecodeOCR(uint response)
{
response = Swapping.Swap(response);
if(ocr == null)
return null;
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
};
var sb = new StringBuilder();
sb.AppendLine("MultiMediaCard Operation Conditions Register:");
if(!ocr.PowerUp)
sb.AppendLine("\tDevice is powering up");
switch(ocr.AccessMode)
{
case 0:
sb.AppendLine("\tDevice is byte addressed");
break;
case 2:
sb.AppendLine("\tDevice is sector addressed");
break;
default:
sb.AppendFormat("\tUnknown device access mode {0}", ocr.AccessMode).AppendLine();
break;
}
public static OCR DecodeOCR(byte[] response) =>
response?.Length != 4 ? null : DecodeOCR(BitConverter.ToUInt32(response, 0));
if(ocr.ThreeFive)
sb.AppendLine("\tDevice can work with supply 3.5~3.6V");
public static string PrettifyOCR(OCR ocr)
{
if(ocr == null)
return null;
if(ocr.ThreeFour)
sb.AppendLine("\tDevice can work with supply 3.4~3.5V");
var sb = new StringBuilder();
sb.AppendLine("MultiMediaCard Operation Conditions Register:");
if(ocr.ThreeThree)
sb.AppendLine("\tDevice can work with supply 3.3~3.4V");
if(!ocr.PowerUp)
sb.AppendLine("\tDevice is powering up");
if(ocr.ThreeTwo)
sb.AppendLine("\tDevice can work with supply 3.2~3.3V");
switch(ocr.AccessMode)
{
case 0:
sb.AppendLine("\tDevice is byte addressed");
if(ocr.ThreeOne)
sb.AppendLine("\tDevice can work with supply 3.1~3.2V");
break;
case 2:
sb.AppendLine("\tDevice is sector addressed");
if(ocr.TwoNine)
sb.AppendLine("\tDevice can work with supply 2.9~3.0V");
break;
default:
sb.AppendFormat("\tUnknown device access mode {0}", ocr.AccessMode).AppendLine();
if(ocr.TwoEight)
sb.AppendLine("\tDevice can work with supply 2.8~2.9V");
break;
}
if(ocr.TwoSeven)
sb.AppendLine("\tDevice can work with supply 2.7~2.8V");
if(ocr.ThreeFive)
sb.AppendLine("\tDevice can work with supply 3.5~3.6V");
if(ocr.TwoSix)
sb.AppendLine("\tDevice can work with supply 2.6~2.7V");
if(ocr.ThreeFour)
sb.AppendLine("\tDevice can work with supply 3.4~3.5V");
if(ocr.TwoFive)
sb.AppendLine("\tDevice can work with supply 2.5~2.6V");
if(ocr.ThreeThree)
sb.AppendLine("\tDevice can work with supply 3.3~3.4V");
if(ocr.TwoFour)
sb.AppendLine("\tDevice can work with supply 2.4~2.5V");
if(ocr.ThreeTwo)
sb.AppendLine("\tDevice can work with supply 3.2~3.3V");
if(ocr.TwoThree)
sb.AppendLine("\tDevice can work with supply 2.3~2.4V");
if(ocr.ThreeOne)
sb.AppendLine("\tDevice can work with supply 3.1~3.2V");
if(ocr.TwoTwo)
sb.AppendLine("\tDevice can work with supply 2.2~2.3V");
if(ocr.TwoNine)
sb.AppendLine("\tDevice can work with supply 2.9~3.0V");
if(ocr.TwoOne)
sb.AppendLine("\tDevice can work with supply 2.1~2.2V");
if(ocr.TwoEight)
sb.AppendLine("\tDevice can work with supply 2.8~2.9V");
if(ocr.TwoZero)
sb.AppendLine("\tDevice can work with supply 2.0~2.1V");
if(ocr.TwoSeven)
sb.AppendLine("\tDevice can work with supply 2.7~2.8V");
if(ocr.OneSix)
sb.AppendLine("\tDevice can work with supply 1.65~1.95V");
if(ocr.TwoSix)
sb.AppendLine("\tDevice can work with supply 2.6~2.7V");
if(ocr.TwoFive)
sb.AppendLine("\tDevice can work with supply 2.5~2.6V");
if(ocr.TwoFour)
sb.AppendLine("\tDevice can work with supply 2.4~2.5V");
if(ocr.TwoThree)
sb.AppendLine("\tDevice can work with supply 2.3~2.4V");
if(ocr.TwoTwo)
sb.AppendLine("\tDevice can work with supply 2.2~2.3V");
if(ocr.TwoOne)
sb.AppendLine("\tDevice can work with supply 2.1~2.2V");
if(ocr.TwoZero)
sb.AppendLine("\tDevice can work with supply 2.0~2.1V");
if(ocr.OneSix)
sb.AppendLine("\tDevice can work with supply 1.65~1.95V");
return sb.ToString();
}
public static string PrettifyOCR(byte[] response) => PrettifyOCR(DecodeOCR(response));
public static string PrettifyOCR(uint response) => PrettifyOCR(DecodeOCR(response));
return sb.ToString();
}
public static string PrettifyOCR(byte[] response) => PrettifyOCR(DecodeOCR(response));
public static string PrettifyOCR(uint response) => PrettifyOCR(DecodeOCR(response));
}

View File

@@ -30,20 +30,19 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.MMC
namespace Aaru.Decoders.MMC;
/// <summary>Decodes MultiMediaCard vendors</summary>
public static class VendorString
{
/// <summary>Decodes MultiMediaCard vendors</summary>
public static class VendorString
/// <summary>Converts the byte value of a MultiMediaCard vendor ID to the manufacturer's name string</summary>
/// <param name="mmcVendorId">MMC vendor ID</param>
/// <returns>Manufacturer</returns>
public static string Prettify(byte mmcVendorId) => mmcVendorId switch
{
/// <summary>Converts the byte value of a MultiMediaCard vendor ID to the manufacturer's name string</summary>
/// <param name="mmcVendorId">MMC vendor ID</param>
/// <returns>Manufacturer</returns>
public static string Prettify(byte mmcVendorId) => mmcVendorId switch
{
0x07 => "Nokia",
0x15 => "Samsung",
0x2C => "extreMEmory",
_ => $"Unknown manufacturer ID 0x{mmcVendorId:X2}"
};
}
0x07 => "Nokia",
0x15 => "Samsung",
0x2C => "extreMEmory",
_ => $"Unknown manufacturer ID 0x{mmcVendorId:X2}"
};
}