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:
@@ -59,12 +59,13 @@ namespace Aaru.Core.Devices.Dumping
|
||||
/// <summary>Dumps an optical disc</summary>
|
||||
void Mmc()
|
||||
{
|
||||
MediaType dskType = MediaType.Unknown;
|
||||
bool sense;
|
||||
byte[] tmpBuf;
|
||||
bool compactDisc = true;
|
||||
bool gotConfiguration = false;
|
||||
bool isXbox = false;
|
||||
MediaType dskType = MediaType.Unknown;
|
||||
bool sense;
|
||||
byte[] tmpBuf;
|
||||
bool compactDisc = true;
|
||||
bool gotConfiguration = false;
|
||||
bool isXbox = false;
|
||||
DVDDecryption dvdDecrypt = null;
|
||||
_speedMultiplier = 1;
|
||||
|
||||
// TODO: Log not only what is it reading, but if it was read correctly or not.
|
||||
@@ -528,7 +529,7 @@ namespace Aaru.Core.Devices.Dumping
|
||||
{
|
||||
UpdateStatus?.Invoke("Drive reports disc uses CSS copy protection.");
|
||||
|
||||
var dvdDecrypt = new DVDDecryption(_dev);
|
||||
dvdDecrypt = new DVDDecryption(_dev);
|
||||
|
||||
sense = dvdDecrypt.ReadBusKey(out cmdBuf, out _,
|
||||
CSS_CPRM.DecodeLeadInCopyright(cmdBuf)!.Value.
|
||||
@@ -866,7 +867,7 @@ namespace Aaru.Core.Devices.Dumping
|
||||
return;
|
||||
}
|
||||
|
||||
Sbc(mediaTags, dskType, true);
|
||||
Sbc(mediaTags, dskType, true, dvdDecrypt);
|
||||
}
|
||||
|
||||
static void AddMediaTagToSidecar(string outputPath, KeyValuePair<MediaTagType, byte[]> tag,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -53,6 +53,7 @@ using DeviceReport = Aaru.Core.Devices.Report.DeviceReport;
|
||||
using MediaType = Aaru.CommonTypes.MediaType;
|
||||
using TrackType = Aaru.CommonTypes.Enums.TrackType;
|
||||
using Version = Aaru.CommonTypes.Interop.Version;
|
||||
using DVDDecryption = Aaru.Decryption.DVD.Dump;
|
||||
|
||||
// ReSharper disable JoinDeclarationAndInitializer
|
||||
|
||||
@@ -65,7 +66,9 @@ namespace Aaru.Core.Devices.Dumping
|
||||
/// <param name="opticalDisc">If device contains an optical disc (e.g. DVD or BD)</param>
|
||||
/// <param name="mediaTags">Media tags as retrieved in MMC layer</param>
|
||||
/// <param name="dskType">Disc type as detected in SCSI or MMC layer</param>
|
||||
void Sbc(Dictionary<MediaTagType, byte[]> mediaTags, MediaType dskType, bool opticalDisc)
|
||||
/// <param name="dvdDecrypt">DVD CSS decryption module</param>
|
||||
void Sbc(Dictionary<MediaTagType, byte[]> mediaTags, MediaType dskType, bool opticalDisc,
|
||||
DVDDecryption dvdDecrypt = null)
|
||||
{
|
||||
bool sense;
|
||||
byte scsiMediumType = 0;
|
||||
@@ -671,7 +674,7 @@ namespace Aaru.Core.Devices.Dumping
|
||||
else
|
||||
ReadSbcData(blocks, blocksToRead, blockSize, currentTry, extents, ref currentSpeed, ref minSpeed,
|
||||
ref maxSpeed, ref totalDuration, scsiReader, mhddLog, ibgLog, ref imageWriteDuration,
|
||||
ref newTrim);
|
||||
ref newTrim, dvdDecrypt, mediaTags[MediaTagType.DVD_DiscKey_Decrypted]);
|
||||
|
||||
end = DateTime.UtcNow;
|
||||
mhddLog.Close();
|
||||
|
||||
Reference in New Issue
Block a user