mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add dumping of title keys
This commit is contained in:
@@ -26,9 +26,14 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Extents;
|
||||
using Aaru.Core.Logging;
|
||||
using Aaru.Decoders.DVD;
|
||||
using Aaru.Decryption;
|
||||
using Aaru.Decryption.DVD;
|
||||
using Schemas;
|
||||
using DVDDecryption = Aaru.Decryption.DVD.Dump;
|
||||
|
||||
// ReSharper disable JoinDeclarationAndInitializer
|
||||
// ReSharper disable InlineOutVariableDeclaration
|
||||
@@ -53,10 +58,12 @@ namespace Aaru.Core.Devices.Dumping
|
||||
/// <param name="ibgLog">ImgBurn log</param>
|
||||
/// <param name="imageWriteDuration">Total time spent writing to image</param>
|
||||
/// <param name="newTrim">Set if we need to start a trim</param>
|
||||
/// <param name="dvdDecrypt">DVD CSS decryption module</param>
|
||||
/// <param name="discKey">The DVD disc key</param>
|
||||
void ReadSbcData(in ulong blocks, in uint maxBlocksToRead, in uint blockSize, DumpHardwareType currentTry,
|
||||
ExtentsULong extents, ref double currentSpeed, ref double minSpeed, ref double maxSpeed,
|
||||
ref double totalDuration, Reader scsiReader, MhddLog mhddLog, IbgLog ibgLog,
|
||||
ref double imageWriteDuration, ref bool newTrim)
|
||||
ref double imageWriteDuration, ref bool newTrim, DVDDecryption dvdDecrypt, byte[] discKey)
|
||||
{
|
||||
ulong sectorSpeedStart = 0;
|
||||
bool sense;
|
||||
@@ -97,6 +104,90 @@ namespace Aaru.Core.Devices.Dumping
|
||||
if(!sense &&
|
||||
!_dev.Error)
|
||||
{
|
||||
if(_decryption)
|
||||
{
|
||||
if(_titleKeys && discKey != null)
|
||||
{
|
||||
for(ulong j = 0; j < blocksToRead; j++)
|
||||
{
|
||||
if(_aborted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(!_resume.MissingTitleKeys.Contains(i + j))
|
||||
{
|
||||
// Key is already dumped.
|
||||
continue;
|
||||
}
|
||||
|
||||
byte[] tmpBuf;
|
||||
|
||||
bool tmpSense = dvdDecrypt.ReadTitleKey(out tmpBuf, out _,
|
||||
DvdCssKeyClass.DvdCssCppmOrCprm, i + j,
|
||||
_dev.Timeout, out _);
|
||||
|
||||
if(!tmpSense)
|
||||
{
|
||||
CSS_CPRM.TitleKey? titleKey = CSS.DecodeTitleKey(tmpBuf, dvdDecrypt.BusKey);
|
||||
|
||||
if(titleKey.HasValue)
|
||||
{
|
||||
_outputPlugin.WriteSectorTag(new[]
|
||||
{
|
||||
titleKey.Value.CMI
|
||||
}, i + j, SectorTagType.DvdCmi);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
if((titleKey.Value.CMI & 0x80) >> 7 == 0)
|
||||
{
|
||||
// The CMI indicates this sector is not encrypted.
|
||||
_outputPlugin.WriteSectorTag(new byte[]
|
||||
{
|
||||
0, 0, 0, 0, 0
|
||||
}, i + j, SectorTagType.DvdTitleKey);
|
||||
|
||||
_outputPlugin.WriteSectorTag(new byte[]
|
||||
{
|
||||
0, 0, 0, 0, 0
|
||||
}, i + j, SectorTagType.DvdTitleKeyDecrypted);
|
||||
|
||||
_resume.MissingTitleKeys.Remove(i + j);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(titleKey.Value.Key.All(k => k == 0))
|
||||
{
|
||||
// According to libdvdcss, if the key is all zeroes, the sector is actually
|
||||
// not encrypted even if the CMI says it is.
|
||||
_outputPlugin.WriteSectorTag(new byte[]
|
||||
{
|
||||
0, 0, 0, 0, 0
|
||||
}, i + j, SectorTagType.DvdTitleKey);
|
||||
|
||||
_outputPlugin.WriteSectorTag(new byte[]
|
||||
{
|
||||
0, 0, 0, 0, 0
|
||||
}, i + j, SectorTagType.DvdTitleKeyDecrypted);
|
||||
|
||||
_resume.MissingTitleKeys.Remove(i + j);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
_outputPlugin.WriteSectorTag(titleKey.Value.Key, i + j, SectorTagType.DvdTitleKey);
|
||||
_resume.MissingTitleKeys.Remove(i + j);
|
||||
|
||||
CSS.DecryptTitleKey(0, discKey, titleKey.Value.Key, out tmpBuf);
|
||||
_outputPlugin.WriteSectorTag(tmpBuf, i + j, SectorTagType.DvdTitleKeyDecrypted);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mhddLog.Write(i, cmdDuration);
|
||||
ibgLog.Write(i, currentSpeed * 1024);
|
||||
DateTime writeStart = DateTime.Now;
|
||||
|
||||
Reference in New Issue
Block a user