mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Added tests for SecureDigital commands.
This commit is contained in:
@@ -51,7 +51,9 @@ namespace DiscImageChef.Tests.Devices.SecureDigital
|
||||
DicConsole.WriteLine("Send a SecureDigital command to the device:");
|
||||
DicConsole.WriteLine("1.- Send SD_SEND_OP_COND command.");
|
||||
DicConsole.WriteLine("2.- Send SD_STATUS command.");
|
||||
DicConsole.WriteLine("3.- Send SEND_SCR command.");
|
||||
DicConsole.WriteLine("3.- Send SEND_CID command.");
|
||||
DicConsole.WriteLine("4.- Send SEND_CSD command.");
|
||||
DicConsole.WriteLine("5.- Send SEND_SCR command.");
|
||||
DicConsole.WriteLine("0.- Return to SecureDigital/MultiMediaCard commands menu.");
|
||||
DicConsole.Write("Choose: ");
|
||||
|
||||
@@ -68,6 +70,21 @@ namespace DiscImageChef.Tests.Devices.SecureDigital
|
||||
case 0:
|
||||
DicConsole.WriteLine("Returning to SecureDigital/MultiMediaCard commands menu...");
|
||||
return;
|
||||
case 1:
|
||||
SendOpCond(devPath, dev);
|
||||
continue;
|
||||
case 2:
|
||||
Status(devPath, dev);
|
||||
continue;
|
||||
case 3:
|
||||
SendCID(devPath, dev);
|
||||
continue;
|
||||
case 4:
|
||||
SendCSD(devPath, dev);
|
||||
continue;
|
||||
case 5:
|
||||
SendSCR(devPath, dev);
|
||||
continue;
|
||||
default:
|
||||
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
@@ -75,5 +92,414 @@ namespace DiscImageChef.Tests.Devices.SecureDigital
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SendOpCond(string devPath, Device dev)
|
||||
{
|
||||
start:
|
||||
System.Console.Clear();
|
||||
bool sense = dev.ReadSDOCR(out byte[] buffer, out uint[] response, dev.Timeout, out double duration);
|
||||
|
||||
menu:
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("Sending SD_SEND_OP_COND to the device:");
|
||||
DicConsole.WriteLine("Command took {0} ms.", duration);
|
||||
DicConsole.WriteLine("Sense is {0}.", sense);
|
||||
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
|
||||
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
|
||||
DicConsole.WriteLine("Response has {0} elements.", response == null ? "null" : response.Length.ToString());
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Choose what to do:");
|
||||
DicConsole.WriteLine("1.- Print buffer.");
|
||||
DicConsole.WriteLine("2.- Decode buffer.");
|
||||
DicConsole.WriteLine("3.- Print response buffer.");
|
||||
DicConsole.WriteLine("4.- Send command again.");
|
||||
DicConsole.WriteLine("0.- Return to SecureDigital commands menu.");
|
||||
DicConsole.Write("Choose: ");
|
||||
|
||||
string strDev = System.Console.ReadLine();
|
||||
if(!int.TryParse(strDev, out int item))
|
||||
{
|
||||
DicConsole.WriteLine("Not a number. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
|
||||
switch(item)
|
||||
{
|
||||
case 0:
|
||||
DicConsole.WriteLine("Returning to SecureDigital commands menu...");
|
||||
return;
|
||||
case 1:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SD_SEND_OP_COND buffer:");
|
||||
if(buffer != null)
|
||||
PrintHex.PrintHexArray(buffer, 64);
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 2:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SD_SEND_OP_COND decoded buffer:");
|
||||
if(buffer != null)
|
||||
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifyOCR(buffer));
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 3:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SD_SEND_OP_COND response:");
|
||||
if(response != null)
|
||||
{
|
||||
foreach(uint res in response)
|
||||
DicConsole.Write("0x{0:x8} ", res);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 4:
|
||||
goto start;
|
||||
default:
|
||||
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void Status(string devPath, Device dev)
|
||||
{
|
||||
start:
|
||||
System.Console.Clear();
|
||||
bool sense = dev.ReadSDStatus(out byte[] buffer, out uint[] response, dev.Timeout, out double duration);
|
||||
|
||||
menu:
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("Sending SD_STATUS to the device:");
|
||||
DicConsole.WriteLine("Command took {0} ms.", duration);
|
||||
DicConsole.WriteLine("Sense is {0}.", sense);
|
||||
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
|
||||
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
|
||||
DicConsole.WriteLine("Response has {0} elements.", response == null ? "null" : response.Length.ToString());
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Choose what to do:");
|
||||
DicConsole.WriteLine("1.- Print buffer.");
|
||||
DicConsole.WriteLine("2.- Print response buffer.");
|
||||
DicConsole.WriteLine("3.- Send command again.");
|
||||
DicConsole.WriteLine("0.- Return to SecureDigital commands menu.");
|
||||
DicConsole.Write("Choose: ");
|
||||
|
||||
string strDev = System.Console.ReadLine();
|
||||
if(!int.TryParse(strDev, out int item))
|
||||
{
|
||||
DicConsole.WriteLine("Not a number. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
|
||||
switch(item)
|
||||
{
|
||||
case 0:
|
||||
DicConsole.WriteLine("Returning to SecureDigital commands menu...");
|
||||
return;
|
||||
case 1:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SD_STATUS buffer:");
|
||||
if(buffer != null)
|
||||
PrintHex.PrintHexArray(buffer, 64);
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 2:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SD_STATUS response:");
|
||||
if(response != null)
|
||||
{
|
||||
foreach(uint res in response)
|
||||
DicConsole.Write("0x{0:x8} ", res);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 3:
|
||||
goto start;
|
||||
default:
|
||||
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
}
|
||||
|
||||
static void SendCID(string devPath, Device dev)
|
||||
{
|
||||
start:
|
||||
System.Console.Clear();
|
||||
bool sense = dev.ReadCID(out byte[] buffer, out uint[] response, dev.Timeout, out double duration);
|
||||
|
||||
menu:
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("Sending SEND_CID to the device:");
|
||||
DicConsole.WriteLine("Command took {0} ms.", duration);
|
||||
DicConsole.WriteLine("Sense is {0}.", sense);
|
||||
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
|
||||
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
|
||||
DicConsole.WriteLine("Response has {0} elements.", response == null ? "null" : response.Length.ToString());
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Choose what to do:");
|
||||
DicConsole.WriteLine("1.- Print buffer.");
|
||||
DicConsole.WriteLine("2.- Decode buffer.");
|
||||
DicConsole.WriteLine("3.- Print response buffer.");
|
||||
DicConsole.WriteLine("4.- Send command again.");
|
||||
DicConsole.WriteLine("0.- Return to SecureDigital commands menu.");
|
||||
DicConsole.Write("Choose: ");
|
||||
|
||||
string strDev = System.Console.ReadLine();
|
||||
if(!int.TryParse(strDev, out int item))
|
||||
{
|
||||
DicConsole.WriteLine("Not a number. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
|
||||
switch(item)
|
||||
{
|
||||
case 0:
|
||||
DicConsole.WriteLine("Returning to SecureDigital commands menu...");
|
||||
return;
|
||||
case 1:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_CID buffer:");
|
||||
if(buffer != null)
|
||||
PrintHex.PrintHexArray(buffer, 64);
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 2:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_CID decoded buffer:");
|
||||
if(buffer != null)
|
||||
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifyCID(buffer));
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 3:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_CID response:");
|
||||
if(response != null)
|
||||
{
|
||||
foreach(uint res in response)
|
||||
DicConsole.Write("0x{0:x8} ", res);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 4:
|
||||
goto start;
|
||||
default:
|
||||
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
}
|
||||
|
||||
static void SendCSD(string devPath, Device dev)
|
||||
{
|
||||
start:
|
||||
System.Console.Clear();
|
||||
bool sense = dev.ReadCSD(out byte[] buffer, out uint[] response, dev.Timeout, out double duration);
|
||||
|
||||
menu:
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("Sending SEND_CSD to the device:");
|
||||
DicConsole.WriteLine("Command took {0} ms.", duration);
|
||||
DicConsole.WriteLine("Sense is {0}.", sense);
|
||||
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
|
||||
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
|
||||
DicConsole.WriteLine("Response has {0} elements.", response == null ? "null" : response.Length.ToString());
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Choose what to do:");
|
||||
DicConsole.WriteLine("1.- Print buffer.");
|
||||
DicConsole.WriteLine("2.- Decode buffer.");
|
||||
DicConsole.WriteLine("3.- Print response buffer.");
|
||||
DicConsole.WriteLine("4.- Send command again.");
|
||||
DicConsole.WriteLine("0.- Return to SecureDigital commands menu.");
|
||||
DicConsole.Write("Choose: ");
|
||||
|
||||
string strDev = System.Console.ReadLine();
|
||||
if(!int.TryParse(strDev, out int item))
|
||||
{
|
||||
DicConsole.WriteLine("Not a number. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
|
||||
switch(item)
|
||||
{
|
||||
case 0:
|
||||
DicConsole.WriteLine("Returning to SecureDigital commands menu...");
|
||||
return;
|
||||
case 1:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_CSD buffer:");
|
||||
if(buffer != null)
|
||||
PrintHex.PrintHexArray(buffer, 64);
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 2:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_CSD decoded buffer:");
|
||||
if(buffer != null)
|
||||
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifyCSD(buffer));
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 3:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_CSD response:");
|
||||
if(response != null)
|
||||
{
|
||||
foreach(uint res in response)
|
||||
DicConsole.Write("0x{0:x8} ", res);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 4:
|
||||
goto start;
|
||||
default:
|
||||
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
}
|
||||
|
||||
static void SendSCR(string devPath, Device dev)
|
||||
{
|
||||
start:
|
||||
System.Console.Clear();
|
||||
bool sense = dev.ReadSCR(out byte[] buffer, out uint[] response, dev.Timeout, out double duration);
|
||||
|
||||
menu:
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("Sending SEND_SCR to the device:");
|
||||
DicConsole.WriteLine("Command took {0} ms.", duration);
|
||||
DicConsole.WriteLine("Sense is {0}.", sense);
|
||||
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
|
||||
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
|
||||
DicConsole.WriteLine("Response has {0} elements.", response == null ? "null" : response.Length.ToString());
|
||||
DicConsole.WriteLine();
|
||||
DicConsole.WriteLine("Choose what to do:");
|
||||
DicConsole.WriteLine("1.- Print buffer.");
|
||||
DicConsole.WriteLine("2.- Decode buffer.");
|
||||
DicConsole.WriteLine("3.- Print response buffer.");
|
||||
DicConsole.WriteLine("4.- Send command again.");
|
||||
DicConsole.WriteLine("0.- Return to SecureDigital commands menu.");
|
||||
DicConsole.Write("Choose: ");
|
||||
|
||||
string strDev = System.Console.ReadLine();
|
||||
if(!int.TryParse(strDev, out int item))
|
||||
{
|
||||
DicConsole.WriteLine("Not a number. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
|
||||
switch(item)
|
||||
{
|
||||
case 0:
|
||||
DicConsole.WriteLine("Returning to SecureDigital commands menu...");
|
||||
return;
|
||||
case 1:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_SCR buffer:");
|
||||
if(buffer != null)
|
||||
PrintHex.PrintHexArray(buffer, 64);
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 2:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_SCR decoded buffer:");
|
||||
if(buffer != null)
|
||||
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifySCR(buffer));
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 3:
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
DicConsole.WriteLine("SEND_SCR response:");
|
||||
if(response != null)
|
||||
{
|
||||
foreach(uint res in response)
|
||||
DicConsole.Write("0x{0:x8} ", res);
|
||||
DicConsole.WriteLine();
|
||||
}
|
||||
DicConsole.WriteLine("Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
DicConsole.WriteLine("Device: {0}", devPath);
|
||||
goto menu;
|
||||
case 4:
|
||||
goto start;
|
||||
default:
|
||||
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
|
||||
System.Console.ReadKey();
|
||||
System.Console.Clear();
|
||||
goto menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user