mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: Reformat code.
This commit is contained in:
@@ -50,11 +50,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
{
|
||||
public static CID DecodeCID(uint[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
if(response == null) return null;
|
||||
|
||||
if(response.Length != 4)
|
||||
return null;
|
||||
if(response.Length != 4) return null;
|
||||
|
||||
byte[] data = new byte[16];
|
||||
byte[] tmp = new byte[4];
|
||||
@@ -73,11 +71,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static CID DecodeCID(byte[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
if(response == null) return null;
|
||||
|
||||
if(response.Length != 16)
|
||||
return null;
|
||||
if(response.Length != 16) return null;
|
||||
|
||||
byte[] tmp;
|
||||
|
||||
@@ -99,8 +95,7 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static string PrettifyCID(CID cid)
|
||||
{
|
||||
if(cid == null)
|
||||
return null;
|
||||
if(cid == null) return null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -108,9 +103,11 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
sb.AppendFormat("\tManufacturer: {0}", VendorString.Prettify(cid.Manufacturer)).AppendLine();
|
||||
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 revision: {0:X2}.{1:X2}", (cid.ProductRevision & 0xF0) >> 4,
|
||||
cid.ProductRevision & 0x0F).AppendLine();
|
||||
sb.AppendFormat("\tProduct serial number: {0}", cid.ProductSerialNumber).AppendLine();
|
||||
sb.AppendFormat("\tDevice manufactured month {0} of {1}", (cid.ManufacturingDate & 0xF00) >> 8, (cid.ManufacturingDate & 0xFF) + 2000).AppendLine();
|
||||
sb.AppendFormat("\tDevice manufactured month {0} of {1}", (cid.ManufacturingDate & 0xF00) >> 8,
|
||||
(cid.ManufacturingDate & 0xFF) + 2000).AppendLine();
|
||||
sb.AppendFormat("\tCID CRC: 0x{0:X2}", cid.CRC).AppendLine();
|
||||
|
||||
return sb.ToString();
|
||||
@@ -126,4 +123,4 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
return PrettifyCID(DecodeCID(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,11 +72,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
{
|
||||
public static CSD DecodeCSD(uint[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
if(response == null) return null;
|
||||
|
||||
if(response.Length != 4)
|
||||
return null;
|
||||
if(response.Length != 4) return null;
|
||||
|
||||
byte[] data = new byte[16];
|
||||
byte[] tmp = new byte[4];
|
||||
@@ -95,11 +93,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static CSD DecodeCSD(byte[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
if(response == null) return null;
|
||||
|
||||
if(response.Length != 16)
|
||||
return null;
|
||||
if(response.Length != 16) return null;
|
||||
|
||||
CSD csd = new CSD();
|
||||
|
||||
@@ -122,8 +118,7 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
csd.WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2);
|
||||
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
|
||||
}
|
||||
else
|
||||
csd.Size = (uint)(((response[7] & 0x3F) << 16) + (response[8] << 8) + response[9]);
|
||||
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));
|
||||
@@ -143,8 +138,7 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static string PrettifyCSD(CSD csd)
|
||||
{
|
||||
if(csd == null)
|
||||
return null;
|
||||
if(csd == null) return null;
|
||||
|
||||
double unitFactor = 0;
|
||||
double multiplier = 0;
|
||||
@@ -250,6 +244,7 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
multiplier = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
result = unitFactor * multiplier;
|
||||
sb.AppendFormat("\tAsynchronous data access time is {0}{1}", result, unit).AppendLine();
|
||||
|
||||
@@ -327,29 +322,25 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
multiplier = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
result = unitFactor * multiplier;
|
||||
sb.AppendFormat("\tDevice's transfer speed: {0}{1}", result, unit).AppendLine();
|
||||
|
||||
unit = "";
|
||||
for(int cl = 0, mask = 1; cl <= 11; cl++, mask <<= 1)
|
||||
{
|
||||
if((csd.Classes & mask) == mask)
|
||||
unit += string.Format(" {0}", cl);
|
||||
if((csd.Classes & mask) == mask) unit += string.Format(" {0}", cl);
|
||||
}
|
||||
|
||||
sb.AppendFormat("\tDevice support command classes {0}", unit).AppendLine();
|
||||
sb.AppendFormat("\tRead block length is {0} bytes", Math.Pow(2, csd.ReadBlockLength)).AppendLine();
|
||||
|
||||
if(csd.ReadsPartialBlocks)
|
||||
sb.AppendLine("\tDevice allows reading partial blocks");
|
||||
if(csd.ReadsPartialBlocks) sb.AppendLine("\tDevice allows reading partial blocks");
|
||||
|
||||
if(csd.WriteMisalignment)
|
||||
sb.AppendLine("\tWrite commands can cross physical block boundaries");
|
||||
if(csd.ReadMisalignment)
|
||||
sb.AppendLine("\tRead commands can cross physical block boundaries");
|
||||
if(csd.WriteMisalignment) sb.AppendLine("\tWrite commands can cross physical block boundaries");
|
||||
if(csd.ReadMisalignment) sb.AppendLine("\tRead commands can cross physical block boundaries");
|
||||
|
||||
if(csd.DSRImplemented)
|
||||
sb.AppendLine("\tDevice implements configurable driver stage");
|
||||
if(csd.DSRImplemented) sb.AppendLine("\tDevice implements configurable driver stage");
|
||||
|
||||
if(csd.Structure == 0)
|
||||
{
|
||||
@@ -357,14 +348,10 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
sb.AppendFormat("\tDevice has {0} blocks", (int)result).AppendLine();
|
||||
|
||||
result = (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2) * Math.Pow(2, csd.ReadBlockLength);
|
||||
if(result > 1073741824)
|
||||
sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
|
||||
else if(result > 1048576)
|
||||
sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
|
||||
else if(result > 1024)
|
||||
sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
|
||||
else
|
||||
sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
|
||||
if(result > 1073741824) sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
|
||||
else if(result > 1048576) sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
|
||||
else if(result > 1024) sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
|
||||
else sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -374,12 +361,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
sb.AppendFormat("\tDevice has {0} TiB", result / 1099511627776.0).AppendLine();
|
||||
else if(result > 1073741824)
|
||||
sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
|
||||
else if(result > 1048576)
|
||||
sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
|
||||
else if(result > 1024)
|
||||
sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
|
||||
else
|
||||
sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
|
||||
else if(result > 1048576) sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
|
||||
else if(result > 1024) sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
|
||||
else sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
|
||||
}
|
||||
|
||||
if(csd.Structure == 0)
|
||||
@@ -496,39 +480,35 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(csd.EraseBlockEnable)
|
||||
sb.AppendLine("\tDevice can erase multiple blocks");
|
||||
if(csd.EraseBlockEnable) sb.AppendLine("\tDevice can erase multiple blocks");
|
||||
|
||||
// TODO: Check specification
|
||||
sb.AppendFormat("\tDevice must erase a minimum of {0} blocks at a time", Convert.ToUInt32(csd.EraseSectorSize) + 1).AppendLine();
|
||||
sb.AppendFormat("\tDevice must erase a minimum of {0} blocks at a time",
|
||||
Convert.ToUInt32(csd.EraseSectorSize) + 1).AppendLine();
|
||||
|
||||
if(csd.WriteProtectGroupEnable)
|
||||
{
|
||||
sb.AppendLine("\tDevice can write protect regions");
|
||||
// TODO: Check specification
|
||||
unitFactor = Convert.ToDouble(csd.WriteProtectGroupSize);
|
||||
sb.AppendFormat("\tDevice can write protect a minimum of {0} blocks at a time", (int)(result + 1)).AppendLine();
|
||||
sb.AppendFormat("\tDevice can write protect a minimum of {0} blocks at a time", (int)(result + 1))
|
||||
.AppendLine();
|
||||
}
|
||||
else
|
||||
sb.AppendLine("\tDevice can't write protect regions");
|
||||
else sb.AppendLine("\tDevice can't write protect regions");
|
||||
}
|
||||
|
||||
sb.AppendFormat("\tWriting is {0} times slower than reading", Math.Pow(2, csd.WriteSpeedFactor)).AppendLine();
|
||||
sb.AppendFormat("\tWriting is {0} times slower than reading", Math.Pow(2, csd.WriteSpeedFactor))
|
||||
.AppendLine();
|
||||
|
||||
sb.AppendFormat("\tWrite block length is {0} bytes", Math.Pow(2, csd.WriteBlockLength)).AppendLine();
|
||||
|
||||
if(csd.WritesPartialBlocks)
|
||||
sb.AppendLine("\tDevice allows writing partial blocks");
|
||||
if(csd.WritesPartialBlocks) sb.AppendLine("\tDevice allows writing partial blocks");
|
||||
|
||||
if(!csd.Copy)
|
||||
sb.AppendLine("\tDevice contents are original");
|
||||
if(!csd.Copy) sb.AppendLine("\tDevice contents are original");
|
||||
|
||||
if(csd.PermanentWriteProtect)
|
||||
sb.AppendLine("\tDevice is permanently write protected");
|
||||
if(csd.PermanentWriteProtect) sb.AppendLine("\tDevice is permanently write protected");
|
||||
|
||||
if(csd.TemporaryWriteProtect)
|
||||
sb.AppendLine("\tDevice is temporarily write protected");
|
||||
if(csd.TemporaryWriteProtect) sb.AppendLine("\tDevice is temporarily write protected");
|
||||
|
||||
if(!csd.FileFormatGroup)
|
||||
{
|
||||
@@ -549,7 +529,8 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
}
|
||||
}
|
||||
else
|
||||
sb.AppendFormat("\tDevice uses unknown file format code {0} and file format group 1", csd.FileFormat).AppendLine();
|
||||
sb.AppendFormat("\tDevice uses unknown file format code {0} and file format group 1", csd.FileFormat)
|
||||
.AppendLine();
|
||||
|
||||
sb.AppendFormat("\tCSD CRC: 0x{0:X2}", csd.CRC).AppendLine();
|
||||
|
||||
@@ -566,4 +547,4 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
return PrettifyCSD(DecodeCSD(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,48 +79,32 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static OCR DecodeOCR(byte[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
if(response == null) return null;
|
||||
|
||||
if(response.Length != 4)
|
||||
return null;
|
||||
if(response.Length != 4) return null;
|
||||
|
||||
return DecodeOCR(BitConverter.ToUInt32(response, 0));
|
||||
}
|
||||
|
||||
public static string PrettifyOCR(OCR ocr)
|
||||
{
|
||||
if(ocr == null)
|
||||
return null;
|
||||
if(ocr == null) return null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("SecureDigital Operation Conditions Register:");
|
||||
if(!ocr.PowerUp)
|
||||
sb.AppendLine("\tDevice is powering up");
|
||||
if(ocr.CCS)
|
||||
sb.AppendLine("\tDevice is SDHC, SDXC or higher");
|
||||
if(ocr.UHS)
|
||||
sb.AppendLine("\tDevice is UHS-II or higher");
|
||||
if(ocr.ThreeFive)
|
||||
sb.AppendLine("\tDevice can work with supply 3.5~3.6V");
|
||||
if(ocr.ThreeFour)
|
||||
sb.AppendLine("\tDevice can work with supply 3.4~3.5V");
|
||||
if(ocr.ThreeThree)
|
||||
sb.AppendLine("\tDevice can work with supply 3.3~3.4V");
|
||||
if(ocr.ThreeTwo)
|
||||
sb.AppendLine("\tDevice can work with supply 3.2~3.3V");
|
||||
if(ocr.ThreeOne)
|
||||
sb.AppendLine("\tDevice can work with supply 3.1~3.2V");
|
||||
if(ocr.TwoNine)
|
||||
sb.AppendLine("\tDevice can work with supply 2.9~3.0V");
|
||||
if(ocr.TwoEight)
|
||||
sb.AppendLine("\tDevice can work with supply 2.8~2.9V");
|
||||
if(ocr.TwoSeven)
|
||||
sb.AppendLine("\tDevice can work with supply 2.7~2.8V");
|
||||
if(ocr.OneEight)
|
||||
sb.AppendLine("\tDevice can switch to work with 1.8V supply");
|
||||
if(ocr.LowPower)
|
||||
sb.AppendLine("\tDevice is in low power mode");
|
||||
if(!ocr.PowerUp) sb.AppendLine("\tDevice is powering up");
|
||||
if(ocr.CCS) sb.AppendLine("\tDevice is SDHC, SDXC or higher");
|
||||
if(ocr.UHS) sb.AppendLine("\tDevice is UHS-II or higher");
|
||||
if(ocr.ThreeFive) sb.AppendLine("\tDevice can work with supply 3.5~3.6V");
|
||||
if(ocr.ThreeFour) sb.AppendLine("\tDevice can work with supply 3.4~3.5V");
|
||||
if(ocr.ThreeThree) sb.AppendLine("\tDevice can work with supply 3.3~3.4V");
|
||||
if(ocr.ThreeTwo) sb.AppendLine("\tDevice can work with supply 3.2~3.3V");
|
||||
if(ocr.ThreeOne) sb.AppendLine("\tDevice can work with supply 3.1~3.2V");
|
||||
if(ocr.TwoNine) sb.AppendLine("\tDevice can work with supply 2.9~3.0V");
|
||||
if(ocr.TwoEight) sb.AppendLine("\tDevice can work with supply 2.8~2.9V");
|
||||
if(ocr.TwoSeven) sb.AppendLine("\tDevice can work with supply 2.7~2.8V");
|
||||
if(ocr.OneEight) sb.AppendLine("\tDevice can switch to work with 1.8V supply");
|
||||
if(ocr.LowPower) sb.AppendLine("\tDevice is in low power mode");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -135,4 +119,4 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
return PrettifyOCR(DecodeOCR(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
{
|
||||
public static SCR DecodeSCR(uint[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
if(response == null) return null;
|
||||
|
||||
if(response.Length != 2)
|
||||
return null;
|
||||
if(response.Length != 2) return null;
|
||||
|
||||
byte[] data = new byte[8];
|
||||
byte[] tmp = new byte[4];
|
||||
@@ -73,11 +71,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static SCR DecodeSCR(byte[] response)
|
||||
{
|
||||
if(response == null)
|
||||
return null;
|
||||
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);
|
||||
@@ -98,14 +94,12 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
|
||||
public static string PrettifySCR(SCR scr)
|
||||
{
|
||||
if(scr == null)
|
||||
return null;
|
||||
if(scr == null) return null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("SecureDigital Device Configuration Register:");
|
||||
|
||||
if(scr.Structure != 0)
|
||||
sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine();
|
||||
if(scr.Structure != 0) sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine();
|
||||
|
||||
if(scr.Spec == 0 && scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0)
|
||||
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.0x");
|
||||
@@ -120,8 +114,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
else if(scr.Spec == 2 && scr.Spec3 == true && scr.SpecX == 1)
|
||||
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 5.xx");
|
||||
else
|
||||
sb.AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
|
||||
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();
|
||||
sb
|
||||
.AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
|
||||
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();
|
||||
switch(scr.Security)
|
||||
{
|
||||
case 0:
|
||||
@@ -140,26 +135,22 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
sb.AppendLine("\tDevice uses CPRM according to specification version 3.xx");
|
||||
break;
|
||||
default:
|
||||
sb.AppendFormat("\tDevice uses unknown CPRM specification with code {0}", scr.Security).AppendLine();
|
||||
sb.AppendFormat("\tDevice uses unknown CPRM specification with code {0}", scr.Security)
|
||||
.AppendLine();
|
||||
break;
|
||||
}
|
||||
|
||||
if((scr.BusWidth & 0x01) == 0x01)
|
||||
sb.AppendLine("\tDevice supports 1-bit data bus");
|
||||
if((scr.BusWidth & 0x04) == 0x04)
|
||||
sb.AppendLine("\tDevice supports 4-bit data bus");
|
||||
if((scr.BusWidth & 0x01) == 0x01) sb.AppendLine("\tDevice supports 1-bit data bus");
|
||||
if((scr.BusWidth & 0x04) == 0x04) sb.AppendLine("\tDevice supports 4-bit data bus");
|
||||
|
||||
if(scr.ExtendedSecurity != 0)
|
||||
sb.AppendLine("\tDevice supports extended security");
|
||||
if(scr.ExtendedSecurity != 0) sb.AppendLine("\tDevice supports extended security");
|
||||
|
||||
if((scr.CommandSupport & 0x08) == 0x08)
|
||||
sb.AppendLine("\tDevice supports extension register multi-block commands");
|
||||
if((scr.CommandSupport & 0x04) == 0x04)
|
||||
sb.AppendLine("\tDevice supports extension register single-block commands");
|
||||
if((scr.CommandSupport & 0x02) == 0x02)
|
||||
sb.AppendLine("\tDevice supports set block count command");
|
||||
if((scr.CommandSupport & 0x01) == 0x01)
|
||||
sb.AppendLine("\tDevice supports speed class control command");
|
||||
if((scr.CommandSupport & 0x02) == 0x02) sb.AppendLine("\tDevice supports set block count command");
|
||||
if((scr.CommandSupport & 0x01) == 0x01) sb.AppendLine("\tDevice supports speed class control command");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -174,4 +165,4 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
return PrettifySCR(DecodeSCR(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,11 +38,9 @@ namespace DiscImageChef.Decoders.SecureDigital
|
||||
{
|
||||
switch(SDVendorID)
|
||||
{
|
||||
case 0xAA:
|
||||
return "QEMU";
|
||||
default:
|
||||
return string.Format("Unknown manufacturer ID 0x{0:X2}", SDVendorID);
|
||||
case 0xAA: return "QEMU";
|
||||
default: return string.Format("Unknown manufacturer ID 0x{0:X2}", SDVendorID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user