2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-19 02:28:40 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : CSS&CPRM.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:28:40 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:28:40 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes DVD CSS & CPRM structures.
|
2015-10-19 02:28:40 +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:28:40 +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:28:40 +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:28:40 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-10-19 02:28:40 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-12-01 04:23:08 +00:00
|
|
|
using System.Text;
|
2015-10-19 02:28:40 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.DVD
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// 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
|
|
|
|
|
/// ECMA 365
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
2017-12-22 02:04:18 +00:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
|
|
|
|
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
|
2015-10-19 02:28:40 +01:00
|
|
|
public static class CSS_CPRM
|
|
|
|
|
{
|
|
|
|
|
public struct LeadInCopyright
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:28:40 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 4
|
|
|
|
|
/// Copy protection system type
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
2015-12-02 07:10:52 +00:00
|
|
|
public CopyrightType CopyrightType;
|
2015-10-19 02:28:40 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 5
|
|
|
|
|
/// Bitmask of regions where this disc is playable
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte RegionInformation;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 6
|
|
|
|
|
/// Reserved
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved3;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7
|
|
|
|
|
/// Reserved
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct DiscKey
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:28:40 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 4 to 2052
|
|
|
|
|
/// Disc key for CSS, Album Identifier for CPPM
|
2015-10-19 02:28:40 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte[] Key;
|
|
|
|
|
}
|
2015-12-01 04:23:08 +00:00
|
|
|
|
|
|
|
|
public static LeadInCopyright? DecodeLeadInCopyright(byte[] response)
|
|
|
|
|
{
|
2017-12-22 02:04:18 +00:00
|
|
|
if(response?.Length != 8) return null;
|
2015-12-01 04:23:08 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
return new LeadInCopyright
|
|
|
|
|
{
|
|
|
|
|
DataLength = (ushort)((response[0] << 8) + response[1]),
|
|
|
|
|
Reserved1 = response[2],
|
|
|
|
|
Reserved2 = response[3],
|
|
|
|
|
CopyrightType = (CopyrightType)response[4],
|
|
|
|
|
RegionInformation = response[5],
|
|
|
|
|
Reserved3 = response[6],
|
|
|
|
|
Reserved4 = response[7]
|
|
|
|
|
};
|
2015-12-01 04:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyLeadInCopyright(LeadInCopyright? cmi)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(cmi == null) return null;
|
2015-12-01 04:23:08 +00:00
|
|
|
|
|
|
|
|
LeadInCopyright decoded = cmi.Value;
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(decoded.CopyrightType)
|
2015-12-01 04:23:08 +00:00
|
|
|
{
|
2015-12-02 07:10:52 +00:00
|
|
|
case CopyrightType.NoProtection:
|
2015-12-01 04:23:08 +00:00
|
|
|
sb.AppendLine("Disc has no encryption.");
|
|
|
|
|
break;
|
2015-12-02 07:10:52 +00:00
|
|
|
case CopyrightType.CSS:
|
2015-12-01 04:23:08 +00:00
|
|
|
sb.AppendLine("Disc is encrypted using CSS or CPPM.");
|
|
|
|
|
break;
|
2015-12-02 07:10:52 +00:00
|
|
|
case CopyrightType.CPRM:
|
2015-12-01 04:23:08 +00:00
|
|
|
sb.AppendLine("Disc is encrypted using CPRM.");
|
|
|
|
|
break;
|
2015-12-02 07:10:52 +00:00
|
|
|
case CopyrightType.AACS:
|
2015-12-01 04:23:08 +00:00
|
|
|
sb.AppendLine("Disc is encrypted using AACS.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sb.AppendFormat("Disc is encrypted using unknown algorithm with ID {0}.", decoded.CopyrightType);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.CopyrightType == 0) return sb.ToString();
|
2015-12-01 04:23:08 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.RegionInformation == 0xFF) sb.AppendLine("Disc cannot be played in any region at all.");
|
|
|
|
|
else if(decoded.RegionInformation == 0x00) sb.AppendLine("Disc can be played in any region.");
|
2015-12-01 04:23:08 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append("Disc can be played in the following regions:");
|
2017-12-19 20:33:03 +00:00
|
|
|
if((decoded.RegionInformation & 0x01) != 0x01) sb.Append(" 0");
|
|
|
|
|
if((decoded.RegionInformation & 0x02) != 0x02) sb.Append(" 1");
|
|
|
|
|
if((decoded.RegionInformation & 0x04) != 0x04) sb.Append(" 2");
|
|
|
|
|
if((decoded.RegionInformation & 0x08) != 0x08) sb.Append(" 3");
|
|
|
|
|
if((decoded.RegionInformation & 0x10) != 0x10) sb.Append(" 4");
|
|
|
|
|
if((decoded.RegionInformation & 0x20) != 0x20) sb.Append(" 5");
|
|
|
|
|
if((decoded.RegionInformation & 0x40) != 0x40) sb.Append(" 6");
|
|
|
|
|
if((decoded.RegionInformation & 0x80) != 0x80) sb.Append(" 7");
|
2015-12-01 04:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string PrettifyLeadInCopyright(byte[] response)
|
|
|
|
|
{
|
|
|
|
|
return PrettifyLeadInCopyright(DecodeLeadInCopyright(response));
|
|
|
|
|
}
|
2015-10-19 02:28:40 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|