diff --git a/Aaru.Partitions/AppleMap.cs b/Aaru.Partitions/AppleMap.cs index c8976575b..b807c8ca4 100644 --- a/Aaru.Partitions/AppleMap.cs +++ b/Aaru.Partitions/AppleMap.cs @@ -36,6 +36,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Text; using Aaru.CommonTypes; +using Aaru.CommonTypes.Attributes; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; using Aaru.Helpers; @@ -49,7 +50,7 @@ namespace Aaru.Partitions; /// /// Implements decoding of the Apple Partition Map [SuppressMessage("ReSharper", "UnusedMember.Local")] -public sealed class AppleMap : IPartition +public sealed partial class AppleMap : IPartition { /// "ER", driver descriptor magic const ushort DDM_MAGIC = 0x4552; @@ -91,7 +92,7 @@ public sealed class AppleMap : IPartition { case 256: { - byte[] tmp = new byte[512]; + var tmp = new byte[512]; Array.Copy(ddmSector, 0, tmp, 0, 256); ddmSector = tmp; maxDrivers = 29; @@ -102,7 +103,8 @@ public sealed class AppleMap : IPartition return false; } - AppleDriverDescriptorMap ddm = Marshal.ByteArrayToStructureBigEndian(ddmSector); + AppleDriverDescriptorMap ddm = + Marshal.ByteArrayToStructureBigEndianGenerated(ddmSector); AaruLogging.Debug(MODULE_NAME, "ddm.sbSig = 0x{0:X4}", ddm.sbSig); AaruLogging.Debug(MODULE_NAME, "ddm.sbBlockSize = {0}", ddm.sbBlockSize); @@ -120,11 +122,11 @@ public sealed class AppleMap : IPartition { ddm.sbMap = new AppleDriverEntry[ddm.sbDrvrCount]; - for(int i = 0; i < ddm.sbDrvrCount; i++) + for(var i = 0; i < ddm.sbDrvrCount; i++) { - byte[] tmp = new byte[8]; + var tmp = new byte[8]; Array.Copy(ddmSector, 18 + i * 8, tmp, 0, 8); - ddm.sbMap[i] = Marshal.ByteArrayToStructureBigEndian(tmp); + ddm.sbMap[i] = Marshal.ByteArrayToStructureBigEndianGenerated(tmp); AaruLogging.Debug(MODULE_NAME, "ddm.sbMap[{1}].ddBlock = {0}", ddm.sbMap[i].ddBlock, i); @@ -158,33 +160,24 @@ public sealed class AppleMap : IPartition if(errno != ErrorNumber.NoError) return false; AppleOldDevicePartitionMap oldMap = - Marshal.ByteArrayToStructureBigEndian(partSector); + Marshal.ByteArrayToStructureBigEndianGenerated(partSector); // This is the easy one, no sector size mixing if(oldMap.pdSig == APM_MAGIC_OLD) { - for(int i = 2; i < partSector.Length; i += 12) + for(var i = 2; i < partSector.Length; i += 12) { - byte[] tmp = new byte[12]; + var tmp = new byte[12]; Array.Copy(partSector, i, tmp, 0, 12); AppleMapOldPartitionEntry oldEntry = - Marshal.ByteArrayToStructureBigEndian(tmp); + Marshal.ByteArrayToStructureBigEndianGenerated(tmp); - AaruLogging.Debug(MODULE_NAME, - "old_map.sbMap[{1}].pdStart = {0}", - oldEntry.pdStart, - (i - 2) / 12); + AaruLogging.Debug(MODULE_NAME, "old_map.sbMap[{1}].pdStart = {0}", oldEntry.pdStart, (i - 2) / 12); - AaruLogging.Debug(MODULE_NAME, - "old_map.sbMap[{1}].pdSize = {0}", - oldEntry.pdSize, - (i - 2) / 12); + AaruLogging.Debug(MODULE_NAME, "old_map.sbMap[{1}].pdSize = {0}", oldEntry.pdSize, (i - 2) / 12); - AaruLogging.Debug(MODULE_NAME, - "old_map.sbMap[{1}].pdFSID = 0x{0:X8}", - oldEntry.pdFSID, - (i - 2) / 12); + AaruLogging.Debug(MODULE_NAME, "old_map.sbMap[{1}].pdFSID = 0x{0:X8}", oldEntry.pdFSID, (i - 2) / 12); if(oldEntry is { pdSize: 0, pdFSID: 0 }) { @@ -221,9 +214,9 @@ public sealed class AppleMap : IPartition // If sector is bigger than 512 if(ddmSector.Length > 512) { - byte[] tmp = new byte[512]; + var tmp = new byte[512]; Array.Copy(ddmSector, 512, tmp, 0, 512); - entry = Marshal.ByteArrayToStructureBigEndian(tmp); + entry = Marshal.ByteArrayToStructureBigEndianGenerated(tmp); // Check for a partition entry that's 512-byte aligned if(entry.signature == APM_MAGIC) @@ -236,7 +229,7 @@ public sealed class AppleMap : IPartition } else { - entry = Marshal.ByteArrayToStructureBigEndian(partSector); + entry = Marshal.ByteArrayToStructureBigEndianGenerated(partSector); if(entry.signature == APM_MAGIC) { @@ -252,7 +245,7 @@ public sealed class AppleMap : IPartition } else { - entry = Marshal.ByteArrayToStructureBigEndian(partSector); + entry = Marshal.ByteArrayToStructureBigEndianGenerated(partSector); if(entry.signature == APM_MAGIC) { @@ -275,15 +268,15 @@ public sealed class AppleMap : IPartition AaruLogging.Debug(MODULE_NAME, "skip_ddm = {0}", skipDdm); AaruLogging.Debug(MODULE_NAME, "sectors_to_read = {0}", sectorsToRead); - byte[] copy = new byte[entries.Length - skipDdm]; + var copy = new byte[entries.Length - skipDdm]; Array.Copy(entries, skipDdm, copy, 0, copy.Length); entries = copy; - for(int i = 0; i < entryCount; i++) + for(var i = 0; i < entryCount; i++) { - byte[] tmp = new byte[entrySize]; + var tmp = new byte[entrySize]; Array.Copy(entries, i * entrySize, tmp, 0, entrySize); - entry = Marshal.ByteArrayToStructureBigEndian(tmp); + entry = Marshal.ByteArrayToStructureBigEndianGenerated(tmp); if(entry.signature != APM_MAGIC) continue; @@ -293,15 +286,9 @@ public sealed class AppleMap : IPartition AaruLogging.Debug(MODULE_NAME, "dpme[{0}].start = {1}", i, entry.start); AaruLogging.Debug(MODULE_NAME, "dpme[{0}].sectors = {1}", i, entry.sectors); - AaruLogging.Debug(MODULE_NAME, - "dpme[{0}].name = \"{1}\"", - i, - StringHandlers.CToString(entry.name)); + AaruLogging.Debug(MODULE_NAME, "dpme[{0}].name = \"{1}\"", i, StringHandlers.CToString(entry.name)); - AaruLogging.Debug(MODULE_NAME, - "dpme[{0}].type = \"{1}\"", - i, - StringHandlers.CToString(entry.type)); + AaruLogging.Debug(MODULE_NAME, "dpme[{0}].type = \"{1}\"", i, StringHandlers.CToString(entry.type)); AaruLogging.Debug(MODULE_NAME, "dpme[{0}].first_data_block = {1}", i, entry.first_data_block); @@ -323,9 +310,9 @@ public sealed class AppleMap : IPartition AaruLogging.Debug(MODULE_NAME, "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum); AaruLogging.Debug(MODULE_NAME, - "dpme[{0}].processor = \"{1}\"", - i, - StringHandlers.CToString(entry.processor)); + "dpme[{0}].processor = \"{1}\"", + i, + StringHandlers.CToString(entry.processor)); var flags = (AppleMapFlags)entry.flags; @@ -388,9 +375,9 @@ public sealed class AppleMap : IPartition else if(partition.Start < imagePlugin.Info.Sectors) { AaruLogging.Debug(MODULE_NAME, - Localization.Cutting_last_partition_end_0_to_media_size_1, - partition.End, - imagePlugin.Info.Sectors - 1); + Localization.Cutting_last_partition_end_0_to_media_size_1, + partition.End, + imagePlugin.Info.Sectors - 1); partition.Length = imagePlugin.Info.Sectors - partition.Start; partitions.Add(partition); @@ -399,9 +386,9 @@ public sealed class AppleMap : IPartition else { AaruLogging.Debug(MODULE_NAME, - Localization.Not_adding_partition_because_start_0_is_outside_media_size_1, - partition.Start, - imagePlugin.Info.Sectors - 1); + Localization.Not_adding_partition_because_start_0_is_outside_media_size_1, + partition.Start, + imagePlugin.Info.Sectors - 1); } } @@ -413,22 +400,23 @@ public sealed class AppleMap : IPartition #region Nested type: AppleDriverDescriptorMap [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct AppleDriverDescriptorMap + [SwapEndian] + partial struct AppleDriverDescriptorMap { /// Signature - public readonly ushort sbSig; + public ushort sbSig; /// Bytes per sector - public readonly ushort sbBlockSize; + public ushort sbBlockSize; /// Sectors of the disk - public readonly uint sbBlocks; + public uint sbBlocks; /// Device type - public readonly ushort sbDevType; + public ushort sbDevType; /// Device ID - public readonly ushort sbDevId; + public ushort sbDevId; /// Reserved - public readonly uint sbData; + public uint sbData; /// Number of entries of the driver descriptor - public readonly ushort sbDrvrCount; + public ushort sbDrvrCount; /// Entries of the driver descriptor [MarshalAs(UnmanagedType.ByValArray, SizeConst = 61)] public AppleDriverEntry[] sbMap; @@ -439,14 +427,15 @@ public sealed class AppleMap : IPartition #region Nested type: AppleDriverEntry [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct AppleDriverEntry + [SwapEndian] + partial struct AppleDriverEntry { /// First sector of the driver - public readonly uint ddBlock; + public uint ddBlock; /// Size in 512bytes sectors of the driver - public readonly ushort ddSize; + public ushort ddSize; /// Operating system (MacOS = 1) - public readonly ushort ddType; + public ushort ddType; } #endregion @@ -487,14 +476,15 @@ public sealed class AppleMap : IPartition #region Nested type: AppleMapOldPartitionEntry [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct AppleMapOldPartitionEntry + [SwapEndian] + partial struct AppleMapOldPartitionEntry { /// First sector of the partition - public readonly uint pdStart; + public uint pdStart; /// Number of sectors of the partition - public readonly uint pdSize; + public uint pdSize; /// Partition type - public readonly uint pdFSID; + public uint pdFSID; } #endregion @@ -502,50 +492,51 @@ public sealed class AppleMap : IPartition #region Nested type: AppleMapPartitionEntry [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct AppleMapPartitionEntry + [SwapEndian] + partial struct AppleMapPartitionEntry { /// Signature - public readonly ushort signature; + public ushort signature; /// Reserved - public readonly ushort reserved1; + public ushort reserved1; /// Number of entries on the partition map, each one sector - public readonly uint entries; + public uint entries; /// First sector of the partition - public readonly uint start; + public uint start; /// Number of sectos of the partition - public readonly uint sectors; + public uint sectors; /// Partition name, 32 bytes, null-padded [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] - public readonly byte[] name; + public byte[] name; /// Partition type. 32 bytes, null-padded [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] - public readonly byte[] type; + public byte[] type; /// First sector of the data area - public readonly uint first_data_block; + public uint first_data_block; /// Number of sectors of the data area - public readonly uint data_sectors; + public uint data_sectors; /// Partition flags - public readonly uint flags; + public uint flags; /// First sector of the boot code - public readonly uint first_boot_block; + public uint first_boot_block; /// Size in bytes of the boot code - public readonly uint boot_size; + public uint boot_size; /// Load address of the boot code - public readonly uint load_address; + public uint load_address; /// Load address of the boot code - public readonly uint load_address2; + public uint load_address2; /// Entry point of the boot code - public readonly uint entry_point; + public uint entry_point; /// Entry point of the boot code - public readonly uint entry_point2; + public uint entry_point2; /// Boot code checksum - public readonly uint checksum; + public uint checksum; /// Processor type, 16 bytes, null-padded [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] - public readonly byte[] processor; + public byte[] processor; /// Boot arguments [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] - public readonly uint[] boot_arguments; + public uint[] boot_arguments; } #endregion @@ -553,13 +544,14 @@ public sealed class AppleMap : IPartition #region Nested type: AppleOldDevicePartitionMap [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct AppleOldDevicePartitionMap + [SwapEndian] + partial struct AppleOldDevicePartitionMap { /// Signature - public readonly ushort pdSig; + public ushort pdSig; /// Entries of the driver descriptor [MarshalAs(UnmanagedType.ByValArray, SizeConst = 42)] - public readonly AppleMapOldPartitionEntry[] pdMap; + public AppleMapOldPartitionEntry[] pdMap; } #endregion