mirror of
https://github.com/aaru-dps/Aaru.git
synced 2026-07-08 17:56:18 +00:00
Identify HD DVD video ISOs
This commit is contained in:
65
Aaru.Decryption/Aacs/HDDVD.cs
Normal file
65
Aaru.Decryption/Aacs/HDDVD.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : HDDVD.cs
|
||||
// Author(s) : Rebecca Wallander <sakcheen@gmail.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// HD DVD video disc helpers.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2026 Rebecca Wallander
|
||||
// ****************************************************************************/
|
||||
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
|
||||
namespace Aaru.Decryption.Aacs;
|
||||
|
||||
/// <summary>Aligns contiguous 2048-byte sectors to CPS units for decrypt during image conversion.</summary>
|
||||
public sealed class HDDVD
|
||||
{
|
||||
/// <summary>
|
||||
/// HD DVD video discs always have a <c>HVDVD_TS</c> folder. If it doesn't have one, it's not a HD DVD video.
|
||||
/// </summary>
|
||||
/// <param name="input"><c>IOpticalMediaImage</c> to check for <c>HVDVD_TS</c> folder in.</param>
|
||||
/// <param name="fs"><c>IReadOnlyFilesystem</c> to check in.</param>
|
||||
/// <param name="partition"><c>Partition</c> to check in.</param>
|
||||
/// <returns><c>true</c> if <c>HVDVD_TS</c> folder was found.</returns>
|
||||
public static bool HasHdDvdVideoTsFolder(IOpticalMediaImage input, IReadOnlyFilesystem fs, Partition partition)
|
||||
{
|
||||
ErrorNumber error = fs.Mount(input, partition, null, null, null);
|
||||
|
||||
if(error != ErrorNumber.NoError) return false;
|
||||
|
||||
error = fs.Stat("HVDVD_TS", out FileEntryInfo stat);
|
||||
fs.Unmount();
|
||||
|
||||
return error == ErrorNumber.NoError;
|
||||
}
|
||||
}
|
||||
189
Aaru.Images/ZZZRawImage/HdDvdIsoProbe.cs
Normal file
189
Aaru.Images/ZZZRawImage/HdDvdIsoProbe.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : HdDvdIsoProbe.cs
|
||||
// Author(s) : Rebecca Wallander <sakcheen@gmail.com>
|
||||
//
|
||||
// Component : Disk image plugins.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Detects HD DVD-Video layout on bare .iso images (HVDVD_TS folder).
|
||||
// Aaru.Core.Partitions.GetAll cannot be called from this assembly because
|
||||
// Aaru.Core references Aaru.Images; the partition walk below mirrors the
|
||||
// non-tape, in Partitions.GetAll. If we find a simpler way to detect a
|
||||
// HD DVD-Video layout, we should use that instead.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2026 Rebecca Wallander
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Aaru.Decryption.Aacs;
|
||||
|
||||
namespace Aaru.Images;
|
||||
|
||||
public sealed partial class ZZZRawImage
|
||||
{
|
||||
/// <summary>True if a filesystem under some partition exposes the HD DVD-Video <c>HVDVD_TS</c> folder.</summary>
|
||||
bool TryDetectHdDvdVideoIso()
|
||||
{
|
||||
IMediaImage image = this;
|
||||
IOpticalMediaImage optical = this;
|
||||
PluginRegister plugins = PluginRegister.Singleton;
|
||||
List<Partition> parts = EnumeratePartitionsForHdDvdProbe(image);
|
||||
|
||||
foreach(Partition partition in parts)
|
||||
{
|
||||
foreach(IFilesystem fs in plugins.Filesystems.Values)
|
||||
{
|
||||
if(fs is not IReadOnlyFilesystem rofs)
|
||||
continue;
|
||||
|
||||
if(!fs.Identify(image, partition))
|
||||
continue;
|
||||
|
||||
if(HDDVD.HasHdDvdVideoTsFolder(optical, rofs, partition))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists partitions the same way as <see cref="Aaru.Core.Partitions.GetAll"/> for images that are not
|
||||
/// tape.
|
||||
/// </summary>
|
||||
static List<Partition> EnumeratePartitionsForHdDvdProbe(IMediaImage image)
|
||||
{
|
||||
PluginRegister plugins = PluginRegister.Singleton;
|
||||
List<Partition> foundPartitions = [];
|
||||
List<Partition> childPartitions = [];
|
||||
List<ulong> checkedLocations = [];
|
||||
|
||||
var partitionableImage = image as IPartitionableMediaImage;
|
||||
|
||||
// Getting all partitions from device (e.g. tracks)
|
||||
if(partitionableImage?.Partitions != null)
|
||||
{
|
||||
foreach(Partition imagePartition in partitionableImage.Partitions)
|
||||
{
|
||||
foreach(IPartition plugin in plugins.Partitions.Values)
|
||||
{
|
||||
if(plugin is null) continue;
|
||||
|
||||
if(!plugin.GetInformation(image, out List<Partition> partitions, imagePartition.Start)) continue;
|
||||
|
||||
foundPartitions.AddRange(partitions);
|
||||
}
|
||||
|
||||
checkedLocations.Add(imagePartition.Start);
|
||||
}
|
||||
}
|
||||
|
||||
if(!checkedLocations.Contains(0) && image.Info.Sectors > 0)
|
||||
{
|
||||
foreach(IPartition plugin in plugins.Partitions.Values)
|
||||
{
|
||||
if(plugin is null)
|
||||
continue;
|
||||
|
||||
if(!plugin.GetInformation(image, out List<Partition> partitions, 0))
|
||||
continue;
|
||||
|
||||
foundPartitions.AddRange(partitions);
|
||||
}
|
||||
|
||||
checkedLocations.Add(0);
|
||||
}
|
||||
|
||||
while(foundPartitions.Count > 0)
|
||||
{
|
||||
if(checkedLocations.Contains(foundPartitions[0].Start))
|
||||
{
|
||||
childPartitions.Add(foundPartitions[0]);
|
||||
foundPartitions.RemoveAt(0);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Partition> children = [];
|
||||
|
||||
foreach(IPartition plugin in plugins.Partitions.Values)
|
||||
{
|
||||
if(plugin is null)
|
||||
continue;
|
||||
|
||||
if(!plugin.GetInformation(image, out List<Partition> partitions, foundPartitions[0].Start))
|
||||
continue;
|
||||
|
||||
children.AddRange(partitions);
|
||||
}
|
||||
|
||||
checkedLocations.Add(foundPartitions[0].Start);
|
||||
|
||||
if(children.Count > 0)
|
||||
{
|
||||
foundPartitions.RemoveAt(0);
|
||||
|
||||
foreach(Partition child in children)
|
||||
{
|
||||
if(checkedLocations.Contains(child.Start))
|
||||
childPartitions.Add(child);
|
||||
else
|
||||
foundPartitions.Add(child);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
childPartitions.Add(foundPartitions[0]);
|
||||
foundPartitions.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
if(partitionableImage is not null)
|
||||
{
|
||||
List<ulong> startLocations =
|
||||
childPartitions.ConvertAll(static detectedPartition => detectedPartition.Start);
|
||||
|
||||
if(partitionableImage.Partitions != null)
|
||||
{
|
||||
childPartitions.AddRange(partitionableImage.Partitions.Where(imagePartition =>
|
||||
!startLocations.Contains(imagePartition
|
||||
.Start)));
|
||||
}
|
||||
}
|
||||
|
||||
Partition[] childArray = childPartitions.OrderBy(static part => part.Start)
|
||||
.ThenBy(static part => part.Length)
|
||||
.ThenBy(static part => part.Scheme)
|
||||
.ToArray();
|
||||
|
||||
for(long i = 0; i < childArray.LongLength; i++)
|
||||
childArray[i].Sequence = (ulong)i;
|
||||
|
||||
return childArray.ToList();
|
||||
}
|
||||
}
|
||||
@@ -619,6 +619,16 @@ public sealed partial class ZZZRawImage
|
||||
else if(gcMagic == NGC_GC_MAGIC) _imageInfo.MediaType = MediaType.GOD;
|
||||
}
|
||||
|
||||
// Check for HD DVD video discs: .iso extension, size divisible by 2048, contains HVDVD_TS folder
|
||||
// Needed for identifying the correct AACS path, so we don't misidentify it as a BD video disc
|
||||
if(_extension == ".iso" &&
|
||||
_imageInfo.SectorSize == 2048 &&
|
||||
_imageInfo.ImageSize % 2048 == 0 &&
|
||||
_imageInfo.Sectors > 0 &&
|
||||
(_imageInfo.MediaType == MediaType.BDR || _imageInfo.MediaType == MediaType.BDRXL) &&
|
||||
TryDetectHdDvdVideoIso())
|
||||
_imageInfo.MediaType = MediaType.HDDVDROM;
|
||||
|
||||
// Check for bare .bca sidecar (64 bytes) for GameCube/Wii discs
|
||||
if(_imageInfo.MediaType is MediaType.GOD or MediaType.WOD && !_mediaTags.ContainsKey(MediaTagType.DVD_BCA))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user