Skip to content

Commit

Permalink
Add reader for DiscImageCreator DVD Raw dumps (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeShemp committed Aug 22, 2023
1 parent d1d9e08 commit ebf893e
Show file tree
Hide file tree
Showing 19 changed files with 794 additions and 91 deletions.
2 changes: 1 addition & 1 deletion Aaru.CommonTypes
10 changes: 5 additions & 5 deletions Aaru.Core/Devices/Dumping/Sbc/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void ReadSbcData(in ulong blocks, in uint maxBlocksToRead, in uint blockSize, Du
outputFormat.WriteSectorTag(new[]
{
titleKey.Value.CMI
}, i + j, SectorTagType.DvdCmi);
}, i + j, SectorTagType.DvdSectorCmi);
else
continue;

Expand All @@ -147,7 +147,7 @@ void ReadSbcData(in ulong blocks, in uint maxBlocksToRead, in uint blockSize, Du
outputFormat.WriteSectorTag(new byte[]
{
0, 0, 0, 0, 0
}, i + j, SectorTagType.DvdTitleKey);
}, i + j, SectorTagType.DvdSectorTitleKey);

outputFormat.WriteSectorTag(new byte[]
{
Expand All @@ -166,7 +166,7 @@ void ReadSbcData(in ulong blocks, in uint maxBlocksToRead, in uint blockSize, Du
outputFormat.WriteSectorTag(new byte[]
{
0, 0, 0, 0, 0
}, i + j, SectorTagType.DvdTitleKey);
}, i + j, SectorTagType.DvdSectorTitleKey);

outputFormat.WriteSectorTag(new byte[]
{
Expand All @@ -178,7 +178,7 @@ void ReadSbcData(in ulong blocks, in uint maxBlocksToRead, in uint blockSize, Du
continue;
}

outputFormat.WriteSectorTag(titleKey.Value.Key, i + j, SectorTagType.DvdTitleKey);
outputFormat.WriteSectorTag(titleKey.Value.Key, i + j, SectorTagType.DvdSectorTitleKey);
_resume.MissingTitleKeys.Remove(i + j);

CSS.DecryptTitleKey(discKey, titleKey.Value.Key, out tmpBuf);
Expand All @@ -190,7 +190,7 @@ void ReadSbcData(in ulong blocks, in uint maxBlocksToRead, in uint blockSize, Du
// Todo: Flag in the outputFormat that a sector has been decrypted
{
ErrorNumber errno =
outputFormat.ReadSectorsTag(i, blocksToRead, SectorTagType.DvdCmi, out byte[] cmi);
outputFormat.ReadSectorsTag(i, blocksToRead, SectorTagType.DvdSectorCmi, out byte[] cmi);

if(errno != ErrorNumber.NoError)
ErrorMessage?.Invoke(string.Format(Localization.Core.Error_retrieving_CMI_for_sector_0, i));
Expand Down
6 changes: 3 additions & 3 deletions Aaru.Core/Devices/Dumping/Sbc/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void RetryTitleKeys(DVDDecryption dvdDecrypt, byte[] discKey, ref double totalDu
outputFormat.WriteSectorTag(new[]
{
titleKey.Value.CMI
}, missingKey, SectorTagType.DvdCmi);
}, missingKey, SectorTagType.DvdSectorCmi);

// If the CMI bit is 1, the sector is using copy protection, else it is not
// If the decoded title key is zeroed, there should be no copy protection
Expand All @@ -388,7 +388,7 @@ void RetryTitleKeys(DVDDecryption dvdDecrypt, byte[] discKey, ref double totalDu
outputFormat.WriteSectorTag(new byte[]
{
0, 0, 0, 0, 0
}, missingKey, SectorTagType.DvdTitleKey);
}, missingKey, SectorTagType.DvdSectorTitleKey);

outputFormat.WriteSectorTag(new byte[]
{
Expand All @@ -404,7 +404,7 @@ void RetryTitleKeys(DVDDecryption dvdDecrypt, byte[] discKey, ref double totalDu
}
else
{
outputFormat.WriteSectorTag(titleKey.Value.Key, missingKey, SectorTagType.DvdTitleKey);
outputFormat.WriteSectorTag(titleKey.Value.Key, missingKey, SectorTagType.DvdSectorTitleKey);
_resume.MissingTitleKeys.Remove(missingKey);

if(discKey != null)
Expand Down
1 change: 1 addition & 0 deletions Aaru.Core/Media/Detection/MMC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
using Aaru.Devices;
using Aaru.Helpers;
using DMI = Aaru.Decoders.Xbox.DMI;
using Sector = Aaru.Decoders.CD.Sector;

namespace Aaru.Core.Media.Detection;

Expand Down
2 changes: 1 addition & 1 deletion Aaru.Decoders
2 changes: 1 addition & 1 deletion Aaru.Devices/Device/ScsiCommands/SBC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public bool Read6(out byte[] buffer, out byte[] senseBuffer, uint lba, uint bloc
/// If set to <c>true</c> requested blocks shall be assigned the lowest retention priority on cache
/// fetch/retain.
/// </param>
/// <param name="fua">If set to <c>true</c> requested blocks MUST bu read from medium and not the cache.</param>
/// <param name="fua">If set to <c>true</c> requested blocks MUST be read from medium and not the cache.</param>
/// <param name="fuaNv">
/// If set to <c>true</c> requested blocks will be returned from non-volatile cache. If they're not
/// present they shall be stored there.
Expand Down
5 changes: 4 additions & 1 deletion Aaru.Images/AaruFormat/AaruFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ public sealed partial class AaruFormat : IWritableOpticalImage, IVerifiableImage
/// <summary>If DDT is on-disk, this is the image stream offset at which it starts.</summary>
long _outMemoryDdtPosition;
bool _rewinded;
byte[] _sectorCpiMai;
byte[] _sectorCprMai;
byte[] _sectorIed;
byte[] _sectorId;
byte[] _sectorEdc;
byte[] _sectorDecryptedTitleKey;
/// <summary>Cache for data that prefixes the user data on a sector (e.g. sync).</summary>
byte[] _sectorPrefix;
Expand Down
12 changes: 9 additions & 3 deletions Aaru.Images/AaruFormat/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,16 @@ enum DataType : ushort
CompactDiscLeadIn = 79,
/// <summary>Decrypted DVD Disc Key</summary>
DvdDiscKeyDecrypted = 80,
/// <summary>DVD CPI_MAI</summary>
DvdSectorCpiMai = 81,
/// <summary>DVD Copyright Management Information (CPR_MAI)</summary>
DvdSectorCprMai = 81,
/// <summary>Decrypted DVD Title Key</summary>
DvdSectorTitleKeyDecrypted = 82
DvdSectorTitleKeyDecrypted = 82,
/// <summary>DVD Identification Data (ID)</summary>
DvdSectorId = 83,
/// <summary>DVD ID Error Detection Code (IED)</summary>
DvdSectorIed = 84,
/// <summary>DVD Error Detection Code (EDC)</summary>
DvdSectorEdc = 85
}

/// <summary>List of known blocks types</summary>
Expand Down
97 changes: 85 additions & 12 deletions Aaru.Images/AaruFormat/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,47 @@ public ErrorNumber Open(IFilter imageFilter)
GC.GetTotalMemory(false));

break;
case DataType.DvdSectorCpiMai:
_sectorCpiMai = data;
case DataType.DvdSectorCprMai:
_sectorCprMai = data;

if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdCmi))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdCmi);
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdSectorCmi))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdSectorCmi);

