2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-12-01 03:23:31 +00:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : DI.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-12-01 03:23:31 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-12-01 03:23:31 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes Blu-ray Disc Information.
|
2015-12-01 03:23:31 +00: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-12-01 03:23:31 +00: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-12-01 03:23:31 +00: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-12-01 03:23:31 +00:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-12-01 03:23:31 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-12-01 03:23:31 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-12-01 03:23:31 +00:00
|
|
|
using System.Text;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Console;
|
2015-12-01 03:23:31 +00:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.Bluray
|
|
|
|
|
{
|
|
|
|
|
/// <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
|
2015-12-01 03:23:31 +00: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-12-01 03:23:31 +00:00
|
|
|
public static class DI
|
|
|
|
|
{
|
|
|
|
|
#region Private constants
|
|
|
|
|
const string DiscTypeBDROM = "BDO";
|
2018-03-26 17:39:49 +01:00
|
|
|
const string DiscTypeBDRE = "BDW";
|
|
|
|
|
const string DiscTypeBDR = "BDR";
|
2015-12-01 03:23:31 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Disc Information Unit Identifier "DI"
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
const ushort DIUIdentifier = 0x4449;
|
2015-12-01 03:23:31 +00:00
|
|
|
#endregion Private constants
|
|
|
|
|
|
|
|
|
|
#region Public methods
|
|
|
|
|
public static DiscInformation? Decode(byte[] DIResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(DIResponse == null) return null;
|
2015-12-01 03:23:31 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(DIResponse.Length != 4100)
|
2015-12-01 03:23:31 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BD Disc Information decoder",
|
|
|
|
|
"Found incorrect Blu-ray Disc Information size ({0} bytes)",
|
|
|
|
|
DIResponse.Length);
|
2015-12-01 03:23:31 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiscInformation decoded = new DiscInformation();
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
decoded.DataLength = BigEndianBitConverter.ToUInt16(DIResponse, 0);
|
2018-03-26 17:39:49 +01:00
|
|
|
decoded.Reserved1 = DIResponse[2];
|
|
|
|
|
decoded.Reserved2 = DIResponse[3];
|
2015-12-01 03:23:31 +00:00
|
|
|
|
2018-03-26 17:39:49 +01:00
|
|
|
int offset = 4;
|
|
|
|
|
List<DiscInformationUnits> units = new List<DiscInformationUnits>();
|
2015-12-01 03:23:31 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
while(true)
|
2015-12-01 03:23:31 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(offset >= 100) break;
|
2015-12-01 03:23:31 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
DiscInformationUnits unit = new DiscInformationUnits
|
|
|
|
|
{
|
|
|
|
|
Signature = BigEndianBitConverter.ToUInt16(DIResponse, 0 + offset)
|
|
|
|
|
};
|
2015-12-01 03:23:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(unit.Signature != DIUIdentifier) break;
|
2015-12-01 03:23:31 +00:00
|
|
|
|
2018-03-26 17:39:49 +01:00
|
|
|
unit.Format = DIResponse[2 + offset];
|
|
|
|
|
unit.UnitsPerBlock = DIResponse[3 + offset];
|
|
|
|
|
unit.Legacy = DIResponse[4 + offset];
|
|
|
|
|
unit.Sequence = DIResponse[5 + offset];
|
|
|
|
|
unit.Length = DIResponse[6 + offset];
|
|
|
|
|
unit.Reserved = DIResponse[7 + offset];
|
2015-12-01 03:23:31 +00:00
|
|
|
unit.DiscTypeIdentifier = new byte[3];
|
|
|
|
|
Array.Copy(DIResponse, 8 + offset, unit.DiscTypeIdentifier, 0, 3);
|
|
|
|
|
unit.DiscSizeClassVersion = DIResponse[11 + offset];
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(Encoding.ASCII.GetString(unit.DiscTypeIdentifier))
|
2015-12-01 03:23:31 +00:00
|
|
|
{
|
|
|
|
|
case DiscTypeBDROM:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
unit.FormatDependentContents = new byte[52];
|
2018-03-26 17:39:49 +01:00
|
|
|
Array.Copy(DIResponse, 12 + offset, unit.FormatDependentContents, 0, 52);
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2015-12-01 03:23:31 +00:00
|
|
|
case DiscTypeBDRE:
|
|
|
|
|
case DiscTypeBDR:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
unit.FormatDependentContents = new byte[88];
|
2018-03-26 17:39:49 +01:00
|
|
|
Array.Copy(DIResponse, 12 + offset, unit.FormatDependentContents, 0, 88);
|
2017-12-19 20:33:03 +00:00
|
|
|
unit.ManufacturerID = new byte[6];
|
|
|
|
|
Array.Copy(DIResponse, 100 + offset, unit.ManufacturerID, 0, 6);
|
|
|
|
|
unit.MediaTypeID = new byte[3];
|
|
|
|
|
Array.Copy(DIResponse, 106 + offset, unit.MediaTypeID, 0, 3);
|
2018-03-26 17:39:49 +01:00
|
|
|
unit.TimeStamp = BigEndianBitConverter.ToUInt16(DIResponse, 109 + offset);
|
|
|
|
|
unit.ProductRevisionNumber = DIResponse[111 + offset];
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2015-12-01 03:23:31 +00:00
|
|
|
default:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("BD Disc Information decoder",
|
|
|
|
|
"Found unknown disc type identifier \"{0}\"",
|
|
|
|
|
Encoding.ASCII.GetString(unit.DiscTypeIdentifier));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-12-01 03:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
units.Add(unit);
|
|
|
|
|
|
|
|
|
|
offset += unit.Length;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(units.Count <= 0) return decoded;
|
|
|
|
|
|
|
|
|
|
decoded.Units = new DiscInformationUnits[units.Count];
|
|
|
|
|
for(int i = 0; i < units.Count; i++) decoded.Units[i] = units[i];
|
2015-12-01 03:23:31 +00:00
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Prettify(DiscInformation? DIResponse)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(DIResponse == null) return null;
|
2015-12-01 03:23:31 +00:00
|
|
|
|
|
|
|
|
DiscInformation response = DIResponse.Value;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
foreach(DiscInformationUnits unit in response.Units)
|
2015-12-01 03:23:31 +00:00
|
|
|
{
|
|
|
|
|
sb.AppendFormat("DI Unit Sequence: {0}", unit.Sequence).AppendLine();
|
|
|
|
|
sb.AppendFormat("DI Unit Format: 0x{0:X2}", unit.Format).AppendLine();
|
|
|
|
|
sb.AppendFormat("There are {0} per block", unit.UnitsPerBlock).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
if(Encoding.ASCII.GetString(unit.DiscTypeIdentifier) != DiscTypeBDROM)
|
2015-12-01 03:23:31 +00:00
|
|
|
sb.AppendFormat("Legacy value: 0x{0:X2}", unit.Legacy).AppendLine();
|
|
|
|
|
sb.AppendFormat("DI Unit is {0} bytes", unit.Length).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Disc type identifier: \"{0}\"", Encoding.ASCII.GetString(unit.DiscTypeIdentifier))
|
|
|
|
|
.AppendLine();
|
2015-12-01 03:23:31 +00:00
|
|
|
sb.AppendFormat("Disc size/class/version: {0}", unit.DiscSizeClassVersion).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
if(Encoding.ASCII.GetString(unit.DiscTypeIdentifier) == DiscTypeBDR ||
|
2017-12-19 20:33:03 +00:00
|
|
|
Encoding.ASCII.GetString(unit.DiscTypeIdentifier) == DiscTypeBDRE)
|
2015-12-01 03:23:31 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Disc manufacturer ID: \"{0}\"", Encoding.ASCII.GetString(unit.ManufacturerID))
|
|
|
|
|
.AppendLine();
|
|
|
|
|
sb.AppendFormat("Disc media type ID: \"{0}\"", Encoding.ASCII.GetString(unit.MediaTypeID))
|
|
|
|
|
.AppendLine();
|
2015-12-01 03:23:31 +00:00
|
|
|
sb.AppendFormat("Disc timestamp: 0x{0:X2}", unit.TimeStamp).AppendLine();
|
|
|
|
|
sb.AppendFormat("Disc product revison number: {0}", unit.ProductRevisionNumber).AppendLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("Blu-ray DI Unit format dependent contents as hex follows:");
|
|
|
|
|
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(unit.FormatDependentContents, 80));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Prettify(byte[] DIResponse)
|
|
|
|
|
{
|
|
|
|
|
return Prettify(Decode(DIResponse));
|
|
|
|
|
}
|
|
|
|
|
#endregion Public methods
|
|
|
|
|
|
|
|
|
|
#region Public structures
|
|
|
|
|
public struct DiscInformation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Always 4098
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-12-01 03:23:31 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 4 to 4099
|
|
|
|
|
/// Disc information units
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public DiscInformationUnits[] Units;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct DiscInformationUnits
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 0
|
|
|
|
|
/// "DI"
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort Signature;
|
2015-12-01 03:23:31 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2
|
|
|
|
|
/// Disc information format
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Format;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Number of DI units per block
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte UnitsPerBlock;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 4
|
|
|
|
|
/// Reserved for BD-ROM, legacy information for BD-R/-RE
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Legacy;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 5
|
|
|
|
|
/// Sequence number for this DI unit
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Sequence;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 6
|
|
|
|
|
/// Number of bytes used by this DI unit, should be 64 for BD-ROM and 112 for BD-R/-RE
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Length;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7
|
|
|
|
|
/// Reserved
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 8 to 10
|
|
|
|
|
/// Disc type identifier
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte[] DiscTypeIdentifier;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 11
|
|
|
|
|
/// Disc size/class/version
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DiscSizeClassVersion;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 12 to 63 for BD-ROM, bytes 12 to 99 for BD-R/-RE
|
|
|
|
|
/// Format dependent contents, disclosed in private blu-ray specifications
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte[] FormatDependentContents;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 100 to 105, BD-R/-RE only
|
|
|
|
|
/// Manufacturer ID
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte[] ManufacturerID;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 106 to 108, BD-R/-RE only
|
|
|
|
|
/// Media type ID
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte[] MediaTypeID;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 109 to 110, BD-R/-RE only
|
|
|
|
|
/// Timestamp
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort TimeStamp;
|
2015-12-01 03:23:31 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 111
|
|
|
|
|
/// Product revision number
|
2015-12-01 03:23:31 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte ProductRevisionNumber;
|
|
|
|
|
}
|
|
|
|
|
#endregion Public structures
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|