Files
Aaru/Aaru.Filesystems/ISO9660/PathTable.cs

118 lines
4.2 KiB
C#
Raw Normal View History

2019-07-31 20:10:27 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2019-07-31 20:10:27 +01:00
// ----------------------------------------------------------------------------
//
// Filename : PathTable.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : ISO9660 filesystem plugin.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2024-05-01 04:17:32 +01:00
// Copyright © 2011-2024 Natalia Portillo
// In the loving memory of Facunda "Tata" Suárez Domínguez, R.I.P. 2019/07/24
2019-07-31 20:10:27 +01:00
// ****************************************************************************/
2019-07-29 02:45:46 +01:00
using System.Collections.Generic;
2020-02-27 00:33:26 +00:00
using Aaru.Helpers;
2019-07-29 02:45:46 +01:00
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
public sealed partial class ISO9660
2019-07-29 02:45:46 +01:00
{
2022-03-06 13:29:38 +00:00
PathTableEntryInternal[] DecodePathTable(byte[] data)
2019-07-29 02:45:46 +01:00
{
2024-05-01 04:05:22 +01:00
if(data is null || data.Length == 0) return null;
2019-07-29 02:45:46 +01:00
2024-05-01 04:39:38 +01:00
List<PathTableEntryInternal> table = [];
2019-07-29 02:45:46 +01:00
var off = 0;
2022-03-06 13:29:38 +00:00
PathTableEntry entry =
Marshal.ByteArrayToStructureBigEndian<PathTableEntry>(data, off, Marshal.SizeOf<PathTableEntry>());
2022-03-06 13:29:38 +00:00
if(entry.name_len != 1 ||
entry.parent_dirno != 1 ||
data.Length <= Marshal.SizeOf<PathTableEntry>() ||
data[Marshal.SizeOf<PathTableEntry>()] != 0x00)
return null;
2019-07-29 02:45:46 +01:00
2022-03-06 13:29:38 +00:00
while(off < data.Length)
{
2022-03-07 07:36:44 +00:00
entry = Marshal.ByteArrayToStructureBigEndian<PathTableEntry>(data, off, Marshal.SizeOf<PathTableEntry>());
2019-07-29 02:45:46 +01:00
2024-05-01 04:05:22 +01:00
if(entry.name_len == 0) break;
2019-07-29 02:45:46 +01:00
2022-03-06 13:29:38 +00:00
off += Marshal.SizeOf<PathTableEntry>();
2019-07-29 02:45:46 +01:00
2023-10-05 01:52:48 +01:00
string name = _encoding.GetString(data, off, entry.name_len);
2019-07-29 02:45:46 +01:00
2022-03-06 13:29:38 +00:00
table.Add(new PathTableEntryInternal
{
Extent = entry.start_lbn,
Name = name,
Parent = entry.parent_dirno,
XattrLength = entry.xattr_len
});
2019-07-29 02:45:46 +01:00
2022-03-06 13:29:38 +00:00
off += entry.name_len;
2019-07-29 02:45:46 +01:00
2024-05-01 04:05:22 +01:00
if(entry.name_len % 2 != 0) off++;
2019-07-29 02:45:46 +01:00
}
2022-03-06 13:29:38 +00:00
return table.ToArray();
}
2022-03-06 13:29:38 +00:00
PathTableEntryInternal[] DecodeHighSierraPathTable(byte[] data)
{
2024-05-01 04:05:22 +01:00
if(data is null) return null;
2024-05-01 04:39:38 +01:00
List<PathTableEntryInternal> table = [];
2020-02-29 18:03:35 +00:00
var off = 0;
2022-03-06 13:29:38 +00:00
while(off < data.Length)
{
HighSierraPathTableEntry entry =
2024-05-01 04:05:22 +01:00
Marshal.ByteArrayToStructureBigEndian<HighSierraPathTableEntry>(data,
off,
Marshal
.SizeOf<
HighSierraPathTableEntry>());
2024-05-01 04:05:22 +01:00
if(entry.name_len == 0) break;
2022-03-06 13:29:38 +00:00
off += Marshal.SizeOf<HighSierraPathTableEntry>();
2023-10-05 01:52:48 +01:00
string name = _encoding.GetString(data, off, entry.name_len);
2022-03-06 13:29:38 +00:00
table.Add(new PathTableEntryInternal
{
Extent = entry.start_lbn,
Name = name,
Parent = entry.parent_dirno,
XattrLength = entry.xattr_len
});
2022-03-06 13:29:38 +00:00
off += entry.name_len;
2024-05-01 04:05:22 +01:00
if(entry.name_len % 2 != 0) off++;
}
2022-03-06 13:29:38 +00:00
return table.ToArray();
2019-07-29 02:45:46 +01:00
}
}