diff --git a/DiscImageChef.Filesystems/ISO9660/Consts.cs b/DiscImageChef.Filesystems/ISO9660/Consts.cs index 63c220f94..6fc2960e0 100644 --- a/DiscImageChef.Filesystems/ISO9660/Consts.cs +++ b/DiscImageChef.Filesystems/ISO9660/Consts.cs @@ -35,6 +35,9 @@ namespace DiscImageChef.Filesystems.ISO9660 { public partial class ISO9660 : Filesystem { + readonly string IsoMagic = "CD001"; + readonly string HighSierraMagic = "CDROM"; + [Flags] enum FileFlags : byte { diff --git a/DiscImageChef.Filesystems/ISO9660/ISO9660.cs b/DiscImageChef.Filesystems/ISO9660/ISO9660.cs index c60dcfb46..fb4b39d7b 100644 --- a/DiscImageChef.Filesystems/ISO9660/ISO9660.cs +++ b/DiscImageChef.Filesystems/ISO9660/ISO9660.cs @@ -40,7 +40,6 @@ namespace DiscImageChef.Filesystems.ISO9660 // TODO: Apple extensiones, requires XA or advance RR interpretation. // TODO: Check ECMA-167 // TODO: Check ECMA-168 - // TODO: HighSierra public partial class ISO9660 : Filesystem { public ISO9660() diff --git a/DiscImageChef.Filesystems/ISO9660/Info.cs b/DiscImageChef.Filesystems/ISO9660/Info.cs index 540755ef5..97019b957 100644 --- a/DiscImageChef.Filesystems/ISO9660/Info.cs +++ b/DiscImageChef.Filesystems/ISO9660/Info.cs @@ -60,16 +60,19 @@ namespace DiscImageChef.Filesystems.ISO9660 VDType = vd_sector[0 + xa_off]; byte[] VDMagic = new byte[5]; + byte[] HSMagic = new byte[5]; - // Wrong, VDs can be any order! - if(VDType == 255) // Supposedly we are in the PVD. + // This indicates the end of a volume descriptor. HighSierra here would have 16 so no problem + if(VDType == 255) return false; Array.Copy(vd_sector, 0x001 + xa_off, VDMagic, 0, 5); + Array.Copy(vd_sector, 0x009 + xa_off, HSMagic, 0, 5); DicConsole.DebugWriteLine("ISO9660 plugin", "VDMagic = {0}", CurrentEncoding.GetString(VDMagic)); + DicConsole.DebugWriteLine("ISO9660 plugin", "HSMagic = {0}", CurrentEncoding.GetString(HSMagic)); - return CurrentEncoding.GetString(VDMagic) == "CD001"; + return CurrentEncoding.GetString(VDMagic) == IsoMagic || CurrentEncoding.GetString(HSMagic) == HighSierraMagic; } public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, Partition partition, out string information) @@ -79,6 +82,7 @@ namespace DiscImageChef.Filesystems.ISO9660 bool RockRidge = false; byte VDType; // Volume Descriptor Type, should be 1 or 2. byte[] VDMagic = new byte[5]; // Volume Descriptor magic "CD001" + byte[] HSMagic = new byte[5]; // Volume Descriptor magic "CDROM" string BootSpec = ""; @@ -88,6 +92,7 @@ namespace DiscImageChef.Filesystems.ISO9660 PrimaryVolumeDescriptor? pvd = null; PrimaryVolumeDescriptor? jolietvd = null; BootRecord? bvd = null; + HighSierraPrimaryVolumeDescriptor? hsvd = null; // ISO9660 is designed for 2048 bytes/sector devices if(imagePlugin.GetSectorSize() < 2048) @@ -99,22 +104,24 @@ namespace DiscImageChef.Filesystems.ISO9660 ulong counter = 0; + byte[] vd_sector = imagePlugin.ReadSector(16 + counter + partition.Start); + int xa_off = imagePlugin.GetSectorSize() == 2336 ? 8 : 0; + Array.Copy(vd_sector, 0x009 + xa_off, HSMagic, 0, 5); + bool HighSierra = CurrentEncoding.GetString(HSMagic) == HighSierraMagic; + int hs_off = 0; + if(HighSierra) + hs_off = 8; + while(true) { DicConsole.DebugWriteLine("ISO9660 plugin", "Processing VD loop no. {0}", counter); // Seek to Volume Descriptor DicConsole.DebugWriteLine("ISO9660 plugin", "Reading sector {0}", 16 + counter + partition.Start); byte[] vd_sector_tmp = imagePlugin.ReadSector(16 + counter + partition.Start); - byte[] vd_sector; - if(vd_sector_tmp.Length == 2336) - { - vd_sector = new byte[2336 - 8]; - Array.Copy(vd_sector_tmp, 8, vd_sector, 0, 2336 - 8); - } - else - vd_sector = vd_sector_tmp; + vd_sector = new byte[vd_sector_tmp.Length - xa_off]; + Array.Copy(vd_sector_tmp, xa_off, vd_sector, 0, vd_sector.Length); - VDType = vd_sector[0]; + VDType = vd_sector[0 + hs_off]; DicConsole.DebugWriteLine("ISO9660 plugin", "VDType = {0}", VDType); if(VDType == 255) // Supposedly we are in the PVD. @@ -125,8 +132,9 @@ namespace DiscImageChef.Filesystems.ISO9660 } Array.Copy(vd_sector, 0x001, VDMagic, 0, 5); + Array.Copy(vd_sector, 0x009, HSMagic, 0, 5); - if(CurrentEncoding.GetString(VDMagic) != "CD001") // Recognized, it is an ISO9660, now check for rest of data. + if(CurrentEncoding.GetString(VDMagic) != IsoMagic && CurrentEncoding.GetString(HSMagic) != HighSierraMagic) // Recognized, it is an ISO9660, now check for rest of data. { if(counter == 0) return; @@ -139,7 +147,7 @@ namespace DiscImageChef.Filesystems.ISO9660 { bvd = new BootRecord(); IntPtr ptr = Marshal.AllocHGlobal(2048); - Marshal.Copy(vd_sector, 0, ptr, 2048); + Marshal.Copy(vd_sector, hs_off, ptr, 2048 - hs_off); bvd = (BootRecord)Marshal.PtrToStructure(ptr, typeof(BootRecord)); Marshal.FreeHGlobal(ptr); @@ -152,11 +160,22 @@ namespace DiscImageChef.Filesystems.ISO9660 } case 1: { - pvd = new PrimaryVolumeDescriptor(); - IntPtr ptr = Marshal.AllocHGlobal(2048); - Marshal.Copy(vd_sector, 0, ptr, 2048); - pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(ptr, typeof(PrimaryVolumeDescriptor)); - Marshal.FreeHGlobal(ptr); + if(HighSierra) + { + hsvd = new HighSierraPrimaryVolumeDescriptor(); + IntPtr ptr = Marshal.AllocHGlobal(2048); + Marshal.Copy(vd_sector, 0, ptr, 2048); + hsvd = (HighSierraPrimaryVolumeDescriptor)Marshal.PtrToStructure(ptr, typeof(HighSierraPrimaryVolumeDescriptor)); + Marshal.FreeHGlobal(ptr); + } + else + { + pvd = new PrimaryVolumeDescriptor(); + IntPtr ptr = Marshal.AllocHGlobal(2048); + Marshal.Copy(vd_sector, 0, ptr, 2048); + pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(ptr, typeof(PrimaryVolumeDescriptor)); + Marshal.FreeHGlobal(ptr); + } break; } case 2: @@ -194,17 +213,20 @@ namespace DiscImageChef.Filesystems.ISO9660 xmlFSType = new Schemas.FileSystemType(); - if(pvd == null) + if(pvd == null && hsvd == null) { information = "ERROR: Could not find primary volume descriptor"; return; } - decodedVD = DecodeVolumeDescriptor(pvd.Value); + if(HighSierra) + decodedVD = DecodeVolumeDescriptor(hsvd.Value); + else + decodedVD = DecodeVolumeDescriptor(pvd.Value); + if(jolietvd != null) decodedJolietVD = DecodeJolietDescriptor(jolietvd.Value); - ulong i = (ulong)BitConverter.ToInt32(VDPathTableStart, 0); DicConsole.DebugWriteLine("ISO9660 plugin", "VDPathTableStart = {0} + {1} = {2}", i, partition.Start, i + partition.Start); @@ -234,7 +256,7 @@ namespace DiscImageChef.Filesystems.ISO9660 Decoders.Sega.Saturn.IPBin? Saturn = Decoders.Sega.Saturn.DecodeIPBin(ipbin_sector); Decoders.Sega.Dreamcast.IPBin? Dreamcast = Decoders.Sega.Dreamcast.DecodeIPBin(ipbin_sector); - ISOMetadata.AppendFormat("ISO9660 file system").AppendLine(); + ISOMetadata.AppendFormat("{0} file system", HighSierra ? "High Sierra Format" : "ISO9660").AppendLine(); if(jolietvd != null) ISOMetadata.AppendFormat("Joliet extensions present.").AppendLine(); if(RockRidge) @@ -306,7 +328,7 @@ namespace DiscImageChef.Filesystems.ISO9660 ISOMetadata.AppendFormat("Volume has always been effective.").AppendLine(); } - xmlFSType.Type = "ISO9660"; + xmlFSType.Type = HighSierra ? "High Sierra Format" : "ISO9660"; if(jolietvd != null) { diff --git a/DiscImageChef.Filesystems/ISO9660/Structs.cs b/DiscImageChef.Filesystems/ISO9660/Structs.cs index 8f85eaca2..a4be4c00d 100644 --- a/DiscImageChef.Filesystems/ISO9660/Structs.cs +++ b/DiscImageChef.Filesystems/ISO9660/Structs.cs @@ -50,7 +50,7 @@ namespace DiscImageChef.Filesystems.ISO9660 public byte[] system_id; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] volume_id; - public ulong reserved2; + public ulong reserved1; public uint volume_space_size; public uint volume_space_size_be; // Only used in SVDs @@ -93,11 +93,77 @@ namespace DiscImageChef.Filesystems.ISO9660 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)] public byte[] effective_date; public byte file_structure_version; - public byte reserved4; + public byte reserved2; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] public byte[] application_data; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 653)] - public byte[] reserved5; + public byte[] reserved3; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + struct HighSierraPrimaryVolumeDescriptor + { + public uint volume_lbn; + public uint volume_lbn_be; + public byte type; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)] + public byte[] id; + public byte version; + // Only used in SVDs + public byte flags; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] system_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] volume_id; + public ulong reserved1; + public uint volume_space_size; + public uint volume_space_size_be; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] escape_sequences; + public ushort volume_set_size; + public ushort volume_set_size_be; + public ushort volume_sequence_number; + public ushort volume_sequence_number_be; + public ushort logical_block_size; + public ushort logical_block_size_be; + public uint path_table_size; + public uint path_table_size_be; + public uint manditory_path_table_lsb; + public uint opt_path_table_lsb_1; + public uint opt_path_table_lsb_2; + public uint opt_path_table_lsb_3; + public uint manditory_path_table_msb; + public uint opt_path_table_msb_1; + public uint opt_path_table_msb_2; + public uint opt_path_table_msb_3; + public HighSierraDirectoryRecord root_directory_record; + public byte root_directory_name; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] + public byte[] volume_set_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] + public byte[] publisher_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] + public byte[] preparer_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] + public byte[] application_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] copyright_file_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public byte[] abstract_file_id; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] creation_date; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] modification_date; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] expiration_date; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] effective_date; + public byte file_structure_version; + public byte reserved2; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] + public byte[] application_data; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 680)] + public byte[] reserved3; } [StructLayout(LayoutKind.Sequential, Pack = 1)] @@ -154,6 +220,26 @@ namespace DiscImageChef.Filesystems.ISO9660 public byte name_len; } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + struct HighSierraDirectoryRecord + { + public byte length; + public byte xattr_len; + public uint extent; + public uint extent_be; + public uint size; + public uint size_be; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public byte[] date; + public FileFlags flags; + public byte reserved; + public byte interleave_size; + public byte interleave; + public ushort volume_sequence_number; + public ushort volume_sequence_number_be; + public byte name_len; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ExtendedAttributeRecord { @@ -306,5 +392,56 @@ namespace DiscImageChef.Filesystems.ISO9660 return decodedVD; } + + static DecodedVolumeDescriptor DecodeVolumeDescriptor(HighSierraPrimaryVolumeDescriptor pvd) + { + DecodedVolumeDescriptor decodedVD = new DecodedVolumeDescriptor(); + + decodedVD.SystemIdentifier = Encoding.ASCII.GetString(pvd.system_id).TrimEnd().Trim(new[] { '\0' }); + decodedVD.VolumeIdentifier = Encoding.ASCII.GetString(pvd.volume_id).TrimEnd().Trim(new[] { '\0' }); + decodedVD.VolumeSetIdentifier = Encoding.ASCII.GetString(pvd.volume_set_id).TrimEnd().Trim(new[] { '\0' }); + decodedVD.PublisherIdentifier = Encoding.ASCII.GetString(pvd.publisher_id).TrimEnd().Trim(new[] { '\0' }); + decodedVD.DataPreparerIdentifier = Encoding.ASCII.GetString(pvd.preparer_id).TrimEnd().Trim(new[] { '\0' }); + decodedVD.ApplicationIdentifier = Encoding.ASCII.GetString(pvd.application_data).TrimEnd().Trim(new[] { '\0' }); + if(pvd.creation_date[0] == '0' || pvd.creation_date[0] == 0x00) + decodedVD.CreationTime = DateTime.MinValue; + else + decodedVD.CreationTime = DateHandlers.HighSierraToDateTime(pvd.creation_date); + + if(pvd.modification_date[0] == '0' || pvd.modification_date[0] == 0x00) + { + decodedVD.HasModificationTime = false; + } + else + { + decodedVD.HasModificationTime = true; + decodedVD.ModificationTime = DateHandlers.HighSierraToDateTime(pvd.modification_date); + } + + if(pvd.expiration_date[0] == '0' || pvd.expiration_date[0] == 0x00) + { + decodedVD.HasExpirationTime = false; + } + else + { + decodedVD.HasExpirationTime = true; + decodedVD.ExpirationTime = DateHandlers.HighSierraToDateTime(pvd.expiration_date); + } + + if(pvd.effective_date[0] == '0' || pvd.effective_date[0] == 0x00) + { + decodedVD.HasEffectiveTime = false; + } + else + { + decodedVD.HasEffectiveTime = true; + decodedVD.EffectiveTime = DateHandlers.HighSierraToDateTime(pvd.effective_date); + } + + decodedVD.Blocks = pvd.volume_space_size; + decodedVD.BlockSize = pvd.logical_block_size; + + return decodedVD; + } } } diff --git a/DiscImageChef.Helpers/DateHandlers.cs b/DiscImageChef.Helpers/DateHandlers.cs index 0c63e4499..915f31b27 100644 --- a/DiscImageChef.Helpers/DateHandlers.cs +++ b/DiscImageChef.Helpers/DateHandlers.cs @@ -81,6 +81,13 @@ namespace DiscImageChef return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + public static DateTime HighSierraToDateTime(byte[] VDDateTime) + { + byte[] isotime = new byte[17]; + Array.Copy(VDDateTime, 0, isotime, 0, 16); + return ISO9660ToDateTime(isotime); + } + public static DateTime ISO9660ToDateTime(byte[] VDDateTime) { int year, month, day, hour, minute, second, hundredths; diff --git a/README.md b/README.md index 6aa108512..3e867e7a9 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ Supported file systems for identification and information only * Flash-Friendly File System (F2FS) * Fossil file system (from Plan9) * HAMMER file system +* High Sierra Format * HP Logical Interchange Format * IBM Journaling File System (JFS) * ISO9660