Sanity check D1/D2/PIC lengths, check getkey log D2/PIC

This commit is contained in:
Deterous
2023-10-31 16:57:58 +13:00
parent 50fc41e03e
commit 14df0affc6
2 changed files with 46 additions and 12 deletions
+38 -10
View File
@@ -84,19 +84,52 @@ namespace LibIRD
/// D1 key /// D1 key
/// </summary> /// </summary>
/// <remarks>16 bytes</remarks> /// <remarks>16 bytes</remarks>
public byte[] Data1Key { get; set; } public byte[] Data1Key
{
get { return _data1Key; }
set
{
if (value != null && value.Length == 16)
_data1Key = value;
else
throw new ArgumentException("Data 1 Key must be a byte array of length 16", nameof(value));
}
}
private byte[] _data1Key;
/// <summary> /// <summary>
/// D2 key /// D2 key
/// </summary> /// </summary>
/// <remarks>16 bytes</remarks> /// <remarks>16 bytes</remarks>
public byte[] Data2Key { get; set; } public byte[] Data2Key
{
get { return _data2Key; }
set
{
if (value != null && value.Length == 16)
_data2Key = value;
else
throw new ArgumentException("Data 2 Key must be a byte array of length 16", nameof(value));
}
}
private byte[] _data2Key;
/// <summary> /// <summary>
/// Uncompressed PIC data /// Uncompressed PIC data
/// </summary> /// </summary>
/// <remarks>115 bytes</remarks> /// <remarks>115 bytes</remarks>
public byte[] PIC { get; set; } public byte[] PIC
{
get { return _pic; }
set
{
if (value != null && value.Length == 115)
_pic = value;
else
throw new ArgumentException("PIC must be a byte array of length 115", nameof(value));
}
}
private byte[] _pic;
#endregion #endregion
@@ -181,7 +214,7 @@ namespace LibIRD
public byte[][] FileHashes { get; private set; } public byte[][] FileHashes { get; private set; }
/// <summary> /// <summary>
/// Gzipped IRD content 32-bit CRC "IEEE 802.3" hash, little endian /// IRD content 32-bit CRC "IEEE 802.3" hash, little endian
/// </summary> /// </summary>
public uint CRC { get; private set; } public uint CRC { get; private set; }
@@ -386,12 +419,7 @@ namespace LibIRD
// Get PIC from log // Get PIC from log
string discPICStr = ""; string discPICStr = "";
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ discPICStr += sr.ReadLine() ?? throw new InvalidDataException("Incomplete PIC in .getkey.log");
line = sr.ReadLine();
if (line == null)
throw new InvalidDataException("Incomplete PIC in .getkey.log");
discPICStr += line;
}
// Validate PIC from log // Validate PIC from log
if (discPICStr.Length != 256) if (discPICStr.Length != 256)
throw new InvalidDataException("Unexpected PIC in .getkey.log"); throw new InvalidDataException("Unexpected PIC in .getkey.log");
+8 -2
View File
@@ -209,11 +209,17 @@ namespace LibIRD
// Parse .getkey.log for the Disc Key (Data1Key) // Parse .getkey.log for the Disc Key (Data1Key)
ParseGetKeyLog(getKeyLog); ParseGetKeyLog(getKeyLog);
// Generate Data 2 using Disc ID, discarding ID from getKeyLog // Generate Data 2 using Disc ID
GenerateD2(GenerateID(size)); GenerateD2(GenerateID(size));
byte[] d2 = Data2Key;
if (!((ReadOnlySpan<byte>)Data2Key).SequenceEqual(d2))
throw new InvalidDataException("Unexpected Disc ID in .getkey.log");
// Generate Disc PIC, discarding PIC from getKeyLog // Generate Disc PIC
byte[] pic = PIC;
GeneratePIC(size); GeneratePIC(size);
if (!((ReadOnlySpan<byte>) PIC).SequenceEqual(pic))
throw new InvalidDataException("Unexpected PIC in .getkey.log");
// Generate Unique Identifier using ISO CRC32 // Generate Unique Identifier using ISO CRC32
GenerateUID(isoPath); GenerateUID(isoPath);