diff --git a/DiscImageChef.DiscImages/Alcohol120/Write.cs b/DiscImageChef.DiscImages/Alcohol120/Write.cs index e1731c158..5881b1a1d 100644 --- a/DiscImageChef.DiscImages/Alcohol120/Write.cs +++ b/DiscImageChef.DiscImages/Alcohol120/Write.cs @@ -34,12 +34,12 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Decoders.CD; +using DiscImageChef.Helpers; using Schemas; using TrackType = DiscImageChef.CommonTypes.Enums.TrackType; @@ -427,24 +427,24 @@ namespace DiscImageChef.DiscImages alcToc = new Dictionary>(); writingTracks = writingTracks.OrderBy(t => t.TrackSession).ThenBy(t => t.TrackSequence).ToList(); alcTrackExtras = new Dictionary(); - long currentTrackOffset = header.sessionOffset + Marshal.SizeOf(typeof(AlcoholSession)) * sessions; + long currentTrackOffset = header.sessionOffset + Marshal.SizeOf() * sessions; FullTOC.CDFullTOC? decodedToc = FullTOC.Decode(fullToc); long currentExtraOffset = currentTrackOffset; for(int i = 1; i <= sessions; i++) if(decodedToc.HasValue) - currentExtraOffset += Marshal.SizeOf(typeof(AlcoholTrack)) * + currentExtraOffset += Marshal.SizeOf() * decodedToc.Value.TrackDescriptors.Count(t => t.SessionNumber == i); else { - currentExtraOffset += Marshal.SizeOf(typeof(AlcoholTrack)) * 3; - currentExtraOffset += Marshal.SizeOf(typeof(AlcoholTrack)) * + currentExtraOffset += Marshal.SizeOf() * 3; + currentExtraOffset += Marshal.SizeOf() * writingTracks.Count(t => t.TrackSession == i); - if(i < sessions) currentExtraOffset += Marshal.SizeOf(typeof(AlcoholTrack)) * 2; + if(i < sessions) currentExtraOffset += Marshal.SizeOf() * 2; } - long footerOffset = currentExtraOffset + Marshal.SizeOf(typeof(AlcoholTrackExtra)) * writingTracks.Count; + long footerOffset = currentExtraOffset + Marshal.SizeOf() * writingTracks.Count; if(bca != null) { header.bcaOffset = (uint)footerOffset; @@ -546,7 +546,7 @@ namespace DiscImageChef.DiscImages unknown = new byte[18], unknown2 = new byte[24] }); - currentTrackOffset += Marshal.SizeOf(typeof(AlcoholTrack)); + currentTrackOffset += Marshal.SizeOf(); } else { @@ -591,7 +591,7 @@ namespace DiscImageChef.DiscImages unknown = new byte[18], unknown2 = new byte[24] }); - currentTrackOffset += Marshal.SizeOf(typeof(AlcoholTrack)) * 3; + currentTrackOffset += Marshal.SizeOf() * 3; } foreach(Track track in writingTracks.Where(t => t.TrackSession == i).OrderBy(t => t.TrackSequence)) @@ -653,8 +653,8 @@ namespace DiscImageChef.DiscImages thisSessionTracks.Add((int)track.TrackSequence, alcTrk); - currentTrackOffset += Marshal.SizeOf(typeof(AlcoholTrack)); - currentExtraOffset += Marshal.SizeOf(typeof(AlcoholTrackExtra)); + currentTrackOffset += Marshal.SizeOf(); + currentExtraOffset += Marshal.SizeOf(); AlcoholTrackExtra trkExtra = new AlcoholTrackExtra { @@ -701,7 +701,7 @@ namespace DiscImageChef.DiscImages unknown = new byte[18], unknown2 = new byte[24] }); - currentTrackOffset += Marshal.SizeOf(typeof(AlcoholTrack)); + currentTrackOffset += Marshal.SizeOf(); } else if(i < sessions) { @@ -738,7 +738,7 @@ namespace DiscImageChef.DiscImages unknown2 = new byte[24] }); - currentTrackOffset += Marshal.SizeOf(typeof(AlcoholTrack)) * 2; + currentTrackOffset += Marshal.SizeOf() * 2; } alcToc.Add(i, thisSessionTracks); @@ -746,7 +746,7 @@ namespace DiscImageChef.DiscImages alcFooter = new AlcoholFooter { - filenameOffset = (uint)(footerOffset + Marshal.SizeOf(typeof(AlcoholFooter))), widechar = 1 + filenameOffset = (uint)(footerOffset + Marshal.SizeOf()), widechar = 1 }; byte[] filename = Encoding.Unicode.GetBytes("*.mdf"); // Yup, Alcohol stores no filename but a wildcard. @@ -755,11 +755,11 @@ namespace DiscImageChef.DiscImages // Write header descriptorStream.Seek(0, SeekOrigin.Begin); - byte[] block = new byte[Marshal.SizeOf(header)]; - blockPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, blockPtr, true); - Marshal.Copy(blockPtr, block, 0, block.Length); - Marshal.FreeHGlobal(blockPtr); + byte[] block = new byte[Marshal.SizeOf()]; + blockPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, blockPtr, true); + System.Runtime.InteropServices.Marshal.Copy(blockPtr, block, 0, block.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(blockPtr); descriptorStream.Write(block, 0, block.Length); // Write DVD structures if pressent @@ -788,11 +788,11 @@ namespace DiscImageChef.DiscImages descriptorStream.Seek(header.sessionOffset, SeekOrigin.Begin); foreach(AlcoholSession session in alcSessions.Values) { - block = new byte[Marshal.SizeOf(session)]; - blockPtr = Marshal.AllocHGlobal(Marshal.SizeOf(session)); - Marshal.StructureToPtr(session, blockPtr, true); - Marshal.Copy(blockPtr, block, 0, block.Length); - Marshal.FreeHGlobal(blockPtr); + block = new byte[Marshal.SizeOf()]; + blockPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(session, blockPtr, true); + System.Runtime.InteropServices.Marshal.Copy(blockPtr, block, 0, block.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(blockPtr); descriptorStream.Write(block, 0, block.Length); } @@ -802,11 +802,11 @@ namespace DiscImageChef.DiscImages descriptorStream.Seek(alcSessions.First(t => t.Key == kvp.Key).Value.trackOffset, SeekOrigin.Begin); foreach(AlcoholTrack track in kvp.Value.Values) { - block = new byte[Marshal.SizeOf(track)]; - blockPtr = Marshal.AllocHGlobal(Marshal.SizeOf(track)); - Marshal.StructureToPtr(track, blockPtr, true); - Marshal.Copy(blockPtr, block, 0, block.Length); - Marshal.FreeHGlobal(blockPtr); + block = new byte[Marshal.SizeOf()]; + blockPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(track, blockPtr, true); + System.Runtime.InteropServices.Marshal.Copy(blockPtr, block, 0, block.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(blockPtr); descriptorStream.Write(block, 0, block.Length); if(isDvd) continue; @@ -816,11 +816,12 @@ namespace DiscImageChef.DiscImages descriptorStream.Seek(track.extraOffset, SeekOrigin.Begin); if(alcTrackExtras.TryGetValue(track.point, out AlcoholTrackExtra extra)) { - block = new byte[Marshal.SizeOf(extra)]; - blockPtr = Marshal.AllocHGlobal(Marshal.SizeOf(extra)); - Marshal.StructureToPtr(extra, blockPtr, true); - Marshal.Copy(blockPtr, block, 0, block.Length); - Marshal.FreeHGlobal(blockPtr); + block = new byte[Marshal.SizeOf()]; + blockPtr = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(extra, blockPtr, true); + System.Runtime.InteropServices.Marshal.Copy(blockPtr, block, 0, block.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(blockPtr); descriptorStream.Write(block, 0, block.Length); } @@ -837,11 +838,11 @@ namespace DiscImageChef.DiscImages // Write footer descriptorStream.Seek(footerOffset, SeekOrigin.Begin); - block = new byte[Marshal.SizeOf(alcFooter)]; - blockPtr = Marshal.AllocHGlobal(Marshal.SizeOf(alcFooter)); - Marshal.StructureToPtr(alcFooter, blockPtr, true); - Marshal.Copy(blockPtr, block, 0, block.Length); - Marshal.FreeHGlobal(blockPtr); + block = new byte[Marshal.SizeOf()]; + blockPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(alcFooter, blockPtr, true); + System.Runtime.InteropServices.Marshal.Copy(blockPtr, block, 0, block.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(blockPtr); descriptorStream.Write(block, 0, block.Length); // Write filename diff --git a/DiscImageChef.DiscImages/Anex86/Identify.cs b/DiscImageChef.DiscImages/Anex86/Identify.cs index de9801123..6f6a9f76f 100644 --- a/DiscImageChef.DiscImages/Anex86/Identify.cs +++ b/DiscImageChef.DiscImages/Anex86/Identify.cs @@ -31,9 +31,9 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -44,14 +44,12 @@ namespace DiscImageChef.DiscImages Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); - fdihdr = new Anex86Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(fdihdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(fdihdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - fdihdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + fdihdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.unknown = {0}", fdihdr.unknown); DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.hddtype = {0}", fdihdr.hddtype); diff --git a/DiscImageChef.DiscImages/Anex86/Read.cs b/DiscImageChef.DiscImages/Anex86/Read.cs index ec902cf8f..df1b38bf6 100644 --- a/DiscImageChef.DiscImages/Anex86/Read.cs +++ b/DiscImageChef.DiscImages/Anex86/Read.cs @@ -32,11 +32,11 @@ using System; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -47,14 +47,12 @@ namespace DiscImageChef.DiscImages Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); - fdihdr = new Anex86Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(fdihdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(fdihdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - fdihdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + fdihdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); imageInfo.MediaType = Geometry.GetMediaType(((ushort)fdihdr.cylinders, (byte)fdihdr.heads, (ushort)fdihdr.spt, (uint)fdihdr.bps, MediaEncoding.MFM, diff --git a/DiscImageChef.DiscImages/Anex86/Write.cs b/DiscImageChef.DiscImages/Anex86/Write.cs index 096c3e40a..dea9952f1 100644 --- a/DiscImageChef.DiscImages/Anex86/Write.cs +++ b/DiscImageChef.DiscImages/Anex86/Write.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -187,11 +187,11 @@ namespace DiscImageChef.DiscImages } } - byte[] hdr = new byte[Marshal.SizeOf(fdihdr)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fdihdr)); - Marshal.StructureToPtr(fdihdr, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(fdihdr, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/Apple2MG/Write.cs b/DiscImageChef.DiscImages/Apple2MG/Write.cs index 67bfaa914..3f71b0673 100644 --- a/DiscImageChef.DiscImages/Apple2MG/Write.cs +++ b/DiscImageChef.DiscImages/Apple2MG/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -193,11 +193,11 @@ namespace DiscImageChef.DiscImages writingStream.WriteByte(0); } - byte[] hdr = new byte[Marshal.SizeOf(typeof(A2ImgHeader))]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(A2ImgHeader))); - Marshal.StructureToPtr(imageHeader, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(imageHeader, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/Apridisk/Read.cs b/DiscImageChef.DiscImages/Apridisk/Read.cs index 15146690f..533dee074 100644 --- a/DiscImageChef.DiscImages/Apridisk/Read.cs +++ b/DiscImageChef.DiscImages/Apridisk/Read.cs @@ -32,12 +32,12 @@ using System; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -54,7 +54,7 @@ namespace DiscImageChef.DiscImages int totalCylinders = -1; int totalHeads = -1; int maxSector = -1; - int recordSize = Marshal.SizeOf(typeof(ApridiskRecord)); + int recordSize = Marshal.SizeOf(); // Count cylinders while(stream.Position < stream.Length) @@ -62,7 +62,7 @@ namespace DiscImageChef.DiscImages byte[] recB = new byte[recordSize]; stream.Read(recB, 0, recordSize); - ApridiskRecord record = Helpers.Marshal.ByteArrayToStructureLittleEndian(recB); + ApridiskRecord record = Marshal.ByteArrayToStructureLittleEndian(recB); switch(record.type) { @@ -149,7 +149,7 @@ namespace DiscImageChef.DiscImages byte[] recB = new byte[recordSize]; stream.Read(recB, 0, recordSize); - ApridiskRecord record = Helpers.Marshal.ByteArrayToStructureLittleEndian(recB); + ApridiskRecord record = Marshal.ByteArrayToStructureLittleEndian(recB); switch(record.type) { diff --git a/DiscImageChef.DiscImages/Apridisk/Write.cs b/DiscImageChef.DiscImages/Apridisk/Write.cs index c8955dcad..08dff411e 100644 --- a/DiscImageChef.DiscImages/Apridisk/Write.cs +++ b/DiscImageChef.DiscImages/Apridisk/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -149,8 +149,8 @@ namespace DiscImageChef.DiscImages writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(signature, 0, signature.Length); - byte[] hdr = new byte[Marshal.SizeOf(typeof(ApridiskRecord))]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ApridiskRecord))); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); for(ushort c = 0; c < imageInfo.Cylinders; c++) { @@ -164,15 +164,15 @@ namespace DiscImageChef.DiscImages { type = RecordType.Sector, compression = CompressType.Uncompresed, - headerSize = (ushort)Marshal.SizeOf(typeof(ApridiskRecord)), + headerSize = (ushort)Marshal.SizeOf(), dataSize = (uint)sectorsData[c][h][s].Length, head = h, sector = s, cylinder = c }; - Marshal.StructureToPtr(record, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.StructureToPtr(record, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); writingStream.Write(hdr, 0, hdr.Length); writingStream.Write(sectorsData[c][h][s], 0, sectorsData[c][h][s].Length); @@ -187,15 +187,15 @@ namespace DiscImageChef.DiscImages { type = RecordType.Creator, compression = CompressType.Uncompresed, - headerSize = (ushort)Marshal.SizeOf(typeof(ApridiskRecord)), + headerSize = (ushort)Marshal.SizeOf(), dataSize = (uint)creatorBytes.Length + 1, head = 0, sector = 0, cylinder = 0 }; - Marshal.StructureToPtr(creatorRecord, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.StructureToPtr(creatorRecord, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); writingStream.Write(hdr, 0, hdr.Length); writingStream.Write(creatorBytes, 0, creatorBytes.Length); @@ -209,22 +209,22 @@ namespace DiscImageChef.DiscImages { type = RecordType.Comment, compression = CompressType.Uncompresed, - headerSize = (ushort)Marshal.SizeOf(typeof(ApridiskRecord)), + headerSize = (ushort)Marshal.SizeOf(), dataSize = (uint)commentBytes.Length + 1, head = 0, sector = 0, cylinder = 0 }; - Marshal.StructureToPtr(commentRecord, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.StructureToPtr(commentRecord, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); writingStream.Write(hdr, 0, hdr.Length); writingStream.Write(commentBytes, 0, commentBytes.Length); writingStream.WriteByte(0); // Termination } - Marshal.FreeHGlobal(hdrPtr); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Flush(); writingStream.Close(); diff --git a/DiscImageChef.DiscImages/CDRWin/Verify.cs b/DiscImageChef.DiscImages/CDRWin/Verify.cs index 311fed934..ca473c202 100644 --- a/DiscImageChef.DiscImages/CDRWin/Verify.cs +++ b/DiscImageChef.DiscImages/CDRWin/Verify.cs @@ -42,78 +42,6 @@ namespace DiscImageChef.DiscImages { public partial class CdrWin { - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - public bool? VerifyMediaImage() { if(discimage.DiscHashes.Count == 0) return null; @@ -218,5 +146,77 @@ namespace DiscImageChef.DiscImages return null; } + + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CloneCD/Write.cs b/DiscImageChef.DiscImages/CloneCD/Write.cs index 462a9221c..7b0bbfe83 100644 --- a/DiscImageChef.DiscImages/CloneCD/Write.cs +++ b/DiscImageChef.DiscImages/CloneCD/Write.cs @@ -410,9 +410,9 @@ namespace DiscImageChef.DiscImages for(int i = 0; i < toc.TrackDescriptors.Length; i++) { long alba = MsfToLba((toc.TrackDescriptors[i].Min, toc.TrackDescriptors[i].Sec, - toc.TrackDescriptors[i].Frame)); + toc.TrackDescriptors[i].Frame)); long plba = MsfToLba((toc.TrackDescriptors[i].PMIN, toc.TrackDescriptors[i].PSEC, - toc.TrackDescriptors[i].PFRAME)); + toc.TrackDescriptors[i].PFRAME)); if(alba > 405000) alba = (alba - 405000 + 300) * -1; if(plba > 405000) plba = (plba - 405000 + 300) * -1; diff --git a/DiscImageChef.DiscImages/D88/Identify.cs b/DiscImageChef.DiscImages/D88/Identify.cs index 86480a076..d1a175e43 100644 --- a/DiscImageChef.DiscImages/D88/Identify.cs +++ b/DiscImageChef.DiscImages/D88/Identify.cs @@ -32,10 +32,10 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -48,14 +48,12 @@ namespace DiscImageChef.DiscImages // Even if disk name is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p Encoding shiftjis = Encoding.GetEncoding("shift_jis"); - D88Header d88Hdr = new D88Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(d88Hdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(d88Hdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - d88Hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + D88Header d88Hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("D88 plugin", "d88hdr.name = \"{0}\"", StringHandlers.CToString(d88Hdr.name, shiftjis)); diff --git a/DiscImageChef.DiscImages/D88/Read.cs b/DiscImageChef.DiscImages/D88/Read.cs index c23127cc6..897051cee 100644 --- a/DiscImageChef.DiscImages/D88/Read.cs +++ b/DiscImageChef.DiscImages/D88/Read.cs @@ -34,13 +34,13 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using DiscImageChef.Decoders.Floppy; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -53,13 +53,11 @@ namespace DiscImageChef.DiscImages // Even if disk name is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p Encoding shiftjis = Encoding.GetEncoding("shift_jis"); - D88Header d88Hdr = new D88Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(d88Hdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(d88Hdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - d88Hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + D88Header d88Hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("D88 plugin", "d88hdr.name = \"{0}\"", StringHandlers.CToString(d88Hdr.name, shiftjis)); @@ -89,12 +87,11 @@ namespace DiscImageChef.DiscImages if(trkCounter == 0) return false; - SectorHeader sechdr = new SectorHeader(); - hdrB = new byte[Marshal.SizeOf(sechdr)]; + hdrB = new byte[Marshal.SizeOf()]; stream.Seek(d88Hdr.track_table[0], SeekOrigin.Begin); stream.Read(hdrB, 0, hdrB.Length); - sechdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + SectorHeader sechdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("D88 plugin", "sechdr.c = {0}", sechdr.c); DicConsole.DebugWriteLine("D88 plugin", "sechdr.h = {0}", sechdr.h); @@ -117,7 +114,7 @@ namespace DiscImageChef.DiscImages stream.Read(hdrB, 0, hdrB.Length); SortedDictionary sectors = new SortedDictionary(); - sechdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + sechdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); if(sechdr.spt != spt || sechdr.n != bps) { @@ -136,7 +133,7 @@ namespace DiscImageChef.DiscImages sectors.Add(sechdr.r, secB); stream.Read(hdrB, 0, hdrB.Length); - sechdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + sechdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); if(sechdr.spt == spt && sechdr.n == bps) continue; diff --git a/DiscImageChef.DiscImages/DART/Identify.cs b/DiscImageChef.DiscImages/DART/Identify.cs index 73bc10d91..225ed1fde 100644 --- a/DiscImageChef.DiscImages/DART/Identify.cs +++ b/DiscImageChef.DiscImages/DART/Identify.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -44,12 +44,11 @@ namespace DiscImageChef.DiscImages if(stream.Length < 84) return false; - DartHeader header = new DartHeader(); stream.Seek(0, SeekOrigin.Begin); - byte[] headerB = new byte[Marshal.SizeOf(header)]; + byte[] headerB = new byte[Marshal.SizeOf()]; - stream.Read(headerB, 0, Marshal.SizeOf(header)); - header = Helpers.Marshal.ByteArrayToStructureBigEndian(headerB); + stream.Read(headerB, 0, Marshal.SizeOf()); + DartHeader header = Marshal.ByteArrayToStructureBigEndian(headerB); if(header.srcCmp > COMPRESS_NONE) return false; diff --git a/DiscImageChef.DiscImages/DART/Read.cs b/DiscImageChef.DiscImages/DART/Read.cs index 7678eb394..200a89ad1 100644 --- a/DiscImageChef.DiscImages/DART/Read.cs +++ b/DiscImageChef.DiscImages/DART/Read.cs @@ -32,7 +32,6 @@ using System; using System.IO; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using Claunia.Encoding; using Claunia.RsrcFork; @@ -42,6 +41,7 @@ using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Compression; using DiscImageChef.Console; +using DiscImageChef.Helpers; using Version = Resources.Version; namespace DiscImageChef.DiscImages @@ -54,12 +54,11 @@ namespace DiscImageChef.DiscImages if(stream.Length < 84) return false; - DartHeader header = new DartHeader(); stream.Seek(0, SeekOrigin.Begin); - byte[] headerB = new byte[Marshal.SizeOf(header)]; + byte[] headerB = new byte[Marshal.SizeOf()]; - stream.Read(headerB, 0, Marshal.SizeOf(header)); - header = Helpers.Marshal.ByteArrayToStructureBigEndian(headerB); + stream.Read(headerB, 0, Marshal.SizeOf()); + DartHeader header = Marshal.ByteArrayToStructureBigEndian(headerB); if(header.srcCmp > COMPRESS_NONE) return false; diff --git a/DiscImageChef.DiscImages/DIM/Properties.cs b/DiscImageChef.DiscImages/DIM/Properties.cs index 565c91029..5d8c3a1ab 100644 --- a/DiscImageChef.DiscImages/DIM/Properties.cs +++ b/DiscImageChef.DiscImages/DIM/Properties.cs @@ -41,17 +41,17 @@ namespace DiscImageChef.DiscImages { public partial class Dim { - public string Name => "DIM Disk Image"; - public Guid Id => new Guid("0240B7B1-E959-4CDC-B0BD-386D6E467B88"); - public ImageInfo Info => imageInfo; - public string Author => "Natalia Portillo"; - public string Format => "DIM disk image"; public List Partitions => throw new FeatureUnsupportedImageException("Feature not supported by image format"); public List Tracks => throw new FeatureUnsupportedImageException("Feature not supported by image format"); public List Sessions => throw new FeatureUnsupportedImageException("Feature not supported by image format"); + public string Name => "DIM Disk Image"; + public Guid Id => new Guid("0240B7B1-E959-4CDC-B0BD-386D6E467B88"); + public ImageInfo Info => imageInfo; + public string Author => "Natalia Portillo"; + public string Format => "DIM disk image"; public List DumpHardware => null; public CICMMetadataType CicmMetadata => null; } diff --git a/DiscImageChef.DiscImages/DiscFerret/Read.cs b/DiscImageChef.DiscImages/DiscFerret/Read.cs index a76dd378a..473fd6c59 100644 --- a/DiscImageChef.DiscImages/DiscFerret/Read.cs +++ b/DiscImageChef.DiscImages/DiscFerret/Read.cs @@ -33,10 +33,10 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -61,10 +61,9 @@ namespace DiscImageChef.DiscImages { long thisOffset = stream.Position; - DfiBlockHeader blockHeader = new DfiBlockHeader(); - byte[] blk = new byte[Marshal.SizeOf(blockHeader)]; - stream.Read(blk, 0, Marshal.SizeOf(blockHeader)); - blockHeader = Helpers.Marshal.ByteArrayToStructureBigEndian(blk); + byte[] blk = new byte[Marshal.SizeOf()]; + stream.Read(blk, 0, Marshal.SizeOf()); + DfiBlockHeader blockHeader = Marshal.ByteArrayToStructureBigEndian(blk); DicConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.cylinder = {1}", thisOffset, blockHeader.cylinder); diff --git a/DiscImageChef.DiscImages/DiscImageChef/Helpers.cs b/DiscImageChef.DiscImages/DiscImageChef/Helpers.cs index 2027025af..d9f700ec6 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/Helpers.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/Helpers.cs @@ -31,12 +31,12 @@ // ****************************************************************************/ using System; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.Decoders.ATA; using DiscImageChef.Decoders.SCSI; using DiscImageChef.Decoders.SecureDigital; +using DiscImageChef.Helpers; using VendorString = DiscImageChef.Decoders.SecureDigital.VendorString; namespace DiscImageChef.DiscImages @@ -231,7 +231,7 @@ namespace DiscImageChef.DiscImages if(ddtEntryCache.TryGetValue(sectorAddress, out ulong entry)) return entry; long oldPosition = imageStream.Position; - imageStream.Position = outMemoryDdtPosition + Marshal.SizeOf(typeof(DdtHeader)); + imageStream.Position = outMemoryDdtPosition + Marshal.SizeOf(); imageStream.Position += (long)(sectorAddress * sizeof(ulong)); byte[] temp = new byte[sizeof(ulong)]; imageStream.Read(temp, 0, sizeof(ulong)); @@ -254,7 +254,7 @@ namespace DiscImageChef.DiscImages } long oldPosition = imageStream.Position; - imageStream.Position = outMemoryDdtPosition + Marshal.SizeOf(typeof(DdtHeader)); + imageStream.Position = outMemoryDdtPosition + Marshal.SizeOf(); imageStream.Position += (long)(sectorAddress * sizeof(ulong)); imageStream.Write(BitConverter.GetBytes(pointer), 0, sizeof(ulong)); imageStream.Position = oldPosition; diff --git a/DiscImageChef.DiscImages/DiscImageChef/Identify.cs b/DiscImageChef.DiscImages/DiscImageChef/Identify.cs index f00450eb8..285bf99a3 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/Identify.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/Identify.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -43,12 +43,11 @@ namespace DiscImageChef.DiscImages imageStream = imageFilter.GetDataForkStream(); imageStream.Seek(0, SeekOrigin.Begin); - if(imageStream.Length < Marshal.SizeOf(header)) return false; + if(imageStream.Length < Marshal.SizeOf()) return false; - header = new DicHeader(); - structureBytes = new byte[Marshal.SizeOf(header)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - header = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + header = Marshal.ByteArrayToStructureLittleEndian(structureBytes); return header.identifier == DIC_MAGIC && header.imageMajorVersion <= DICF_VERSION; } diff --git a/DiscImageChef.DiscImages/DiscImageChef/Properties.cs b/DiscImageChef.DiscImages/DiscImageChef/Properties.cs index 1240a2408..bd74283de 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/Properties.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/Properties.cs @@ -61,20 +61,20 @@ namespace DiscImageChef.DiscImages new[] { ("sectors_per_block", typeof(uint), - "How many sectors to store per block (will be rounded to next power of two)", 4096U), + "How many sectors to store per block (will be rounded to next power of two)", 4096U), ("dictionary", typeof(uint), "Size, in bytes, of the LZMA dictionary", (uint)(1 << 25)), ("max_ddt_size", typeof(uint), - "Maximum size, in mebibytes, for in-memory DDT. If image needs a bigger one, it will be on-disk", - 256U), + "Maximum size, in mebibytes, for in-memory DDT. If image needs a bigger one, it will be on-disk", + 256U), ("md5", typeof(bool), "Calculate and store MD5 of image's user data", (object)false), ("sha1", typeof(bool), "Calculate and store SHA1 of image's user data", (object)false), ("sha256", typeof(bool), "Calculate and store SHA256 of image's user data", (object)false), ("spamsum", typeof(bool), "Calculate and store SpamSum of image's user data", (object)false), ("deduplicate", typeof(bool), - "Store only unique sectors. This consumes more memory and is slower, but it's enabled by default", - (object)true), + "Store only unique sectors. This consumes more memory and is slower, but it's enabled by default", + (object)true), ("nocompress", typeof(bool), - "Don't compress user data blocks. Other blocks will still be compressed", (object)false) + "Don't compress user data blocks. Other blocks will still be compressed", (object)false) }; public IEnumerable KnownExtensions => new[] {".dicf"}; public bool IsWriting { get; private set; } diff --git a/DiscImageChef.DiscImages/DiscImageChef/Read.cs b/DiscImageChef.DiscImages/DiscImageChef/Read.cs index f71ec7144..7b92347d2 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/Read.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/Read.cs @@ -34,7 +34,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using System.Xml; using System.Xml.Serialization; @@ -47,6 +46,7 @@ using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; +using DiscImageChef.Helpers; using Schemas; using SharpCompress.Compressors.LZMA; using TrackType = DiscImageChef.CommonTypes.Enums.TrackType; @@ -60,12 +60,11 @@ namespace DiscImageChef.DiscImages imageStream = imageFilter.GetDataForkStream(); imageStream.Seek(0, SeekOrigin.Begin); - if(imageStream.Length < Marshal.SizeOf(header)) return false; + if(imageStream.Length < Marshal.SizeOf()) return false; - header = new DicHeader(); - structureBytes = new byte[Marshal.SizeOf(header)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - header = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + header = Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(header.imageMajorVersion > DICF_VERSION) throw new FeatureUnsupportedImageException($"Image version {header.imageMajorVersion} not recognized."); @@ -77,10 +76,9 @@ namespace DiscImageChef.DiscImages // Read the index header imageStream.Position = (long)header.indexOffset; - IndexHeader idxHeader = new IndexHeader(); - structureBytes = new byte[Marshal.SizeOf(idxHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - idxHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + IndexHeader idxHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(idxHeader.identifier != BlockType.Index) throw new FeatureUnsupportedImageException("Index not found!"); @@ -91,10 +89,9 @@ namespace DiscImageChef.DiscImages index = new List(); for(ushort i = 0; i < idxHeader.entries; i++) { - IndexEntry entry = new IndexEntry(); - structureBytes = new byte[Marshal.SizeOf(entry)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - entry = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + IndexEntry entry = Marshal.ByteArrayToStructureLittleEndian(structureBytes); DicConsole.DebugWriteLine("DiscImageChef format plugin", "Block type {0} with data type {1} is indexed to be at {2}", entry.blockType, entry.dataType, entry.offset); @@ -116,11 +113,9 @@ namespace DiscImageChef.DiscImages imageStream.Position = (long)entry.offset; - BlockHeader blockHeader = new BlockHeader(); - structureBytes = new byte[Marshal.SizeOf(blockHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - blockHeader = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + BlockHeader blockHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); imageInfo.ImageSize += blockHeader.cmpLength; // Unused, skip @@ -282,11 +277,9 @@ namespace DiscImageChef.DiscImages // Only user data deduplication tables are used right now if(entry.dataType == DataType.UserData) { - DdtHeader ddtHeader = new DdtHeader(); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - ddtHeader = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DdtHeader ddtHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); imageInfo.ImageSize += ddtHeader.cmpLength; if(ddtHeader.identifier != BlockType.DeDuplicationTable) break; @@ -334,11 +327,9 @@ namespace DiscImageChef.DiscImages else if(entry.dataType == DataType.CdSectorPrefixCorrected || entry.dataType == DataType.CdSectorSuffixCorrected) { - DdtHeader ddtHeader = new DdtHeader(); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - ddtHeader = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DdtHeader ddtHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); imageInfo.ImageSize += ddtHeader.cmpLength; if(ddtHeader.identifier != BlockType.DeDuplicationTable) break; @@ -384,10 +375,9 @@ namespace DiscImageChef.DiscImages break; // Logical geometry block. It doesn't have a CRC coz, well, it's not so important case BlockType.GeometryBlock: - geometryBlock = new GeometryBlock(); - structureBytes = new byte[Marshal.SizeOf(geometryBlock)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - geometryBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + geometryBlock = Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(geometryBlock.identifier == BlockType.GeometryBlock) { DicConsole.DebugWriteLine("DiscImageChef format plugin", @@ -402,10 +392,10 @@ namespace DiscImageChef.DiscImages break; // Metadata block case BlockType.MetadataBlock: - MetadataBlock metadataBlock = new MetadataBlock(); - structureBytes = new byte[Marshal.SizeOf(metadataBlock)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - metadataBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + MetadataBlock metadataBlock = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(metadataBlock.identifier != entry.blockType) { @@ -570,10 +560,10 @@ namespace DiscImageChef.DiscImages break; // Optical disc tracks block case BlockType.TracksBlock: - TracksHeader tracksHeader = new TracksHeader(); - structureBytes = new byte[Marshal.SizeOf(tracksHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - tracksHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + TracksHeader tracksHeader = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(tracksHeader.identifier != BlockType.TracksBlock) { DicConsole.DebugWriteLine("DiscImageChef format plugin", @@ -582,7 +572,7 @@ namespace DiscImageChef.DiscImages break; } - structureBytes = new byte[Marshal.SizeOf(typeof(TrackEntry)) * tracksHeader.entries]; + structureBytes = new byte[Marshal.SizeOf() * tracksHeader.entries]; imageStream.Read(structureBytes, 0, structureBytes.Length); Crc64Context.Data(structureBytes, out byte[] trksCrc); if(BitConverter.ToUInt64(trksCrc, 0) != tracksHeader.crc64) @@ -604,10 +594,10 @@ namespace DiscImageChef.DiscImages for(ushort i = 0; i < tracksHeader.entries; i++) { - TrackEntry trackEntry = new TrackEntry(); - structureBytes = new byte[Marshal.SizeOf(trackEntry)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - trackEntry = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + TrackEntry trackEntry = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); Tracks.Add(new Track { @@ -631,10 +621,10 @@ namespace DiscImageChef.DiscImages break; // CICM XML metadata block case BlockType.CicmBlock: - CicmMetadataBlock cicmBlock = new CicmMetadataBlock(); - structureBytes = new byte[Marshal.SizeOf(cicmBlock)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - cicmBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + CicmMetadataBlock cicmBlock = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(cicmBlock.identifier != BlockType.CicmBlock) break; DicConsole.DebugWriteLine("DiscImageChef format plugin", @@ -660,11 +650,10 @@ namespace DiscImageChef.DiscImages break; // Dump hardware block case BlockType.DumpHardwareBlock: - DumpHardwareHeader dumpBlock = new DumpHardwareHeader(); - structureBytes = new byte[Marshal.SizeOf(dumpBlock)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - dumpBlock = Helpers - .Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DumpHardwareHeader dumpBlock = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break; DicConsole.DebugWriteLine("DiscImageChef format plugin", @@ -687,11 +676,10 @@ namespace DiscImageChef.DiscImages for(ushort i = 0; i < dumpBlock.entries; i++) { - DumpHardwareEntry dumpEntry = new DumpHardwareEntry(); - structureBytes = new byte[Marshal.SizeOf(dumpEntry)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - dumpEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DumpHardwareEntry dumpEntry = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); DumpHardwareType dump = new DumpHardwareType { @@ -933,10 +921,9 @@ namespace DiscImageChef.DiscImages // Read block header imageStream.Position = (long)blockOffset; - blockHeader = new BlockHeader(); - structureBytes = new byte[Marshal.SizeOf(blockHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - blockHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + blockHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); // Decompress block switch(blockHeader.compression) diff --git a/DiscImageChef.DiscImages/DiscImageChef/Verify.cs b/DiscImageChef.DiscImages/DiscImageChef/Verify.cs index 93031f9f9..e7f58855f 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/Verify.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/Verify.cs @@ -32,10 +32,10 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using DiscImageChef.Checksums; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -48,10 +48,9 @@ namespace DiscImageChef.DiscImages header.indexOffset); imageStream.Position = (long)header.indexOffset; - IndexHeader idxHeader = new IndexHeader(); - structureBytes = new byte[Marshal.SizeOf(idxHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - idxHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + IndexHeader idxHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(idxHeader.identifier != BlockType.Index) { @@ -62,7 +61,7 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("DiscImageChef format plugin", "Index at {0} contains {1} entries", header.indexOffset, idxHeader.entries); - structureBytes = new byte[Marshal.SizeOf(typeof(IndexEntry)) * idxHeader.entries]; + structureBytes = new byte[Marshal.SizeOf() * idxHeader.entries]; imageStream.Read(structureBytes, 0, structureBytes.Length); Crc64Context.Data(structureBytes, out byte[] verifyCrc); @@ -78,10 +77,9 @@ namespace DiscImageChef.DiscImages List vrIndex = new List(); for(ushort i = 0; i < idxHeader.entries; i++) { - IndexEntry entry = new IndexEntry(); - structureBytes = new byte[Marshal.SizeOf(entry)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - entry = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + IndexEntry entry = Marshal.ByteArrayToStructureLittleEndian(structureBytes); DicConsole.DebugWriteLine("DiscImageChef format plugin", "Block type {0} with data type {1} is indexed to be at {2}", entry.blockType, entry.dataType, entry.offset); @@ -101,10 +99,9 @@ namespace DiscImageChef.DiscImages switch(entry.blockType) { case BlockType.DataBlock: - BlockHeader blockHeader = new BlockHeader(); - structureBytes = new byte[Marshal.SizeOf(blockHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - blockHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + BlockHeader blockHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); crcVerify = new Crc64Context(); readBytes = 0; @@ -137,10 +134,9 @@ namespace DiscImageChef.DiscImages break; case BlockType.DeDuplicationTable: - DdtHeader ddtHeader = new DdtHeader(); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - ddtHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DdtHeader ddtHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); crcVerify = new Crc64Context(); readBytes = 0; @@ -173,16 +169,15 @@ namespace DiscImageChef.DiscImages break; case BlockType.TracksBlock: - TracksHeader trkHeader = new TracksHeader(); - structureBytes = new byte[Marshal.SizeOf(trkHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - trkHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + TracksHeader trkHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); DicConsole.DebugWriteLine("DiscImageChef format plugin", "Track block at {0} contains {1} entries", header.indexOffset, trkHeader.entries); - structureBytes = new byte[Marshal.SizeOf(typeof(TrackEntry)) * trkHeader.entries]; + structureBytes = new byte[Marshal.SizeOf() * trkHeader.entries]; imageStream.Read(structureBytes, 0, structureBytes.Length); Crc64Context.Data(structureBytes, out verifyCrc); diff --git a/DiscImageChef.DiscImages/DiscImageChef/Write.cs b/DiscImageChef.DiscImages/DiscImageChef/Write.cs index 729fe97ce..26a0e3419 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/Write.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/Write.cs @@ -34,7 +34,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using System.Xml; @@ -48,6 +47,7 @@ using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; using DiscImageChef.Decoders; +using DiscImageChef.Helpers; using Schemas; using SharpCompress.Compressors.LZMA; using TrackType = DiscImageChef.CommonTypes.Enums.TrackType; @@ -207,12 +207,11 @@ namespace DiscImageChef.DiscImages } // Check if appending to an existing image - if(imageStream.Length > Marshal.SizeOf(typeof(DicHeader))) + if(imageStream.Length > Marshal.SizeOf()) { - header = new DicHeader(); - structureBytes = new byte[Marshal.SizeOf(header)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - header = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + header = Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(header.identifier != DIC_MAGIC) { @@ -240,7 +239,7 @@ namespace DiscImageChef.DiscImages identifier = DIC_MAGIC, mediaType = mediaType, creationTime = DateTime.UtcNow.ToFileTimeUtc() }; - imageStream.Write(new byte[Marshal.SizeOf(typeof(DicHeader))], 0, Marshal.SizeOf(typeof(DicHeader))); + imageStream.Write(new byte[Marshal.SizeOf()], 0, Marshal.SizeOf()); } header.application = "DiscImageChef"; @@ -261,10 +260,9 @@ namespace DiscImageChef.DiscImages spamsumProvider = null; imageStream.Position = (long)header.indexOffset; - IndexHeader idxHeader = new IndexHeader(); - structureBytes = new byte[Marshal.SizeOf(idxHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - idxHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + IndexHeader idxHeader = Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(idxHeader.identifier != BlockType.Index) { @@ -277,10 +275,9 @@ namespace DiscImageChef.DiscImages for(ushort i = 0; i < idxHeader.entries; i++) { - IndexEntry entry = new IndexEntry(); - structureBytes = new byte[Marshal.SizeOf(entry)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - entry = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + IndexEntry entry = Marshal.ByteArrayToStructureLittleEndian(structureBytes); DicConsole.DebugWriteLine("DiscImageChef format plugin", "Block type {0} with data type {1} is indexed to be at {2}", entry.blockType, entry.dataType, entry.offset); @@ -310,11 +307,10 @@ namespace DiscImageChef.DiscImages default: continue; } - BlockHeader blockHeader = new BlockHeader(); - structureBytes = new byte[Marshal.SizeOf(blockHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - blockHeader = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + BlockHeader blockHeader = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); imageInfo.ImageSize += blockHeader.cmpLength; if(blockHeader.identifier != entry.blockType) @@ -404,10 +400,10 @@ namespace DiscImageChef.DiscImages // Only user data deduplication tables are used right now if(entry.dataType == DataType.UserData) { - DdtHeader ddtHeader = new DdtHeader(); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - ddtHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DdtHeader ddtHeader = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(ddtHeader.identifier != BlockType.DeDuplicationTable) break; @@ -461,10 +457,10 @@ namespace DiscImageChef.DiscImages else if(entry.dataType == DataType.CdSectorPrefixCorrected || entry.dataType == DataType.CdSectorSuffixCorrected) { - DdtHeader ddtHeader = new DdtHeader(); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - ddtHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DdtHeader ddtHeader = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(ddtHeader.identifier != BlockType.DeDuplicationTable) break; @@ -524,11 +520,10 @@ namespace DiscImageChef.DiscImages break; // CICM XML metadata block case BlockType.CicmBlock: - CicmMetadataBlock cicmBlock = new CicmMetadataBlock(); - structureBytes = new byte[Marshal.SizeOf(cicmBlock)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - cicmBlock = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + CicmMetadataBlock cicmBlock = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(cicmBlock.identifier != BlockType.CicmBlock) break; DicConsole.DebugWriteLine("DiscImageChef format plugin", @@ -555,11 +550,10 @@ namespace DiscImageChef.DiscImages break; // Dump hardware block case BlockType.DumpHardwareBlock: - DumpHardwareHeader dumpBlock = new DumpHardwareHeader(); - structureBytes = new byte[Marshal.SizeOf(dumpBlock)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - dumpBlock = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DumpHardwareHeader dumpBlock = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break; DicConsole.DebugWriteLine("DiscImageChef format plugin", @@ -582,11 +576,10 @@ namespace DiscImageChef.DiscImages for(ushort i = 0; i < dumpBlock.entries; i++) { - DumpHardwareEntry dumpEntry = new DumpHardwareEntry(); - structureBytes = new byte[Marshal.SizeOf(dumpEntry)]; + structureBytes = new byte[Marshal.SizeOf()]; imageStream.Read(structureBytes, 0, structureBytes.Length); - dumpEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(structureBytes); + DumpHardwareEntry dumpEntry = + Marshal.ByteArrayToStructureLittleEndian(structureBytes); DumpHardwareType dump = new DumpHardwareType { @@ -724,11 +717,12 @@ namespace DiscImageChef.DiscImages length = sectors * sizeof(ulong) }; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(ddtHeader)); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; - Marshal.StructureToPtr(ddtHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); structureBytes = null; @@ -938,11 +932,11 @@ namespace DiscImageChef.DiscImages offset = (ulong)imageStream.Position }); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(currentBlockHeader)); - structureBytes = new byte[Marshal.SizeOf(currentBlockHeader)]; - Marshal.StructureToPtr(currentBlockHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(currentBlockHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); structureBytes = null; if(currentBlockHeader.compression == CompressionType.Lzma) @@ -1530,11 +1524,11 @@ namespace DiscImageChef.DiscImages offset = (ulong)imageStream.Position }); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(currentBlockHeader)); - structureBytes = new byte[Marshal.SizeOf(currentBlockHeader)]; - Marshal.StructureToPtr(currentBlockHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(currentBlockHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); structureBytes = null; if(currentBlockHeader.compression == CompressionType.Lzma) @@ -1602,11 +1596,11 @@ namespace DiscImageChef.DiscImages blockStream.Close(); blockStream = null; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(tagBlock)); - structureBytes = new byte[Marshal.SizeOf(tagBlock)]; - Marshal.StructureToPtr(tagBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(tagBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(tagBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -1630,11 +1624,11 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing geometry block to position {0}", idxEntry.offset); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(geometryBlock)); - structureBytes = new byte[Marshal.SizeOf(geometryBlock)]; - Marshal.StructureToPtr(geometryBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(geometryBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); index.RemoveAll(t => t.blockType == BlockType.GeometryBlock && t.dataType == DataType.NoData); @@ -1686,11 +1680,13 @@ namespace DiscImageChef.DiscImages extents = (uint)dump.Extents.Length }; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(dumpEntry)); - structureBytes = new byte[Marshal.SizeOf(dumpEntry)]; - Marshal.StructureToPtr(dumpEntry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(dumpEntry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); dumpMs.Write(structureBytes, 0, structureBytes.Length); if(dumpManufacturer != null) @@ -1767,11 +1763,12 @@ namespace DiscImageChef.DiscImages length = (uint)dumpMs.Length }; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(dumpBlock)); - structureBytes = new byte[Marshal.SizeOf(dumpBlock)]; - Marshal.StructureToPtr(dumpBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(dumpBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(dumpMs.ToArray(), 0, (int)dumpMs.Length); @@ -1799,11 +1796,12 @@ namespace DiscImageChef.DiscImages CicmMetadataBlock cicmBlock = new CicmMetadataBlock {identifier = BlockType.CicmBlock, length = (uint)cicmMs.Length}; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(cicmBlock)); - structureBytes = new byte[Marshal.SizeOf(cicmBlock)]; - Marshal.StructureToPtr(cicmBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(cicmBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(cicmMs.ToArray(), 0, (int)cicmMs.Length); @@ -1823,11 +1821,13 @@ namespace DiscImageChef.DiscImages byte[] md5 = md5Provider.Final(); ChecksumEntry md5Entry = new ChecksumEntry {type = ChecksumAlgorithm.Md5, length = (uint)md5.Length}; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(md5Entry)); - structureBytes = new byte[Marshal.SizeOf(md5Entry)]; - Marshal.StructureToPtr(md5Entry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(md5Entry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(md5, 0, md5.Length); chkHeader.entries++; @@ -1838,11 +1838,13 @@ namespace DiscImageChef.DiscImages byte[] sha1 = sha1Provider.Final(); ChecksumEntry sha1Entry = new ChecksumEntry {type = ChecksumAlgorithm.Sha1, length = (uint)sha1.Length}; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(sha1Entry)); - structureBytes = new byte[Marshal.SizeOf(sha1Entry)]; - Marshal.StructureToPtr(sha1Entry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(sha1Entry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(sha1, 0, sha1.Length); chkHeader.entries++; @@ -1853,11 +1855,13 @@ namespace DiscImageChef.DiscImages byte[] sha256 = sha256Provider.Final(); ChecksumEntry sha256Entry = new ChecksumEntry {type = ChecksumAlgorithm.Sha256, length = (uint)sha256.Length}; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(sha256Entry)); - structureBytes = new byte[Marshal.SizeOf(sha256Entry)]; - Marshal.StructureToPtr(sha256Entry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(sha256Entry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(sha256, 0, sha256.Length); chkHeader.entries++; @@ -1868,11 +1872,13 @@ namespace DiscImageChef.DiscImages byte[] spamsum = Encoding.ASCII.GetBytes(spamsumProvider.End()); ChecksumEntry spamsumEntry = new ChecksumEntry {type = ChecksumAlgorithm.SpamSum, length = (uint)spamsum.Length}; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(spamsumEntry)); - structureBytes = new byte[Marshal.SizeOf(spamsumEntry)]; - Marshal.StructureToPtr(spamsumEntry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(spamsumEntry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(spamsum, 0, spamsum.Length); chkHeader.entries++; @@ -1891,11 +1897,13 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing checksum block to position {0}", idxEntry.offset); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(chkHeader)); - structureBytes = new byte[Marshal.SizeOf(chkHeader)]; - Marshal.StructureToPtr(chkHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(chkHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(chkMs.ToArray(), 0, (int)chkMs.Length); @@ -1948,11 +1956,11 @@ namespace DiscImageChef.DiscImages cmpCrc64Context.Update(blockStream.ToArray()); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(ddtHeader)); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; - Marshal.StructureToPtr(ddtHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); structureBytes = null; imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2025,11 +2033,13 @@ namespace DiscImageChef.DiscImages (endCompress - startCompress).TotalSeconds); } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(prefixBlock)); - structureBytes = new byte[Marshal.SizeOf(prefixBlock)]; - Marshal.StructureToPtr(prefixBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(prefixBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(prefixBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2091,11 +2101,13 @@ namespace DiscImageChef.DiscImages (endCompress - startCompress).TotalSeconds); } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(prefixBlock)); - structureBytes = new byte[Marshal.SizeOf(prefixBlock)]; - Marshal.StructureToPtr(prefixBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(prefixBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(prefixBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2199,11 +2211,13 @@ namespace DiscImageChef.DiscImages cmpCrc64Context.Update(blockStream.ToArray()); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(ddtHeader)); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; - Marshal.StructureToPtr(ddtHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); structureBytes = null; imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2255,11 +2269,13 @@ namespace DiscImageChef.DiscImages cmpCrc64Context.Update(blockStream.ToArray()); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(ddtHeader)); - structureBytes = new byte[Marshal.SizeOf(ddtHeader)]; - Marshal.StructureToPtr(ddtHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); structureBytes = null; imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2325,11 +2341,13 @@ namespace DiscImageChef.DiscImages (endCompress - startCompress).TotalSeconds); } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(prefixBlock)); - structureBytes = new byte[Marshal.SizeOf(prefixBlock)]; - Marshal.StructureToPtr(prefixBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(prefixBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(prefixBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2395,11 +2413,13 @@ namespace DiscImageChef.DiscImages (endCompress - startCompress).TotalSeconds); } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(suffixBlock)); - structureBytes = new byte[Marshal.SizeOf(suffixBlock)]; - Marshal.StructureToPtr(suffixBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(suffixBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(suffixBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2467,11 +2487,13 @@ namespace DiscImageChef.DiscImages (endCompress - startCompress).TotalSeconds); } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(subheaderBlock)); - structureBytes = new byte[Marshal.SizeOf(subheaderBlock)]; - Marshal.StructureToPtr(subheaderBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(subheaderBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(subheaderBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2540,11 +2562,13 @@ namespace DiscImageChef.DiscImages (endCompress - startCompress).TotalSeconds); } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(subchannelBlock)); - structureBytes = new byte[Marshal.SizeOf(subchannelBlock)]; - Marshal.StructureToPtr(subchannelBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(subchannelBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(subchannelBlock.compression == CompressionType.Lzma || subchannelBlock.compression == CompressionType.LzmaClauniaSubchannelTransform) @@ -2588,11 +2612,13 @@ namespace DiscImageChef.DiscImages foreach(TrackEntry entry in trackEntries) { - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(entry)); - structureBytes = new byte[Marshal.SizeOf(entry)]; - Marshal.StructureToPtr(entry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(entry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); blockStream.Write(structureBytes, 0, structureBytes.Length); } @@ -2616,11 +2642,13 @@ namespace DiscImageChef.DiscImages offset = (ulong)imageStream.Position }); - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(trkHeader)); - structureBytes = new byte[Marshal.SizeOf(trkHeader)]; - Marshal.StructureToPtr(trkHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(trkHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length); blockStream.Close(); @@ -2715,11 +2743,13 @@ namespace DiscImageChef.DiscImages subchannelBlock.compression = CompressionType.Lzma; } - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(subchannelBlock)); - structureBytes = new byte[Marshal.SizeOf(subchannelBlock)]; - Marshal.StructureToPtr(subchannelBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(subchannelBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, + structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); if(subchannelBlock.compression == CompressionType.Lzma) imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); @@ -2739,7 +2769,7 @@ namespace DiscImageChef.DiscImages SetMetadataFromTags(); MetadataBlock metadataBlock = new MetadataBlock(); blockStream = new MemoryStream(); - blockStream.Write(new byte[Marshal.SizeOf(metadataBlock)], 0, Marshal.SizeOf(metadataBlock)); + blockStream.Write(new byte[Marshal.SizeOf()], 0, Marshal.SizeOf()); byte[] tmpUtf16Le; if(imageInfo.MediaSequence > 0 && imageInfo.LastMediaSequence > 0) @@ -2875,11 +2905,12 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing metadata to position {0}", imageStream.Position); metadataBlock.blockSize = (uint)blockStream.Length; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(metadataBlock)); - structureBytes = new byte[Marshal.SizeOf(metadataBlock)]; - Marshal.StructureToPtr(metadataBlock, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = + System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(metadataBlock, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); blockStream.Position = 0; blockStream.Write(structureBytes, 0, structureBytes.Length); index.RemoveAll(t => t.blockType == BlockType.MetadataBlock && t.dataType == DataType.NoData); @@ -2904,11 +2935,11 @@ namespace DiscImageChef.DiscImages // Write index to memory foreach(IndexEntry entry in index) { - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(entry)); - structureBytes = new byte[Marshal.SizeOf(entry)]; - Marshal.StructureToPtr(entry, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(entry, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); blockStream.Write(structureBytes, 0, structureBytes.Length); } @@ -2922,11 +2953,11 @@ namespace DiscImageChef.DiscImages }; // Write index to disk - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(idxHeader)); - structureBytes = new byte[Marshal.SizeOf(idxHeader)]; - Marshal.StructureToPtr(idxHeader, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(idxHeader, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length); blockStream.Close(); @@ -2935,11 +2966,11 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing header"); header.lastWrittenTime = DateTime.UtcNow.ToFileTimeUtc(); imageStream.Position = 0; - structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - structureBytes = new byte[Marshal.SizeOf(header)]; - Marshal.StructureToPtr(header, structurePointer, true); - Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); - Marshal.FreeHGlobal(structurePointer); + structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + structureBytes = new byte[Marshal.SizeOf()]; + System.Runtime.InteropServices.Marshal.StructureToPtr(header, structurePointer, true); + System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer); imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Flush(); diff --git a/DiscImageChef.DiscImages/DriDiskCopy/Identify.cs b/DiscImageChef.DiscImages/DriDiskCopy/Identify.cs index 931558d39..67be83543 100644 --- a/DiscImageChef.DiscImages/DriDiskCopy/Identify.cs +++ b/DiscImageChef.DiscImages/DriDiskCopy/Identify.cs @@ -31,10 +31,10 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -44,13 +44,13 @@ namespace DiscImageChef.DiscImages { Stream stream = imageFilter.GetDataForkStream(); - if((stream.Length - Marshal.SizeOf(typeof(DriFooter))) % 512 != 0) return false; + if((stream.Length - Marshal.SizeOf()) % 512 != 0) return false; - byte[] buffer = new byte[Marshal.SizeOf(typeof(DriFooter))]; + byte[] buffer = new byte[Marshal.SizeOf()]; stream.Seek(-buffer.Length, SeekOrigin.End); stream.Read(buffer, 0, buffer.Length); - DriFooter tmpFooter = Helpers.Marshal.ByteArrayToStructureLittleEndian(buffer); + DriFooter tmpFooter = Marshal.ByteArrayToStructureLittleEndian(buffer); string sig = StringHandlers.CToString(tmpFooter.signature); @@ -89,7 +89,7 @@ namespace DiscImageChef.DiscImages if(tmpFooter.bpb.sptrack * tmpFooter.bpb.cylinders * tmpFooter.bpb.heads != tmpFooter.bpb.sectors) return false; - return tmpFooter.bpb.sectors * tmpFooter.bpb.bps + Marshal.SizeOf(tmpFooter) == stream.Length; + return tmpFooter.bpb.sectors * tmpFooter.bpb.bps + Marshal.SizeOf() == stream.Length; } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DriDiskCopy/Read.cs b/DiscImageChef.DiscImages/DriDiskCopy/Read.cs index 4f12be7e6..ac537e79d 100644 --- a/DiscImageChef.DiscImages/DriDiskCopy/Read.cs +++ b/DiscImageChef.DiscImages/DriDiskCopy/Read.cs @@ -32,12 +32,12 @@ using System; using System.IO; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -47,13 +47,13 @@ namespace DiscImageChef.DiscImages { Stream stream = imageFilter.GetDataForkStream(); - if((stream.Length - Marshal.SizeOf(typeof(DriFooter))) % 512 != 0) return false; + if((stream.Length - Marshal.SizeOf()) % 512 != 0) return false; - byte[] buffer = new byte[Marshal.SizeOf(typeof(DriFooter))]; + byte[] buffer = new byte[Marshal.SizeOf()]; stream.Seek(-buffer.Length, SeekOrigin.End); stream.Read(buffer, 0, buffer.Length); - footer = Helpers.Marshal.ByteArrayToStructureLittleEndian(buffer); + footer = Marshal.ByteArrayToStructureLittleEndian(buffer); string sig = StringHandlers.CToString(footer.signature); @@ -64,7 +64,7 @@ namespace DiscImageChef.DiscImages if(footer.bpb.sptrack * footer.bpb.cylinders * footer.bpb.heads != footer.bpb.sectors) return false; - if(footer.bpb.sectors * footer.bpb.bps + Marshal.SizeOf(footer) != stream.Length) return false; + if(footer.bpb.sectors * footer.bpb.bps + Marshal.SizeOf() != stream.Length) return false; imageInfo.Cylinders = footer.bpb.cylinders; imageInfo.Heads = footer.bpb.heads; @@ -75,7 +75,7 @@ namespace DiscImageChef.DiscImages driImageFilter = imageFilter; - imageInfo.ImageSize = (ulong)(stream.Length - Marshal.SizeOf(footer)); + imageInfo.ImageSize = (ulong)(stream.Length - Marshal.SizeOf()); imageInfo.CreationTime = imageFilter.GetCreationTime(); imageInfo.LastModificationTime = imageFilter.GetLastWriteTime(); diff --git a/DiscImageChef.DiscImages/DriDiskCopy/Write.cs b/DiscImageChef.DiscImages/DriDiskCopy/Write.cs index 91af0e0b7..89a63b42e 100644 --- a/DiscImageChef.DiscImages/DriDiskCopy/Write.cs +++ b/DiscImageChef.DiscImages/DriDiskCopy/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -184,11 +184,11 @@ namespace DiscImageChef.DiscImages return false; } - byte[] hdr = new byte[Marshal.SizeOf(footer)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(footer)); - Marshal.StructureToPtr(footer, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(footer, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.End); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/IMD/Read.cs b/DiscImageChef.DiscImages/IMD/Read.cs index f18d05f09..1f4c7b17e 100644 --- a/DiscImageChef.DiscImages/IMD/Read.cs +++ b/DiscImageChef.DiscImages/IMD/Read.cs @@ -160,8 +160,8 @@ namespace DiscImageChef.DiscImages mediaEncoding = MediaEncoding.FM; imageInfo.MediaType = Geometry.GetMediaType(((ushort)imageInfo.Cylinders, (byte)imageInfo.Heads, - (ushort)imageInfo.SectorsPerTrack, imageInfo.SectorSize, - mediaEncoding, false)); + (ushort)imageInfo.SectorsPerTrack, imageInfo.SectorSize, + mediaEncoding, false)); switch(imageInfo.MediaType) { diff --git a/DiscImageChef.DiscImages/KryoFlux/Identify.cs b/DiscImageChef.DiscImages/KryoFlux/Identify.cs index 0f1153f4b..145f72e23 100644 --- a/DiscImageChef.DiscImages/KryoFlux/Identify.cs +++ b/DiscImageChef.DiscImages/KryoFlux/Identify.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -40,23 +40,21 @@ namespace DiscImageChef.DiscImages { public bool Identify(IFilter imageFilter) { - OobBlock header = new OobBlock(); - Stream stream = imageFilter.GetDataForkStream(); + Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); - if(stream.Length < Marshal.SizeOf(header)) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] hdr = new byte[Marshal.SizeOf(header)]; - stream.Read(hdr, 0, Marshal.SizeOf(header)); + byte[] hdr = new byte[Marshal.SizeOf()]; + stream.Read(hdr, 0, Marshal.SizeOf()); - header = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdr); + OobBlock header = Marshal.ByteArrayToStructureLittleEndian(hdr); - OobBlock footer = new OobBlock(); - stream.Seek(-Marshal.SizeOf(footer), SeekOrigin.End); + stream.Seek(-Marshal.SizeOf(), SeekOrigin.End); - hdr = new byte[Marshal.SizeOf(footer)]; - stream.Read(hdr, 0, Marshal.SizeOf(footer)); + hdr = new byte[Marshal.SizeOf()]; + stream.Read(hdr, 0, Marshal.SizeOf()); - footer = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdr); + OobBlock footer = Marshal.ByteArrayToStructureLittleEndian(hdr); return header.blockId == BlockIds.Oob && header.blockType == OobTypes.KFInfo && footer.blockId == BlockIds.Oob && footer.blockType == OobTypes.EOF && footer.length == 0x0D0D; diff --git a/DiscImageChef.DiscImages/KryoFlux/Read.cs b/DiscImageChef.DiscImages/KryoFlux/Read.cs index d6ab39ed8..e9ed46fdb 100644 --- a/DiscImageChef.DiscImages/KryoFlux/Read.cs +++ b/DiscImageChef.DiscImages/KryoFlux/Read.cs @@ -35,11 +35,11 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using DiscImageChef.Filters; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -47,23 +47,21 @@ namespace DiscImageChef.DiscImages { public bool Open(IFilter imageFilter) { - OobBlock header = new OobBlock(); - Stream stream = imageFilter.GetDataForkStream(); + Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); - if(stream.Length < Marshal.SizeOf(header)) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] hdr = new byte[Marshal.SizeOf(header)]; - stream.Read(hdr, 0, Marshal.SizeOf(header)); + byte[] hdr = new byte[Marshal.SizeOf()]; + stream.Read(hdr, 0, Marshal.SizeOf()); - header = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdr); + OobBlock header = Marshal.ByteArrayToStructureLittleEndian(hdr); - OobBlock footer = new OobBlock(); - stream.Seek(-Marshal.SizeOf(footer), SeekOrigin.End); + stream.Seek(-Marshal.SizeOf(), SeekOrigin.End); - hdr = new byte[Marshal.SizeOf(footer)]; - stream.Read(hdr, 0, Marshal.SizeOf(footer)); + hdr = new byte[Marshal.SizeOf()]; + stream.Read(hdr, 0, Marshal.SizeOf()); - footer = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdr); + OobBlock footer = Marshal.ByteArrayToStructureLittleEndian(hdr); if(header.blockId != BlockIds.Oob || header.blockType != OobTypes.KFInfo || footer.blockId != BlockIds.Oob || footer.blockType != OobTypes.EOF || @@ -131,12 +129,11 @@ namespace DiscImageChef.DiscImages case (byte)BlockIds.Oob: { trackStream.Position--; - OobBlock oobBlk = new OobBlock(); - byte[] oob = new byte[Marshal.SizeOf(oobBlk)]; - trackStream.Read(oob, 0, Marshal.SizeOf(oobBlk)); + byte[] oob = new byte[Marshal.SizeOf()]; + trackStream.Read(oob, 0, Marshal.SizeOf()); - oobBlk = Helpers.Marshal.ByteArrayToStructureLittleEndian(oob); + OobBlock oobBlk = Marshal.ByteArrayToStructureLittleEndian(oob); if(oobBlk.blockType == OobTypes.EOF) { diff --git a/DiscImageChef.DiscImages/MaxiDisk/Write.cs b/DiscImageChef.DiscImages/MaxiDisk/Write.cs index b8124ec40..e671928c9 100644 --- a/DiscImageChef.DiscImages/MaxiDisk/Write.cs +++ b/DiscImageChef.DiscImages/MaxiDisk/Write.cs @@ -39,7 +39,6 @@ using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Helpers; using Schemas; -using Marshal = System.Runtime.InteropServices.Marshal; namespace DiscImageChef.DiscImages { @@ -128,7 +127,7 @@ namespace DiscImageChef.DiscImages return false; } - writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(HdkHeader)) + sectorAddress * imageInfo.SectorSize), + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); @@ -156,7 +155,7 @@ namespace DiscImageChef.DiscImages return false; } - writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(HdkHeader)) + sectorAddress * imageInfo.SectorSize), + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); @@ -198,11 +197,11 @@ namespace DiscImageChef.DiscImages i >>= 1; } - byte[] hdr = new byte[Marshal.SizeOf(header)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/NHDr0/Identify.cs b/DiscImageChef.DiscImages/NHDr0/Identify.cs index b0b8ac2f1..fafc6e184 100644 --- a/DiscImageChef.DiscImages/NHDr0/Identify.cs +++ b/DiscImageChef.DiscImages/NHDr0/Identify.cs @@ -32,10 +32,10 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -48,14 +48,12 @@ namespace DiscImageChef.DiscImages // Even if comment is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p Encoding shiftjis = Encoding.GetEncoding("shift_jis"); - nhdhdr = new Nhdr0Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(nhdhdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(nhdhdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - nhdhdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + nhdhdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); if(!nhdhdr.szFileID.SequenceEqual(signature)) return false; diff --git a/DiscImageChef.DiscImages/NHDr0/Read.cs b/DiscImageChef.DiscImages/NHDr0/Read.cs index 4cf63117a..1104c1f8f 100644 --- a/DiscImageChef.DiscImages/NHDr0/Read.cs +++ b/DiscImageChef.DiscImages/NHDr0/Read.cs @@ -32,11 +32,11 @@ using System; using System.IO; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -49,14 +49,12 @@ namespace DiscImageChef.DiscImages // Even if comment is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p Encoding shiftjis = Encoding.GetEncoding("shift_jis"); - nhdhdr = new Nhdr0Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(nhdhdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(nhdhdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - nhdhdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + nhdhdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); imageInfo.MediaType = MediaType.GENERIC_HDD; diff --git a/DiscImageChef.DiscImages/NHDr0/Write.cs b/DiscImageChef.DiscImages/NHDr0/Write.cs index d1412cdd5..19afa824d 100644 --- a/DiscImageChef.DiscImages/NHDr0/Write.cs +++ b/DiscImageChef.DiscImages/NHDr0/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -100,9 +100,8 @@ namespace DiscImageChef.DiscImages return false; } - writingStream - .Seek((long)((ulong)Marshal.SizeOf(typeof(Nhdr0Header)) + sectorAddress * imageInfo.SectorSize), - SeekOrigin.Begin); + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), + SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); ErrorMessage = ""; @@ -129,9 +128,8 @@ namespace DiscImageChef.DiscImages return false; } - writingStream - .Seek((long)((ulong)Marshal.SizeOf(typeof(Nhdr0Header)) + sectorAddress * imageInfo.SectorSize), - SeekOrigin.Begin); + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), + SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); ErrorMessage = ""; @@ -184,7 +182,7 @@ namespace DiscImageChef.DiscImages { szFileID = signature, szComment = new byte[0x100], - dwHeadSize = Marshal.SizeOf(typeof(Nhdr0Header)), + dwHeadSize = Marshal.SizeOf(), dwCylinder = (byte)imageInfo.Cylinders, wHead = (byte)imageInfo.Heads, wSect = (byte)imageInfo.SectorsPerTrack, @@ -200,11 +198,11 @@ namespace DiscImageChef.DiscImages commentBytes.Length >= 0x100 ? 0x100 : commentBytes.Length); } - byte[] hdr = new byte[Marshal.SizeOf(header)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/Parallels/Identify.cs b/DiscImageChef.DiscImages/Parallels/Identify.cs index befc2c594..6909073d3 100644 --- a/DiscImageChef.DiscImages/Parallels/Identify.cs +++ b/DiscImageChef.DiscImages/Parallels/Identify.cs @@ -32,8 +32,8 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -46,9 +46,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] pHdrB = new byte[Marshal.SizeOf(pHdr)]; - stream.Read(pHdrB, 0, Marshal.SizeOf(pHdr)); - pHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(pHdrB); + byte[] pHdrB = new byte[Marshal.SizeOf()]; + stream.Read(pHdrB, 0, Marshal.SizeOf()); + pHdr = Marshal.ByteArrayToStructureLittleEndian(pHdrB); return parallelsMagic.SequenceEqual(pHdr.magic) || parallelsExtMagic.SequenceEqual(pHdr.magic); } diff --git a/DiscImageChef.DiscImages/Parallels/Read.cs b/DiscImageChef.DiscImages/Parallels/Read.cs index 1ba454f2c..aea7b9898 100644 --- a/DiscImageChef.DiscImages/Parallels/Read.cs +++ b/DiscImageChef.DiscImages/Parallels/Read.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -51,9 +51,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] pHdrB = new byte[Marshal.SizeOf(pHdr)]; - stream.Read(pHdrB, 0, Marshal.SizeOf(pHdr)); - pHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(pHdrB); + byte[] pHdrB = new byte[Marshal.SizeOf()]; + stream.Read(pHdrB, 0, Marshal.SizeOf()); + pHdr = Marshal.ByteArrayToStructureLittleEndian(pHdrB); DicConsole.DebugWriteLine("Parallels plugin", "pHdr.magic = {0}", StringHandlers.CToString(pHdr.magic)); diff --git a/DiscImageChef.DiscImages/Parallels/Write.cs b/DiscImageChef.DiscImages/Parallels/Write.cs index 2f6325552..a549bdb13 100644 --- a/DiscImageChef.DiscImages/Parallels/Write.cs +++ b/DiscImageChef.DiscImages/Parallels/Write.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -77,8 +77,8 @@ namespace DiscImageChef.DiscImages uint batEntries = (uint)(sectors * sectorSize / DEFAULT_CLUSTER_SIZE); if(sectors * sectorSize % DEFAULT_CLUSTER_SIZE > 0) batEntries++; - uint headerSectors = (uint)Marshal.SizeOf(typeof(ParallelsHeader)) + batEntries * 4; - if((uint)Marshal.SizeOf(typeof(ParallelsHeader)) + batEntries % 4 > 0) headerSectors++; + uint headerSectors = (uint)Marshal.SizeOf() + batEntries * 4; + if((uint)Marshal.SizeOf() + batEntries % 4 > 0) headerSectors++; pHdr = new ParallelsHeader { @@ -227,11 +227,11 @@ namespace DiscImageChef.DiscImages } } - byte[] hdr = new byte[Marshal.SizeOf(typeof(ParallelsHeader))]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ParallelsHeader))); - Marshal.StructureToPtr(pHdr, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(pHdr, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/PartClone/Identify.cs b/DiscImageChef.DiscImages/PartClone/Identify.cs index cbc63d331..d09bae3bb 100644 --- a/DiscImageChef.DiscImages/PartClone/Identify.cs +++ b/DiscImageChef.DiscImages/PartClone/Identify.cs @@ -32,8 +32,8 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -46,9 +46,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] pHdrB = new byte[Marshal.SizeOf(pHdr)]; - stream.Read(pHdrB, 0, Marshal.SizeOf(pHdr)); - pHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(pHdrB); + byte[] pHdrB = new byte[Marshal.SizeOf()]; + stream.Read(pHdrB, 0, Marshal.SizeOf()); + pHdr = Marshal.ByteArrayToStructureLittleEndian(pHdrB); if(stream.Position + (long)pHdr.totalBlocks > stream.Length) return false; diff --git a/DiscImageChef.DiscImages/PartClone/Read.cs b/DiscImageChef.DiscImages/PartClone/Read.cs index cbdbd13ad..839c424a2 100644 --- a/DiscImageChef.DiscImages/PartClone/Read.cs +++ b/DiscImageChef.DiscImages/PartClone/Read.cs @@ -34,13 +34,13 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Extents; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -53,9 +53,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] pHdrB = new byte[Marshal.SizeOf(pHdr)]; - stream.Read(pHdrB, 0, Marshal.SizeOf(pHdr)); - pHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(pHdrB); + byte[] pHdrB = new byte[Marshal.SizeOf()]; + stream.Read(pHdrB, 0, Marshal.SizeOf()); + pHdr = Marshal.ByteArrayToStructureLittleEndian(pHdrB); DicConsole.DebugWriteLine("PartClone plugin", "pHdr.magic = {0}", StringHandlers.CToString(pHdr.magic)); DicConsole.DebugWriteLine("PartClone plugin", "pHdr.filesystem = {0}", diff --git a/DiscImageChef.DiscImages/Partimage/Identify.cs b/DiscImageChef.DiscImages/Partimage/Identify.cs index 5ac7f7f26..a9d6418ff 100644 --- a/DiscImageChef.DiscImages/Partimage/Identify.cs +++ b/DiscImageChef.DiscImages/Partimage/Identify.cs @@ -32,8 +32,8 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -46,9 +46,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] pHdrB = new byte[Marshal.SizeOf(cVolumeHeader)]; - stream.Read(pHdrB, 0, Marshal.SizeOf(cVolumeHeader)); - cVolumeHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(pHdrB); + byte[] pHdrB = new byte[Marshal.SizeOf()]; + stream.Read(pHdrB, 0, Marshal.SizeOf()); + cVolumeHeader = Marshal.ByteArrayToStructureLittleEndian(pHdrB); return partimageMagic.SequenceEqual(cVolumeHeader.magic); } diff --git a/DiscImageChef.DiscImages/Partimage/Read.cs b/DiscImageChef.DiscImages/Partimage/Read.cs index 1c97d6b27..9232e3c17 100644 --- a/DiscImageChef.DiscImages/Partimage/Read.cs +++ b/DiscImageChef.DiscImages/Partimage/Read.cs @@ -33,13 +33,13 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Extents; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -52,9 +52,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] hdrB = new byte[Marshal.SizeOf(cVolumeHeader)]; - stream.Read(hdrB, 0, Marshal.SizeOf(cVolumeHeader)); - cVolumeHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + byte[] hdrB = new byte[Marshal.SizeOf()]; + stream.Read(hdrB, 0, Marshal.SizeOf()); + cVolumeHeader = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("Partimage plugin", "CVolumeHeader.magic = {0}", StringHandlers.CToString(cVolumeHeader.magic)); @@ -69,9 +69,9 @@ namespace DiscImageChef.DiscImages if(cVolumeHeader.volumeNumber > 0) throw new FeatureSupportedButNotImplementedImageException("Support for multiple volumes not supported"); - hdrB = new byte[Marshal.SizeOf(cMainHeader)]; - stream.Read(hdrB, 0, Marshal.SizeOf(cMainHeader)); - cMainHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + hdrB = new byte[Marshal.SizeOf()]; + stream.Read(hdrB, 0, Marshal.SizeOf()); + cMainHeader = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szFileSystem = {0}", StringHandlers.CToString(cMainHeader.szFileSystem)); @@ -183,9 +183,9 @@ namespace DiscImageChef.DiscImages magic = StringHandlers.CToString(hdrB); if(!magic.Equals(MAGIC_BEGIN_LOCALHEADER)) throw new ImageNotSupportedException("Cannot find local header"); - hdrB = new byte[Marshal.SizeOf(typeof(CLocalHeader))]; - stream.Read(hdrB, 0, Marshal.SizeOf(typeof(CLocalHeader))); - CLocalHeader localHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + hdrB = new byte[Marshal.SizeOf()]; + stream.Read(hdrB, 0, Marshal.SizeOf()); + CLocalHeader localHeader = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwBlockSize = {0}", localHeader.qwBlockSize); DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwUsedBlocks = {0}", localHeader.qwUsedBlocks); @@ -226,7 +226,7 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("Partimage plugin", "dataOff = {0}", dataOff); // Seek to tail - stream.Seek(-(Marshal.SizeOf(typeof(CMainTail)) + MAGIC_BEGIN_TAIL.Length), SeekOrigin.End); + stream.Seek(-(Marshal.SizeOf() + MAGIC_BEGIN_TAIL.Length), SeekOrigin.End); hdrB = new byte[MAGIC_BEGIN_TAIL.Length]; stream.Read(hdrB, 0, MAGIC_BEGIN_TAIL.Length); @@ -281,7 +281,7 @@ namespace DiscImageChef.DiscImages imageInfo.Version = StringHandlers.CToString(cMainHeader.szVersion); imageInfo.Comments = StringHandlers.CToString(cMainHeader.szPartDescription); imageInfo.ImageSize = - (ulong)(stream.Length - (dataOff + Marshal.SizeOf(typeof(CMainTail)) + MAGIC_BEGIN_TAIL.Length)); + (ulong)(stream.Length - (dataOff + Marshal.SizeOf() + MAGIC_BEGIN_TAIL.Length)); imageStream = stream; return true; @@ -306,8 +306,7 @@ namespace DiscImageChef.DiscImages // How many stored bytes to skip (long)(blockOff * imageInfo.SectorSize) + // How many bytes of CRC blocks to skip - (long)(blockOff / (CHECK_FREQUENCY / imageInfo.SectorSize)) * - Marshal.SizeOf(typeof(CCheck)); + (long)(blockOff / (CHECK_FREQUENCY / imageInfo.SectorSize)) * Marshal.SizeOf(); sector = new byte[imageInfo.SectorSize]; imageStream.Seek(imageOff, SeekOrigin.Begin); diff --git a/DiscImageChef.DiscImages/QCOW/Write.cs b/DiscImageChef.DiscImages/QCOW/Write.cs index ea4ef78a1..0733c82e3 100644 --- a/DiscImageChef.DiscImages/QCOW/Write.cs +++ b/DiscImageChef.DiscImages/QCOW/Write.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -82,7 +82,7 @@ namespace DiscImageChef.DiscImages size = sectors * sectorSize, cluster_bits = 12, l2_bits = 9, - l1_table_offset = (ulong)Marshal.SizeOf(typeof(QCowHeader)) + l1_table_offset = (ulong)Marshal.SizeOf() }; int shift = qHdr.cluster_bits + qHdr.l2_bits; diff --git a/DiscImageChef.DiscImages/QCOW2/Identify.cs b/DiscImageChef.DiscImages/QCOW2/Identify.cs index a1839a779..e7f5d8a7e 100644 --- a/DiscImageChef.DiscImages/QCOW2/Identify.cs +++ b/DiscImageChef.DiscImages/QCOW2/Identify.cs @@ -31,9 +31,9 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -46,9 +46,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] qHdrB = new byte[Marshal.SizeOf(qHdr)]; - stream.Read(qHdrB, 0, Marshal.SizeOf(qHdr)); - qHdr = Helpers.Marshal.ByteArrayToStructureBigEndian(qHdrB); + byte[] qHdrB = new byte[Marshal.SizeOf()]; + stream.Read(qHdrB, 0, Marshal.SizeOf()); + qHdr = Marshal.ByteArrayToStructureBigEndian(qHdrB); DicConsole.DebugWriteLine("QCOW plugin", "qHdr.magic = 0x{0:X8}", qHdr.magic); DicConsole.DebugWriteLine("QCOW plugin", "qHdr.version = {0}", qHdr.version); diff --git a/DiscImageChef.DiscImages/QCOW2/Read.cs b/DiscImageChef.DiscImages/QCOW2/Read.cs index bb902eac9..ec8dfd75d 100644 --- a/DiscImageChef.DiscImages/QCOW2/Read.cs +++ b/DiscImageChef.DiscImages/QCOW2/Read.cs @@ -33,12 +33,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; using SharpCompress.Compressors; using SharpCompress.Compressors.Deflate; @@ -53,9 +53,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] qHdrB = new byte[Marshal.SizeOf(qHdr)]; - stream.Read(qHdrB, 0, Marshal.SizeOf(qHdr)); - qHdr = Helpers.Marshal.ByteArrayToStructureBigEndian(qHdrB); + byte[] qHdrB = new byte[Marshal.SizeOf()]; + stream.Read(qHdrB, 0, Marshal.SizeOf()); + qHdr = Marshal.ByteArrayToStructureBigEndian(qHdrB); DicConsole.DebugWriteLine("QCOW plugin", "qHdr.magic = 0x{0:X8}", qHdr.magic); DicConsole.DebugWriteLine("QCOW plugin", "qHdr.version = {0}", qHdr.version); diff --git a/DiscImageChef.DiscImages/QCOW2/Write.cs b/DiscImageChef.DiscImages/QCOW2/Write.cs index c1182059d..110b543d4 100644 --- a/DiscImageChef.DiscImages/QCOW2/Write.cs +++ b/DiscImageChef.DiscImages/QCOW2/Write.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -84,7 +84,7 @@ namespace DiscImageChef.DiscImages version = version3 ? QCOW_VERSION3 : QCOW_VERSION2, size = sectors * sectorSize, cluster_bits = 16, - header_length = (uint)Marshal.SizeOf(typeof(QCow2Header)) + header_length = (uint)Marshal.SizeOf() }; clusterSize = 1 << (int)qHdr.cluster_bits; diff --git a/DiscImageChef.DiscImages/QED/Write.cs b/DiscImageChef.DiscImages/QED/Write.cs index 07ca03e8f..b9804467f 100644 --- a/DiscImageChef.DiscImages/QED/Write.cs +++ b/DiscImageChef.DiscImages/QED/Write.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -245,11 +245,11 @@ namespace DiscImageChef.DiscImages return false; } - byte[] hdr = new byte[Marshal.SizeOf(typeof(QedHeader))]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(QedHeader))); - Marshal.StructureToPtr(qHdr, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(qHdr, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/RayDIM/Identify.cs b/DiscImageChef.DiscImages/RayDIM/Identify.cs index 63ecacf67..eac65d31c 100644 --- a/DiscImageChef.DiscImages/RayDIM/Identify.cs +++ b/DiscImageChef.DiscImages/RayDIM/Identify.cs @@ -31,10 +31,10 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -44,13 +44,13 @@ namespace DiscImageChef.DiscImages { Stream stream = imageFilter.GetDataForkStream(); - if(stream.Length < Marshal.SizeOf(typeof(RayHdr))) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] buffer = new byte[Marshal.SizeOf(typeof(RayHdr))]; + byte[] buffer = new byte[Marshal.SizeOf()]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, buffer.Length); - RayHdr header = Helpers.Marshal.ByteArrayToStructureLittleEndian(buffer); + RayHdr header = Marshal.ByteArrayToStructureLittleEndian(buffer); string signature = StringHandlers.CToString(header.signature); diff --git a/DiscImageChef.DiscImages/RayDIM/Read.cs b/DiscImageChef.DiscImages/RayDIM/Read.cs index 2598d948a..02a8046b8 100644 --- a/DiscImageChef.DiscImages/RayDIM/Read.cs +++ b/DiscImageChef.DiscImages/RayDIM/Read.cs @@ -32,11 +32,11 @@ using System; using System.IO; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -46,13 +46,13 @@ namespace DiscImageChef.DiscImages { Stream stream = imageFilter.GetDataForkStream(); - if(stream.Length < Marshal.SizeOf(typeof(RayHdr))) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] buffer = new byte[Marshal.SizeOf(typeof(RayHdr))]; + byte[] buffer = new byte[Marshal.SizeOf()]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, buffer.Length); - RayHdr header = Helpers.Marshal.ByteArrayToStructureLittleEndian(buffer); + RayHdr header = Marshal.ByteArrayToStructureLittleEndian(buffer); string signature = StringHandlers.CToString(header.signature); diff --git a/DiscImageChef.DiscImages/RayDIM/Write.cs b/DiscImageChef.DiscImages/RayDIM/Write.cs index 460503ec4..bc3d979d2 100644 --- a/DiscImageChef.DiscImages/RayDIM/Write.cs +++ b/DiscImageChef.DiscImages/RayDIM/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -116,7 +116,7 @@ namespace DiscImageChef.DiscImages return false; } - writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize), + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); @@ -144,7 +144,7 @@ namespace DiscImageChef.DiscImages return false; } - writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize), + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); @@ -202,11 +202,11 @@ namespace DiscImageChef.DiscImages }; header.signature[0x4A] = 0x00; - byte[] hdr = new byte[Marshal.SizeOf(header)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/RsIde/Read.cs b/DiscImageChef.DiscImages/RsIde/Read.cs index 9b53c6bc4..d3af4ef2a 100644 --- a/DiscImageChef.DiscImages/RsIde/Read.cs +++ b/DiscImageChef.DiscImages/RsIde/Read.cs @@ -33,12 +33,12 @@ using System; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Decoders.ATA; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -49,10 +49,10 @@ namespace DiscImageChef.DiscImages Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); - byte[] hdrB = new byte[Marshal.SizeOf(typeof(RsIdeHeader))]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - RsIdeHeader hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + RsIdeHeader hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); if(!hdr.magic.SequenceEqual(signature)) return false; diff --git a/DiscImageChef.DiscImages/RsIde/Write.cs b/DiscImageChef.DiscImages/RsIde/Write.cs index c444f623b..d7e87840d 100644 --- a/DiscImageChef.DiscImages/RsIde/Write.cs +++ b/DiscImageChef.DiscImages/RsIde/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Decoders.ATA; +using DiscImageChef.Helpers; using Schemas; using Version = DiscImageChef.CommonTypes.Interop.Version; @@ -120,9 +120,8 @@ namespace DiscImageChef.DiscImages return false; } - writingStream - .Seek((long)((ulong)Marshal.SizeOf(typeof(RsIdeHeader)) + sectorAddress * imageInfo.SectorSize), - SeekOrigin.Begin); + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), + SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); ErrorMessage = ""; @@ -149,9 +148,8 @@ namespace DiscImageChef.DiscImages return false; } - writingStream - .Seek((long)((ulong)Marshal.SizeOf(typeof(RsIdeHeader)) + sectorAddress * imageInfo.SectorSize), - SeekOrigin.Begin); + writingStream.Seek((long)((ulong)Marshal.SizeOf() + sectorAddress * imageInfo.SectorSize), + SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); ErrorMessage = ""; @@ -204,7 +202,7 @@ namespace DiscImageChef.DiscImages { magic = signature, identify = new byte[106], - dataOff = (ushort)Marshal.SizeOf(typeof(RsIdeHeader)), + dataOff = (ushort)Marshal.SizeOf(), revision = 1, reserved = new byte[11] }; @@ -246,11 +244,12 @@ namespace DiscImageChef.DiscImages if(string.IsNullOrEmpty(imageInfo.DriveSerialNumber)) imageInfo.DriveSerialNumber = $"{new Random().NextDouble():16X}"; - byte[] ataIdBytes = new byte[Marshal.SizeOf(ataId)]; - IntPtr ptr = Marshal.AllocHGlobal(512); - Marshal.StructureToPtr(ataId, ptr, true); - Marshal.Copy(ptr, ataIdBytes, 0, Marshal.SizeOf(ataId)); - Marshal.FreeHGlobal(ptr); + byte[] ataIdBytes = new byte[Marshal.SizeOf()]; + IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512); + System.Runtime.InteropServices.Marshal.StructureToPtr(ataId, ptr, true); + System.Runtime.InteropServices.Marshal.Copy(ptr, ataIdBytes, 0, + Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr); Array.Copy(ScrambleAtaString(imageInfo.DriveManufacturer + " " + imageInfo.DriveModel, 40), 0, ataIdBytes, 27 * 2, 40); @@ -260,11 +259,11 @@ namespace DiscImageChef.DiscImages } else Array.Copy(identify, 0, header.identify, 0, 106); - byte[] hdr = new byte[Marshal.SizeOf(header)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/SaveDskF/Write.cs b/DiscImageChef.DiscImages/SaveDskF/Write.cs index 66d36c822..139e519ed 100644 --- a/DiscImageChef.DiscImages/SaveDskF/Write.cs +++ b/DiscImageChef.DiscImages/SaveDskF/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -128,7 +128,7 @@ namespace DiscImageChef.DiscImages if(!string.IsNullOrWhiteSpace(imageInfo.Comments)) { byte[] commentsBytes = Encoding.GetEncoding("ibm437").GetBytes(imageInfo.Comments); - header.commentOffset = (ushort)Marshal.SizeOf(header); + header.commentOffset = (ushort)Marshal.SizeOf(); writingStream.Seek(header.commentOffset, SeekOrigin.Begin); writingStream.Write(commentsBytes, 0, commentsBytes.Length >= 512 - header.commentOffset @@ -136,11 +136,11 @@ namespace DiscImageChef.DiscImages : commentsBytes.Length); } - byte[] hdr = new byte[Marshal.SizeOf(header)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); @@ -156,11 +156,11 @@ namespace DiscImageChef.DiscImages } while(b >= 0); - hdr = new byte[Marshal.SizeOf(header)]; - hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header)); - Marshal.StructureToPtr(header, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + hdr = new byte[Marshal.SizeOf()]; + hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/SuperCardPro/Identify.cs b/DiscImageChef.DiscImages/SuperCardPro/Identify.cs index f9881d7a4..4e11869a3 100644 --- a/DiscImageChef.DiscImages/SuperCardPro/Identify.cs +++ b/DiscImageChef.DiscImages/SuperCardPro/Identify.cs @@ -32,8 +32,8 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -44,12 +44,12 @@ namespace DiscImageChef.DiscImages Header = new ScpHeader(); Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); - if(stream.Length < Marshal.SizeOf(Header)) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] hdr = new byte[Marshal.SizeOf(Header)]; - stream.Read(hdr, 0, Marshal.SizeOf(Header)); + byte[] hdr = new byte[Marshal.SizeOf()]; + stream.Read(hdr, 0, Marshal.SizeOf()); - Header = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdr); + Header = Marshal.ByteArrayToStructureLittleEndian(hdr); return scpSignature.SequenceEqual(Header.signature); } diff --git a/DiscImageChef.DiscImages/SuperCardPro/Read.cs b/DiscImageChef.DiscImages/SuperCardPro/Read.cs index 46e107f33..050a5e918 100644 --- a/DiscImageChef.DiscImages/SuperCardPro/Read.cs +++ b/DiscImageChef.DiscImages/SuperCardPro/Read.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -48,12 +48,12 @@ namespace DiscImageChef.DiscImages Header = new ScpHeader(); scpStream = imageFilter.GetDataForkStream(); scpStream.Seek(0, SeekOrigin.Begin); - if(scpStream.Length < Marshal.SizeOf(Header)) return false; + if(scpStream.Length < Marshal.SizeOf()) return false; - byte[] hdr = new byte[Marshal.SizeOf(Header)]; - scpStream.Read(hdr, 0, Marshal.SizeOf(Header)); + byte[] hdr = new byte[Marshal.SizeOf()]; + scpStream.Read(hdr, 0, Marshal.SizeOf()); - Header = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdr); + Header = Marshal.ByteArrayToStructureLittleEndian(hdr); DicConsole.DebugWriteLine("SuperCardPro plugin", "header.signature = \"{0}\"", StringHandlers.CToString(Header.signature)); @@ -101,10 +101,10 @@ namespace DiscImageChef.DiscImages for(byte r = 0; r < Header.revolutions; r++) { - byte[] rev = new byte[Marshal.SizeOf(typeof(TrackEntry))]; - scpStream.Read(rev, 0, Marshal.SizeOf(typeof(TrackEntry))); + byte[] rev = new byte[Marshal.SizeOf()]; + scpStream.Read(rev, 0, Marshal.SizeOf()); - trk.Entries[r] = Helpers.Marshal.ByteArrayToStructureLittleEndian(rev); + trk.Entries[r] = Marshal.ByteArrayToStructureLittleEndian(rev); // De-relative offsets trk.Entries[r].dataOffset += Header.offsets[t]; } @@ -125,14 +125,14 @@ namespace DiscImageChef.DiscImages if(footerMagic == FOOTER_SIGNATURE) { - scpStream.Seek(-Marshal.SizeOf(typeof(ScpFooter)), SeekOrigin.Current); + scpStream.Seek(-Marshal.SizeOf(), SeekOrigin.Current); DicConsole.DebugWriteLine("SuperCardPro plugin", "Found footer at {0}", scpStream.Position); - byte[] ftr = new byte[Marshal.SizeOf(typeof(ScpFooter))]; - scpStream.Read(ftr, 0, Marshal.SizeOf(typeof(ScpFooter))); + byte[] ftr = new byte[Marshal.SizeOf()]; + scpStream.Read(ftr, 0, Marshal.SizeOf()); - ScpFooter footer = Helpers.Marshal.ByteArrayToStructureLittleEndian(ftr); + ScpFooter footer = Marshal.ByteArrayToStructureLittleEndian(ftr); DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.manufacturerOffset = 0x{0:X8}", footer.manufacturerOffset); diff --git a/DiscImageChef.DiscImages/UDIF/Identify.cs b/DiscImageChef.DiscImages/UDIF/Identify.cs index 6edd57d78..08bdc720e 100644 --- a/DiscImageChef.DiscImages/UDIF/Identify.cs +++ b/DiscImageChef.DiscImages/UDIF/Identify.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -44,20 +44,20 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - stream.Seek(-Marshal.SizeOf(footer), SeekOrigin.End); - byte[] footerB = new byte[Marshal.SizeOf(footer)]; + stream.Seek(-Marshal.SizeOf(), SeekOrigin.End); + byte[] footerB = new byte[Marshal.SizeOf()]; - stream.Read(footerB, 0, Marshal.SizeOf(footer)); - footer = Helpers.Marshal.ByteArrayToStructureBigEndian(footerB); + stream.Read(footerB, 0, Marshal.SizeOf()); + footer = Marshal.ByteArrayToStructureBigEndian(footerB); if(footer.signature == UDIF_SIGNATURE) return true; // Old UDIF as created by DiskCopy 6.5 using "OBSOLETE" format. (DiskCopy 5 rumored format?) stream.Seek(0, SeekOrigin.Begin); - byte[] headerB = new byte[Marshal.SizeOf(footer)]; + byte[] headerB = new byte[Marshal.SizeOf()]; - stream.Read(headerB, 0, Marshal.SizeOf(footer)); - footer = Helpers.Marshal.ByteArrayToStructureBigEndian(headerB); + stream.Read(headerB, 0, Marshal.SizeOf()); + footer = Marshal.ByteArrayToStructureBigEndian(headerB); return footer.signature == UDIF_SIGNATURE; } diff --git a/DiscImageChef.DiscImages/UDIF/Read.cs b/DiscImageChef.DiscImages/UDIF/Read.cs index 46e216e7a..ba8ec9a0c 100644 --- a/DiscImageChef.DiscImages/UDIF/Read.cs +++ b/DiscImageChef.DiscImages/UDIF/Read.cs @@ -34,7 +34,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using Claunia.PropertyList; using Claunia.RsrcFork; using DiscImageChef.CommonTypes; @@ -43,6 +42,7 @@ using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Compression; using DiscImageChef.Console; +using DiscImageChef.Helpers; using Ionic.Zlib; using SharpCompress.Compressors.ADC; using SharpCompress.Compressors.BZip2; @@ -58,19 +58,19 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - stream.Seek(-Marshal.SizeOf(footer), SeekOrigin.End); - byte[] footerB = new byte[Marshal.SizeOf(footer)]; + stream.Seek(-Marshal.SizeOf(), SeekOrigin.End); + byte[] footerB = new byte[Marshal.SizeOf()]; - stream.Read(footerB, 0, Marshal.SizeOf(footer)); - footer = Helpers.Marshal.ByteArrayToStructureBigEndian(footerB); + stream.Read(footerB, 0, Marshal.SizeOf()); + footer = Marshal.ByteArrayToStructureBigEndian(footerB); if(footer.signature != UDIF_SIGNATURE) { stream.Seek(0, SeekOrigin.Begin); - footerB = new byte[Marshal.SizeOf(footer)]; + footerB = new byte[Marshal.SizeOf()]; - stream.Read(footerB, 0, Marshal.SizeOf(footer)); - footer = Helpers.Marshal.ByteArrayToStructureBigEndian(footerB); + stream.Read(footerB, 0, Marshal.SizeOf()); + footer = Marshal.ByteArrayToStructureBigEndian(footerB); if(footer.signature != UDIF_SIGNATURE) throw new Exception("Unable to find UDIF signature."); @@ -251,9 +251,9 @@ namespace DiscImageChef.DiscImages foreach(byte[] blkxBytes in blkxList) { BlockHeader bHdr = new BlockHeader(); - byte[] bHdrB = new byte[Marshal.SizeOf(bHdr)]; - Array.Copy(blkxBytes, 0, bHdrB, 0, Marshal.SizeOf(bHdr)); - bHdr = Helpers.Marshal.ByteArrayToStructureBigEndian(bHdrB); + byte[] bHdrB = new byte[Marshal.SizeOf()]; + Array.Copy(blkxBytes, 0, bHdrB, 0, Marshal.SizeOf()); + bHdr = Marshal.ByteArrayToStructureBigEndian(bHdrB); DicConsole.DebugWriteLine("UDIF plugin", "bHdr.signature = 0x{0:X8}", bHdr.signature); DicConsole.DebugWriteLine("UDIF plugin", "bHdr.version = {0}", bHdr.version); @@ -280,10 +280,10 @@ namespace DiscImageChef.DiscImages for(int i = 0; i < bHdr.chunks; i++) { BlockChunk bChnk = new BlockChunk(); - byte[] bChnkB = new byte[Marshal.SizeOf(bChnk)]; - Array.Copy(blkxBytes, Marshal.SizeOf(bHdr) + Marshal.SizeOf(bChnk) * i, bChnkB, 0, - Marshal.SizeOf(bChnk)); - bChnk = Helpers.Marshal.ByteArrayToStructureBigEndian(bChnkB); + byte[] bChnkB = new byte[Marshal.SizeOf()]; + Array.Copy(blkxBytes, Marshal.SizeOf() + Marshal.SizeOf() * i, bChnkB, + 0, Marshal.SizeOf()); + bChnk = Marshal.ByteArrayToStructureBigEndian(bChnkB); DicConsole.DebugWriteLine("UDIF plugin", "bHdr.chunk[{0}].type = 0x{1:X8}", i, bChnk.type); DicConsole.DebugWriteLine("UDIF plugin", "bHdr.chunk[{0}].comment = {1}", i, bChnk.comment); diff --git a/DiscImageChef.DiscImages/UkvFdi/Identify.cs b/DiscImageChef.DiscImages/UkvFdi/Identify.cs index d126b3223..9dd2c786b 100644 --- a/DiscImageChef.DiscImages/UkvFdi/Identify.cs +++ b/DiscImageChef.DiscImages/UkvFdi/Identify.cs @@ -32,8 +32,8 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -46,11 +46,11 @@ namespace DiscImageChef.DiscImages FdiHeader hdr = new FdiHeader(); - if(stream.Length < Marshal.SizeOf(hdr)) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] hdrB = new byte[Marshal.SizeOf(hdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); return hdr.magic.SequenceEqual(signature); } diff --git a/DiscImageChef.DiscImages/UkvFdi/Read.cs b/DiscImageChef.DiscImages/UkvFdi/Read.cs index 2bec5b4ca..0744ab7c0 100644 --- a/DiscImageChef.DiscImages/UkvFdi/Read.cs +++ b/DiscImageChef.DiscImages/UkvFdi/Read.cs @@ -32,11 +32,11 @@ using System; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -49,12 +49,12 @@ namespace DiscImageChef.DiscImages FdiHeader hdr = new FdiHeader(); - if(stream.Length < Marshal.SizeOf(hdr)) return false; + if(stream.Length < Marshal.SizeOf()) return false; - byte[] hdrB = new byte[Marshal.SizeOf(hdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.addInfoLen = {0}", hdr.addInfoLen); DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.cylinders = {0}", hdr.cylinders); diff --git a/DiscImageChef.DiscImages/VDI/Identify.cs b/DiscImageChef.DiscImages/VDI/Identify.cs index 151527a61..fc63eb3cd 100644 --- a/DiscImageChef.DiscImages/VDI/Identify.cs +++ b/DiscImageChef.DiscImages/VDI/Identify.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -45,9 +45,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] vHdrB = new byte[Marshal.SizeOf(vHdr)]; - stream.Read(vHdrB, 0, Marshal.SizeOf(vHdr)); - vHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vHdrB); + byte[] vHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vHdrB, 0, Marshal.SizeOf()); + vHdr = Marshal.ByteArrayToStructureLittleEndian(vHdrB); return vHdr.magic == VDI_MAGIC; } diff --git a/DiscImageChef.DiscImages/VDI/Read.cs b/DiscImageChef.DiscImages/VDI/Read.cs index cf081d089..5090e9e2c 100644 --- a/DiscImageChef.DiscImages/VDI/Read.cs +++ b/DiscImageChef.DiscImages/VDI/Read.cs @@ -33,12 +33,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -51,9 +51,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] vHdrB = new byte[Marshal.SizeOf(vHdr)]; - stream.Read(vHdrB, 0, Marshal.SizeOf(vHdr)); - vHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vHdrB); + byte[] vHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vHdrB, 0, Marshal.SizeOf()); + vHdr = Marshal.ByteArrayToStructureLittleEndian(vHdrB); DicConsole.DebugWriteLine("VirtualBox plugin", "vHdr.creator = {0}", vHdr.creator); DicConsole.DebugWriteLine("VirtualBox plugin", "vHdr.magic = {0}", vHdr.magic); diff --git a/DiscImageChef.DiscImages/VDI/Write.cs b/DiscImageChef.DiscImages/VDI/Write.cs index 6aad4efba..567d64e48 100644 --- a/DiscImageChef.DiscImages/VDI/Write.cs +++ b/DiscImageChef.DiscImages/VDI/Write.cs @@ -34,10 +34,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -88,7 +88,7 @@ namespace DiscImageChef.DiscImages magic = VDI_MAGIC, majorVersion = 1, minorVersion = 1, - headerSize = Marshal.SizeOf(typeof(VdiHeader)) - 72, + headerSize = Marshal.SizeOf() - 72, imageType = VdiImageType.Normal, offsetBlocks = sectorSize, offsetData = currentWritingPosition, @@ -241,11 +241,11 @@ namespace DiscImageChef.DiscImages } } - byte[] hdr = new byte[Marshal.SizeOf(typeof(VdiHeader))]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VdiHeader))); - Marshal.StructureToPtr(vHdr, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(vHdr, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.DiscImages/VHDX/Identify.cs b/DiscImageChef.DiscImages/VHDX/Identify.cs index 3db78a6d9..5ee6dcb7b 100644 --- a/DiscImageChef.DiscImages/VHDX/Identify.cs +++ b/DiscImageChef.DiscImages/VHDX/Identify.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System.IO; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -45,9 +45,9 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] vhdxIdB = new byte[Marshal.SizeOf(vhdxId)]; - stream.Read(vhdxIdB, 0, Marshal.SizeOf(vhdxId)); - vhdxId = Helpers.Marshal.ByteArrayToStructureLittleEndian(vhdxIdB); + byte[] vhdxIdB = new byte[Marshal.SizeOf()]; + stream.Read(vhdxIdB, 0, Marshal.SizeOf()); + vhdxId = Marshal.ByteArrayToStructureLittleEndian(vhdxIdB); return vhdxId.signature == VHDX_SIGNATURE; } diff --git a/DiscImageChef.DiscImages/VHDX/Read.cs b/DiscImageChef.DiscImages/VHDX/Read.cs index d95ee5669..0613bfcb5 100644 --- a/DiscImageChef.DiscImages/VHDX/Read.cs +++ b/DiscImageChef.DiscImages/VHDX/Read.cs @@ -33,13 +33,13 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -52,40 +52,40 @@ namespace DiscImageChef.DiscImages if(stream.Length < 512) return false; - byte[] vhdxIdB = new byte[Marshal.SizeOf(vhdxId)]; - stream.Read(vhdxIdB, 0, Marshal.SizeOf(vhdxId)); - vhdxId = Helpers.Marshal.ByteArrayToStructureLittleEndian(vhdxIdB); + byte[] vhdxIdB = new byte[Marshal.SizeOf()]; + stream.Read(vhdxIdB, 0, Marshal.SizeOf()); + vhdxId = Marshal.ByteArrayToStructureLittleEndian(vhdxIdB); if(vhdxId.signature != VHDX_SIGNATURE) return false; imageInfo.Application = Encoding.Unicode.GetString(vhdxId.creator); stream.Seek(64 * 1024, SeekOrigin.Begin); - byte[] vHdrB = new byte[Marshal.SizeOf(vHdr)]; - stream.Read(vHdrB, 0, Marshal.SizeOf(vHdr)); - vHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vHdrB); + byte[] vHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vHdrB, 0, Marshal.SizeOf()); + vHdr = Marshal.ByteArrayToStructureLittleEndian(vHdrB); if(vHdr.Signature != VHDX_HEADER_SIG) { stream.Seek(128 * 1024, SeekOrigin.Begin); - vHdrB = new byte[Marshal.SizeOf(vHdr)]; - stream.Read(vHdrB, 0, Marshal.SizeOf(vHdr)); - vHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vHdrB); + vHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vHdrB, 0, Marshal.SizeOf()); + vHdr = Marshal.ByteArrayToStructureLittleEndian(vHdrB); if(vHdr.Signature != VHDX_HEADER_SIG) throw new ImageNotSupportedException("VHDX header not found"); } stream.Seek(192 * 1024, SeekOrigin.Begin); - byte[] vRegTableB = new byte[Marshal.SizeOf(vRegHdr)]; - stream.Read(vRegTableB, 0, Marshal.SizeOf(vRegHdr)); - vRegHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vRegTableB); + byte[] vRegTableB = new byte[Marshal.SizeOf()]; + stream.Read(vRegTableB, 0, Marshal.SizeOf()); + vRegHdr = Marshal.ByteArrayToStructureLittleEndian(vRegTableB); if(vRegHdr.signature != VHDX_REGION_SIG) { stream.Seek(256 * 1024, SeekOrigin.Begin); - vRegTableB = new byte[Marshal.SizeOf(vRegHdr)]; - stream.Read(vRegTableB, 0, Marshal.SizeOf(vRegHdr)); - vRegHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vRegTableB); + vRegTableB = new byte[Marshal.SizeOf()]; + stream.Read(vRegTableB, 0, Marshal.SizeOf()); + vRegHdr = Marshal.ByteArrayToStructureLittleEndian(vRegTableB); if(vRegHdr.signature != VHDX_REGION_SIG) throw new ImageNotSupportedException("VHDX region table not found"); @@ -94,9 +94,9 @@ namespace DiscImageChef.DiscImages vRegs = new VhdxRegionTableEntry[vRegHdr.entries]; for(int i = 0; i < vRegs.Length; i++) { - byte[] vRegB = new byte[Marshal.SizeOf(vRegs[i])]; - stream.Read(vRegB, 0, Marshal.SizeOf(vRegs[i])); - vRegs[i] = Helpers.Marshal.ByteArrayToStructureLittleEndian(vRegB); + byte[] vRegB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(vRegs[i])]; + stream.Read(vRegB, 0, System.Runtime.InteropServices.Marshal.SizeOf(vRegs[i])); + vRegs[i] = Marshal.ByteArrayToStructureLittleEndian(vRegB); if(vRegs[i].guid == batGuid) batOffset = (long)vRegs[i].offset; @@ -114,16 +114,16 @@ namespace DiscImageChef.DiscImages uint fileParamsOff = 0, vdSizeOff = 0, p83Off = 0, logOff = 0, physOff = 0, parentOff = 0; stream.Seek(metadataOffset, SeekOrigin.Begin); - byte[] metTableB = new byte[Marshal.SizeOf(vMetHdr)]; - stream.Read(metTableB, 0, Marshal.SizeOf(vMetHdr)); - vMetHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(metTableB); + byte[] metTableB = new byte[Marshal.SizeOf()]; + stream.Read(metTableB, 0, Marshal.SizeOf()); + vMetHdr = Marshal.ByteArrayToStructureLittleEndian(metTableB); vMets = new VhdxMetadataTableEntry[vMetHdr.entries]; for(int i = 0; i < vMets.Length; i++) { - byte[] vMetB = new byte[Marshal.SizeOf(vMets[i])]; - stream.Read(vMetB, 0, Marshal.SizeOf(vMets[i])); - vMets[i] = Helpers.Marshal.ByteArrayToStructureLittleEndian(vMetB); + byte[] vMetB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(vMets[i])]; + stream.Read(vMetB, 0, System.Runtime.InteropServices.Marshal.SizeOf(vMets[i])); + vMets[i] = Marshal.ByteArrayToStructureLittleEndian(vMetB); if(vMets[i].itemId == fileParametersGuid) fileParamsOff = vMets[i].offset; @@ -194,9 +194,9 @@ namespace DiscImageChef.DiscImages if(parentOff != 0 && (vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT) { stream.Seek(parentOff + metadataOffset, SeekOrigin.Begin); - byte[] vParHdrB = new byte[Marshal.SizeOf(vMetHdr)]; - stream.Read(vParHdrB, 0, Marshal.SizeOf(vMetHdr)); - vParHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vParHdrB); + byte[] vParHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vParHdrB, 0, Marshal.SizeOf()); + vParHdr = Marshal.ByteArrayToStructureLittleEndian(vParHdrB); if(vParHdr.locatorType != parentTypeVhdxGuid) throw new @@ -205,9 +205,9 @@ namespace DiscImageChef.DiscImages vPars = new VhdxParentLocatorEntry[vParHdr.keyValueCount]; for(int i = 0; i < vPars.Length; i++) { - byte[] vParB = new byte[Marshal.SizeOf(vPars[i])]; - stream.Read(vParB, 0, Marshal.SizeOf(vPars[i])); - vPars[i] = Helpers.Marshal.ByteArrayToStructureLittleEndian(vParB); + byte[] vParB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(vPars[i])]; + stream.Read(vParB, 0, System.Runtime.InteropServices.Marshal.SizeOf(vPars[i])); + vPars[i] = Marshal.ByteArrayToStructureLittleEndian(vParB); } } else if((vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT) diff --git a/DiscImageChef.DiscImages/VMware/Identify.cs b/DiscImageChef.DiscImages/VMware/Identify.cs index 9df22627b..14928a820 100644 --- a/DiscImageChef.DiscImages/VMware/Identify.cs +++ b/DiscImageChef.DiscImages/VMware/Identify.cs @@ -32,8 +32,8 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -45,25 +45,25 @@ namespace DiscImageChef.DiscImages byte[] ddfMagic = new byte[0x15]; - if(stream.Length > Marshal.SizeOf(vmEHdr)) + if(stream.Length > Marshal.SizeOf()) { stream.Seek(0, SeekOrigin.Begin); - byte[] vmEHdrB = new byte[Marshal.SizeOf(vmEHdr)]; - stream.Read(vmEHdrB, 0, Marshal.SizeOf(vmEHdr)); - vmEHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vmEHdrB); + byte[] vmEHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vmEHdrB, 0, Marshal.SizeOf()); + vmEHdr = Marshal.ByteArrayToStructureLittleEndian(vmEHdrB); stream.Seek(0, SeekOrigin.Begin); stream.Read(ddfMagic, 0, 0x15); vmCHdr = new VMwareCowHeader(); - if(stream.Length <= Marshal.SizeOf(vmCHdr)) + if(stream.Length <= Marshal.SizeOf()) return ddfMagicBytes.SequenceEqual(ddfMagic) || vmEHdr.magic == VMWARE_EXTENT_MAGIC || vmCHdr.magic == VMWARE_COW_MAGIC; stream.Seek(0, SeekOrigin.Begin); - byte[] vmCHdrB = new byte[Marshal.SizeOf(vmCHdr)]; - stream.Read(vmCHdrB, 0, Marshal.SizeOf(vmCHdr)); - vmCHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vmCHdrB); + byte[] vmCHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vmCHdrB, 0, Marshal.SizeOf()); + vmCHdr = Marshal.ByteArrayToStructureLittleEndian(vmCHdrB); return ddfMagicBytes.SequenceEqual(ddfMagic) || vmEHdr.magic == VMWARE_EXTENT_MAGIC || vmCHdr.magic == VMWARE_COW_MAGIC; diff --git a/DiscImageChef.DiscImages/VMware/Read.cs b/DiscImageChef.DiscImages/VMware/Read.cs index ec18aa128..cbf5479e9 100644 --- a/DiscImageChef.DiscImages/VMware/Read.cs +++ b/DiscImageChef.DiscImages/VMware/Read.cs @@ -34,13 +34,13 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -54,20 +54,20 @@ namespace DiscImageChef.DiscImages vmCHdr = new VMwareCowHeader(); bool embedded = false; - if(stream.Length > Marshal.SizeOf(vmEHdr)) + if(stream.Length > Marshal.SizeOf()) { stream.Seek(0, SeekOrigin.Begin); - byte[] vmEHdrB = new byte[Marshal.SizeOf(vmEHdr)]; - stream.Read(vmEHdrB, 0, Marshal.SizeOf(vmEHdr)); - vmEHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vmEHdrB); + byte[] vmEHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vmEHdrB, 0, Marshal.SizeOf()); + vmEHdr = Marshal.ByteArrayToStructureLittleEndian(vmEHdrB); } - if(stream.Length > Marshal.SizeOf(vmCHdr)) + if(stream.Length > Marshal.SizeOf()) { stream.Seek(0, SeekOrigin.Begin); - byte[] vmCHdrB = new byte[Marshal.SizeOf(vmCHdr)]; - stream.Read(vmCHdrB, 0, Marshal.SizeOf(vmCHdr)); - vmCHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vmCHdrB); + byte[] vmCHdrB = new byte[Marshal.SizeOf()]; + stream.Read(vmCHdrB, 0, Marshal.SizeOf()); + vmCHdr = Marshal.ByteArrayToStructureLittleEndian(vmCHdrB); } MemoryStream ddfStream = new MemoryStream(); @@ -130,13 +130,13 @@ namespace DiscImageChef.DiscImages IFilter extentFilter = new FiltersList().GetFilter(curPath); Stream extentStream = extentFilter.GetDataForkStream(); - if(stream.Length > Marshal.SizeOf(vmCHdr)) + if(stream.Length > Marshal.SizeOf()) { VMwareCowHeader extHdrCow = new VMwareCowHeader(); extentStream.Seek(0, SeekOrigin.Begin); - byte[] vmCHdrB = new byte[Marshal.SizeOf(extHdrCow)]; - extentStream.Read(vmCHdrB, 0, Marshal.SizeOf(extHdrCow)); - extHdrCow = Helpers.Marshal.ByteArrayToStructureLittleEndian(vmCHdrB); + byte[] vmCHdrB = new byte[Marshal.SizeOf()]; + extentStream.Read(vmCHdrB, 0, Marshal.SizeOf()); + extHdrCow = Marshal.ByteArrayToStructureLittleEndian(vmCHdrB); if(extHdrCow.magic != VMWARE_COW_MAGIC) break; @@ -299,10 +299,9 @@ namespace DiscImageChef.DiscImages if(extentStream.Length < SECTOR_SIZE) throw new Exception($"Extent {extent.Filename} is too small."); - VMwareExtentHeader extentHdr = new VMwareExtentHeader(); - byte[] extentHdrB = new byte[Marshal.SizeOf(extentHdr)]; - extentStream.Read(extentHdrB, 0, Marshal.SizeOf(extentHdr)); - extentHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(extentHdrB); + byte[] extentHdrB = new byte[Marshal.SizeOf()]; + extentStream.Read(extentHdrB, 0, Marshal.SizeOf()); + VMwareExtentHeader extentHdr = Marshal.ByteArrayToStructureLittleEndian(extentHdrB); if(extentHdr.magic != VMWARE_EXTENT_MAGIC) throw new Exception($"{extent.Filter} is not an VMware extent."); diff --git a/DiscImageChef.DiscImages/VMware/Structs.cs b/DiscImageChef.DiscImages/VMware/Structs.cs index 2f69bf346..73f8d3b4d 100644 --- a/DiscImageChef.DiscImages/VMware/Structs.cs +++ b/DiscImageChef.DiscImages/VMware/Structs.cs @@ -40,23 +40,24 @@ namespace DiscImageChef.DiscImages [StructLayout(LayoutKind.Sequential, Pack = 1)] struct VMwareExtentHeader { - public uint magic; - public uint version; - public uint flags; - public ulong capacity; - public ulong grainSize; - public ulong descriptorOffset; - public ulong descriptorSize; - public uint GTEsPerGT; - public ulong rgdOffset; - public ulong gdOffset; - public ulong overhead; - [MarshalAs(UnmanagedType.U1)] public bool uncleanShutdown; - public byte singleEndLineChar; - public byte nonEndLineChar; - public byte doubleEndLineChar1; - public byte doubleEndLineChar2; - public ushort compression; + public uint magic; + public uint version; + public uint flags; + public ulong capacity; + public ulong grainSize; + public ulong descriptorOffset; + public ulong descriptorSize; + public uint GTEsPerGT; + public ulong rgdOffset; + public ulong gdOffset; + public ulong overhead; + [MarshalAs(UnmanagedType.U1)] + public bool uncleanShutdown; + public byte singleEndLineChar; + public byte nonEndLineChar; + public byte doubleEndLineChar1; + public byte doubleEndLineChar2; + public ushort compression; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 433)] public byte[] padding; } @@ -87,7 +88,8 @@ namespace DiscImageChef.DiscImages public uint savedGeneration; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] reserved; - [MarshalAs(UnmanagedType.U1)] public bool uncleanShutdown; + [MarshalAs(UnmanagedType.U1)] + public bool uncleanShutdown; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 396)] public byte[] padding; } diff --git a/DiscImageChef.DiscImages/Virtual98/Identify.cs b/DiscImageChef.DiscImages/Virtual98/Identify.cs index d28010aec..e6c39f0b1 100644 --- a/DiscImageChef.DiscImages/Virtual98/Identify.cs +++ b/DiscImageChef.DiscImages/Virtual98/Identify.cs @@ -32,10 +32,10 @@ using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -48,14 +48,12 @@ namespace DiscImageChef.DiscImages // Even if comment is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p Encoding shiftjis = Encoding.GetEncoding("shift_jis"); - v98Hdr = new Virtual98Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(v98Hdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(v98Hdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - v98Hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + v98Hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); if(!v98Hdr.signature.SequenceEqual(signature)) return false; diff --git a/DiscImageChef.DiscImages/Virtual98/Read.cs b/DiscImageChef.DiscImages/Virtual98/Read.cs index 17e5c58c0..3d3758244 100644 --- a/DiscImageChef.DiscImages/Virtual98/Read.cs +++ b/DiscImageChef.DiscImages/Virtual98/Read.cs @@ -32,11 +32,11 @@ using System; using System.IO; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; namespace DiscImageChef.DiscImages { @@ -49,14 +49,12 @@ namespace DiscImageChef.DiscImages // Even if comment is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p Encoding shiftjis = Encoding.GetEncoding("shift_jis"); - v98Hdr = new Virtual98Header(); + if(stream.Length < Marshal.SizeOf()) return false; - if(stream.Length < Marshal.SizeOf(v98Hdr)) return false; - - byte[] hdrB = new byte[Marshal.SizeOf(v98Hdr)]; + byte[] hdrB = new byte[Marshal.SizeOf()]; stream.Read(hdrB, 0, hdrB.Length); - v98Hdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(hdrB); + v98Hdr = Marshal.ByteArrayToStructureLittleEndian(hdrB); imageInfo.MediaType = MediaType.GENERIC_HDD; diff --git a/DiscImageChef.DiscImages/Virtual98/Write.cs b/DiscImageChef.DiscImages/Virtual98/Write.cs index 3b1c5daf9..ee553222b 100644 --- a/DiscImageChef.DiscImages/Virtual98/Write.cs +++ b/DiscImageChef.DiscImages/Virtual98/Write.cs @@ -34,11 +34,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.DiscImages @@ -202,11 +202,11 @@ namespace DiscImageChef.DiscImages Array.Copy(commentsBytes, 0, v98Hdr.comment, 0, commentsBytes.Length >= 128 ? 128 : commentsBytes.Length); - byte[] hdr = new byte[Marshal.SizeOf(v98Hdr)]; - IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(v98Hdr)); - Marshal.StructureToPtr(v98Hdr, hdrPtr, true); - Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); - Marshal.FreeHGlobal(hdrPtr); + byte[] hdr = new byte[Marshal.SizeOf()]; + IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf()); + System.Runtime.InteropServices.Marshal.StructureToPtr(v98Hdr, hdrPtr, true); + System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); + System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); diff --git a/DiscImageChef.Filesystems/AODOS.cs b/DiscImageChef.Filesystems/AODOS.cs index 402a969a0..b7b6e53a3 100644 --- a/DiscImageChef.Filesystems/AODOS.cs +++ b/DiscImageChef.Filesystems/AODOS.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -63,7 +64,7 @@ namespace DiscImageChef.Filesystems if(imagePlugin.Info.Sectors != 800 && imagePlugin.Info.Sectors != 1600) return false; byte[] sector = imagePlugin.ReadSector(0); - AODOS_BootBlock bb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + AODOS_BootBlock bb = Marshal.ByteArrayToStructureLittleEndian(sector); return bb.identifier.SequenceEqual(AODOSIdentifier); } @@ -73,7 +74,7 @@ namespace DiscImageChef.Filesystems { Encoding = Encoding.GetEncoding("koi8-r"); byte[] sector = imagePlugin.ReadSector(0); - AODOS_BootBlock bb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + AODOS_BootBlock bb = Marshal.ByteArrayToStructureLittleEndian(sector); StringBuilder sbInformation = new StringBuilder(); diff --git a/DiscImageChef.Filesystems/APFS.cs b/DiscImageChef.Filesystems/APFS.cs index 9acefcb8e..23351bee7 100644 --- a/DiscImageChef.Filesystems/APFS.cs +++ b/DiscImageChef.Filesystems/APFS.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -57,10 +58,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSector(partition.Start); ApfsContainerSuperBlock nxSb; - try - { - nxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - } + try { nxSb = Marshal.ByteArrayToStructureLittleEndian(sector); } catch { return false; } return nxSb.magic == APFS_CONTAINER_MAGIC; @@ -79,10 +77,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSector(partition.Start); ApfsContainerSuperBlock nxSb; - try - { - nxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - } + try { nxSb = Marshal.ByteArrayToStructureLittleEndian(sector); } catch { return; } if(nxSb.magic != APFS_CONTAINER_MAGIC) return; diff --git a/DiscImageChef.Filesystems/Acorn.cs b/DiscImageChef.Filesystems/Acorn.cs index 6b26b99dc..28ed885b6 100644 --- a/DiscImageChef.Filesystems/Acorn.cs +++ b/DiscImageChef.Filesystems/Acorn.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -93,18 +94,18 @@ namespace DiscImageChef.Filesystems if(imagePlugin.Info.SectorSize < 256) return false; - byte[] sector; + byte[] sector; // ADFS-S, ADFS-M, ADFS-L, ADFS-D without partitions if(partition.Start == 0) { sector = imagePlugin.ReadSector(0); - byte oldChk0 = AcornMapChecksum(sector, 255); - OldMapSector0 oldMap0 = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + byte oldChk0 = AcornMapChecksum(sector, 255); + OldMapSector0 oldMap0 = Marshal.ByteArrayToStructureLittleEndian(sector); sector = imagePlugin.ReadSector(1); - byte oldChk1 = AcornMapChecksum(sector, 255); - OldMapSector1 oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + byte oldChk1 = AcornMapChecksum(sector, 255); + OldMapSector1 oldMap1 = Marshal.ByteArrayToStructureLittleEndian(sector); DicConsole.DebugWriteLine("ADFS Plugin", "oldMap0.checksum = {0}", oldMap0.checksum); DicConsole.DebugWriteLine("ADFS Plugin", "oldChk0 = {0}", oldChk0); @@ -116,7 +117,7 @@ namespace DiscImageChef.Filesystems byte[] tmp = new byte[256]; Array.Copy(sector, 256, tmp, 0, 256); oldChk1 = AcornMapChecksum(tmp, 255); - oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian(tmp); + oldMap1 = Marshal.ByteArrayToStructureLittleEndian(tmp); } DicConsole.DebugWriteLine("ADFS Plugin", "oldMap1.checksum = {0}", oldMap1.checksum); @@ -138,8 +139,8 @@ namespace DiscImageChef.Filesystems sector = tmp; } - OldDirectory oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - byte dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1); + OldDirectory oldRoot = Marshal.ByteArrayToStructureLittleEndian(sector); + byte dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1); DicConsole.DebugWriteLine("ADFS Plugin", "oldRoot.header.magic at 0x200 = {0}", oldRoot.header.magic); @@ -165,7 +166,7 @@ namespace DiscImageChef.Filesystems sector = tmp; } - oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + oldRoot = Marshal.ByteArrayToStructureLittleEndian(sector); dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1); DicConsole.DebugWriteLine("ADFS Plugin", "oldRoot.header.magic at 0x400 = {0}", @@ -203,12 +204,12 @@ namespace DiscImageChef.Filesystems if(newChk == sector[0] && newChk != 0) { - NewMap nmap = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + NewMap nmap = Marshal.ByteArrayToStructureLittleEndian(sector); drSb = nmap.discRecord; } else if(bootChk == bootSector[0x1FF]) { - BootBlock bBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian(bootSector); + BootBlock bBlock = Marshal.ByteArrayToStructureLittleEndian(bootSector); drSb = bBlock.discRecord; } else return false; @@ -246,21 +247,21 @@ namespace DiscImageChef.Filesystems XmlFsType = new FileSystemType(); information = ""; - ulong sbSector; - byte[] sector; - uint sectorsToRead; - ulong bytes; + ulong sbSector; + byte[] sector; + uint sectorsToRead; + ulong bytes; // ADFS-S, ADFS-M, ADFS-L, ADFS-D without partitions if(partition.Start == 0) { sector = imagePlugin.ReadSector(0); - byte oldChk0 = AcornMapChecksum(sector, 255); - OldMapSector0 oldMap0 = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + byte oldChk0 = AcornMapChecksum(sector, 255); + OldMapSector0 oldMap0 = Marshal.ByteArrayToStructureLittleEndian(sector); sector = imagePlugin.ReadSector(1); - byte oldChk1 = AcornMapChecksum(sector, 255); - OldMapSector1 oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + byte oldChk1 = AcornMapChecksum(sector, 255); + OldMapSector1 oldMap1 = Marshal.ByteArrayToStructureLittleEndian(sector); // According to documentation map1 MUST start on sector 1. On ADFS-D it starts at 0x100, not on sector 1 (0x400) if(oldMap0.checksum == oldChk0 && oldMap1.checksum != oldChk1 && sector.Length >= 512) @@ -269,7 +270,7 @@ namespace DiscImageChef.Filesystems byte[] tmp = new byte[256]; Array.Copy(sector, 256, tmp, 0, 256); oldChk1 = AcornMapChecksum(tmp, 255); - oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian(tmp); + oldMap1 = Marshal.ByteArrayToStructureLittleEndian(tmp); } if(oldMap0.checksum == oldChk0 && oldMap1.checksum == oldChk1 && oldMap0.checksum != 0 && @@ -306,7 +307,7 @@ namespace DiscImageChef.Filesystems sector = tmp; } - OldDirectory oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + OldDirectory oldRoot = Marshal.ByteArrayToStructureLittleEndian(sector); if(oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC) namebytes = oldRoot.tail.name; @@ -327,7 +328,7 @@ namespace DiscImageChef.Filesystems sector = tmp; } - oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + oldRoot = Marshal.ByteArrayToStructureLittleEndian(sector); if(oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC) namebytes = oldRoot.tail.name; @@ -343,7 +344,7 @@ namespace DiscImageChef.Filesystems sector = tmp; } - NewDirectory newRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + NewDirectory newRoot = Marshal.ByteArrayToStructureLittleEndian(sector); if(newRoot.header.magic == NEW_DIR_MAGIC && newRoot.tail.magic == NEW_DIR_MAGIC) namebytes = newRoot.tail.title; } @@ -392,12 +393,12 @@ namespace DiscImageChef.Filesystems if(newChk == sector[0] && newChk != 0) { - NewMap nmap = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + NewMap nmap = Marshal.ByteArrayToStructureLittleEndian(sector); drSb = nmap.discRecord; } else if(bootChk == bootSector[0x1FF]) { - BootBlock bBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + BootBlock bBlock = Marshal.ByteArrayToStructureLittleEndian(sector); drSb = bBlock.discRecord; } else return; diff --git a/DiscImageChef.Filesystems/AppleDOS/Dir.cs b/DiscImageChef.Filesystems/AppleDOS/Dir.cs index 6e7683c5f..3514391b8 100644 --- a/DiscImageChef.Filesystems/AppleDOS/Dir.cs +++ b/DiscImageChef.Filesystems/AppleDOS/Dir.cs @@ -34,8 +34,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; namespace DiscImageChef.Filesystems.AppleDOS { @@ -98,7 +98,7 @@ namespace DiscImageChef.Filesystems.AppleDOS if(debug) catalogMs.Write(catSectorB, 0, catSectorB.Length); // Read the catalog sector - CatalogSector catSector = Helpers.Marshal.ByteArrayToStructureLittleEndian(catSectorB); + CatalogSector catSector = Marshal.ByteArrayToStructureLittleEndian(catSectorB); foreach(FileEntry entry in catSector.entries.Where(entry => entry.extentTrack > 0)) { diff --git a/DiscImageChef.Filesystems/AppleDOS/File.cs b/DiscImageChef.Filesystems/AppleDOS/File.cs index a4ad6a1ee..78a020782 100644 --- a/DiscImageChef.Filesystems/AppleDOS/File.cs +++ b/DiscImageChef.Filesystems/AppleDOS/File.cs @@ -34,8 +34,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; using FileAttributes = DiscImageChef.CommonTypes.Structs.FileAttributes; namespace DiscImageChef.Filesystems.AppleDOS @@ -179,7 +179,7 @@ namespace DiscImageChef.Filesystems.AppleDOS if(debug) tsListMs.Write(tsSectorB, 0, tsSectorB.Length); // Read the track/sector list sector - TrackSectorList tsSector = Helpers.Marshal.ByteArrayToStructureLittleEndian(tsSectorB); + TrackSectorList tsSector = Marshal.ByteArrayToStructureLittleEndian(tsSectorB); if(tsSector.sectorOffset > expectedBlock) { diff --git a/DiscImageChef.Filesystems/AppleDOS/Info.cs b/DiscImageChef.Filesystems/AppleDOS/Info.cs index a2fffe036..399545be9 100644 --- a/DiscImageChef.Filesystems/AppleDOS/Info.cs +++ b/DiscImageChef.Filesystems/AppleDOS/Info.cs @@ -30,12 +30,11 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; -using System.Runtime.InteropServices; using System.Text; using Claunia.Encoding; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; using Schemas; using Encoding = System.Text.Encoding; @@ -52,7 +51,7 @@ namespace DiscImageChef.Filesystems.AppleDOS int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16; byte[] vtocB = imagePlugin.ReadSector((ulong)(17 * spt)); - vtoc = Helpers.Marshal.ByteArrayToStructureLittleEndian(vtocB); + vtoc = Marshal.ByteArrayToStructureLittleEndian(vtocB); return vtoc.catalogSector < spt && vtoc.maxTrackSectorPairsPerSector <= 122 && vtoc.sectorsPerTrack == spt && vtoc.bytesPerSector == 256; @@ -69,7 +68,7 @@ namespace DiscImageChef.Filesystems.AppleDOS spt = imagePlugin.Info.Sectors == 455 ? 13 : 16; byte[] vtocB = imagePlugin.ReadSector((ulong)(17 * spt)); - vtoc = Helpers.Marshal.ByteArrayToStructureLittleEndian(vtocB); + vtoc = Marshal.ByteArrayToStructureLittleEndian(vtocB); sb.AppendLine("Apple DOS File System"); sb.AppendLine(); diff --git a/DiscImageChef.Filesystems/AppleDOS/Super.cs b/DiscImageChef.Filesystems/AppleDOS/Super.cs index cefd2b75f..92e0353ad 100644 --- a/DiscImageChef.Filesystems/AppleDOS/Super.cs +++ b/DiscImageChef.Filesystems/AppleDOS/Super.cs @@ -30,14 +30,13 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using Claunia.Encoding; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; +using DiscImageChef.Helpers; using Schemas; using Encoding = System.Text.Encoding; @@ -77,7 +76,7 @@ namespace DiscImageChef.Filesystems.AppleDOS // Read the VTOC vtocBlocks = device.ReadSector((ulong)(17 * sectorsPerTrack)); - vtoc = Helpers.Marshal.ByteArrayToStructureLittleEndian(vtocBlocks); + vtoc = Marshal.ByteArrayToStructureLittleEndian(vtocBlocks); track1UsedByFiles = false; track2UsedByFiles = false; diff --git a/DiscImageChef.Filesystems/AtheOS.cs b/DiscImageChef.Filesystems/AtheOS.cs index 5ffc12721..040a05932 100644 --- a/DiscImageChef.Filesystems/AtheOS.cs +++ b/DiscImageChef.Filesystems/AtheOS.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -94,7 +95,7 @@ namespace DiscImageChef.Filesystems byte[] sbSector = new byte[AFS_SUPERBLOCK_SIZE]; Array.Copy(tmp, offset, sbSector, 0, AFS_SUPERBLOCK_SIZE); - AtheosSuperBlock afsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sbSector); + AtheosSuperBlock afsSb = Marshal.ByteArrayToStructureLittleEndian(sbSector); sb.AppendLine("Atheos filesystem"); diff --git a/DiscImageChef.Filesystems/BFS.cs b/DiscImageChef.Filesystems/BFS.cs index 14df85827..48381a3fc 100644 --- a/DiscImageChef.Filesystems/BFS.cs +++ b/DiscImageChef.Filesystems/BFS.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -127,11 +128,8 @@ namespace DiscImageChef.Filesystems else return; } - if(littleEndian) - { - besb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sbSector); - } - else besb = Helpers.Marshal.ByteArrayToStructureBigEndian(sbSector); + if(littleEndian) besb = Marshal.ByteArrayToStructureLittleEndian(sbSector); + else besb = Marshal.ByteArrayToStructureBigEndian(sbSector); sb.AppendLine(littleEndian ? "Little-endian BeFS" : "Big-endian BeFS"); diff --git a/DiscImageChef.Filesystems/BTRFS.cs b/DiscImageChef.Filesystems/BTRFS.cs index 79234df4d..8e7d36f28 100644 --- a/DiscImageChef.Filesystems/BTRFS.cs +++ b/DiscImageChef.Filesystems/BTRFS.cs @@ -37,6 +37,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -65,10 +66,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSectors(sbSectorOff + partition.Start, sbSectorSize); SuperBlock btrfsSb; - try - { - btrfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - } + try { btrfsSb = Marshal.ByteArrayToStructureLittleEndian(sector); } catch { return false; } DicConsole.DebugWriteLine("BTRFS Plugin", "sbSectorOff = {0}", sbSectorOff); @@ -92,7 +90,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSectors(sbSectorOff + partition.Start, sbSectorSize); - SuperBlock btrfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + SuperBlock btrfsSb = Marshal.ByteArrayToStructureLittleEndian(sector); DicConsole.DebugWriteLine("BTRFS Plugin", "btrfsSb.checksum = {0}", btrfsSb.checksum); DicConsole.DebugWriteLine("BTRFS Plugin", "btrfsSb.uuid = {0}", btrfsSb.uuid); diff --git a/DiscImageChef.Filesystems/CBM.cs b/DiscImageChef.Filesystems/CBM.cs index 38e824538..138ce5f23 100644 --- a/DiscImageChef.Filesystems/CBM.cs +++ b/DiscImageChef.Filesystems/CBM.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; using Encoding = System.Text.Encoding; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -63,7 +64,7 @@ namespace DiscImageChef.Filesystems if(imagePlugin.Info.Sectors == 3200) { sector = imagePlugin.ReadSector(1560); - CommodoreHeader cbmHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + CommodoreHeader cbmHdr = Marshal.ByteArrayToStructureLittleEndian(sector); if(cbmHdr.diskDosVersion == 0x44 && cbmHdr.dosVersion == 0x33 && cbmHdr.diskVersion == 0x44) return true; @@ -71,7 +72,7 @@ namespace DiscImageChef.Filesystems else { sector = imagePlugin.ReadSector(357); - CommodoreBam cbmBam = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + CommodoreBam cbmBam = Marshal.ByteArrayToStructureLittleEndian(sector); if(cbmBam.dosVersion == 0x41 && (cbmBam.doubleSided == 0x00 || cbmBam.doubleSided == 0x80) && cbmBam.unused1 == 0x00 && cbmBam.directoryTrack == 0x12) return true; @@ -98,7 +99,7 @@ namespace DiscImageChef.Filesystems if(imagePlugin.Info.Sectors == 3200) { sector = imagePlugin.ReadSector(1560); - CommodoreHeader cbmHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + CommodoreHeader cbmHdr = Marshal.ByteArrayToStructureLittleEndian(sector); sbInformation.AppendFormat("Directory starts at track {0} sector {1}", cbmHdr.directoryTrack, cbmHdr.directorySector).AppendLine(); @@ -119,7 +120,7 @@ namespace DiscImageChef.Filesystems else { sector = imagePlugin.ReadSector(357); - CommodoreBam cbmBam = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + CommodoreBam cbmBam = Marshal.ByteArrayToStructureLittleEndian(sector); sbInformation.AppendFormat("Directory starts at track {0} sector {1}", cbmBam.directoryTrack, cbmBam.directorySector).AppendLine(); diff --git a/DiscImageChef.Filesystems/CPM/Dir.cs b/DiscImageChef.Filesystems/CPM/Dir.cs index dd46871c4..0cef91bd6 100644 --- a/DiscImageChef.Filesystems/CPM/Dir.cs +++ b/DiscImageChef.Filesystems/CPM/Dir.cs @@ -32,9 +32,9 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes.Structs; +using DiscImageChef.Helpers; namespace DiscImageChef.Filesystems.CPM { @@ -71,8 +71,7 @@ namespace DiscImageChef.Filesystems.CPM for(int off = 0; off < directory.Length; off += 32) { - DirectoryEntry entry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, off, 32); + DirectoryEntry entry = Marshal.ByteArrayToStructureLittleEndian(directory, off, 32); if((entry.statusUser & 0x7F) < 0x20) { diff --git a/DiscImageChef.Filesystems/CPM/Info.cs b/DiscImageChef.Filesystems/CPM/Info.cs index e1fe95eed..3ce90c899 100644 --- a/DiscImageChef.Filesystems/CPM/Info.cs +++ b/DiscImageChef.Filesystems/CPM/Info.cs @@ -33,11 +33,11 @@ using System; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.Filesystems.CPM @@ -181,7 +181,7 @@ namespace DiscImageChef.Filesystems.CPM // Read the superblock AmstradSuperBlock amsSb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(sector, amsSbOffset, 16); + Marshal.ByteArrayToStructureLittleEndian(sector, amsSbOffset, 16); // Check that format byte and sidedness indicate the same number of sizes if(amsSb.format == 0 && (amsSb.sidedness & 0x02) == 0 || @@ -297,8 +297,7 @@ namespace DiscImageChef.Filesystems.CPM if(sum == 0) { // Read the superblock - HardDiskSuperBlock hddSb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + HardDiskSuperBlock hddSb = Marshal.ByteArrayToStructureLittleEndian(sector); // Calculate volume size sectorSize = (ulong)(hddSb.recordsPerSector * 128); diff --git a/DiscImageChef.Filesystems/CPM/Super.cs b/DiscImageChef.Filesystems/CPM/Super.cs index 6e2828340..911a8283f 100644 --- a/DiscImageChef.Filesystems/CPM/Super.cs +++ b/DiscImageChef.Filesystems/CPM/Super.cs @@ -36,12 +36,12 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; +using DiscImageChef.Helpers; using Schemas; using FileAttributes = DiscImageChef.CommonTypes.Structs.FileAttributes; using FileSystemInfo = DiscImageChef.CommonTypes.Structs.FileSystemInfo; @@ -224,7 +224,7 @@ namespace DiscImageChef.Filesystems.CPM if(allocationBlocks.Count > 256) { DirectoryEntry16 entry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); + Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); bool hidden = (entry.statusUser & 0x80) == 0x80; bool rdOnly = (entry.filename[0] & 0x80) == 0x80 || (entry.extension[0] & 0x80) == 0x80; @@ -311,7 +311,7 @@ namespace DiscImageChef.Filesystems.CPM else { DirectoryEntry entry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); + Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); bool hidden = (entry.statusUser & 0x80) == 0x80; bool rdOnly = (entry.filename[0] & 0x80) == 0x80 || (entry.extension[0] & 0x80) == 0x80; @@ -398,8 +398,7 @@ namespace DiscImageChef.Filesystems.CPM // A password entry (or a file entry in PDOS, but this does not handle that case) else if((directory[dOff] & 0x7F) >= 0x10 && (directory[dOff] & 0x7F) < 0x20) { - PasswordEntry entry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); + PasswordEntry entry = Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); int user = entry.userNumber & 0x0F; @@ -443,7 +442,7 @@ namespace DiscImageChef.Filesystems.CPM { case 0x20: LabelEntry labelEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); + Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); // The volume label defines if one of the fields in CP/M 3 timestamp is a creation or an // access time @@ -476,7 +475,7 @@ namespace DiscImageChef.Filesystems.CPM directory[dOff + 30] == 0x00 && directory[dOff + 31] == 0x00) { DateEntry dateEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); + Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); FileEntryInfo fInfo; @@ -529,8 +528,7 @@ namespace DiscImageChef.Filesystems.CPM else if(directory[dOff + 1] == 0x00) { TrdPartyDateEntry trdPartyDateEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(directory, dOff, - 32); + Marshal.ByteArrayToStructureLittleEndian(directory, dOff, 32); FileEntryInfo fInfo; diff --git a/DiscImageChef.Filesystems/Cram.cs b/DiscImageChef.Filesystems/Cram.cs index 013236ff9..5c5d1979b 100644 --- a/DiscImageChef.Filesystems/Cram.cs +++ b/DiscImageChef.Filesystems/Cram.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -77,10 +78,10 @@ namespace DiscImageChef.Filesystems switch(magic) { case CRAM_MAGIC: - crSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + crSb = Marshal.ByteArrayToStructureLittleEndian(sector); break; case CRAM_CIGAM: - crSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + crSb = Marshal.ByteArrayToStructureBigEndian(sector); littleEndian = false; break; } diff --git a/DiscImageChef.Filesystems/ECMA67.cs b/DiscImageChef.Filesystems/ECMA67.cs index 0c8c73f00..00d860189 100644 --- a/DiscImageChef.Filesystems/ECMA67.cs +++ b/DiscImageChef.Filesystems/ECMA67.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -60,7 +61,7 @@ namespace DiscImageChef.Filesystems if(sector.Length != 128) return false; - VolumeLabel vol = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + VolumeLabel vol = Marshal.ByteArrayToStructureLittleEndian(sector); return ecma67_magic.SequenceEqual(vol.labelIdentifier) && vol.labelNumber == 1 && vol.recordLength == 0x31; } @@ -73,7 +74,7 @@ namespace DiscImageChef.Filesystems StringBuilder sbInformation = new StringBuilder(); - VolumeLabel vol = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + VolumeLabel vol = Marshal.ByteArrayToStructureLittleEndian(sector); sbInformation.AppendLine("ECMA-67"); diff --git a/DiscImageChef.Filesystems/EFS.cs b/DiscImageChef.Filesystems/EFS.cs index 797ee3b17..7912dd656 100644 --- a/DiscImageChef.Filesystems/EFS.cs +++ b/DiscImageChef.Filesystems/EFS.cs @@ -39,6 +39,7 @@ using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -60,19 +61,17 @@ namespace DiscImageChef.Filesystems // Misaligned if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc) { - EFS_Superblock efsSb = new EFS_Superblock(); - - uint sbSize = (uint)((Marshal.SizeOf(efsSb) + 0x200) / imagePlugin.Info.SectorSize); - if((Marshal.SizeOf(efsSb) + 0x200) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)((Marshal.SizeOf() + 0x200) / imagePlugin.Info.SectorSize); + if((Marshal.SizeOf() + 0x200) % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(efsSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - byte[] sbpiece = new byte[Marshal.SizeOf(efsSb)]; + byte[] sbpiece = new byte[Marshal.SizeOf()]; - Array.Copy(sector, 0x200, sbpiece, 0, Marshal.SizeOf(efsSb)); + Array.Copy(sector, 0x200, sbpiece, 0, Marshal.SizeOf()); - efsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sbpiece); + EFS_Superblock efsSb = Marshal.ByteArrayToStructureBigEndian(sbpiece); DicConsole.DebugWriteLine("EFS plugin", "magic at 0x{0:X3} = 0x{1:X8} (expected 0x{2:X8} or 0x{3:X8})", 0x200, efsSb.sb_magic, EFS_MAGIC, EFS_MAGIC_NEW); @@ -81,15 +80,13 @@ namespace DiscImageChef.Filesystems } else { - EFS_Superblock efsSb = new EFS_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(efsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(efsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + 1, sbSize); - if(sector.Length < Marshal.SizeOf(efsSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - efsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + EFS_Superblock efsSb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("EFS plugin", "magic at {0} = 0x{1:X8} (expected 0x{2:X8} or 0x{3:X8})", 1, efsSb.sb_magic, EFS_MAGIC, EFS_MAGIC_NEW); @@ -112,30 +109,30 @@ namespace DiscImageChef.Filesystems // Misaligned if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc) { - uint sbSize = (uint)((Marshal.SizeOf(efsSb) + 0x400) / imagePlugin.Info.SectorSize); - if((Marshal.SizeOf(efsSb) + 0x400) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)((Marshal.SizeOf() + 0x400) / imagePlugin.Info.SectorSize); + if((Marshal.SizeOf() + 0x400) % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(efsSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - byte[] sbpiece = new byte[Marshal.SizeOf(efsSb)]; + byte[] sbpiece = new byte[Marshal.SizeOf()]; - Array.Copy(sector, 0x200, sbpiece, 0, Marshal.SizeOf(efsSb)); + Array.Copy(sector, 0x200, sbpiece, 0, Marshal.SizeOf()); - efsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sbpiece); + efsSb = Marshal.ByteArrayToStructureBigEndian(sbpiece); DicConsole.DebugWriteLine("EFS plugin", "magic at 0x{0:X3} = 0x{1:X8} (expected 0x{2:X8} or 0x{3:X8})", 0x200, efsSb.sb_magic, EFS_MAGIC, EFS_MAGIC_NEW); } else { - uint sbSize = (uint)(Marshal.SizeOf(efsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(efsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + 1, sbSize); - if(sector.Length < Marshal.SizeOf(efsSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - efsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + efsSb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("EFS plugin", "magic at {0} = 0x{1:X8} (expected 0x{2:X8} or 0x{3:X8})", 1, efsSb.sb_magic, EFS_MAGIC, EFS_MAGIC_NEW); diff --git a/DiscImageChef.Filesystems/F2FS.cs b/DiscImageChef.Filesystems/F2FS.cs index 7cd6af3fe..40b3ee381 100644 --- a/DiscImageChef.Filesystems/F2FS.cs +++ b/DiscImageChef.Filesystems/F2FS.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -62,17 +63,15 @@ namespace DiscImageChef.Filesystems uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - F2FS_Superblock f2fsSb = new F2FS_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(f2fsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(f2fsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + sbAddr >= partition.End) return false; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(f2fsSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - f2fsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + F2FS_Superblock f2fsSb = Marshal.ByteArrayToStructureLittleEndian(sector); return f2fsSb.magic == F2FS_MAGIC; } @@ -87,15 +86,13 @@ namespace DiscImageChef.Filesystems uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - F2FS_Superblock f2fsSb = new F2FS_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(f2fsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(f2fsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(f2fsSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - f2fsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + F2FS_Superblock f2fsSb = Marshal.ByteArrayToStructureLittleEndian(sector); if(f2fsSb.magic != F2FS_MAGIC) return; diff --git a/DiscImageChef.Filesystems/FAT.cs b/DiscImageChef.Filesystems/FAT.cs index 52a255b69..d496cfc30 100644 --- a/DiscImageChef.Filesystems/FAT.cs +++ b/DiscImageChef.Filesystems/FAT.cs @@ -516,17 +516,17 @@ namespace DiscImageChef.Filesystems if(imagePlugin.Info.SectorSize >= 256 && !useHumanBpb) { - atariBpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - msxBpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - dos2Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - dos30Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - dos32Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - dos33Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - shortEbpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - ebpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - shortFat32Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - fat32Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); - apricotBpb = Helpers.Marshal.ByteArrayToStructureLittleEndian(bpbSector); + atariBpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + msxBpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + dos2Bpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + dos30Bpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + dos32Bpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + dos33Bpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + shortEbpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + ebpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + shortFat32Bpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + fat32Bpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); + apricotBpb = Marshal.ByteArrayToStructureLittleEndian(bpbSector); int bitsInBpsAtari = CountBits.Count(atariBpb.bps); int bitsInBpsMsx = CountBits.Count(msxBpb.bps); @@ -1095,8 +1095,8 @@ namespace DiscImageChef.Filesystems if(fat32Bpb.fsinfo_sector + partition.Start <= partition.End) { - byte[] fsinfoSector = imagePlugin.ReadSector(fat32Bpb.fsinfo_sector + partition.Start); - FsInfoSector fsInfo = Helpers.Marshal.ByteArrayToStructureLittleEndian(fsinfoSector); + byte[] fsinfoSector = imagePlugin.ReadSector(fat32Bpb.fsinfo_sector + partition.Start); + FsInfoSector fsInfo = Marshal.ByteArrayToStructureLittleEndian(fsinfoSector); if(fsInfo.signature1 == FSINFO_SIGNATURE1 && fsInfo.signature2 == FSINFO_SIGNATURE2 && fsInfo.signature3 == FSINFO_SIGNATURE3) @@ -1530,7 +1530,7 @@ namespace DiscImageChef.Filesystems if(rootDirectory[i + 0x0B] != 0x08 && rootDirectory[i + 0x0B] != 0x28) continue; DirectoryEntry entry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(rootDirectory, i, 32); + Marshal.ByteArrayToStructureLittleEndian(rootDirectory, i, 32); byte[] fullname = new byte[11]; Array.Copy(entry.filename, 0, fullname, 0, 8); diff --git a/DiscImageChef.Filesystems/FFS.cs b/DiscImageChef.Filesystems/FFS.cs index 73a90e20b..1830d7696 100644 --- a/DiscImageChef.Filesystems/FFS.cs +++ b/DiscImageChef.Filesystems/FFS.cs @@ -39,6 +39,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; using time_t = System.Int32; using ufs_daddr_t = System.Int32; @@ -205,9 +206,9 @@ namespace DiscImageChef.Filesystems // Fun with seeking follows on superblock reading! ufs_sb_sectors = imagePlugin.ReadSectors(sb_offset, sb_size_in_sectors); - UFSSuperBlock ufs_sb = Helpers.Marshal.ByteArrayToStructureLittleEndian(ufs_sb_sectors); + UFSSuperBlock ufs_sb = Marshal.ByteArrayToStructureLittleEndian(ufs_sb_sectors); - UFSSuperBlock bs_sfu = Helpers.Marshal.ByteArrayToStructureBigEndian(ufs_sb_sectors); + UFSSuperBlock bs_sfu = Marshal.ByteArrayToStructureBigEndian(ufs_sb_sectors); if(bs_sfu.fs_magic == UFS_MAGIC && ufs_sb.fs_magic == UFS_CIGAM || bs_sfu.fs_magic == UFS_MAGIC_BW && ufs_sb.fs_magic == UFS_CIGAM_BW || bs_sfu.fs_magic == UFS2_MAGIC && ufs_sb.fs_magic == UFS2_CIGAM || diff --git a/DiscImageChef.Filesystems/HAMMER.cs b/DiscImageChef.Filesystems/HAMMER.cs index 97ca3e471..3d23299f1 100644 --- a/DiscImageChef.Filesystems/HAMMER.cs +++ b/DiscImageChef.Filesystems/HAMMER.cs @@ -40,6 +40,7 @@ using Schemas; using hammer_crc_t = System.UInt32; using hammer_off_t = System.UInt64; using hammer_tid_t = System.UInt64; +using Marshal = DiscImageChef.Helpers.Marshal; #pragma warning disable 169 @@ -92,10 +93,8 @@ namespace DiscImageChef.Filesystems ulong magic = BitConverter.ToUInt64(sbSector, 0); if(magic == HAMMER_FSBUF_VOLUME) - { - hammerSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sbSector); - } - else hammerSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sbSector); + hammerSb = Marshal.ByteArrayToStructureLittleEndian(sbSector); + else hammerSb = Marshal.ByteArrayToStructureBigEndian(sbSector); sb.AppendLine("HAMMER filesystem"); diff --git a/DiscImageChef.Filesystems/HPFS.cs b/DiscImageChef.Filesystems/HPFS.cs index 7782fa768..93678d241 100644 --- a/DiscImageChef.Filesystems/HPFS.cs +++ b/DiscImageChef.Filesystems/HPFS.cs @@ -37,6 +37,7 @@ using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -77,11 +78,11 @@ namespace DiscImageChef.Filesystems imagePlugin.ReadSector(17 + partition.Start); // Seek to spareblock, on logical sector 17 HpfsBiosParameterBlock hpfsBpb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(hpfsBpbSector); + Marshal.ByteArrayToStructureLittleEndian(hpfsBpbSector); - HpfsSuperBlock hpfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(hpfsSbSector); + HpfsSuperBlock hpfsSb = Marshal.ByteArrayToStructureLittleEndian(hpfsSbSector); - HpfsSpareBlock hpfsSp = Helpers.Marshal.ByteArrayToStructureLittleEndian(hpfsSpSector); + HpfsSpareBlock hpfsSp = Marshal.ByteArrayToStructureLittleEndian(hpfsSpSector); if(StringHandlers.CToString(hpfsBpb.fs_type) != "HPFS " || hpfsSb.magic1 != 0xF995E849 || hpfsSb.magic2 != 0xFA53E9C5 || hpfsSp.magic1 != 0xF9911849 || diff --git a/DiscImageChef.Filesystems/HPOFS.cs b/DiscImageChef.Filesystems/HPOFS.cs index a359f3aa8..971ddcf2e 100644 --- a/DiscImageChef.Filesystems/HPOFS.cs +++ b/DiscImageChef.Filesystems/HPOFS.cs @@ -39,6 +39,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -65,8 +66,7 @@ namespace DiscImageChef.Filesystems if(hpofsBpbSector.Length < 512) return false; - BiosParameterBlock bpb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(hpofsBpbSector); + BiosParameterBlock bpb = Marshal.ByteArrayToStructureLittleEndian(hpofsBpbSector); return bpb.fs_type.SequenceEqual(hpofsType); } @@ -86,12 +86,9 @@ namespace DiscImageChef.Filesystems byte[] volInfoSector = imagePlugin.ReadSector(14 + partition.Start); // Seek to volume information block, on logical sector 14 - BiosParameterBlock bpb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(hpofsBpbSector); - MediaInformationBlock mib = - Helpers.Marshal.ByteArrayToStructureBigEndian(medInfoSector); - VolumeInformationBlock vib = - Helpers.Marshal.ByteArrayToStructureBigEndian(volInfoSector); + BiosParameterBlock bpb = Marshal.ByteArrayToStructureLittleEndian(hpofsBpbSector); + MediaInformationBlock mib = Marshal.ByteArrayToStructureBigEndian(medInfoSector); + VolumeInformationBlock vib = Marshal.ByteArrayToStructureBigEndian(volInfoSector); DicConsole.DebugWriteLine("HPOFS Plugin", "bpb.oem_name = \"{0}\"", StringHandlers.CToString(bpb.oem_name)); diff --git a/DiscImageChef.Filesystems/ISO9660/Info.cs b/DiscImageChef.Filesystems/ISO9660/Info.cs index dceed45ff..a02179d55 100644 --- a/DiscImageChef.Filesystems/ISO9660/Info.cs +++ b/DiscImageChef.Filesystems/ISO9660/Info.cs @@ -32,13 +32,13 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using DiscImageChef.Decoders.Sega; +using DiscImageChef.Helpers; using Schemas; namespace DiscImageChef.Filesystems.ISO9660 @@ -148,15 +148,16 @@ namespace DiscImageChef.Filesystems.ISO9660 { case 0: { - bvd = Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector, hsOff, 2048 - hsOff); + bvd = Marshal.ByteArrayToStructureLittleEndian(vdSector, hsOff, 2048 - hsOff); bootSpec = "Unknown"; if(Encoding.GetString(bvd.Value.system_id).Substring(0, 23) == "EL TORITO SPECIFICATION") { bootSpec = "El Torito"; - torito = Helpers - .Marshal.ByteArrayToStructureLittleEndian(vdSector, hsOff, 2048 - hsOff); + torito = + Marshal.ByteArrayToStructureLittleEndian(vdSector, hsOff, + 2048 - hsOff); } break; @@ -164,25 +165,18 @@ namespace DiscImageChef.Filesystems.ISO9660 case 1: { if(highSierra) - { - hsvd = - Helpers.Marshal - .ByteArrayToStructureLittleEndian(vdSector); - } + hsvd = Marshal + .ByteArrayToStructureLittleEndian(vdSector); else if(cdi) - fsvd = - Helpers.Marshal.ByteArrayToStructureBigEndian(vdSector); - else - { - pvd = Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector); - } + fsvd = Marshal.ByteArrayToStructureBigEndian(vdSector); + else pvd = Marshal.ByteArrayToStructureLittleEndian(vdSector); break; } case 2: { PrimaryVolumeDescriptor svd = - Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector); + Marshal.ByteArrayToStructureLittleEndian(vdSector); // Check if this is Joliet if(svd.escape_sequences[0] == '%' && svd.escape_sequences[1] == '/') @@ -257,13 +251,13 @@ namespace DiscImageChef.Filesystems.ISO9660 BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; // Walk thru root directory to see system area extensions in use - while(rootOff + Marshal.SizeOf(typeof(DirectoryRecord)) < rootDir.Length && !cdi) + while(rootOff + Marshal.SizeOf() < rootDir.Length && !cdi) { DirectoryRecord record = - Helpers.Marshal.ByteArrayToStructureLittleEndian(rootDir, rootOff, - Marshal.SizeOf(typeof(DirectoryRecord))); + Marshal.ByteArrayToStructureLittleEndian(rootDir, rootOff, + Marshal.SizeOf()); - int saOff = Marshal.SizeOf(record) + record.name_len; + int saOff = Marshal.SizeOf() + record.name_len; saOff += saOff % 2; int saLen = record.length - saOff; @@ -277,13 +271,13 @@ namespace DiscImageChef.Filesystems.ISO9660 { bool noneFound = true; - if(Marshal.SizeOf(typeof(CdromXa)) + saOff <= saLen) + if(Marshal.SizeOf() + saOff <= saLen) { - CdromXa xa = Helpers.Marshal.ByteArrayToStructureBigEndian(sa); + CdromXa xa = Marshal.ByteArrayToStructureBigEndian(sa); if(xa.signature == XA_MAGIC) { xaExtensions = true; - saOff += Marshal.SizeOf(typeof(CdromXa)); + saOff += Marshal.SizeOf(); noneFound = false; } } @@ -309,18 +303,18 @@ namespace DiscImageChef.Filesystems.ISO9660 switch(appleId) { case AppleOldId.ProDOS: - saOff += Marshal.SizeOf(typeof(AppleProDOSOldSystemUse)); + saOff += Marshal.SizeOf(); break; case AppleOldId.TypeCreator: case AppleOldId.TypeCreatorBundle: - saOff += Marshal.SizeOf(typeof(AppleHFSTypeCreatorSystemUse)); + saOff += Marshal.SizeOf(); break; case AppleOldId.TypeCreatorIcon: case AppleOldId.TypeCreatorIconBundle: - saOff += Marshal.SizeOf(typeof(AppleHFSIconSystemUse)); + saOff += Marshal.SizeOf(); break; case AppleOldId.HFS: - saOff += Marshal.SizeOf(typeof(AppleHFSOldSystemUse)); + saOff += Marshal.SizeOf(); break; } @@ -345,7 +339,7 @@ namespace DiscImageChef.Filesystems.ISO9660 byte[] ce = new byte[sa[saOff + 2]]; Array.Copy(sa, saOff, ce, 0, ce.Length); ContinuationArea ca = - Helpers.Marshal.ByteArrayToStructureBigEndian(ce); + Marshal.ByteArrayToStructureBigEndian(ce); contareas.Add(ca); break; case SUSP_REFERENCE when saOff + sa[saOff + 2] <= saLen: @@ -442,13 +436,13 @@ namespace DiscImageChef.Filesystems.ISO9660 counter = 1; foreach(byte[] erb in refareas) { - ReferenceArea er = Helpers.Marshal.ByteArrayToStructureBigEndian(erb); + ReferenceArea er = Marshal.ByteArrayToStructureBigEndian(erb); string extId = - Encoding.GetString(erb, Marshal.SizeOf(er), er.id_len); + Encoding.GetString(erb, Marshal.SizeOf(), er.id_len); string extDes = - Encoding.GetString(erb, Marshal.SizeOf(er) + er.id_len, er.des_len); - string extSrc = - Encoding.GetString(erb, Marshal.SizeOf(er) + er.id_len + er.des_len, er.src_len); + Encoding.GetString(erb, Marshal.SizeOf() + er.id_len, er.des_len); + string extSrc = Encoding.GetString(erb, Marshal.SizeOf() + er.id_len + er.des_len, + er.src_len); suspInformation.AppendFormat("Extension: {0}", counter).AppendLine(); suspInformation.AppendFormat("\tID: {0}, version {1}", extId, er.ext_ver).AppendLine(); suspInformation.AppendFormat("\tDescription: {0}", extDes).AppendLine(); @@ -555,16 +549,16 @@ namespace DiscImageChef.Filesystems.ISO9660 if(vdSector[toritoOff] != 1) goto exit_torito; ElToritoValidationEntry valentry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, - EL_TORITO_ENTRY_SIZE); + Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, + EL_TORITO_ENTRY_SIZE); if(valentry.signature != EL_TORITO_MAGIC) goto exit_torito; toritoOff += EL_TORITO_ENTRY_SIZE; ElToritoInitialEntry initialEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, - EL_TORITO_ENTRY_SIZE); + Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, + EL_TORITO_ENTRY_SIZE); initialEntry.boot_type = (ElToritoEmulation)((byte)initialEntry.boot_type & 0xF); @@ -631,8 +625,8 @@ namespace DiscImageChef.Filesystems.ISO9660 vdSector[toritoOff] == (byte)ElToritoIndicator.LastHeader)) { ElToritoSectionHeaderEntry sectionHeader = - Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, - EL_TORITO_ENTRY_SIZE); + Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, + EL_TORITO_ENTRY_SIZE); toritoOff += EL_TORITO_ENTRY_SIZE; isoMetadata.AppendFormat("Boot section {0}:", SECTION_COUNTER); @@ -643,8 +637,8 @@ namespace DiscImageChef.Filesystems.ISO9660 entryCounter++) { ElToritoSectionEntry sectionEntry = - Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, - EL_TORITO_ENTRY_SIZE); + Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, + EL_TORITO_ENTRY_SIZE); toritoOff += EL_TORITO_ENTRY_SIZE; isoMetadata.AppendFormat("\tEntry {0}:", entryCounter); @@ -709,8 +703,9 @@ namespace DiscImageChef.Filesystems.ISO9660 while(toritoOff < vdSector.Length) { ElToritoSectionEntryExtension sectionExtension = - Helpers.Marshal.ByteArrayToStructureLittleEndian(vdSector, toritoOff, - EL_TORITO_ENTRY_SIZE); + Marshal.ByteArrayToStructureLittleEndian(vdSector, + toritoOff, + EL_TORITO_ENTRY_SIZE); toritoOff += EL_TORITO_ENTRY_SIZE; if(!sectionExtension.extension_flags.HasFlag(ElToritoFlags.Continued)) break; diff --git a/DiscImageChef.Filesystems/JFS.cs b/DiscImageChef.Filesystems/JFS.cs index 4113a45e6..5b5c47747 100644 --- a/DiscImageChef.Filesystems/JFS.cs +++ b/DiscImageChef.Filesystems/JFS.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -58,7 +59,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSector(partition.Start + bootSectors); if(sector.Length < 512) return false; - JfsSuperBlock jfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + JfsSuperBlock jfsSb = Marshal.ByteArrayToStructureLittleEndian(sector); return jfsSb.s_magic == JFS_MAGIC; } @@ -73,7 +74,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSector(partition.Start + bootSectors); if(sector.Length < 512) return; - JfsSuperBlock jfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + JfsSuperBlock jfsSb = Marshal.ByteArrayToStructureLittleEndian(sector); sb.AppendLine("JFS filesystem"); sb.AppendFormat("Version {0}", jfsSb.s_version).AppendLine(); diff --git a/DiscImageChef.Filesystems/Locus.cs b/DiscImageChef.Filesystems/Locus.cs index 1071c1f94..929560478 100644 --- a/DiscImageChef.Filesystems/Locus.cs +++ b/DiscImageChef.Filesystems/Locus.cs @@ -48,6 +48,7 @@ using fstore_t = System.Int32; using gfs_t = System.Int32; // Inode number using ino_t = System.Int32; +using Marshal = DiscImageChef.Helpers.Marshal; // Filesystem pack number using pckno_t = System.Int16; // Timestamp @@ -79,17 +80,15 @@ namespace DiscImageChef.Filesystems for(ulong location = 0; location <= 8; location++) { - Locus_Superblock locusSb = new Locus_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(locusSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(locusSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + location + sbSize >= imagePlugin.Info.Sectors) break; byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); - if(sector.Length < Marshal.SizeOf(locusSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - locusSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + Locus_Superblock locusSb = Marshal.ByteArrayToStructureLittleEndian(sector); DicConsole.DebugWriteLine("Locus plugin", "magic at {1} = 0x{0:X8}", locusSb.s_magic, location); @@ -112,13 +111,13 @@ namespace DiscImageChef.Filesystems for(ulong location = 0; location <= 8; location++) { - uint sbSize = (uint)(Marshal.SizeOf(locusSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(locusSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); - if(sector.Length < Marshal.SizeOf(locusSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - locusSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + locusSb = Marshal.ByteArrayToStructureLittleEndian(sector); if(locusSb.s_magic == LOCUS_MAGIC || locusSb.s_magic == LOCUS_CIGAM || locusSb.s_magic == LOCUS_MAGIC_OLD || locusSb.s_magic == LOCUS_CIGAM_OLD) break; @@ -131,7 +130,7 @@ namespace DiscImageChef.Filesystems // Numerical arrays are not important for information so no need to swap them if(locusSb.s_magic == LOCUS_CIGAM || locusSb.s_magic == LOCUS_CIGAM_OLD) { - locusSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + locusSb = Marshal.ByteArrayToStructureBigEndian(sector); locusSb.s_flags = (LocusFlags)Swapping.Swap((ushort)locusSb.s_flags); } diff --git a/DiscImageChef.Filesystems/MicroDOS.cs b/DiscImageChef.Filesystems/MicroDOS.cs index 0e769a6eb..d0739de16 100644 --- a/DiscImageChef.Filesystems/MicroDOS.cs +++ b/DiscImageChef.Filesystems/MicroDOS.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -60,7 +61,7 @@ namespace DiscImageChef.Filesystems byte[] bk0 = imagePlugin.ReadSector(0 + partition.Start); - MicroDosBlock0 block0 = Helpers.Marshal.ByteArrayToStructureLittleEndian(bk0); + MicroDosBlock0 block0 = Marshal.ByteArrayToStructureLittleEndian(bk0); return block0.label == MAGIC && block0.mklabel == MAGIC2; } @@ -75,7 +76,7 @@ namespace DiscImageChef.Filesystems byte[] bk0 = imagePlugin.ReadSector(0 + partition.Start); - MicroDosBlock0 block0 = Helpers.Marshal.ByteArrayToStructureLittleEndian(bk0); + MicroDosBlock0 block0 = Marshal.ByteArrayToStructureLittleEndian(bk0); sb.AppendLine("MicroDOS filesystem"); sb.AppendFormat("Volume has {0} blocks ({1} bytes)", block0.blocks, block0.blocks * 512).AppendLine(); diff --git a/DiscImageChef.Filesystems/MinixFS.cs b/DiscImageChef.Filesystems/MinixFS.cs index a84a4291c..8e8416950 100644 --- a/DiscImageChef.Filesystems/MinixFS.cs +++ b/DiscImageChef.Filesystems/MinixFS.cs @@ -37,6 +37,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -230,11 +231,8 @@ namespace DiscImageChef.Filesystems { Minix3SuperBlock mnxSb; - if(littleEndian) - { - mnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(minixSbSector); - } - else mnxSb = Helpers.Marshal.ByteArrayToStructureBigEndian(minixSbSector); + if(littleEndian) mnxSb = Marshal.ByteArrayToStructureLittleEndian(minixSbSector); + else mnxSb = Marshal.ByteArrayToStructureBigEndian(minixSbSector); if(magic != MINIX3_MAGIC && magic != MINIX3_CIGAM) mnxSb.s_blocksize = 1024; @@ -264,10 +262,8 @@ namespace DiscImageChef.Filesystems { MinixSuperBlock mnxSb; - if(littleEndian) - { - mnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(minixSbSector); } - else mnxSb = Helpers.Marshal.ByteArrayToStructureBigEndian(minixSbSector); + if(littleEndian) mnxSb = Marshal.ByteArrayToStructureLittleEndian(minixSbSector); + else mnxSb = Marshal.ByteArrayToStructureBigEndian(minixSbSector); sb.AppendLine(minixVersion); sb.AppendFormat("{0} chars in filename", filenamesize).AppendLine(); diff --git a/DiscImageChef.Filesystems/NILFS2.cs b/DiscImageChef.Filesystems/NILFS2.cs index 9de256e4c..cf210b7e3 100644 --- a/DiscImageChef.Filesystems/NILFS2.cs +++ b/DiscImageChef.Filesystems/NILFS2.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -57,17 +58,15 @@ namespace DiscImageChef.Filesystems uint sbAddr = NILFS2_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - NILFS2_Superblock nilfsSb = new NILFS2_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(nilfsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(nilfsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + sbAddr + sbSize >= partition.End) return false; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(nilfsSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - nilfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + NILFS2_Superblock nilfsSb = Marshal.ByteArrayToStructureLittleEndian(sector); return nilfsSb.magic == NILFS2_MAGIC; } @@ -82,15 +81,13 @@ namespace DiscImageChef.Filesystems uint sbAddr = NILFS2_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - NILFS2_Superblock nilfsSb = new NILFS2_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(nilfsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(nilfsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(nilfsSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - nilfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + NILFS2_Superblock nilfsSb = Marshal.ByteArrayToStructureLittleEndian(sector); if(nilfsSb.magic != NILFS2_MAGIC) return; diff --git a/DiscImageChef.Filesystems/NTFS.cs b/DiscImageChef.Filesystems/NTFS.cs index 74a10e8bf..d0815c012 100644 --- a/DiscImageChef.Filesystems/NTFS.cs +++ b/DiscImageChef.Filesystems/NTFS.cs @@ -37,6 +37,7 @@ using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -82,7 +83,7 @@ namespace DiscImageChef.Filesystems byte[] ntfsBpb = imagePlugin.ReadSector(0 + partition.Start); - NtfsBootBlock ntfsBb = Helpers.Marshal.ByteArrayToStructureLittleEndian(ntfsBpb); + NtfsBootBlock ntfsBb = Marshal.ByteArrayToStructureLittleEndian(ntfsBpb); sb.AppendFormat("{0} bytes per sector", ntfsBb.bps).AppendLine(); sb.AppendFormat("{0} sectors per cluster ({1} bytes)", ntfsBb.spc, ntfsBb.spc * ntfsBb.bps).AppendLine(); diff --git a/DiscImageChef.Filesystems/ODS.cs b/DiscImageChef.Filesystems/ODS.cs index 3e83cc3c7..b668567b5 100644 --- a/DiscImageChef.Filesystems/ODS.cs +++ b/DiscImageChef.Filesystems/ODS.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -99,7 +100,7 @@ namespace DiscImageChef.Filesystems byte[] hbSector = imagePlugin.ReadSector(1 + partition.Start); - OdsHomeBlock homeblock = Helpers.Marshal.ByteArrayToStructureLittleEndian(hbSector); + OdsHomeBlock homeblock = Marshal.ByteArrayToStructureLittleEndian(hbSector); // Optical disc if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc && @@ -112,7 +113,7 @@ namespace DiscImageChef.Filesystems hbSector = new byte[0x200]; Array.Copy(tmp, 0x200, hbSector, 0, 0x200); - homeblock = Helpers.Marshal.ByteArrayToStructureLittleEndian(hbSector); + homeblock = Marshal.ByteArrayToStructureLittleEndian(hbSector); if(StringHandlers.CToString(homeblock.format) != "DECFILE11A " && StringHandlers.CToString(homeblock.format) != "DECFILE11B ") return; diff --git a/DiscImageChef.Filesystems/PCFX.cs b/DiscImageChef.Filesystems/PCFX.cs index ab7075449..b6dac484d 100644 --- a/DiscImageChef.Filesystems/PCFX.cs +++ b/DiscImageChef.Filesystems/PCFX.cs @@ -37,6 +37,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -70,7 +71,7 @@ namespace DiscImageChef.Filesystems information = ""; byte[] sector = imagePlugin.ReadSectors(partition.Start, 2); - PcfxHeader header = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + PcfxHeader header = Marshal.ByteArrayToStructureLittleEndian(sector); string date; DateTime dateTime = DateTime.MinValue; diff --git a/DiscImageChef.Filesystems/QNX4.cs b/DiscImageChef.Filesystems/QNX4.cs index 857d147fd..52aa1a6d9 100644 --- a/DiscImageChef.Filesystems/QNX4.cs +++ b/DiscImageChef.Filesystems/QNX4.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -60,7 +61,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSector(partition.Start + 1); if(sector.Length < 512) return false; - QNX4_Superblock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + QNX4_Superblock qnxSb = Marshal.ByteArrayToStructureLittleEndian(sector); // Check root directory name if(!qnx4_rootDir_fname.SequenceEqual(qnxSb.rootDir.di_fname)) return false; @@ -91,7 +92,7 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSector(partition.Start + 1); if(sector.Length < 512) return; - QNX4_Superblock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + QNX4_Superblock qnxSb = Marshal.ByteArrayToStructureLittleEndian(sector); // Too much useless information /* diff --git a/DiscImageChef.Filesystems/QNX6.cs b/DiscImageChef.Filesystems/QNX6.cs index 45862fc87..aed928102 100644 --- a/DiscImageChef.Filesystems/QNX6.cs +++ b/DiscImageChef.Filesystems/QNX6.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -62,10 +63,9 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSectors(partition.Start + bootSectors, sectors); if(sector.Length < QNX6_SUPER_BLOCK_SIZE) return false; - QNX6_AudiSuperBlock audiSb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(audiSector); + QNX6_AudiSuperBlock audiSb = Marshal.ByteArrayToStructureLittleEndian(audiSector); - QNX6_SuperBlock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + QNX6_SuperBlock qnxSb = Marshal.ByteArrayToStructureLittleEndian(sector); return qnxSb.magic == QNX6_MAGIC || audiSb.magic == QNX6_MAGIC; } @@ -83,10 +83,9 @@ namespace DiscImageChef.Filesystems byte[] sector = imagePlugin.ReadSectors(partition.Start + bootSectors, sectors); if(sector.Length < QNX6_SUPER_BLOCK_SIZE) return; - QNX6_AudiSuperBlock audiSb = - Helpers.Marshal.ByteArrayToStructureLittleEndian(audiSector); + QNX6_AudiSuperBlock audiSb = Marshal.ByteArrayToStructureLittleEndian(audiSector); - QNX6_SuperBlock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + QNX6_SuperBlock qnxSb = Marshal.ByteArrayToStructureLittleEndian(sector); bool audi = audiSb.magic == QNX6_MAGIC; diff --git a/DiscImageChef.Filesystems/RBF.cs b/DiscImageChef.Filesystems/RBF.cs index 727d062e8..a6b42e010 100644 --- a/DiscImageChef.Filesystems/RBF.cs +++ b/DiscImageChef.Filesystems/RBF.cs @@ -37,6 +37,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -61,19 +62,18 @@ namespace DiscImageChef.Filesystems // I've read OS-9/Apple2 has it on sector 15 foreach(int i in new[] {0, 4, 15}) { - ulong location = (ulong)i; - RBF_IdSector rbfSb = new RBF_IdSector(); + ulong location = (ulong)i; - uint sbSize = (uint)(Marshal.SizeOf(rbfSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(rbfSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + location + sbSize >= imagePlugin.Info.Sectors) break; byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); - if(sector.Length < Marshal.SizeOf(rbfSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - rbfSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); - RBF_NewIdSector rbf9000Sb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + RBF_IdSector rbfSb = Marshal.ByteArrayToStructureBigEndian(sector); + RBF_NewIdSector rbf9000Sb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("RBF plugin", "magic at {0} = 0x{1:X8} or 0x{2:X8} (expected 0x{3:X8} or 0x{4:X8})", @@ -99,14 +99,14 @@ namespace DiscImageChef.Filesystems foreach(int i in new[] {0, 4, 15}) { ulong location = (ulong)i; - uint sbSize = (uint)(Marshal.SizeOf(rbfSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(rbfSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); - if(sector.Length < Marshal.SizeOf(rbfSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - rbfSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); - rbf9000Sb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + rbfSb = Marshal.ByteArrayToStructureBigEndian(sector); + rbf9000Sb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("RBF plugin", "magic at {0} = 0x{1:X8} or 0x{2:X8} (expected 0x{3:X8} or 0x{4:X8})", @@ -118,7 +118,7 @@ namespace DiscImageChef.Filesystems if(rbfSb.dd_sync != RBF_SYNC && rbf9000Sb.rid_sync != RBF_SYNC && rbf9000Sb.rid_sync != RBF_CNYS) return; if(rbf9000Sb.rid_sync == RBF_CNYS) - rbf9000Sb = (RBF_NewIdSector)Helpers.Marshal.SwapStructureMembersEndian(rbf9000Sb); + rbf9000Sb = (RBF_NewIdSector)Marshal.SwapStructureMembersEndian(rbf9000Sb); StringBuilder sb = new StringBuilder(); diff --git a/DiscImageChef.Filesystems/RT11.cs b/DiscImageChef.Filesystems/RT11.cs index 94e5dac16..b667798e3 100644 --- a/DiscImageChef.Filesystems/RT11.cs +++ b/DiscImageChef.Filesystems/RT11.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; using Encoding = System.Text.Encoding; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -76,7 +77,7 @@ namespace DiscImageChef.Filesystems byte[] hbSector = imagePlugin.ReadSector(1 + partition.Start); - RT11HomeBlock homeblock = Helpers.Marshal.ByteArrayToStructureLittleEndian(hbSector); + RT11HomeBlock homeblock = Marshal.ByteArrayToStructureLittleEndian(hbSector); /* TODO: Is this correct? * Assembler: diff --git a/DiscImageChef.Filesystems/ReFS.cs b/DiscImageChef.Filesystems/ReFS.cs index 9e498d0c7..eb88c272a 100644 --- a/DiscImageChef.Filesystems/ReFS.cs +++ b/DiscImageChef.Filesystems/ReFS.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -53,17 +54,15 @@ namespace DiscImageChef.Filesystems public bool Identify(IMediaImage imagePlugin, Partition partition) { - RefsVolumeHeader refsVhdr = new RefsVolumeHeader(); - - uint sbSize = (uint)(Marshal.SizeOf(refsVhdr) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(refsVhdr) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + sbSize >= partition.End) return false; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(refsVhdr)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - refsVhdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + RefsVolumeHeader refsVhdr = Marshal.ByteArrayToStructureLittleEndian(sector); return refsVhdr.identifier == FSRS && ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.mustBeZero) && refsVhdr.signature.SequenceEqual(refsSignature); @@ -74,17 +73,16 @@ namespace DiscImageChef.Filesystems { Encoding = Encoding.UTF8; information = ""; - RefsVolumeHeader refsVhdr = new RefsVolumeHeader(); - uint sbSize = (uint)(Marshal.SizeOf(refsVhdr) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(refsVhdr) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + sbSize >= partition.End) return; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(refsVhdr)) return; + if(sector.Length < Marshal.SizeOf()) return; - refsVhdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + RefsVolumeHeader refsVhdr = Marshal.ByteArrayToStructureLittleEndian(sector); DicConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.jump empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.jump)); diff --git a/DiscImageChef.Filesystems/Reiser.cs b/DiscImageChef.Filesystems/Reiser.cs index 987898395..8b4936f1d 100644 --- a/DiscImageChef.Filesystems/Reiser.cs +++ b/DiscImageChef.Filesystems/Reiser.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -61,17 +62,15 @@ namespace DiscImageChef.Filesystems uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - Reiser_Superblock reiserSb = new Reiser_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(reiserSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + sbAddr + sbSize >= partition.End) return false; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(reiserSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + Reiser_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian(sector); return reiser35_magic.SequenceEqual(reiserSb.magic) || reiser36_magic.SequenceEqual(reiserSb.magic) || reiserJr_magic.SequenceEqual(reiserSb.magic); @@ -87,15 +86,13 @@ namespace DiscImageChef.Filesystems uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - Reiser_Superblock reiserSb = new Reiser_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(reiserSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(reiserSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + Reiser_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian(sector); if(!reiser35_magic.SequenceEqual(reiserSb.magic) && !reiser36_magic.SequenceEqual(reiserSb.magic) && !reiserJr_magic.SequenceEqual(reiserSb.magic)) return; diff --git a/DiscImageChef.Filesystems/Reiser4.cs b/DiscImageChef.Filesystems/Reiser4.cs index 7cdb3732d..7951dc075 100644 --- a/DiscImageChef.Filesystems/Reiser4.cs +++ b/DiscImageChef.Filesystems/Reiser4.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -62,17 +63,15 @@ namespace DiscImageChef.Filesystems uint sbAddr = REISER4_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - Reiser4_Superblock reiserSb = new Reiser4_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(reiserSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; if(partition.Start + sbAddr + sbSize >= partition.End) return false; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(reiserSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + Reiser4_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian(sector); return reiser4_magic.SequenceEqual(reiserSb.magic); } @@ -87,15 +86,13 @@ namespace DiscImageChef.Filesystems uint sbAddr = REISER4_SUPER_OFFSET / imagePlugin.Info.SectorSize; if(sbAddr == 0) sbAddr = 1; - Reiser4_Superblock reiserSb = new Reiser4_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(reiserSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); - if(sector.Length < Marshal.SizeOf(reiserSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + Reiser4_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian(sector); if(!reiser4_magic.SequenceEqual(reiserSb.magic)) return; diff --git a/DiscImageChef.Filesystems/Squash.cs b/DiscImageChef.Filesystems/Squash.cs index 5a00ef4c0..6f2a3f573 100644 --- a/DiscImageChef.Filesystems/Squash.cs +++ b/DiscImageChef.Filesystems/Squash.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -77,10 +78,10 @@ namespace DiscImageChef.Filesystems switch(magic) { case SQUASH_MAGIC: - sqSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + sqSb = Marshal.ByteArrayToStructureLittleEndian(sector); break; case SQUASH_CIGAM: - sqSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + sqSb = Marshal.ByteArrayToStructureBigEndian(sector); littleEndian = false; break; } diff --git a/DiscImageChef.Filesystems/UDF.cs b/DiscImageChef.Filesystems/UDF.cs index 62da80aaf..6f0c848ff 100644 --- a/DiscImageChef.Filesystems/UDF.cs +++ b/DiscImageChef.Filesystems/UDF.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -73,7 +74,7 @@ namespace DiscImageChef.Filesystems foreach(ulong position in positions.Where(position => position + partition.Start < partition.End)) { sector = imagePlugin.ReadSector(position); - anchor = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + anchor = Marshal.ByteArrayToStructureLittleEndian(sector); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagIdentifier = {0}", anchor.tag.tagIdentifier); DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorVersion = {0}", @@ -124,7 +125,7 @@ namespace DiscImageChef.Filesystems if(tagId == TagIdentifier.LogicalVolumeDescriptor) { LogicalVolumeDescriptor lvd = - Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + Marshal.ByteArrayToStructureLittleEndian(sector); return UDF_Magic.SequenceEqual(lvd.domainIdentifier.identifier); } @@ -155,7 +156,7 @@ namespace DiscImageChef.Filesystems foreach(ulong position in positions) { sector = imagePlugin.ReadSector(position); - anchor = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + anchor = Marshal.ByteArrayToStructureLittleEndian(sector); if(anchor.tag.tagIdentifier == TagIdentifier.AnchorVolumeDescriptorPointer && @@ -186,10 +187,10 @@ namespace DiscImageChef.Filesystems switch(tagId) { case TagIdentifier.LogicalVolumeDescriptor: - lvd = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + lvd = Marshal.ByteArrayToStructureLittleEndian(sector); break; case TagIdentifier.PrimaryVolumeDescriptor: - pvd = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + pvd = Marshal.ByteArrayToStructureLittleEndian(sector); break; } } @@ -199,19 +200,22 @@ namespace DiscImageChef.Filesystems } sector = imagePlugin.ReadSector(lvd.integritySequenceExtent.location); - lvid = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + lvid = Marshal.ByteArrayToStructureLittleEndian(sector); if(lvid.tag.tagIdentifier == TagIdentifier.LogicalVolumeIntegrityDescriptor && lvid.tag.tagLocation == lvd.integritySequenceExtent.location) - { lvidiu = - Helpers.Marshal.ByteArrayToStructureLittleEndian(sector, - (int)(lvid - .numberOfPartitions * - 8 + 80), - Marshal - .SizeOf(lvidiu)); - } + Marshal.ByteArrayToStructureLittleEndian(sector, + (int) + (lvid + .numberOfPartitions * + 8 + + 80), + System + .Runtime + .InteropServices + .Marshal + .SizeOf(lvidiu)); else lvid = new LogicalVolumeIntegrityDescriptor(); sbInformation.AppendFormat("Volume is number {0} of {1}", pvd.volumeSequenceNumber, diff --git a/DiscImageChef.Filesystems/UNICOS.cs b/DiscImageChef.Filesystems/UNICOS.cs index 7b8486fdb..ffefbd17b 100644 --- a/DiscImageChef.Filesystems/UNICOS.cs +++ b/DiscImageChef.Filesystems/UNICOS.cs @@ -44,6 +44,7 @@ using daddr_t = System.Int64; using dev_t = System.Int64; using extent_t = System.Int64; using ino_t = System.Int64; +using Marshal = DiscImageChef.Helpers.Marshal; using time_t = System.Int64; namespace DiscImageChef.Filesystems @@ -66,15 +67,13 @@ namespace DiscImageChef.Filesystems { if(imagePlugin.Info.SectorSize < 512) return false; - UNICOS_Superblock unicosSb = new UNICOS_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(unicosSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(unicosSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(unicosSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - unicosSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + UNICOS_Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("UNICOS plugin", "magic = 0x{0:X16} (expected 0x{1:X16})", unicosSb.s_magic, UNICOS_MAGIC); @@ -89,15 +88,13 @@ namespace DiscImageChef.Filesystems information = ""; if(imagePlugin.Info.SectorSize < 512) return; - UNICOS_Superblock unicosSb = new UNICOS_Superblock(); - - uint sbSize = (uint)(Marshal.SizeOf(unicosSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(unicosSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(unicosSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - unicosSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + UNICOS_Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian(sector); if(unicosSb.s_magic != UNICOS_MAGIC) return; diff --git a/DiscImageChef.Filesystems/VMfs.cs b/DiscImageChef.Filesystems/VMfs.cs index 143aef35f..f9cc9e773 100644 --- a/DiscImageChef.Filesystems/VMfs.cs +++ b/DiscImageChef.Filesystems/VMfs.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -75,7 +76,7 @@ namespace DiscImageChef.Filesystems ulong vmfsSuperOff = VMFS_BASE / imagePlugin.Info.SectorSize; byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff); - VolumeInfo volInfo = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + VolumeInfo volInfo = Marshal.ByteArrayToStructureLittleEndian(sector); StringBuilder sbInformation = new StringBuilder(); diff --git a/DiscImageChef.Filesystems/VxFS.cs b/DiscImageChef.Filesystems/VxFS.cs index 434247564..131e7d457 100644 --- a/DiscImageChef.Filesystems/VxFS.cs +++ b/DiscImageChef.Filesystems/VxFS.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -73,7 +74,7 @@ namespace DiscImageChef.Filesystems ulong vmfsSuperOff = VXFS_BASE / imagePlugin.Info.SectorSize; byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff); - VxSuperBlock vxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + VxSuperBlock vxSb = Marshal.ByteArrayToStructureLittleEndian(sector); StringBuilder sbInformation = new StringBuilder(); diff --git a/DiscImageChef.Filesystems/XFS.cs b/DiscImageChef.Filesystems/XFS.cs index 8ca974177..3f457db2f 100644 --- a/DiscImageChef.Filesystems/XFS.cs +++ b/DiscImageChef.Filesystems/XFS.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -58,21 +59,19 @@ namespace DiscImageChef.Filesystems // Misaligned if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc) { - XFS_Superblock xfsSb = new XFS_Superblock(); - - uint sbSize = (uint)((Marshal.SizeOf(xfsSb) + 0x400) / imagePlugin.Info.SectorSize); - if((Marshal.SizeOf(xfsSb) + 0x400) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)((Marshal.SizeOf() + 0x400) / imagePlugin.Info.SectorSize); + if((Marshal.SizeOf() + 0x400) % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(xfsSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - byte[] sbpiece = new byte[Marshal.SizeOf(xfsSb)]; + byte[] sbpiece = new byte[Marshal.SizeOf()]; foreach(int location in new[] {0, 0x200, 0x400}) { - Array.Copy(sector, location, sbpiece, 0, Marshal.SizeOf(xfsSb)); + Array.Copy(sector, location, sbpiece, 0, Marshal.SizeOf()); - xfsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sbpiece); + XFS_Superblock xfsSb = Marshal.ByteArrayToStructureBigEndian(sbpiece); DicConsole.DebugWriteLine("XFS plugin", "magic at 0x{0:X3} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); @@ -83,16 +82,15 @@ namespace DiscImageChef.Filesystems else foreach(int i in new[] {0, 1, 2}) { - ulong location = (ulong)i; - XFS_Superblock xfsSb = new XFS_Superblock(); + ulong location = (ulong)i; - uint sbSize = (uint)(Marshal.SizeOf(xfsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(xfsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); - if(sector.Length < Marshal.SizeOf(xfsSb)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - xfsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + XFS_Superblock xfsSb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("XFS plugin", "magic at {0} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); @@ -115,19 +113,19 @@ namespace DiscImageChef.Filesystems // Misaligned if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc) { - uint sbSize = (uint)((Marshal.SizeOf(xfsSb) + 0x400) / imagePlugin.Info.SectorSize); - if((Marshal.SizeOf(xfsSb) + 0x400) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)((Marshal.SizeOf() + 0x400) / imagePlugin.Info.SectorSize); + if((Marshal.SizeOf() + 0x400) % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(xfsSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - byte[] sbpiece = new byte[Marshal.SizeOf(xfsSb)]; + byte[] sbpiece = new byte[Marshal.SizeOf()]; foreach(int location in new[] {0, 0x200, 0x400}) { - Array.Copy(sector, location, sbpiece, 0, Marshal.SizeOf(xfsSb)); + Array.Copy(sector, location, sbpiece, 0, Marshal.SizeOf()); - xfsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sbpiece); + xfsSb = Marshal.ByteArrayToStructureBigEndian(sbpiece); DicConsole.DebugWriteLine("XFS plugin", "magic at 0x{0:X3} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); @@ -139,13 +137,13 @@ namespace DiscImageChef.Filesystems foreach(int i in new[] {0, 1, 2}) { ulong location = (ulong)i; - uint sbSize = (uint)(Marshal.SizeOf(xfsSb) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(xfsSb) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); - if(sector.Length < Marshal.SizeOf(xfsSb)) return; + if(sector.Length < Marshal.SizeOf()) return; - xfsSb = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + xfsSb = Marshal.ByteArrayToStructureBigEndian(sector); DicConsole.DebugWriteLine("XFS plugin", "magic at {0} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); diff --git a/DiscImageChef.Filesystems/Xia.cs b/DiscImageChef.Filesystems/Xia.cs index 6fd107629..dcc1945df 100644 --- a/DiscImageChef.Filesystems/Xia.cs +++ b/DiscImageChef.Filesystems/Xia.cs @@ -36,6 +36,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -58,13 +59,13 @@ namespace DiscImageChef.Filesystems public bool Identify(IMediaImage imagePlugin, Partition partition) { - int sbSizeInBytes = Marshal.SizeOf(typeof(XiaSuperBlock)); + int sbSizeInBytes = Marshal.SizeOf(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if(sbSizeInBytes % imagePlugin.Info.SectorSize > 0) sbSizeInSectors++; if(sbSizeInSectors + partition.Start >= partition.End) return false; - byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors); - XiaSuperBlock supblk = Helpers.Marshal.ByteArrayToStructureLittleEndian(sbSector); + byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors); + XiaSuperBlock supblk = Marshal.ByteArrayToStructureLittleEndian(sbSector); return supblk.s_magic == XIAFS_SUPER_MAGIC; } @@ -77,12 +78,12 @@ namespace DiscImageChef.Filesystems StringBuilder sb = new StringBuilder(); - int sbSizeInBytes = Marshal.SizeOf(typeof(XiaSuperBlock)); + int sbSizeInBytes = Marshal.SizeOf(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if(sbSizeInBytes % imagePlugin.Info.SectorSize > 0) sbSizeInSectors++; - byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors); - XiaSuperBlock supblk = Helpers.Marshal.ByteArrayToStructureLittleEndian(sbSector); + byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors); + XiaSuperBlock supblk = Marshal.ByteArrayToStructureLittleEndian(sbSector); sb.AppendFormat("{0} bytes per zone", supblk.s_zone_size).AppendLine(); sb.AppendFormat("{0} zones in volume ({1} bytes)", supblk.s_nzones, supblk.s_nzones * supblk.s_zone_size) diff --git a/DiscImageChef.Filesystems/dump.cs b/DiscImageChef.Filesystems/dump.cs index a9dfc3609..ef9b163e1 100644 --- a/DiscImageChef.Filesystems/dump.cs +++ b/DiscImageChef.Filesystems/dump.cs @@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; using ufs_daddr_t = System.Int32; namespace DiscImageChef.Filesystems @@ -111,19 +112,15 @@ namespace DiscImageChef.Filesystems // It should be start of a tape or floppy or file if(partition.Start != 0) return false; - spcl16 oldHdr = new spcl16(); - spcl_aix aixHdr = new spcl_aix(); - s_spcl newHdr = new s_spcl(); - - uint sbSize = (uint)(Marshal.SizeOf(newHdr) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(newHdr) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(newHdr)) return false; + if(sector.Length < Marshal.SizeOf()) return false; - oldHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - aixHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - newHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + spcl16 oldHdr = Marshal.ByteArrayToStructureLittleEndian(sector); + spcl_aix aixHdr = Marshal.ByteArrayToStructureLittleEndian(sector); + s_spcl newHdr = Marshal.ByteArrayToStructureLittleEndian(sector); DicConsole.DebugWriteLine("dump(8) plugin", "old magic = 0x{0:X8}", oldHdr.c_magic); DicConsole.DebugWriteLine("dump(8) plugin", "aix magic = 0x{0:X8}", aixHdr.c_magic); @@ -143,19 +140,15 @@ namespace DiscImageChef.Filesystems if(partition.Start != 0) return; - spcl16 oldHdr = new spcl16(); - spcl_aix aixHdr = new spcl_aix(); - s_spcl newHdr = new s_spcl(); - - uint sbSize = (uint)(Marshal.SizeOf(newHdr) / imagePlugin.Info.SectorSize); - if(Marshal.SizeOf(newHdr) % imagePlugin.Info.SectorSize != 0) sbSize++; + uint sbSize = (uint)(Marshal.SizeOf() / imagePlugin.Info.SectorSize); + if(Marshal.SizeOf() % imagePlugin.Info.SectorSize != 0) sbSize++; byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); - if(sector.Length < Marshal.SizeOf(newHdr)) return; + if(sector.Length < Marshal.SizeOf()) return; - oldHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - aixHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); - newHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian(sector); + spcl16 oldHdr = Marshal.ByteArrayToStructureLittleEndian(sector); + spcl_aix aixHdr = Marshal.ByteArrayToStructureLittleEndian(sector); + s_spcl newHdr = Marshal.ByteArrayToStructureLittleEndian(sector); bool useOld = false; bool useAix = false; @@ -164,14 +157,13 @@ namespace DiscImageChef.Filesystems newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_MAGIC || newHdr.c_magic == UFS2_CIGAM) { if(newHdr.c_magic == OFS_CIGAM || newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_CIGAM) - newHdr = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + newHdr = Marshal.ByteArrayToStructureBigEndian(sector); } else if(aixHdr.c_magic == XIX_MAGIC || aixHdr.c_magic == XIX_CIGAM) { useAix = true; - if(aixHdr.c_magic == XIX_CIGAM) - aixHdr = Helpers.Marshal.ByteArrayToStructureBigEndian(sector); + if(aixHdr.c_magic == XIX_CIGAM) aixHdr = Marshal.ByteArrayToStructureBigEndian(sector); } else if(oldHdr.c_magic == OFS_MAGIC) { diff --git a/DiscImageChef.Filesystems/exFAT.cs b/DiscImageChef.Filesystems/exFAT.cs index 4e342cf83..caa08ec8c 100644 --- a/DiscImageChef.Filesystems/exFAT.cs +++ b/DiscImageChef.Filesystems/exFAT.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -60,7 +61,7 @@ namespace DiscImageChef.Filesystems byte[] vbrSector = imagePlugin.ReadSector(0 + partition.Start); if(vbrSector.Length < 512) return false; - VolumeBootRecord vbr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vbrSector); + VolumeBootRecord vbr = Marshal.ByteArrayToStructureLittleEndian(vbrSector); return signature.SequenceEqual(vbr.signature); } @@ -74,15 +75,15 @@ namespace DiscImageChef.Filesystems StringBuilder sb = new StringBuilder(); XmlFsType = new FileSystemType(); - byte[] vbrSector = imagePlugin.ReadSector(0 + partition.Start); - VolumeBootRecord vbr = Helpers.Marshal.ByteArrayToStructureLittleEndian(vbrSector); + byte[] vbrSector = imagePlugin.ReadSector(0 + partition.Start); + VolumeBootRecord vbr = Marshal.ByteArrayToStructureLittleEndian(vbrSector); byte[] parametersSector = imagePlugin.ReadSector(9 + partition.Start); OemParameterTable parametersTable = - Helpers.Marshal.ByteArrayToStructureLittleEndian(parametersSector); + Marshal.ByteArrayToStructureLittleEndian(parametersSector); - byte[] chkSector = imagePlugin.ReadSector(11 + partition.Start); - ChecksumSector chksector = Helpers.Marshal.ByteArrayToStructureLittleEndian(chkSector); + byte[] chkSector = imagePlugin.ReadSector(11 + partition.Start); + ChecksumSector chksector = Marshal.ByteArrayToStructureLittleEndian(chkSector); sb.AppendLine("Microsoft exFAT"); sb.AppendFormat("Partition offset: {0}", vbr.offset).AppendLine(); diff --git a/DiscImageChef.Filesystems/ext2FS.cs b/DiscImageChef.Filesystems/ext2FS.cs index 9ab1e49f2..41e56e287 100644 --- a/DiscImageChef.Filesystems/ext2FS.cs +++ b/DiscImageChef.Filesystems/ext2FS.cs @@ -37,6 +37,7 @@ using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; +using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { @@ -174,7 +175,7 @@ namespace DiscImageChef.Filesystems if(sbSectorOff + partition.Start >= partition.End) return false; - int sbSizeInBytes = Marshal.SizeOf(typeof(ext2FSSuperBlock)); + int sbSizeInBytes = Marshal.SizeOf(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if(sbSizeInBytes % imagePlugin.Info.SectorSize > 0) sbSizeInSectors++; @@ -199,7 +200,7 @@ namespace DiscImageChef.Filesystems bool ext3 = false; bool ext4 = false; - int sbSizeInBytes = Marshal.SizeOf(typeof(ext2FSSuperBlock)); + int sbSizeInBytes = Marshal.SizeOf(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if(sbSizeInBytes % imagePlugin.Info.SectorSize > 0) sbSizeInSectors++; @@ -209,7 +210,7 @@ namespace DiscImageChef.Filesystems byte[] sbSector = imagePlugin.ReadSectors(sbSectorOff + partition.Start, sbSizeInSectors); byte[] sblock = new byte[sbSizeInBytes]; Array.Copy(sbSector, sbOff, sblock, 0, sbSizeInBytes); - ext2FSSuperBlock supblk = Helpers.Marshal.ByteArrayToStructureLittleEndian(sblock); + ext2FSSuperBlock supblk = Marshal.ByteArrayToStructureLittleEndian(sblock); XmlFsType = new FileSystemType(); diff --git a/DiscImageChef.Helpers/Marshal.cs b/DiscImageChef.Helpers/Marshal.cs index 86f6987ed..869c67dc1 100644 --- a/DiscImageChef.Helpers/Marshal.cs +++ b/DiscImageChef.Helpers/Marshal.cs @@ -39,6 +39,13 @@ namespace DiscImageChef.Helpers /// Provides methods to marshal binary data into C# structs public static class Marshal { + /// + /// Returns the size of an unmanaged type in bytes. + /// + /// The type whose size is to be returned. + /// The size, in bytes, of the type that is specified by the generic type parameter. + public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); + /// /// Marshal little-endian binary data to a structure ///