diff --git a/Aaru.Images/NDIF/Read.cs b/Aaru.Images/NDIF/Read.cs index a8b016bd0..00e446830 100644 --- a/Aaru.Images/NDIF/Read.cs +++ b/Aaru.Images/NDIF/Read.cs @@ -85,14 +85,14 @@ public sealed partial class Ndif { if(bcem.Length < 128) return ErrorNumber.InvalidArgument; - _header = Marshal.ByteArrayToStructureBigEndian(bcem); + _header = Marshal.ByteArrayToStructureBigEndianGenerated(bcem); AaruLogging.Debug(MODULE_NAME, "footer.type = {0}", _header.version); AaruLogging.Debug(MODULE_NAME, "footer.driver = {0}", _header.driver); AaruLogging.Debug(MODULE_NAME, - "footer.name = {0}", - StringHandlers.PascalToString(_header.name, Encoding.GetEncoding("macintosh"))); + "footer.name = {0}", + StringHandlers.PascalToString(_header.name, Encoding.GetEncoding("macintosh"))); AaruLogging.Debug(MODULE_NAME, "footer.sectors = {0}", _header.sectors); @@ -115,12 +115,12 @@ public sealed partial class Ndif // Block chunks and headers _chunks = new Dictionary(); - for(int i = 0; i < _header.chunks; i++) + for(var i = 0; i < _header.chunks; i++) { // Obsolete read-only NDIF only prepended the header and then put the image without any kind of block references. // So let's falsify a block chunk - var bChnk = new BlockChunk(); - byte[] sector = new byte[4]; + var bChnk = new BlockChunk(); + var sector = new byte[4]; Array.Copy(bcem, 128 + 0 + i * 12, sector, 1, 3); bChnk.sector = BigEndianBitConverter.ToUInt32(sector, 0); bChnk.type = bcem[128 + 3 + i * 12]; @@ -207,8 +207,8 @@ public sealed partial class Ndif string release = null; string pre = null; - string major = $"{version.MajorVersion}"; - string minor = $".{version.MinorVersion / 10}"; + var major = $"{version.MajorVersion}"; + var minor = $".{version.MinorVersion / 10}"; if(version.MinorVersion % 10 > 0) release = $".{version.MinorVersion % 10}"; @@ -238,9 +238,9 @@ public sealed partial class Ndif } AaruLogging.Debug(MODULE_NAME, - Localization.Image_application_0_version_1, - _imageInfo.Application, - _imageInfo.ApplicationVersion); + Localization.Image_application_0_version_1, + _imageInfo.Application, + _imageInfo.ApplicationVersion); _sectorCache = new Dictionary(); _chunkCache = new Dictionary(); @@ -307,7 +307,7 @@ public sealed partial class Ndif if(_sectorCache.TryGetValue(sectorAddress, out buffer)) return ErrorNumber.NoError; var currentChunk = new BlockChunk(); - bool chunkFound = false; + var chunkFound = false; ulong chunkStartSector = 0; foreach(KeyValuePair kvp in _chunks.Where(kvp => sectorAddress >= kvp.Key)) @@ -327,7 +327,7 @@ public sealed partial class Ndif { if(!_chunkCache.TryGetValue(chunkStartSector, out byte[] data)) { - byte[] cmpBuffer = new byte[currentChunk.length]; + var cmpBuffer = new byte[currentChunk.length]; _imageStream.Seek(currentChunk.offset, SeekOrigin.Begin); _imageStream.EnsureRead(cmpBuffer, 0, cmpBuffer.Length); int realSize; @@ -336,7 +336,7 @@ public sealed partial class Ndif { case CHUNK_TYPE_ADC: { - byte[] tmpBuffer = new byte[_bufferSize]; + var tmpBuffer = new byte[_bufferSize]; realSize = ADC.DecodeBuffer(cmpBuffer, tmpBuffer); data = new byte[realSize]; Array.Copy(tmpBuffer, 0, data, 0, realSize); @@ -346,7 +346,7 @@ public sealed partial class Ndif case CHUNK_TYPE_RLE: { - byte[] tmpBuffer = new byte[_bufferSize]; + var tmpBuffer = new byte[_bufferSize]; realSize = AppleRle.DecodeBuffer(cmpBuffer, tmpBuffer); data = new byte[realSize]; Array.Copy(tmpBuffer, 0, data, 0, realSize); diff --git a/Aaru.Images/NDIF/Structs.cs b/Aaru.Images/NDIF/Structs.cs index cdee1aa13..e4f179b17 100644 --- a/Aaru.Images/NDIF/Structs.cs +++ b/Aaru.Images/NDIF/Structs.cs @@ -33,6 +33,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; +using Aaru.CommonTypes.Attributes; namespace Aaru.Images; @@ -59,38 +60,39 @@ public sealed partial class Ndif #region Nested type: ChunkHeader [StructLayout(LayoutKind.Sequential, Pack = 1)] - readonly struct ChunkHeader + [SwapEndian] + partial struct ChunkHeader { /// Version - public readonly short version; + public short version; /// Filesystem ID - public readonly short driver; + public short driver; /// Disk image name, Str63 (Pascal string) [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] - public readonly byte[] name; + public byte[] name; /// Sectors in image - public readonly uint sectors; + public uint sectors; /// Maximum number of sectors per chunk - public readonly uint maxSectorsPerChunk; + public uint maxSectorsPerChunk; /// Offset to add to every chunk offset - public readonly uint dataOffset; + public uint dataOffset; /// CRC28 of whole image - public readonly uint crc; + public uint crc; /// Set to 1 if segmented - public readonly uint segmented; + public uint segmented; /// Unknown - public readonly uint p1; + public uint p1; /// Unknown - public readonly uint p2; + public uint p2; /// Unknown, spare? [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)] - public readonly uint[] unknown; + public uint[] unknown; /// Set to 1 by ShrinkWrap if image is encrypted - public readonly uint encrypted; + public uint encrypted; /// Set by ShrinkWrap if image is encrypted, value is the same for same password - public readonly uint hash; + public uint hash; /// How many chunks follow the header - public readonly uint chunks; + public uint chunks; } #endregion