if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdTitleKey))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdTitleKey);
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdSectorTitleKey))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdSectorTitleKey);

AaruConsole.DebugWriteLine("Aaru Format plugin", Localization.Memory_snapshot_0_bytes,
GC.GetTotalMemory(false));

break;
case DataType.DvdSectorId:
_sectorId = data;

if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdSectorInformation))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdSectorInformation);

if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdSectorNumber))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdSectorNumber);

AaruConsole.DebugWriteLine("Aaru Format plugin", Localization.Memory_snapshot_0_bytes,
GC.GetTotalMemory(false));

break;
case DataType.DvdSectorIed:
_sectorDecryptedTitleKey = data;

if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdSectorIed))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdSectorIed);

AaruConsole.DebugWriteLine("Aaru Format plugin", Localization.Memory_snapshot_0_bytes,
GC.GetTotalMemory(false));

break;
case DataType.DvdSectorEdc:
_sectorDecryptedTitleKey = data;

if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.DvdSectorEdc))
_imageInfo.ReadableSectorTags.Add(SectorTagType.DvdSectorEdc);

AaruConsole.DebugWriteLine("Aaru Format plugin", Localization.Memory_snapshot_0_bytes,
GC.GetTotalMemory(false));
Expand Down Expand Up @@ -1769,8 +1802,12 @@ public ErrorNumber ReadSectorsTag(ulong sectorAddress, uint length, SectorTagTyp
case SectorTagType.CdSectorSubchannel:
case SectorTagType.CdSectorSubHeader:
case SectorTagType.CdSectorSync:
case SectorTagType.DvdCmi:
case SectorTagType.DvdTitleKey:
case SectorTagType.DvdSectorCmi:
case SectorTagType.DvdSectorTitleKey:
case SectorTagType.DvdSectorInformation:
case SectorTagType.DvdSectorNumber:
case SectorTagType.DvdSectorIed:
case SectorTagType.DvdSectorEdc:
case SectorTagType.DvdTitleKeyDecrypted: break;
case SectorTagType.CdTrackFlags:
if(!_trackFlags.TryGetValue((byte)sectorAddress, out byte flags))
Expand Down Expand Up @@ -1954,21 +1991,57 @@ public ErrorNumber ReadSectorsTag(ulong sectorAddress, uint length, SectorTagTyp
if(_imageInfo.MediaType == MediaType.DVDROM)
switch(tag)
{
case SectorTagType.DvdCmi:
case SectorTagType.DvdSectorCmi:
{
sectorOffset = 0;
sectorSize = 1;
sectorSkip = 5;
dataSource = _sectorCpiMai;
dataSource = _sectorCprMai;

break;
}
case SectorTagType.DvdTitleKey:
case SectorTagType.DvdSectorTitleKey:
{
sectorOffset = 1;
sectorSize = 5;
sectorSkip = 0;
dataSource = _sectorCpiMai;
dataSource = _sectorCprMai;

break;
}
case SectorTagType.DvdSectorInformation:
{
sectorOffset = 0;
sectorSize = 1;
sectorSkip = 3;
dataSource = _sectorId;

break;
}
case SectorTagType.DvdSectorNumber:
{
sectorOffset = 1;
sectorSize = 3;
sectorSkip = 0;
dataSource = _sectorId;

break;
}
case SectorTagType.DvdSectorIed:
{
sectorOffset = 0;
sectorSize = 2;
sectorSkip = 0;
dataSource = _sectorIed;

break;
}
case SectorTagType.DvdSectorEdc:
{
sectorOffset = 0;
sectorSize = 4;
sectorSkip = 0;
dataSource = _sectorEdc;

break;
}
Expand Down
Loading

0 comments on commit ebf893e

Please sign in to comment.