2017-10-09 13:52:26 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ISO.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : ISO9660 filesystem plugin.
|
2017-10-09 13:52:26 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// ISO9660 filesystem structures.
|
2017-10-09 13:52:26 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2017-10-09 13:52:26 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using System;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems.ISO9660
|
|
|
|
|
|
{
|
2017-12-21 16:27:09 +00:00
|
|
|
|
public partial class ISO9660
|
2017-10-09 13:52:26 +01:00
|
|
|
|
{
|
2017-12-24 02:37:41 +00:00
|
|
|
|
static DecodedVolumeDescriptor DecodeVolumeDescriptor(PrimaryVolumeDescriptor pvd)
|
|
|
|
|
|
{
|
|
|
|
|
|
DecodedVolumeDescriptor decodedVD = new DecodedVolumeDescriptor
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
SystemIdentifier = StringHandlers.CToString(pvd.system_id).TrimEnd(),
|
|
|
|
|
|
VolumeIdentifier = StringHandlers.CToString(pvd.volume_id).TrimEnd(),
|
|
|
|
|
|
VolumeSetIdentifier = StringHandlers.CToString(pvd.volume_set_id).TrimEnd(),
|
|
|
|
|
|
PublisherIdentifier = StringHandlers.CToString(pvd.publisher_id).TrimEnd(),
|
2018-01-29 17:36:58 +00:00
|
|
|
|
DataPreparerIdentifier = StringHandlers.CToString(pvd.preparer_id).TrimEnd(),
|
2019-02-12 18:51:15 +00:00
|
|
|
|
ApplicationIdentifier = StringHandlers.CToString(pvd.application_id).TrimEnd()
|
2017-12-24 02:37:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(pvd.creation_date[0] == '0' || pvd.creation_date[0] == 0x00) decodedVD.CreationTime = DateTime.MinValue;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else
|
|
|
|
|
|
decodedVD.CreationTime =
|
|
|
|
|
|
DateHandlers.Iso9660ToDateTime(pvd.creation_date);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
|
|
|
|
|
if(pvd.modification_date[0] == '0' || pvd.modification_date[0] == 0x00)
|
|
|
|
|
|
decodedVD.HasModificationTime = false;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
decodedVD.HasModificationTime = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decodedVD.ModificationTime = DateHandlers.Iso9660ToDateTime(pvd.modification_date);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(pvd.expiration_date[0] == '0' || pvd.expiration_date[0] == 0x00) decodedVD.HasExpirationTime = false;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
decodedVD.HasExpirationTime = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decodedVD.ExpirationTime = DateHandlers.Iso9660ToDateTime(pvd.expiration_date);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(pvd.effective_date[0] == '0' || pvd.effective_date[0] == 0x00) decodedVD.HasEffectiveTime = false;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
decodedVD.HasEffectiveTime = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decodedVD.EffectiveTime = DateHandlers.Iso9660ToDateTime(pvd.effective_date);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decodedVD.Blocks = pvd.volume_space_size;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
decodedVD.BlockSize = pvd.logical_block_size;
|
|
|
|
|
|
|
|
|
|
|
|
return decodedVD;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-09 13:52:26 +01:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct PrimaryVolumeDescriptor
|
|
|
|
|
|
{
|
|
|
|
|
|
public byte type;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
|
|
|
|
|
public byte[] id;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public byte version;
|
|
|
|
|
|
// Only used in SVDs
|
|
|
|
|
|
public byte flags;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] system_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] volume_id;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public ulong reserved1;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public uint volume_space_size;
|
|
|
|
|
|
public uint volume_space_size_be;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
// Only used in SVDs
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[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 type_1_path_table;
|
|
|
|
|
|
public uint opt_type_1_path_table;
|
|
|
|
|
|
public uint type_m_path_table;
|
|
|
|
|
|
public uint opt_type_m_path_table;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public DirectoryRecord root_directory_record;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
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 = 37)]
|
|
|
|
|
|
public byte[] copyright_file_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 37)]
|
|
|
|
|
|
public byte[] abstract_file_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 37)]
|
|
|
|
|
|
public byte[] bibliographic_file_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] creation_date;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] modification_date;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] expiration_date;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] effective_date;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public byte file_structure_version;
|
|
|
|
|
|
public byte reserved2;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
|
|
|
|
|
|
public byte[] application_data;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 653)]
|
|
|
|
|
|
public byte[] reserved3;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct BootRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
public byte type;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
|
|
|
|
|
public byte[] id;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public byte version;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] system_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] boot_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1977)]
|
|
|
|
|
|
public byte[] boot_use;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct PartitionDescriptor
|
|
|
|
|
|
{
|
|
|
|
|
|
public byte type;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
|
|
|
|
|
public byte[] id;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public byte version;
|
|
|
|
|
|
public byte reserved1;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] system_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] partition_id;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public uint partition_location;
|
|
|
|
|
|
public uint partition_location_be;
|
|
|
|
|
|
public uint partition_size;
|
|
|
|
|
|
public uint partition_size_be;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1960)]
|
|
|
|
|
|
public byte[] system_use;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct DirectoryRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
public byte length;
|
|
|
|
|
|
public byte xattr_len;
|
|
|
|
|
|
public uint extent;
|
|
|
|
|
|
public uint extent_be;
|
|
|
|
|
|
public uint size;
|
|
|
|
|
|
public uint size_be;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
|
|
|
|
|
|
public byte[] date;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public FileFlags flags;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public byte file_unit_size;
|
|
|
|
|
|
public byte interleave;
|
|
|
|
|
|
public ushort volume_sequence_number;
|
|
|
|
|
|
public ushort volume_sequence_number_be;
|
|
|
|
|
|
public byte name_len;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
// Followed by name[name_len] and then system area until length arrives
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct ExtendedAttributeRecord
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public ushort owner;
|
|
|
|
|
|
public ushort owner_be;
|
|
|
|
|
|
public ushort group;
|
|
|
|
|
|
public ushort group_be;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public Permissions permissions;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] creation_date;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] modification_date;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] expiration_date;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
|
|
|
|
|
|
public byte[] effective_date;
|
|
|
|
|
|
public RecordFormat record_format;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public RecordAttribute record_attributes;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public ushort record_length;
|
|
|
|
|
|
public ushort record_length_be;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] system_id;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] system_use;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public byte record_version;
|
|
|
|
|
|
public byte escape_len;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] reserved1;
|
2017-10-09 13:52:26 +01:00
|
|
|
|
public ushort app_use_len;
|
|
|
|
|
|
public ushort app_use_len_be;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-13 21:50:10 +01:00
|
|
|
|
// There are two tables one in little endian one in big endian
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct PathTableEntry
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public byte name_len;
|
|
|
|
|
|
public byte xattr_len;
|
|
|
|
|
|
public uint start_lbn;
|
2017-10-13 21:50:10 +01:00
|
|
|
|
public ushort parent_dirno;
|
|
|
|
|
|
// Followed by name[name_len]
|
|
|
|
|
|
}
|
2017-10-09 13:52:26 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|