diff --git a/Aaru.Core/Devices/Dumping/Sbc/Data.cs b/Aaru.Core/Devices/Dumping/Sbc/Data.cs index e1474a87d..7292f1335 100644 --- a/Aaru.Core/Devices/Dumping/Sbc/Data.cs +++ b/Aaru.Core/Devices/Dumping/Sbc/Data.cs @@ -105,91 +105,92 @@ namespace Aaru.Core.Devices.Dumping if(!sense && !_dev.Error) { - if(Settings.Settings.Current.EnableDecryption) + if(Settings.Settings.Current.EnableDecryption && + discKey != null && + _titleKeys) { - if(_titleKeys && discKey != null) + for(ulong j = 0; j < blocksToRead; j++) { - for(ulong j = 0; j < blocksToRead; j++) - { - if(_aborted) - break; + if(_aborted) + break; - if(!_resume.MissingTitleKeys.Contains(i + j)) - // Key is already dumped. + 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; - byte[] tmpBuf; - - bool tmpSense = dvdDecrypt.ReadTitleKey(out tmpBuf, out _, - DvdCssKeyClass.DvdCssCppmOrCprm, i + j, - _dev.Timeout, out _); - - if(!tmpSense) + // If the CMI bit is 1, the sector is using copy protection, else it is not + if((titleKey.Value.CMI & 0x80) >> 7 == 0) { - 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 the CMI bit is 1, the sector is using copy protection, else it is not - if((titleKey.Value.CMI & 0x80) >> 7 == 0) + // The CMI indicates this sector is not encrypted. + _outputPlugin.WriteSectorTag(new byte[] { - // The CMI indicates this sector is not encrypted. - _outputPlugin.WriteSectorTag(new byte[] - { - 0, 0, 0, 0, 0 - }, i + j, SectorTagType.DvdTitleKey); + 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; - } - - // According to libdvdcss, if the key is all zeroes, the sector is actually - // not encrypted even if the CMI says it is. - if(titleKey.Value.Key.All(k => k == 0)) + _outputPlugin.WriteSectorTag(new byte[] { - _outputPlugin.WriteSectorTag(new byte[] - { - 0, 0, 0, 0, 0 - }, i + j, SectorTagType.DvdTitleKey); + 0, 0, 0, 0, 0 + }, i + j, SectorTagType.DvdTitleKeyDecrypted); - _outputPlugin.WriteSectorTag(new byte[] - { - 0, 0, 0, 0, 0 - }, i + j, SectorTagType.DvdTitleKeyDecrypted); + _resume.MissingTitleKeys.Remove(i + j); - _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); + continue; } + + // According to libdvdcss, if the key is all zeroes, the sector is actually + // not encrypted even if the CMI says it is. + if(titleKey.Value.Key.All(k => k == 0)) + { + _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); } } - - if(!_storeEncrypted && _titleKeys) + + if(!_storeEncrypted) + // Todo: Flag in the _outputPlugin that a sector has been decrypted buffer = CSS.DecryptSector(buffer, - _outputPlugin.ReadSectorsTag(i, blocksToRead, SectorTagType.DvdCmi), _outputPlugin.ReadSectorsTag(i, blocksToRead, - SectorTagType.DvdTitleKeyDecrypted), - blocksToRead, blockSize); + SectorTagType.DvdCmi), + _outputPlugin.ReadSectorsTag(i, blocksToRead, + SectorTagType.DvdTitleKeyDecrypted), blocksToRead, + blockSize); } mhddLog.Write(i, cmdDuration); diff --git a/Aaru.Core/Devices/Dumping/Sbc/Dump.cs b/Aaru.Core/Devices/Dumping/Sbc/Dump.cs index 5e2ec1121..b86be096b 100644 --- a/Aaru.Core/Devices/Dumping/Sbc/Dump.cs +++ b/Aaru.Core/Devices/Dumping/Sbc/Dump.cs @@ -668,7 +668,9 @@ namespace Aaru.Core.Devices.Dumping bool newTrim = false; - if(Settings.Settings.Current.EnableDecryption && _titleKeys) + if(Settings.Settings.Current.EnableDecryption && + _titleKeys && + dskType == MediaType.DVDROM) { UpdateStatus?.Invoke("Title keys dumping is enabled. This will be very slow."); _resume.MissingTitleKeys ??= new List(Enumerable.Range(0, (int)blocks).Select(n => (ulong)n)); @@ -1209,4 +1211,4 @@ namespace Aaru.Core.Devices.Dumping Statistics.AddMedia(dskType, true); } } -} +} \ No newline at end of file