mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Strengthen the detection of needing to dump DVD title keys
This commit is contained in:
@@ -105,91 +105,92 @@ namespace Aaru.Core.Devices.Dumping
|
|||||||
if(!sense &&
|
if(!sense &&
|
||||||
!_dev.Error)
|
!_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))
|
if(!_resume.MissingTitleKeys.Contains(i + j))
|
||||||
// Key is already dumped.
|
|
||||||
|
// 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;
|
continue;
|
||||||
|
|
||||||
byte[] tmpBuf;
|
// If the CMI bit is 1, the sector is using copy protection, else it is not
|
||||||
|
if((titleKey.Value.CMI & 0x80) >> 7 == 0)
|
||||||
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);
|
// The CMI indicates this sector is not encrypted.
|
||||||
|
_outputPlugin.WriteSectorTag(new byte[]
|
||||||
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.
|
0, 0, 0, 0, 0
|
||||||
_outputPlugin.WriteSectorTag(new byte[]
|
}, i + j, SectorTagType.DvdTitleKey);
|
||||||
{
|
|
||||||
0, 0, 0, 0, 0
|
|
||||||
}, i + j, SectorTagType.DvdTitleKey);
|
|
||||||
|
|
||||||
_outputPlugin.WriteSectorTag(new byte[]
|
_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[]
|
0, 0, 0, 0, 0
|
||||||
{
|
}, i + j, SectorTagType.DvdTitleKeyDecrypted);
|
||||||
0, 0, 0, 0, 0
|
|
||||||
}, i + j, SectorTagType.DvdTitleKey);
|
|
||||||
|
|
||||||
_outputPlugin.WriteSectorTag(new byte[]
|
_resume.MissingTitleKeys.Remove(i + j);
|
||||||
{
|
|
||||||
0, 0, 0, 0, 0
|
|
||||||
}, i + j, SectorTagType.DvdTitleKeyDecrypted);
|
|
||||||
|
|
||||||
_resume.MissingTitleKeys.Remove(i + j);
|
continue;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Todo: Flag in the _outputPlugin that a sector has been decrypted
|
||||||
buffer = CSS.DecryptSector(buffer,
|
buffer = CSS.DecryptSector(buffer,
|
||||||
_outputPlugin.ReadSectorsTag(i, blocksToRead, SectorTagType.DvdCmi),
|
|
||||||
_outputPlugin.ReadSectorsTag(i, blocksToRead,
|
_outputPlugin.ReadSectorsTag(i, blocksToRead,
|
||||||
SectorTagType.DvdTitleKeyDecrypted),
|
SectorTagType.DvdCmi),
|
||||||
blocksToRead, blockSize);
|
_outputPlugin.ReadSectorsTag(i, blocksToRead,
|
||||||
|
SectorTagType.DvdTitleKeyDecrypted), blocksToRead,
|
||||||
|
blockSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
mhddLog.Write(i, cmdDuration);
|
mhddLog.Write(i, cmdDuration);
|
||||||
|
|||||||
@@ -668,7 +668,9 @@ namespace Aaru.Core.Devices.Dumping
|
|||||||
|
|
||||||
bool newTrim = false;
|
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.");
|
UpdateStatus?.Invoke("Title keys dumping is enabled. This will be very slow.");
|
||||||
_resume.MissingTitleKeys ??= new List<ulong>(Enumerable.Range(0, (int)blocks).Select(n => (ulong)n));
|
_resume.MissingTitleKeys ??= new List<ulong>(Enumerable.Range(0, (int)blocks).Select(n => (ulong)n));
|
||||||
@@ -1209,4 +1211,4 @@ namespace Aaru.Core.Devices.Dumping
|
|||||||
Statistics.AddMedia(dskType, true);
|
Statistics.AddMedia(dskType, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user