2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-19 02:59:32 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : AACS.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes AACS structures.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-19 02:59:32 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-10-19 02:59:32 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-10-19 02:59:32 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.SCSI.MMC
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Information from the following standards:
|
|
|
|
|
/// ANSI X3.304-1997
|
|
|
|
|
/// T10/1048-D revision 9.0
|
|
|
|
|
/// T10/1048-D revision 10a
|
|
|
|
|
/// T10/1228-D revision 7.0c
|
|
|
|
|
/// T10/1228-D revision 11a
|
|
|
|
|
/// T10/1363-D revision 10g
|
|
|
|
|
/// T10/1545-D revision 1d
|
|
|
|
|
/// T10/1545-D revision 5
|
|
|
|
|
/// T10/1545-D revision 5a
|
|
|
|
|
/// T10/1675-D revision 2c
|
|
|
|
|
/// T10/1675-D revision 4
|
|
|
|
|
/// T10/1836-D revision 2g
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class AACS
|
|
|
|
|
{
|
|
|
|
|
public struct AACSVolumeIdentifier
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to end
|
|
|
|
|
/// AACS volume identifier data
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] VolumeIdentifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct AACSMediaSerialNumber
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to end
|
|
|
|
|
/// AACS media serial number
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] MediaSerialNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct AACSMediaIdentifier
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to end
|
|
|
|
|
/// AACS media identifier data
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] MediaIdentifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct AACSMediaKeyBlock
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Number of MKB packs available to transfer
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte TotalPacks;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to end
|
|
|
|
|
/// AACS media key block packs
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] MediaKeyBlockPacks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct AACSDataKeys
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to end
|
|
|
|
|
/// AACS data keys
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] DataKeys;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct AACSLBAExtentsResponse
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data Length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Number of LBA extents the drive can store.
|
2016-07-28 22:25:26 +01:00
|
|
|
/// if(MaxLBAExtents == 0 && DataLength > 2), 256 extents can be stored
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte MaxLBAExtents;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to end
|
|
|
|
|
/// LBA Extents
|
|
|
|
|
/// </summary>
|
|
|
|
|
public AACSLBAExtent[] Extents;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct AACSLBAExtent
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 7
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] Reserved;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 8 to 11
|
|
|
|
|
/// Start LBA of extent
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint StartLBA;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 12 to 15
|
|
|
|
|
/// Extent length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint LBACount;
|
2015-10-19 02:59:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AACSVolumeIdentifier? DecodeAACSVolumeIdentifier(byte[] AACSVIResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSVIResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSVolumeIdentifier decoded = new AACSVolumeIdentifier();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.VolumeIdentifier = new byte[AACSVIResponse.Length - 4];
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSVIResponse, 0);
|
|
|
|
|
decoded.Reserved1 = AACSVIResponse[2];
|
|
|
|
|
decoded.Reserved2 = AACSVIResponse[3];
|
|
|
|
|
Array.Copy(AACSVIResponse, 4, decoded.VolumeIdentifier, 0, AACSVIResponse.Length - 4);
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSVolumeIdentifier(AACSVolumeIdentifier? AACSVIResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSVIResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSVolumeIdentifier response = AACSVIResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
#if DEBUG
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Reserved1 != 0) sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
|
|
|
|
|
if(response.Reserved2 != 0) sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
#endif
|
2015-10-19 02:59:32 +01:00
|
|
|
sb.AppendFormat("AACS Volume Identifier in hex follows:");
|
|
|
|
|
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.VolumeIdentifier, 80));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSVolumeIdentifier(byte[] AACSVIResponse)
|
|
|
|
|
{
|
|
|
|
|
AACSVolumeIdentifier? decoded = DecodeAACSVolumeIdentifier(AACSVIResponse);
|
|
|
|
|
return PrettifyAACSVolumeIdentifier(decoded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AACSMediaSerialNumber? DecodeAACSMediaSerialNumber(byte[] AACSMSNResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSMSNResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSMediaSerialNumber decoded = new AACSMediaSerialNumber();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.MediaSerialNumber = new byte[AACSMSNResponse.Length - 4];
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMSNResponse, 0);
|
|
|
|
|
decoded.Reserved1 = AACSMSNResponse[2];
|
|
|
|
|
decoded.Reserved2 = AACSMSNResponse[3];
|
|
|
|
|
Array.Copy(AACSMSNResponse, 4, decoded.MediaSerialNumber, 0, AACSMSNResponse.Length - 4);
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSMediaSerialNumber(AACSMediaSerialNumber? AACSMSNResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSMSNResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSMediaSerialNumber response = AACSMSNResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
#if DEBUG
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Reserved1 != 0) sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
|
|
|
|
|
if(response.Reserved2 != 0) sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
#endif
|
2015-10-19 02:59:32 +01:00
|
|
|
sb.AppendFormat("AACS Media Serial Number in hex follows:");
|
|
|
|
|
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaSerialNumber, 80));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSMediaSerialNumber(byte[] AACSMSNResponse)
|
|
|
|
|
{
|
|
|
|
|
AACSMediaSerialNumber? decoded = DecodeAACSMediaSerialNumber(AACSMSNResponse);
|
|
|
|
|
return PrettifyAACSMediaSerialNumber(decoded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AACSMediaIdentifier? DecodeAACSMediaIdentifier(byte[] AACSMIResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSMIResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSMediaIdentifier decoded = new AACSMediaIdentifier();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.MediaIdentifier = new byte[AACSMIResponse.Length - 4];
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMIResponse, 0);
|
|
|
|
|
decoded.Reserved1 = AACSMIResponse[2];
|
|
|
|
|
decoded.Reserved2 = AACSMIResponse[3];
|
|
|
|
|
Array.Copy(AACSMIResponse, 4, decoded.MediaIdentifier, 0, AACSMIResponse.Length - 4);
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSMediaIdentifier(AACSMediaIdentifier? AACSMIResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSMIResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSMediaIdentifier response = AACSMIResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
#if DEBUG
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Reserved1 != 0) sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
|
|
|
|
|
if(response.Reserved2 != 0) sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
#endif
|
2015-10-19 02:59:32 +01:00
|
|
|
sb.AppendFormat("AACS Media Identifier in hex follows:");
|
|
|
|
|
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaIdentifier, 80));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSMediaIdentifier(byte[] AACSMIResponse)
|
|
|
|
|
{
|
|
|
|
|
AACSMediaIdentifier? decoded = DecodeAACSMediaIdentifier(AACSMIResponse);
|
|
|
|
|
return PrettifyAACSMediaIdentifier(decoded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AACSMediaKeyBlock? DecodeAACSMediaKeyBlock(byte[] AACSMKBResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSMKBResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSMediaKeyBlock decoded = new AACSMediaKeyBlock();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.MediaKeyBlockPacks = new byte[AACSMKBResponse.Length - 4];
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMKBResponse, 0);
|
|
|
|
|
decoded.Reserved = AACSMKBResponse[2];
|
|
|
|
|
decoded.TotalPacks = AACSMKBResponse[3];
|
|
|
|
|
Array.Copy(AACSMKBResponse, 4, decoded.MediaKeyBlockPacks, 0, AACSMKBResponse.Length - 4);
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSMediaKeyBlock(AACSMediaKeyBlock? AACSMKBResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSMKBResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSMediaKeyBlock response = AACSMKBResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
#if DEBUG
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Reserved != 0) sb.AppendFormat("Reserved = 0x{0:X2}", response.Reserved).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
#endif
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Total number of media key blocks available to transfer {0}", response.TotalPacks)
|
|
|
|
|
.AppendLine();
|
2015-10-19 02:59:32 +01:00
|
|
|
sb.AppendFormat("AACS Media Key Blocks in hex follows:");
|
|
|
|
|
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaKeyBlockPacks, 80));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSMediaKeyBlock(byte[] AACSMKBResponse)
|
|
|
|
|
{
|
|
|
|
|
AACSMediaKeyBlock? decoded = DecodeAACSMediaKeyBlock(AACSMKBResponse);
|
|
|
|
|
return PrettifyAACSMediaKeyBlock(decoded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AACSDataKeys? DecodeAACSDataKeys(byte[] AACSDKResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSDKResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSDataKeys decoded = new AACSDataKeys();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.DataKeys = new byte[AACSDKResponse.Length - 4];
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSDKResponse, 0);
|
|
|
|
|
decoded.Reserved1 = AACSDKResponse[2];
|
|
|
|
|
decoded.Reserved2 = AACSDKResponse[3];
|
|
|
|
|
Array.Copy(AACSDKResponse, 4, decoded.DataKeys, 0, AACSDKResponse.Length - 4);
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSDataKeys(AACSDataKeys? AACSDKResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSDKResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSDataKeys response = AACSDKResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
#if DEBUG
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Reserved1 != 0) sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
|
|
|
|
|
if(response.Reserved2 != 0) sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
#endif
|
2015-10-19 02:59:32 +01:00
|
|
|
sb.AppendFormat("AACS Data Keys in hex follows:");
|
|
|
|
|
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.DataKeys, 80));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSDataKeys(byte[] AACSDKResponse)
|
|
|
|
|
{
|
|
|
|
|
AACSDataKeys? decoded = DecodeAACSDataKeys(AACSDKResponse);
|
|
|
|
|
return PrettifyAACSDataKeys(decoded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AACSLBAExtentsResponse? DecodeAACSLBAExtents(byte[] AACSLBAExtsResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSLBAExtsResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSLBAExtentsResponse decoded = new AACSLBAExtentsResponse();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSLBAExtsResponse, 0);
|
|
|
|
|
decoded.Reserved = AACSLBAExtsResponse[2];
|
|
|
|
|
decoded.MaxLBAExtents = AACSLBAExtsResponse[3];
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if((AACSLBAExtsResponse.Length - 4) % 16 != 0) return decoded;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
decoded.Extents = new AACSLBAExtent[(AACSLBAExtsResponse.Length - 4) / 16];
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
for(int i = 0; i < (AACSLBAExtsResponse.Length - 4) / 16; i++)
|
2015-10-19 02:59:32 +01:00
|
|
|
{
|
|
|
|
|
decoded.Extents[i].Reserved = new byte[8];
|
|
|
|
|
Array.Copy(AACSLBAExtsResponse, 0 + i * 16 + 4, decoded.Extents[i].Reserved, 0, 8);
|
|
|
|
|
decoded.Extents[i].StartLBA = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 8 + i * 16 + 4);
|
|
|
|
|
decoded.Extents[i].LBACount = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 12 + i * 16 + 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSLBAExtents(AACSLBAExtentsResponse? AACSLBAExtsResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(AACSLBAExtsResponse == null) return null;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
AACSLBAExtentsResponse response = AACSLBAExtsResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(response.MaxLBAExtents == 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.DataLength > 2) sb.AppendLine("Drive can store 256 LBA Extents");
|
|
|
|
|
else sb.AppendLine("Drive cannot store LBA Extents");
|
|
|
|
|
else sb.AppendFormat("Drive can store {0} LBA Extents", response.MaxLBAExtents).AppendLine();
|
2015-10-19 02:59:32 +01:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
for(int i = 0; i < response.Extents.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("LBA Extent {0} starts at LBA {1} and goes for {2} sectors", i,
|
|
|
|
|
response.Extents[i].StartLBA, response.Extents[i].LBACount);
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyAACSLBAExtents(byte[] AACSLBAExtsResponse)
|
|
|
|
|
{
|
|
|
|
|
AACSLBAExtentsResponse? decoded = DecodeAACSLBAExtents(AACSLBAExtsResponse);
|
|
|
|
|
return PrettifyAACSLBAExtents(decoded);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|