2019-07-19 12:14:30 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-07-19 16:20:58 +01:00
|
|
|
using System.Globalization;
|
2019-07-19 14:26:02 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2019-07-19 12:14:30 +01:00
|
|
|
using DiscImageChef.CommonTypes.Structs;
|
2019-07-19 14:26:02 +01:00
|
|
|
using DiscImageChef.Helpers;
|
2019-07-19 12:14:30 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems.ISO9660
|
|
|
|
|
{
|
|
|
|
|
public partial class ISO9660
|
|
|
|
|
{
|
2019-07-19 16:20:58 +01:00
|
|
|
Dictionary<string, Dictionary<string, DecodedDirectoryEntry>> directoryCache;
|
|
|
|
|
|
2019-07-19 15:44:40 +01:00
|
|
|
// TODO: Implement path table traversal
|
|
|
|
|
public Errno ReadDir(string path, out List<string> contents)
|
|
|
|
|
{
|
|
|
|
|
contents = null;
|
|
|
|
|
if(!mounted) return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(path) || path == "/")
|
|
|
|
|
{
|
2019-07-19 16:20:58 +01:00
|
|
|
contents = GetFilenames(rootDirectoryCache);
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string cutPath = path.StartsWith("/", StringComparison.Ordinal)
|
|
|
|
|
? path.Substring(1).ToLower(CultureInfo.CurrentUICulture)
|
|
|
|
|
: path.ToLower(CultureInfo.CurrentUICulture);
|
2019-07-19 15:44:40 +01:00
|
|
|
|
2019-07-19 16:20:58 +01:00
|
|
|
if(directoryCache.TryGetValue(cutPath, out Dictionary<string, DecodedDirectoryEntry> currentDirectory))
|
|
|
|
|
{
|
|
|
|
|
contents = currentDirectory.Keys.ToList();
|
2019-07-19 15:44:40 +01:00
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 16:20:58 +01:00
|
|
|
string[] pieces = cutPath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
KeyValuePair<string, DecodedDirectoryEntry> entry =
|
|
|
|
|
rootDirectoryCache.FirstOrDefault(t => t.Key.ToLower(CultureInfo.CurrentUICulture) == pieces[0]);
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(entry.Key)) return Errno.NoSuchFile;
|
|
|
|
|
|
|
|
|
|
if(!entry.Value.Flags.HasFlag(FileFlags.Directory)) return Errno.NotDirectory;
|
|
|
|
|
|
|
|
|
|
string currentPath = pieces[0];
|
|
|
|
|
|
|
|
|
|
currentDirectory = rootDirectoryCache;
|
|
|
|
|
|
|
|
|
|
for(int p = 0; p < pieces.Length; p++)
|
|
|
|
|
{
|
|
|
|
|
entry = currentDirectory.FirstOrDefault(t => t.Key.ToLower(CultureInfo.CurrentUICulture) == pieces[p]);
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(entry.Key)) return Errno.NoSuchFile;
|
|
|
|
|
|
|
|
|
|
if(!entry.Value.Flags.HasFlag(FileFlags.Directory)) return Errno.NotDirectory;
|
|
|
|
|
|
|
|
|
|
currentPath = p == 0 ? pieces[0] : $"{currentPath}/{pieces[p]}";
|
|
|
|
|
uint currentExtent = entry.Value.Extent;
|
|
|
|
|
|
|
|
|
|
if(directoryCache.TryGetValue(currentPath, out currentDirectory)) continue;
|
|
|
|
|
|
|
|
|
|
if(currentExtent == 0) return Errno.InvalidArgument;
|
|
|
|
|
|
|
|
|
|
// TODO: XA, High Sierra
|
2019-07-24 05:27:49 +01:00
|
|
|
uint dirSizeInSectors = entry.Value.Size / 2048;
|
|
|
|
|
if(entry.Value.Size % 2048 > 0) dirSizeInSectors++;
|
|
|
|
|
|
|
|
|
|
byte[] directoryBuffer = image.ReadSectors(currentExtent, dirSizeInSectors);
|
2019-07-19 16:20:58 +01:00
|
|
|
|
|
|
|
|
// TODO: Decode Joliet
|
|
|
|
|
currentDirectory = cdi
|
|
|
|
|
? DecodeCdiDirectory(directoryBuffer)
|
|
|
|
|
: highSierra
|
|
|
|
|
? DecodeHighSierraDirectory(directoryBuffer)
|
|
|
|
|
: DecodeIsoDirectory(directoryBuffer);
|
|
|
|
|
|
2019-07-29 04:00:51 +01:00
|
|
|
if(usePathTable)
|
|
|
|
|
foreach(DecodedDirectoryEntry subDirectory in cdi
|
|
|
|
|
? GetSubdirsFromCdiPathTable(currentPath)
|
|
|
|
|
: highSierra
|
|
|
|
|
? GetSubdirsFromHighSierraPathTable(currentPath)
|
|
|
|
|
: GetSubdirsFromIsoPathTable(currentPath))
|
|
|
|
|
currentDirectory[subDirectory.Filename] = subDirectory;
|
|
|
|
|
|
2019-07-19 16:20:58 +01:00
|
|
|
directoryCache.Add(currentPath, currentDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents = GetFilenames(currentDirectory);
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<string> GetFilenames(Dictionary<string, DecodedDirectoryEntry> dirents)
|
|
|
|
|
{
|
|
|
|
|
List<string> contents = new List<string>();
|
|
|
|
|
foreach(DecodedDirectoryEntry entry in dirents.Values)
|
|
|
|
|
switch(@namespace)
|
|
|
|
|
{
|
|
|
|
|
case Namespace.Normal:
|
2019-07-22 02:58:56 +01:00
|
|
|
contents.Add(entry.Filename.EndsWith(";1", StringComparison.Ordinal)
|
|
|
|
|
? entry.Filename.Substring(0, entry.Filename.Length - 2)
|
|
|
|
|
: entry.Filename);
|
2019-07-19 16:20:58 +01:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Namespace.Vms:
|
|
|
|
|
case Namespace.Joliet:
|
|
|
|
|
case Namespace.Rrip:
|
2019-07-24 04:39:05 +01:00
|
|
|
case Namespace.Romeo:
|
|
|
|
|
contents.Add(entry.Filename);
|
2019-07-19 16:20:58 +01:00
|
|
|
break;
|
|
|
|
|
default: throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return contents;
|
2019-07-19 15:44:40 +01:00
|
|
|
}
|
2019-07-19 14:26:02 +01:00
|
|
|
|
2019-07-19 16:20:58 +01:00
|
|
|
Dictionary<string, DecodedDirectoryEntry> DecodeCdiDirectory(byte[] data) =>
|
|
|
|
|
throw new NotImplementedException();
|
2019-07-19 14:26:02 +01:00
|
|
|
|
2019-07-20 01:42:01 +01:00
|
|
|
Dictionary<string, DecodedDirectoryEntry> DecodeHighSierraDirectory(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>();
|
|
|
|
|
int entryOff = 0;
|
|
|
|
|
|
|
|
|
|
while(entryOff + DirectoryRecordSize < data.Length)
|
|
|
|
|
{
|
|
|
|
|
HighSierraDirectoryRecord record =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(data, entryOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<DirectoryRecord>());
|
|
|
|
|
|
|
|
|
|
if(record.length == 0) break;
|
|
|
|
|
|
|
|
|
|
// Special entries for current and parent directories, skip them
|
|
|
|
|
if(record.name_len == 1)
|
|
|
|
|
if(data[entryOff + DirectoryRecordSize] == 0 || data[entryOff + DirectoryRecordSize] == 1)
|
|
|
|
|
{
|
|
|
|
|
entryOff += record.length;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DecodedDirectoryEntry entry = new DecodedDirectoryEntry
|
|
|
|
|
{
|
|
|
|
|
Extent = record.size == 0 ? 0 : record.extent,
|
|
|
|
|
Size = record.size,
|
|
|
|
|
Flags = record.flags,
|
|
|
|
|
Interleave = record.interleave,
|
|
|
|
|
VolumeSequenceNumber = record.volume_sequence_number,
|
2019-07-23 06:20:00 +01:00
|
|
|
Filename = Encoding.GetString(data, entryOff + DirectoryRecordSize, record.name_len),
|
|
|
|
|
Timestamp = DecodeHighSierraDateTime(record.date)
|
2019-07-20 01:42:01 +01:00
|
|
|
};
|
|
|
|
|
|
2019-07-29 04:00:51 +01:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Directory) && usePathTable)
|
|
|
|
|
{
|
|
|
|
|
entryOff += record.length;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 02:58:56 +01:00
|
|
|
if(!entries.ContainsKey(entry.Filename)) entries.Add(entry.Filename, entry);
|
2019-07-20 01:42:01 +01:00
|
|
|
|
|
|
|
|
entryOff += record.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
2019-07-19 14:26:02 +01:00
|
|
|
|
2019-07-22 02:58:56 +01:00
|
|
|
Dictionary<string, DecodedDirectoryEntry> DecodeIsoDirectory(byte[] data)
|
2019-07-19 14:26:02 +01:00
|
|
|
{
|
2019-07-19 16:20:58 +01:00
|
|
|
Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>();
|
|
|
|
|
int entryOff = 0;
|
2019-07-19 14:26:02 +01:00
|
|
|
|
|
|
|
|
while(entryOff + DirectoryRecordSize < data.Length)
|
|
|
|
|
{
|
|
|
|
|
DirectoryRecord record =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(data, entryOff,
|
|
|
|
|
Marshal.SizeOf<DirectoryRecord>());
|
|
|
|
|
|
|
|
|
|
if(record.length == 0) break;
|
|
|
|
|
|
|
|
|
|
// Special entries for current and parent directories, skip them
|
|
|
|
|
if(record.name_len == 1)
|
|
|
|
|
if(data[entryOff + DirectoryRecordSize] == 0 || data[entryOff + DirectoryRecordSize] == 1)
|
|
|
|
|
{
|
|
|
|
|
entryOff += record.length;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 16:20:58 +01:00
|
|
|
DecodedDirectoryEntry entry = new DecodedDirectoryEntry
|
|
|
|
|
{
|
2019-07-22 02:58:56 +01:00
|
|
|
Extent = record.size == 0 ? 0 : record.extent,
|
|
|
|
|
Size = record.size,
|
|
|
|
|
Flags = record.flags,
|
|
|
|
|
Filename =
|
|
|
|
|
joliet
|
|
|
|
|
? Encoding.BigEndianUnicode.GetString(data, entryOff + DirectoryRecordSize,
|
|
|
|
|
record.name_len)
|
2019-07-23 06:20:00 +01:00
|
|
|
: Encoding.GetString(data, entryOff + DirectoryRecordSize, record.name_len),
|
2019-07-19 16:20:58 +01:00
|
|
|
FileUnitSize = record.file_unit_size,
|
|
|
|
|
Interleave = record.interleave,
|
|
|
|
|
VolumeSequenceNumber = record.volume_sequence_number,
|
2019-07-22 02:28:54 +01:00
|
|
|
Timestamp = DecodeIsoDateTime(record.date)
|
2019-07-19 16:20:58 +01:00
|
|
|
};
|
2019-07-19 14:26:02 +01:00
|
|
|
|
2019-07-29 04:00:51 +01:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Directory) && usePathTable)
|
|
|
|
|
{
|
|
|
|
|
entryOff += record.length;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 05:20:57 +01:00
|
|
|
// TODO: XA
|
2019-07-28 14:03:38 +01:00
|
|
|
int systemAreaStart = entryOff + record.name_len + Marshal.SizeOf<DirectoryRecord>();
|
2019-07-28 13:56:22 +01:00
|
|
|
int systemAreaLength = record.length - record.name_len - Marshal.SizeOf<DirectoryRecord>();
|
2019-07-28 05:20:57 +01:00
|
|
|
|
2019-07-28 14:03:38 +01:00
|
|
|
if(systemAreaStart % 2 != 0)
|
|
|
|
|
{
|
|
|
|
|
systemAreaStart++;
|
|
|
|
|
systemAreaLength--;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 16:55:15 +01:00
|
|
|
DecodeSystemArea(data, systemAreaStart, systemAreaStart + systemAreaLength, ref entry,
|
|
|
|
|
out bool hasResourceFork);
|
2019-07-28 05:20:57 +01:00
|
|
|
|
2019-07-19 14:26:02 +01:00
|
|
|
// TODO: Multi-extent files
|
2019-07-22 01:08:05 +01:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Associated))
|
|
|
|
|
{
|
2019-07-28 05:20:57 +01:00
|
|
|
if(entries.ContainsKey(entry.Filename))
|
|
|
|
|
{
|
|
|
|
|
if(hasResourceFork) entries[entry.Filename].ResourceFork = entry;
|
|
|
|
|
else entries[entry.Filename].AssociatedFile = entry;
|
|
|
|
|
}
|
2019-07-22 01:08:05 +01:00
|
|
|
else
|
2019-07-28 13:56:22 +01:00
|
|
|
{
|
2019-07-22 02:58:56 +01:00
|
|
|
entries[entry.Filename] = new DecodedDirectoryEntry
|
2019-07-22 01:08:05 +01:00
|
|
|
{
|
|
|
|
|
Extent = 0,
|
|
|
|
|
Size = 0,
|
|
|
|
|
Flags = record.flags ^ FileFlags.Associated,
|
|
|
|
|
FileUnitSize = 0,
|
|
|
|
|
Interleave = 0,
|
|
|
|
|
VolumeSequenceNumber = record.volume_sequence_number,
|
2019-07-28 18:19:17 +01:00
|
|
|
Filename = entry.Filename,
|
|
|
|
|
Timestamp = DecodeIsoDateTime(record.date)
|
2019-07-22 01:08:05 +01:00
|
|
|
};
|
2019-07-28 13:56:22 +01:00
|
|
|
|
|
|
|
|
if(hasResourceFork) entries[entry.Filename].ResourceFork = entry;
|
|
|
|
|
else entries[entry.Filename].AssociatedFile = entry;
|
|
|
|
|
}
|
2019-07-22 01:08:05 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-07-22 02:58:56 +01:00
|
|
|
if(entries.ContainsKey(entry.Filename))
|
2019-07-28 05:20:57 +01:00
|
|
|
{
|
2019-07-22 02:58:56 +01:00
|
|
|
entry.AssociatedFile = entries[entry.Filename].AssociatedFile;
|
2019-07-28 05:20:57 +01:00
|
|
|
entry.ResourceFork = entries[entry.Filename].ResourceFork;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 02:58:56 +01:00
|
|
|
entries[entry.Filename] = entry;
|
2019-07-22 01:08:05 +01:00
|
|
|
}
|
2019-07-19 14:26:02 +01:00
|
|
|
|
|
|
|
|
entryOff += record.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
2019-07-28 16:55:15 +01:00
|
|
|
|
2019-07-28 18:19:17 +01:00
|
|
|
void DecodeSystemArea(byte[] data, int start, int end, ref DecodedDirectoryEntry entry,
|
|
|
|
|
out bool hasResourceFork)
|
2019-07-28 16:55:15 +01:00
|
|
|
{
|
|
|
|
|
int systemAreaOff = start;
|
|
|
|
|
hasResourceFork = false;
|
2019-07-28 21:33:05 +01:00
|
|
|
bool continueSymlink = false;
|
|
|
|
|
bool continueSymlinkComponent = false;
|
2019-07-28 16:55:15 +01:00
|
|
|
|
|
|
|
|
while(systemAreaOff + 2 <= end)
|
|
|
|
|
{
|
|
|
|
|
ushort systemAreaSignature = BigEndianBitConverter.ToUInt16(data, systemAreaOff);
|
|
|
|
|
|
|
|
|
|
if(BigEndianBitConverter.ToUInt16(data, systemAreaOff + 6) == XA_MAGIC) systemAreaSignature = XA_MAGIC;
|
|
|
|
|
|
|
|
|
|
switch(systemAreaSignature)
|
|
|
|
|
{
|
|
|
|
|
case APPLE_MAGIC:
|
|
|
|
|
byte appleLength = data[systemAreaOff + 2];
|
|
|
|
|
AppleId appleId = (AppleId)data[systemAreaOff + 3];
|
|
|
|
|
|
2019-07-28 17:04:08 +01:00
|
|
|
// Old AAIP
|
|
|
|
|
if(appleId == AppleId.ProDOS && appleLength != 7) goto case AAIP_MAGIC;
|
|
|
|
|
|
2019-07-28 16:55:15 +01:00
|
|
|
switch(appleId)
|
|
|
|
|
{
|
|
|
|
|
case AppleId.ProDOS:
|
|
|
|
|
AppleProDOSSystemUse appleProDosSystemUse =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<AppleProDOSSystemUse>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
AppleProDOSSystemUse
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
entry.AppleProDosType = appleProDosSystemUse.aux_type;
|
|
|
|
|
entry.AppleDosType = appleProDosSystemUse.type;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case AppleId.HFS:
|
|
|
|
|
AppleHFSSystemUse appleHfsSystemUse =
|
|
|
|
|
Marshal.ByteArrayToStructureBigEndian<AppleHFSSystemUse>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
AppleHFSSystemUse
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
hasResourceFork = true;
|
|
|
|
|
|
|
|
|
|
entry.FinderInfo = new FinderInfo();
|
|
|
|
|
entry.FinderInfo.fdCreator = appleHfsSystemUse.creator;
|
|
|
|
|
entry.FinderInfo.fdFlags = (FinderFlags)appleHfsSystemUse.finder_flags;
|
|
|
|
|
entry.FinderInfo.fdType = appleHfsSystemUse.type;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
systemAreaOff += appleLength;
|
|
|
|
|
break;
|
|
|
|
|
case APPLE_MAGIC_OLD:
|
|
|
|
|
AppleOldId appleOldId = (AppleOldId)data[systemAreaOff + 2];
|
|
|
|
|
|
|
|
|
|
switch(appleOldId)
|
|
|
|
|
{
|
|
|
|
|
case AppleOldId.ProDOS:
|
|
|
|
|
AppleProDOSOldSystemUse appleProDosOldSystemUse =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<AppleProDOSOldSystemUse>(data,
|
|
|
|
|
systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
AppleProDOSOldSystemUse
|
|
|
|
|
>());
|
|
|
|
|
entry.AppleProDosType = appleProDosOldSystemUse.aux_type;
|
|
|
|
|
entry.AppleDosType = appleProDosOldSystemUse.type;
|
|
|
|
|
|
|
|
|
|
systemAreaOff += Marshal.SizeOf<AppleProDOSOldSystemUse>();
|
|
|
|
|
break;
|
|
|
|
|
case AppleOldId.TypeCreator:
|
|
|
|
|
case AppleOldId.TypeCreatorBundle:
|
|
|
|
|
AppleHFSTypeCreatorSystemUse appleHfsTypeCreatorSystemUse =
|
|
|
|
|
Marshal.ByteArrayToStructureBigEndian<AppleHFSTypeCreatorSystemUse>(data,
|
|
|
|
|
systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
AppleHFSTypeCreatorSystemUse
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
hasResourceFork = true;
|
|
|
|
|
|
|
|
|
|
entry.FinderInfo = new FinderInfo();
|
|
|
|
|
entry.FinderInfo.fdCreator = appleHfsTypeCreatorSystemUse.creator;
|
|
|
|
|
entry.FinderInfo.fdType = appleHfsTypeCreatorSystemUse.type;
|
|
|
|
|
|
|
|
|
|
systemAreaOff += Marshal.SizeOf<AppleHFSTypeCreatorSystemUse>();
|
|
|
|
|
break;
|
|
|
|
|
case AppleOldId.TypeCreatorIcon:
|
|
|
|
|
case AppleOldId.TypeCreatorIconBundle:
|
|
|
|
|
AppleHFSIconSystemUse appleHfsIconSystemUse =
|
|
|
|
|
Marshal.ByteArrayToStructureBigEndian<AppleHFSIconSystemUse>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
AppleHFSIconSystemUse
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
hasResourceFork = true;
|
|
|
|
|
|
|
|
|
|
entry.FinderInfo = new FinderInfo();
|
|
|
|
|
entry.FinderInfo.fdCreator = appleHfsIconSystemUse.creator;
|
|
|
|
|
entry.FinderInfo.fdType = appleHfsIconSystemUse.type;
|
|
|
|
|
entry.AppleIcon = appleHfsIconSystemUse.icon;
|
|
|
|
|
|
|
|
|
|
systemAreaOff += Marshal.SizeOf<AppleHFSIconSystemUse>();
|
|
|
|
|
break;
|
|
|
|
|
case AppleOldId.HFS:
|
|
|
|
|
AppleHFSOldSystemUse appleHfsSystemUse =
|
|
|
|
|
Marshal.ByteArrayToStructureBigEndian<AppleHFSOldSystemUse>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
AppleHFSOldSystemUse
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
hasResourceFork = true;
|
|
|
|
|
|
|
|
|
|
entry.FinderInfo = new FinderInfo();
|
|
|
|
|
entry.FinderInfo.fdCreator = appleHfsSystemUse.creator;
|
|
|
|
|
entry.FinderInfo.fdFlags = (FinderFlags)appleHfsSystemUse.finder_flags;
|
|
|
|
|
entry.FinderInfo.fdType = appleHfsSystemUse.type;
|
|
|
|
|
|
|
|
|
|
systemAreaOff += Marshal.SizeOf<AppleHFSOldSystemUse>();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Cannot continue as we don't know this structure size
|
|
|
|
|
systemAreaOff = end;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case XA_MAGIC:
|
|
|
|
|
entry.XA = Marshal.ByteArrayToStructureBigEndian<CdromXa>(data, systemAreaOff,
|
|
|
|
|
Marshal.SizeOf<CdromXa>());
|
|
|
|
|
|
|
|
|
|
systemAreaOff += Marshal.SizeOf<CdromXa>();
|
2019-07-28 17:04:08 +01:00
|
|
|
break;
|
|
|
|
|
// All of these follow the SUSP indication of 2 bytes for signature 1 byte for length
|
|
|
|
|
case AAIP_MAGIC:
|
|
|
|
|
case AMIGA_MAGIC:
|
2019-07-28 17:29:45 +01:00
|
|
|
AmigaEntry amiga =
|
|
|
|
|
Marshal.ByteArrayToStructureBigEndian<AmigaEntry>(data, systemAreaOff,
|
|
|
|
|
Marshal.SizeOf<AmigaEntry>());
|
|
|
|
|
|
|
|
|
|
int protectionLength = 0;
|
|
|
|
|
|
|
|
|
|
if(amiga.flags.HasFlag(AmigaFlags.Protection))
|
|
|
|
|
{
|
|
|
|
|
entry.AmigaProtection =
|
|
|
|
|
Marshal.ByteArrayToStructureBigEndian<AmigaProtection>(data,
|
|
|
|
|
systemAreaOff +
|
|
|
|
|
Marshal.SizeOf<AmigaEntry>(),
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<AmigaProtection>());
|
|
|
|
|
|
|
|
|
|
protectionLength = Marshal.SizeOf<AmigaProtection>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(amiga.flags.HasFlag(AmigaFlags.Comment))
|
|
|
|
|
{
|
|
|
|
|
if(entry.AmigaComment is null) entry.AmigaComment = new byte[0];
|
|
|
|
|
|
|
|
|
|
byte[] newComment = new byte[entry.AmigaComment.Length +
|
|
|
|
|
data
|
|
|
|
|
[systemAreaOff + Marshal.SizeOf<AmigaEntry>() + protectionLength] -
|
|
|
|
|
1];
|
|
|
|
|
|
|
|
|
|
Array.Copy(entry.AmigaComment, 0, newComment, 0, entry.AmigaComment.Length);
|
|
|
|
|
|
|
|
|
|
Array.Copy(data, systemAreaOff + Marshal.SizeOf<AmigaEntry>() + protectionLength,
|
|
|
|
|
newComment, entry.AmigaComment.Length,
|
|
|
|
|
data[systemAreaOff + Marshal.SizeOf<AmigaEntry>() + protectionLength] - 1);
|
|
|
|
|
|
|
|
|
|
entry.AmigaComment = newComment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
systemAreaOff += amiga.length;
|
|
|
|
|
break;
|
2019-07-28 17:31:30 +01:00
|
|
|
// This merely indicates the existence of RRIP extensions, we don't need it
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_MAGIC:
|
2019-07-28 17:31:30 +01:00
|
|
|
byte rripLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += rripLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_POSIX_ATTRIBUTES:
|
2019-07-28 17:46:09 +01:00
|
|
|
byte pxLength = data[systemAreaOff + 2];
|
|
|
|
|
|
|
|
|
|
if(pxLength == 36)
|
|
|
|
|
entry.PosixAttributesOld =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<PosixAttributesOld>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
PosixAttributesOld
|
|
|
|
|
>());
|
|
|
|
|
else if(pxLength >= 44)
|
|
|
|
|
entry.PosixAttributes =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<PosixAttributes>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<PosixAttributes
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
systemAreaOff += pxLength;
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_POSIX_DEV_NO:
|
2019-07-28 17:54:40 +01:00
|
|
|
byte pnLength = data[systemAreaOff + 2];
|
|
|
|
|
|
|
|
|
|
entry.PosixDeviceNumber =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<PosixDeviceNumber>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<PosixDeviceNumber
|
|
|
|
|
>());
|
|
|
|
|
systemAreaOff += pnLength;
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_SYMLINK:
|
2019-07-28 17:55:41 +01:00
|
|
|
byte slLength = data[systemAreaOff + 2];
|
|
|
|
|
|
2019-07-28 21:33:05 +01:00
|
|
|
SymbolicLink sl =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<SymbolicLink>(data, systemAreaOff,
|
|
|
|
|
Marshal.SizeOf<SymbolicLink>());
|
|
|
|
|
|
|
|
|
|
SymbolicLinkComponent slc =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<SymbolicLinkComponent>(data,
|
|
|
|
|
systemAreaOff +
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<SymbolicLink>(),
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
SymbolicLinkComponent
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
if(!continueSymlink || entry.SymbolicLink is null) entry.SymbolicLink = "";
|
|
|
|
|
|
|
|
|
|
if(slc.flags.HasFlag(SymlinkComponentFlags.Root)) entry.SymbolicLink = "/";
|
|
|
|
|
if(slc.flags.HasFlag(SymlinkComponentFlags.Current)) entry.SymbolicLink += ".";
|
|
|
|
|
if(slc.flags.HasFlag(SymlinkComponentFlags.Parent)) entry.SymbolicLink += "..";
|
|
|
|
|
|
|
|
|
|
if(!continueSymlinkComponent && !slc.flags.HasFlag(SymlinkComponentFlags.Root))
|
|
|
|
|
entry.SymbolicLink += "/";
|
|
|
|
|
|
|
|
|
|
entry.SymbolicLink += slc.flags.HasFlag(SymlinkComponentFlags.Networkname)
|
|
|
|
|
? Environment.MachineName
|
|
|
|
|
: joliet
|
|
|
|
|
? Encoding.BigEndianUnicode.GetString(data,
|
|
|
|
|
systemAreaOff +
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<SymbolicLink>() +
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
SymbolicLinkComponent
|
|
|
|
|
>(), slc.length)
|
|
|
|
|
: Encoding.GetString(data,
|
|
|
|
|
systemAreaOff +
|
|
|
|
|
Marshal.SizeOf<SymbolicLink>() +
|
|
|
|
|
Marshal.SizeOf<SymbolicLinkComponent>(),
|
|
|
|
|
slc.length);
|
|
|
|
|
|
|
|
|
|
continueSymlink = entry.Flags.HasFlag(SymlinkFlags.Continue);
|
|
|
|
|
continueSymlinkComponent = entry.Flags.HasFlag(SymlinkComponentFlags.Continue);
|
|
|
|
|
|
|
|
|
|
systemAreaOff += slLength;
|
2019-07-28 17:55:41 +01:00
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_NAME:
|
2019-07-28 18:19:17 +01:00
|
|
|
byte nmLength = data[systemAreaOff + 2];
|
|
|
|
|
|
|
|
|
|
if(@namespace != Namespace.Rrip)
|
|
|
|
|
{
|
|
|
|
|
systemAreaOff += nmLength;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AlternateName alternateName =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<AlternateName>(data, systemAreaOff,
|
|
|
|
|
Marshal.SizeOf<AlternateName>());
|
|
|
|
|
|
|
|
|
|
byte[] nm;
|
|
|
|
|
if(alternateName.flags.HasFlag(AlternateNameFlags.Networkname))
|
|
|
|
|
nm = joliet
|
|
|
|
|
? Encoding.BigEndianUnicode.GetBytes(Environment.MachineName)
|
|
|
|
|
: Encoding.GetBytes(Environment.MachineName);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nm = new byte[nmLength - Marshal.SizeOf<AlternateName>()];
|
|
|
|
|
|
|
|
|
|
Array.Copy(data, systemAreaOff + Marshal.SizeOf<AlternateName>(), nm, 0, nm.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(entry.RockRidgeAlternateName is null) entry.RockRidgeAlternateName = new byte[0];
|
|
|
|
|
|
|
|
|
|
byte[] newNm = new byte[entry.RockRidgeAlternateName.Length + nm.Length];
|
|
|
|
|
Array.Copy(entry.RockRidgeAlternateName, 0, newNm, 0,
|
|
|
|
|
entry.RockRidgeAlternateName.Length);
|
|
|
|
|
Array.Copy(nm, 0, newNm, entry.RockRidgeAlternateName.Length,
|
|
|
|
|
nm.Length);
|
|
|
|
|
|
|
|
|
|
entry.RockRidgeAlternateName = newNm;
|
|
|
|
|
|
|
|
|
|
if(!alternateName.flags.HasFlag(AlternateNameFlags.Continue))
|
|
|
|
|
{
|
|
|
|
|
entry.Filename = joliet
|
|
|
|
|
? Encoding.BigEndianUnicode.GetString(entry.RockRidgeAlternateName)
|
|
|
|
|
: Encoding.GetString(entry.RockRidgeAlternateName);
|
|
|
|
|
entry.RockRidgeAlternateName = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
systemAreaOff += nmLength;
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_CHILDLINK:
|
2019-07-28 18:19:44 +01:00
|
|
|
// TODO
|
|
|
|
|
byte clLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += clLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_PARENTLINK:
|
2019-07-28 18:19:44 +01:00
|
|
|
// TODO
|
|
|
|
|
byte plLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += plLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_RELOCATED_DIR:
|
2019-07-28 18:19:44 +01:00
|
|
|
// TODO
|
|
|
|
|
byte reLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += reLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_TIMESTAMPS:
|
2019-07-28 18:32:15 +01:00
|
|
|
byte tfLength = data[systemAreaOff + 2];
|
|
|
|
|
|
|
|
|
|
Timestamps timestamps =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<Timestamps>(data, systemAreaOff,
|
|
|
|
|
Marshal.SizeOf<Timestamps>());
|
|
|
|
|
|
|
|
|
|
int tfOff = systemAreaOff + Marshal.SizeOf<Timestamps>();
|
|
|
|
|
int tfLen = timestamps.flags.HasFlag(TimestampFlags.LongFormat) ? 17 : 7;
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.Creation))
|
|
|
|
|
{
|
|
|
|
|
entry.RripCreation = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripCreation, 0, tfLen);
|
|
|
|
|
tfOff += tfLen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.Modification))
|
|
|
|
|
{
|
|
|
|
|
entry.RripModify = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripModify, 0, tfLen);
|
|
|
|
|
tfOff += tfLen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.Access))
|
|
|
|
|
{
|
|
|
|
|
entry.RripAccess = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripAccess, 0, tfLen);
|
|
|
|
|
tfOff += tfLen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.AttributeChange))
|
|
|
|
|
{
|
|
|
|
|
entry.RripAttributeChange = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripAttributeChange, 0, tfLen);
|
|
|
|
|
tfOff += tfLen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.Backup))
|
|
|
|
|
{
|
|
|
|
|
entry.RripBackup = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripBackup, 0, tfLen);
|
|
|
|
|
tfOff += tfLen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.Expiration))
|
|
|
|
|
{
|
|
|
|
|
entry.RripExpiration = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripExpiration, 0, tfLen);
|
|
|
|
|
tfOff += tfLen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timestamps.flags.HasFlag(TimestampFlags.Effective))
|
|
|
|
|
{
|
|
|
|
|
entry.RripEffective = new byte[tfLen];
|
|
|
|
|
Array.Copy(data, tfOff, entry.RripEffective, 0, tfLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
systemAreaOff += tfLength;
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case RRIP_SPARSE:
|
2019-07-28 18:32:41 +01:00
|
|
|
// TODO
|
|
|
|
|
byte sfLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += sfLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case SUSP_CONTINUATION:
|
2019-07-28 18:41:33 +01:00
|
|
|
byte ceLength = data[systemAreaOff + 2];
|
|
|
|
|
|
|
|
|
|
ContinuationArea ca =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<ContinuationArea>(data, systemAreaOff,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<ContinuationArea>());
|
|
|
|
|
|
|
|
|
|
uint caOffSector = ca.offset / 2048;
|
|
|
|
|
uint caOff = ca.offset % 2048;
|
|
|
|
|
uint caLenInSectors = ca.ca_length / 2048;
|
|
|
|
|
if((ca.ca_length + caOff) % 2048 > 0) caLenInSectors++;
|
|
|
|
|
|
|
|
|
|
byte[] caData = image.ReadSectors(ca.block + caOffSector, caLenInSectors);
|
|
|
|
|
|
|
|
|
|
DecodeSystemArea(caData, (int)caOff, (int)(caOff + ca.ca_length), ref entry,
|
|
|
|
|
out hasResourceFork);
|
|
|
|
|
|
|
|
|
|
systemAreaOff += ceLength;
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case SUSP_PADDING:
|
2019-07-28 19:10:42 +01:00
|
|
|
// Just padding, skip
|
|
|
|
|
byte pdLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += pdLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case SUSP_INDICATOR:
|
2019-07-28 19:10:42 +01:00
|
|
|
// Only to be found on CURRENT entry of root directory
|
|
|
|
|
byte spLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += spLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case SUSP_TERMINATOR:
|
2019-07-28 19:10:42 +01:00
|
|
|
// Not seen on the wild
|
|
|
|
|
byte stLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += stLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case SUSP_REFERENCE:
|
2019-07-28 19:10:42 +01:00
|
|
|
// Only to be found on CURRENT entry of root directory
|
|
|
|
|
byte erLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += erLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case SUSP_SELECTOR:
|
2019-07-28 19:10:42 +01:00
|
|
|
// Only to be found on CURRENT entry of root directory
|
|
|
|
|
byte esLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += esLength;
|
|
|
|
|
|
|
|
|
|
break;
|
2019-07-28 17:04:08 +01:00
|
|
|
case ZISO_MAGIC:
|
2019-07-28 19:10:42 +01:00
|
|
|
// TODO: Implement support for zisofs
|
|
|
|
|
byte zfLength = data[systemAreaOff + 2];
|
|
|
|
|
systemAreaOff += zfLength;
|
2019-07-28 17:04:08 +01:00
|
|
|
|
2019-07-28 16:55:15 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Cannot continue as we don't know this structure size
|
|
|
|
|
systemAreaOff = end;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-29 04:00:51 +01:00
|
|
|
|
|
|
|
|
PathTableEntryInternal[] GetPathTableEntries(string path)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<PathTableEntryInternal> tableEntries = new PathTableEntryInternal[0];
|
|
|
|
|
List<PathTableEntryInternal> pathTableList = new List<PathTableEntryInternal>(pathTable);
|
|
|
|
|
|
|
|
|
|
if(path == "" || path == "/") tableEntries = pathTable.Where(p => p.Parent == 1 && p != pathTable[0]);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string cutPath = path.StartsWith("/", StringComparison.Ordinal)
|
|
|
|
|
? path.Substring(1).ToLower(CultureInfo.CurrentUICulture)
|
|
|
|
|
: path.ToLower(CultureInfo.CurrentUICulture);
|
|
|
|
|
|
|
|
|
|
string[] pieces = cutPath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
int currentParent = 1;
|
|
|
|
|
int currentPiece = 0;
|
|
|
|
|
|
|
|
|
|
while(currentPiece < pieces.Length)
|
|
|
|
|
{
|
|
|
|
|
PathTableEntryInternal currentEntry = pathTable.FirstOrDefault(p => p.Parent == currentParent &&
|
|
|
|
|
p.Name.ToLower(CultureInfo
|
|
|
|
|
.CurrentUICulture) ==
|
|
|
|
|
pieces[currentPiece]);
|
|
|
|
|
|
|
|
|
|
if(currentEntry is null) break;
|
|
|
|
|
|
|
|
|
|
currentPiece++;
|
|
|
|
|
currentParent = pathTableList.IndexOf(currentEntry) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tableEntries = pathTable.Where(p => p.Parent == currentParent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tableEntries.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DecodedDirectoryEntry[] GetSubdirsFromCdiPathTable(string path) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
DecodedDirectoryEntry[] GetSubdirsFromIsoPathTable(string path)
|
|
|
|
|
{
|
|
|
|
|
PathTableEntryInternal[] tableEntries = GetPathTableEntries(path);
|
|
|
|
|
List<DecodedDirectoryEntry> entries = new List<DecodedDirectoryEntry>();
|
|
|
|
|
foreach(PathTableEntryInternal tEntry in tableEntries)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector = image.ReadSector(tEntry.Extent);
|
|
|
|
|
DirectoryRecord record =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(sector, 0,
|
|
|
|
|
Marshal.SizeOf<DirectoryRecord>());
|
|
|
|
|
|
|
|
|
|
if(record.length == 0) break;
|
|
|
|
|
|
|
|
|
|
DecodedDirectoryEntry entry = new DecodedDirectoryEntry
|
|
|
|
|
{
|
|
|
|
|
Extent = record.size == 0 ? 0 : record.extent,
|
|
|
|
|
Size = record.size,
|
|
|
|
|
Flags = record.flags,
|
|
|
|
|
Filename = tEntry.Name,
|
|
|
|
|
FileUnitSize = record.file_unit_size,
|
|
|
|
|
Interleave = record.interleave,
|
|
|
|
|
VolumeSequenceNumber = record.volume_sequence_number,
|
|
|
|
|
Timestamp = DecodeIsoDateTime(record.date)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: XA
|
|
|
|
|
int systemAreaStart = record.name_len + Marshal.SizeOf<DirectoryRecord>();
|
|
|
|
|
int systemAreaLength = record.length - record.name_len - Marshal.SizeOf<DirectoryRecord>();
|
|
|
|
|
|
|
|
|
|
if(systemAreaStart % 2 != 0)
|
|
|
|
|
{
|
|
|
|
|
systemAreaStart++;
|
|
|
|
|
systemAreaLength--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DecodeSystemArea(sector, systemAreaStart, systemAreaStart + systemAreaLength, ref entry, out _);
|
|
|
|
|
|
|
|
|
|
entries.Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entries.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DecodedDirectoryEntry[] GetSubdirsFromHighSierraPathTable(string path)
|
|
|
|
|
{
|
|
|
|
|
PathTableEntryInternal[] tableEntries = GetPathTableEntries(path);
|
|
|
|
|
List<DecodedDirectoryEntry> entries = new List<DecodedDirectoryEntry>();
|
|
|
|
|
foreach(PathTableEntryInternal tEntry in tableEntries)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector = image.ReadSector(tEntry.Extent);
|
|
|
|
|
HighSierraDirectoryRecord record =
|
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(sector, 0,
|
|
|
|
|
Marshal
|
|
|
|
|
.SizeOf<
|
|
|
|
|
HighSierraDirectoryRecord
|
|
|
|
|
>());
|
|
|
|
|
|
|
|
|
|
DecodedDirectoryEntry entry = new DecodedDirectoryEntry
|
|
|
|
|
{
|
|
|
|
|
Extent = record.size == 0 ? 0 : record.extent,
|
|
|
|
|
Size = record.size,
|
|
|
|
|
Flags = record.flags,
|
|
|
|
|
Filename = tEntry.Name,
|
|
|
|
|
Interleave = record.interleave,
|
|
|
|
|
VolumeSequenceNumber = record.volume_sequence_number,
|
|
|
|
|
Timestamp = DecodeHighSierraDateTime(record.date)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
entries.Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entries.ToArray();
|
|
|
|
|
}
|
2019-07-19 12:14:30 +01:00
|
|
|
}
|
|
|
|
|
}
|