Use new marshaller in dicformat.

This commit is contained in:
2019-03-15 22:07:10 +00:00
parent e8c75801ba
commit 7e741bd9c1
4 changed files with 78 additions and 220 deletions

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
@@ -46,9 +47,9 @@ using DiscImageChef.CommonTypes.Exceptions;
using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.CommonTypes.Structs; using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console; using DiscImageChef.Console;
using DiscImageChef.Helpers;
using Schemas; using Schemas;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using Marshal = DiscImageChef.Helpers.Marshal;
using TrackType = DiscImageChef.CommonTypes.Enums.TrackType; using TrackType = DiscImageChef.CommonTypes.Enums.TrackType;
namespace DiscImageChef.DiscImages namespace DiscImageChef.DiscImages
@@ -78,7 +79,7 @@ namespace DiscImageChef.DiscImages
imageStream.Position = (long)header.indexOffset; imageStream.Position = (long)header.indexOffset;
structureBytes = new byte[Marshal.SizeOf<IndexHeader>()]; structureBytes = new byte[Marshal.SizeOf<IndexHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
IndexHeader idxHeader = Marshal.ByteArrayToStructureLittleEndian<IndexHeader>(structureBytes); IndexHeader idxHeader = Marshal.SpanToStructureLittleEndian<IndexHeader>(structureBytes);
if(idxHeader.identifier != BlockType.Index) throw new FeatureUnsupportedImageException("Index not found!"); if(idxHeader.identifier != BlockType.Index) throw new FeatureUnsupportedImageException("Index not found!");
@@ -91,7 +92,7 @@ namespace DiscImageChef.DiscImages
{ {
structureBytes = new byte[Marshal.SizeOf<IndexEntry>()]; structureBytes = new byte[Marshal.SizeOf<IndexEntry>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
IndexEntry entry = Marshal.ByteArrayToStructureLittleEndian<IndexEntry>(structureBytes); IndexEntry entry = Marshal.SpanToStructureLittleEndian<IndexEntry>(structureBytes);
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
"Block type {0} with data type {1} is indexed to be at {2}", entry.blockType, "Block type {0} with data type {1} is indexed to be at {2}", entry.blockType,
entry.dataType, entry.offset); entry.dataType, entry.offset);
@@ -115,7 +116,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
BlockHeader blockHeader = Marshal.ByteArrayToStructureLittleEndian<BlockHeader>(structureBytes); BlockHeader blockHeader = Marshal.SpanToStructureLittleEndian<BlockHeader>(structureBytes);
imageInfo.ImageSize += blockHeader.cmpLength; imageInfo.ImageSize += blockHeader.cmpLength;
// Unused, skip // Unused, skip
@@ -279,7 +280,7 @@ namespace DiscImageChef.DiscImages
{ {
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DdtHeader ddtHeader = Marshal.ByteArrayToStructureLittleEndian<DdtHeader>(structureBytes); DdtHeader ddtHeader = Marshal.SpanToStructureLittleEndian<DdtHeader>(structureBytes);
imageInfo.ImageSize += ddtHeader.cmpLength; imageInfo.ImageSize += ddtHeader.cmpLength;
if(ddtHeader.identifier != BlockType.DeDuplicationTable) break; if(ddtHeader.identifier != BlockType.DeDuplicationTable) break;
@@ -303,10 +304,7 @@ namespace DiscImageChef.DiscImages
lzmaDdt.Read(decompressedDdt, 0, (int)ddtHeader.length); lzmaDdt.Read(decompressedDdt, 0, (int)ddtHeader.length);
lzmaDdt.Close(); lzmaDdt.Close();
compressedDdtMs.Close(); compressedDdtMs.Close();
userDataDdt = new ulong[ddtHeader.entries]; userDataDdt = MemoryMarshal.Cast<byte, ulong>(decompressedDdt).ToArray();
for(ulong i = 0; i < ddtHeader.entries; i++)
userDataDdt[i] =
BitConverter.ToUInt64(decompressedDdt, (int)(i * sizeof(ulong)));
DateTime ddtEnd = DateTime.UtcNow; DateTime ddtEnd = DateTime.UtcNow;
inMemoryDdt = true; inMemoryDdt = true;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -329,7 +327,7 @@ namespace DiscImageChef.DiscImages
{ {
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DdtHeader ddtHeader = Marshal.ByteArrayToStructureLittleEndian<DdtHeader>(structureBytes); DdtHeader ddtHeader = Marshal.SpanToStructureLittleEndian<DdtHeader>(structureBytes);
imageInfo.ImageSize += ddtHeader.cmpLength; imageInfo.ImageSize += ddtHeader.cmpLength;
if(ddtHeader.identifier != BlockType.DeDuplicationTable) break; if(ddtHeader.identifier != BlockType.DeDuplicationTable) break;
@@ -365,8 +363,7 @@ namespace DiscImageChef.DiscImages
ImageNotSupportedException($"Found unsupported compression algorithm {(ushort)ddtHeader.compression}"); ImageNotSupportedException($"Found unsupported compression algorithm {(ushort)ddtHeader.compression}");
} }
for(ulong i = 0; i < ddtHeader.entries; i++) cdDdt = MemoryMarshal.Cast<byte, uint>(decompressedDdt).ToArray();
cdDdt[i] = BitConverter.ToUInt32(decompressedDdt, (int)(i * sizeof(uint)));
if(entry.dataType == DataType.CdSectorPrefixCorrected) sectorPrefixDdt = cdDdt; if(entry.dataType == DataType.CdSectorPrefixCorrected) sectorPrefixDdt = cdDdt;
else if(entry.dataType == DataType.CdSectorSuffixCorrected) sectorSuffixDdt = cdDdt; else if(entry.dataType == DataType.CdSectorSuffixCorrected) sectorSuffixDdt = cdDdt;
@@ -377,7 +374,7 @@ namespace DiscImageChef.DiscImages
case BlockType.GeometryBlock: case BlockType.GeometryBlock:
structureBytes = new byte[Marshal.SizeOf<GeometryBlock>()]; structureBytes = new byte[Marshal.SizeOf<GeometryBlock>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
geometryBlock = Marshal.ByteArrayToStructureLittleEndian<GeometryBlock>(structureBytes); geometryBlock = Marshal.SpanToStructureLittleEndian<GeometryBlock>(structureBytes);
if(geometryBlock.identifier == BlockType.GeometryBlock) if(geometryBlock.identifier == BlockType.GeometryBlock)
{ {
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -395,7 +392,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<MetadataBlock>()]; structureBytes = new byte[Marshal.SizeOf<MetadataBlock>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
MetadataBlock metadataBlock = MetadataBlock metadataBlock =
Marshal.ByteArrayToStructureLittleEndian<MetadataBlock>(structureBytes); Marshal.SpanToStructureLittleEndian<MetadataBlock>(structureBytes);
if(metadataBlock.identifier != entry.blockType) if(metadataBlock.identifier != entry.blockType)
{ {
@@ -562,8 +559,7 @@ namespace DiscImageChef.DiscImages
case BlockType.TracksBlock: case BlockType.TracksBlock:
structureBytes = new byte[Marshal.SizeOf<TracksHeader>()]; structureBytes = new byte[Marshal.SizeOf<TracksHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
TracksHeader tracksHeader = TracksHeader tracksHeader = Marshal.SpanToStructureLittleEndian<TracksHeader>(structureBytes);
Marshal.ByteArrayToStructureLittleEndian<TracksHeader>(structureBytes);
if(tracksHeader.identifier != BlockType.TracksBlock) if(tracksHeader.identifier != BlockType.TracksBlock)
{ {
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -624,7 +620,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<CicmMetadataBlock>()]; structureBytes = new byte[Marshal.SizeOf<CicmMetadataBlock>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
CicmMetadataBlock cicmBlock = CicmMetadataBlock cicmBlock =
Marshal.ByteArrayToStructureLittleEndian<CicmMetadataBlock>(structureBytes); Marshal.SpanToStructureLittleEndian<CicmMetadataBlock>(structureBytes);
if(cicmBlock.identifier != BlockType.CicmBlock) break; if(cicmBlock.identifier != BlockType.CicmBlock) break;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -653,7 +649,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<DumpHardwareHeader>()]; structureBytes = new byte[Marshal.SizeOf<DumpHardwareHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DumpHardwareHeader dumpBlock = DumpHardwareHeader dumpBlock =
Marshal.ByteArrayToStructureLittleEndian<DumpHardwareHeader>(structureBytes); Marshal.SpanToStructureLittleEndian<DumpHardwareHeader>(structureBytes);
if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break; if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -679,7 +675,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<DumpHardwareEntry>()]; structureBytes = new byte[Marshal.SizeOf<DumpHardwareEntry>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DumpHardwareEntry dumpEntry = DumpHardwareEntry dumpEntry =
Marshal.ByteArrayToStructureLittleEndian<DumpHardwareEntry>(structureBytes); Marshal.SpanToStructureLittleEndian<DumpHardwareEntry>(structureBytes);
DumpHardwareType dump = new DumpHardwareType DumpHardwareType dump = new DumpHardwareType
{ {
@@ -923,7 +919,7 @@ namespace DiscImageChef.DiscImages
imageStream.Position = (long)blockOffset; imageStream.Position = (long)blockOffset;
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
blockHeader = Marshal.ByteArrayToStructureLittleEndian<BlockHeader>(structureBytes); blockHeader = Marshal.SpanToStructureLittleEndian<BlockHeader>(structureBytes);
// Decompress block // Decompress block
switch(blockHeader.compression) switch(blockHeader.compression)

View File

@@ -290,14 +290,6 @@ namespace DiscImageChef.DiscImages
public uint extents; public uint extents;
} }
/// <summary>Dump hardware extent, first and last sector dumped, both inclusive</summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DumpHardwareExtent
{
public ulong start;
public ulong end;
}
/// <summary> /// <summary>
/// Checksum block, contains a checksum of all user data sectors (except for optical discs that is 2352 bytes raw /// Checksum block, contains a checksum of all user data sectors (except for optical discs that is 2352 bytes raw
/// sector if available /// sector if available

View File

@@ -50,7 +50,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<IndexHeader>()]; structureBytes = new byte[Marshal.SizeOf<IndexHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
IndexHeader idxHeader = Marshal.ByteArrayToStructureLittleEndian<IndexHeader>(structureBytes); IndexHeader idxHeader = Marshal.SpanToStructureLittleEndian<IndexHeader>(structureBytes);
if(idxHeader.identifier != BlockType.Index) if(idxHeader.identifier != BlockType.Index)
{ {
@@ -79,7 +79,7 @@ namespace DiscImageChef.DiscImages
{ {
structureBytes = new byte[Marshal.SizeOf<IndexEntry>()]; structureBytes = new byte[Marshal.SizeOf<IndexEntry>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
IndexEntry entry = Marshal.ByteArrayToStructureLittleEndian<IndexEntry>(structureBytes); IndexEntry entry = Marshal.SpanToStructureLittleEndian<IndexEntry>(structureBytes);
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
"Block type {0} with data type {1} is indexed to be at {2}", entry.blockType, "Block type {0} with data type {1} is indexed to be at {2}", entry.blockType,
entry.dataType, entry.offset); entry.dataType, entry.offset);
@@ -101,7 +101,7 @@ namespace DiscImageChef.DiscImages
case BlockType.DataBlock: case BlockType.DataBlock:
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
BlockHeader blockHeader = Marshal.ByteArrayToStructureLittleEndian<BlockHeader>(structureBytes); BlockHeader blockHeader = Marshal.SpanToStructureLittleEndian<BlockHeader>(structureBytes);
crcVerify = new Crc64Context(); crcVerify = new Crc64Context();
readBytes = 0; readBytes = 0;
@@ -136,7 +136,7 @@ namespace DiscImageChef.DiscImages
case BlockType.DeDuplicationTable: case BlockType.DeDuplicationTable:
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DdtHeader ddtHeader = Marshal.ByteArrayToStructureLittleEndian<DdtHeader>(structureBytes); DdtHeader ddtHeader = Marshal.SpanToStructureLittleEndian<DdtHeader>(structureBytes);
crcVerify = new Crc64Context(); crcVerify = new Crc64Context();
readBytes = 0; readBytes = 0;
@@ -171,7 +171,7 @@ namespace DiscImageChef.DiscImages
case BlockType.TracksBlock: case BlockType.TracksBlock:
structureBytes = new byte[Marshal.SizeOf<TracksHeader>()]; structureBytes = new byte[Marshal.SizeOf<TracksHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
TracksHeader trkHeader = Marshal.ByteArrayToStructureLittleEndian<TracksHeader>(structureBytes); TracksHeader trkHeader = Marshal.SpanToStructureLittleEndian<TracksHeader>(structureBytes);
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
"Track block at {0} contains {1} entries", header.indexOffset, "Track block at {0} contains {1} entries", header.indexOffset,

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
@@ -47,9 +48,9 @@ using DiscImageChef.CommonTypes.Exceptions;
using DiscImageChef.CommonTypes.Structs; using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console; using DiscImageChef.Console;
using DiscImageChef.Decoders; using DiscImageChef.Decoders;
using DiscImageChef.Helpers;
using Schemas; using Schemas;
using SharpCompress.Compressors.LZMA; using SharpCompress.Compressors.LZMA;
using Marshal = DiscImageChef.Helpers.Marshal;
using TrackType = DiscImageChef.CommonTypes.Enums.TrackType; using TrackType = DiscImageChef.CommonTypes.Enums.TrackType;
namespace DiscImageChef.DiscImages namespace DiscImageChef.DiscImages
@@ -262,7 +263,7 @@ namespace DiscImageChef.DiscImages
imageStream.Position = (long)header.indexOffset; imageStream.Position = (long)header.indexOffset;
structureBytes = new byte[Marshal.SizeOf<IndexHeader>()]; structureBytes = new byte[Marshal.SizeOf<IndexHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
IndexHeader idxHeader = Marshal.ByteArrayToStructureLittleEndian<IndexHeader>(structureBytes); IndexHeader idxHeader = Marshal.SpanToStructureLittleEndian<IndexHeader>(structureBytes);
if(idxHeader.identifier != BlockType.Index) if(idxHeader.identifier != BlockType.Index)
{ {
@@ -277,7 +278,7 @@ namespace DiscImageChef.DiscImages
{ {
structureBytes = new byte[Marshal.SizeOf<IndexEntry>()]; structureBytes = new byte[Marshal.SizeOf<IndexEntry>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
IndexEntry entry = Marshal.ByteArrayToStructureLittleEndian<IndexEntry>(structureBytes); IndexEntry entry = Marshal.SpanToStructureLittleEndian<IndexEntry>(structureBytes);
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
"Block type {0} with data type {1} is indexed to be at {2}", "Block type {0} with data type {1} is indexed to be at {2}",
entry.blockType, entry.dataType, entry.offset); entry.blockType, entry.dataType, entry.offset);
@@ -309,8 +310,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
BlockHeader blockHeader = BlockHeader blockHeader = Marshal.SpanToStructureLittleEndian<BlockHeader>(structureBytes);
Marshal.ByteArrayToStructureLittleEndian<BlockHeader>(structureBytes);
imageInfo.ImageSize += blockHeader.cmpLength; imageInfo.ImageSize += blockHeader.cmpLength;
if(blockHeader.identifier != entry.blockType) if(blockHeader.identifier != entry.blockType)
@@ -433,10 +433,7 @@ namespace DiscImageChef.DiscImages
lzmaDdt.Read(decompressedDdt, 0, (int)ddtHeader.length); lzmaDdt.Read(decompressedDdt, 0, (int)ddtHeader.length);
lzmaDdt.Close(); lzmaDdt.Close();
compressedDdtMs.Close(); compressedDdtMs.Close();
userDataDdt = new ulong[ddtHeader.entries]; userDataDdt = MemoryMarshal.Cast<byte, ulong>(decompressedDdt).ToArray();
for(ulong i = 0; i < ddtHeader.entries; i++)
userDataDdt[i] =
BitConverter.ToUInt64(decompressedDdt, (int)(i * sizeof(ulong)));
DateTime ddtEnd = DateTime.UtcNow; DateTime ddtEnd = DateTime.UtcNow;
inMemoryDdt = true; inMemoryDdt = true;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -472,7 +469,6 @@ namespace DiscImageChef.DiscImages
} }
byte[] decompressedDdt = new byte[ddtHeader.length]; byte[] decompressedDdt = new byte[ddtHeader.length];
uint[] cdDdt = new uint[ddtHeader.entries];
switch(ddtHeader.compression) switch(ddtHeader.compression)
{ {
@@ -503,8 +499,7 @@ namespace DiscImageChef.DiscImages
ImageNotSupportedException($"Found unsupported compression algorithm {(ushort)ddtHeader.compression}"); ImageNotSupportedException($"Found unsupported compression algorithm {(ushort)ddtHeader.compression}");
} }
for(ulong i = 0; i < ddtHeader.entries; i++) uint[] cdDdt = MemoryMarshal.Cast<byte, uint>(decompressedDdt).ToArray();
cdDdt[i] = BitConverter.ToUInt32(decompressedDdt, (int)(i * sizeof(uint)));
switch(entry.dataType) switch(entry.dataType)
{ {
@@ -523,7 +518,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<CicmMetadataBlock>()]; structureBytes = new byte[Marshal.SizeOf<CicmMetadataBlock>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
CicmMetadataBlock cicmBlock = CicmMetadataBlock cicmBlock =
Marshal.ByteArrayToStructureLittleEndian<CicmMetadataBlock>(structureBytes); Marshal.SpanToStructureLittleEndian<CicmMetadataBlock>(structureBytes);
if(cicmBlock.identifier != BlockType.CicmBlock) break; if(cicmBlock.identifier != BlockType.CicmBlock) break;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -553,7 +548,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<DumpHardwareHeader>()]; structureBytes = new byte[Marshal.SizeOf<DumpHardwareHeader>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DumpHardwareHeader dumpBlock = DumpHardwareHeader dumpBlock =
Marshal.ByteArrayToStructureLittleEndian<DumpHardwareHeader>(structureBytes); Marshal.SpanToStructureLittleEndian<DumpHardwareHeader>(structureBytes);
if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break; if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -579,7 +574,7 @@ namespace DiscImageChef.DiscImages
structureBytes = new byte[Marshal.SizeOf<DumpHardwareEntry>()]; structureBytes = new byte[Marshal.SizeOf<DumpHardwareEntry>()];
imageStream.Read(structureBytes, 0, structureBytes.Length); imageStream.Read(structureBytes, 0, structureBytes.Length);
DumpHardwareEntry dumpEntry = DumpHardwareEntry dumpEntry =
Marshal.ByteArrayToStructureLittleEndian<DumpHardwareEntry>(structureBytes); Marshal.SpanToStructureLittleEndian<DumpHardwareEntry>(structureBytes);
DumpHardwareType dump = new DumpHardwareType DumpHardwareType dump = new DumpHardwareType
{ {
@@ -717,12 +712,8 @@ namespace DiscImageChef.DiscImages
length = sectors * sizeof(ulong) length = sectors * sizeof(ulong)
}; };
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<DdtHeader>());
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref ddtHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
structureBytes = null; structureBytes = null;
@@ -932,11 +923,8 @@ namespace DiscImageChef.DiscImages
offset = (ulong)imageStream.Position offset = (ulong)imageStream.Position
}); });
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(currentBlockHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref currentBlockHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
structureBytes = null; structureBytes = null;
if(currentBlockHeader.compression == CompressionType.Lzma) if(currentBlockHeader.compression == CompressionType.Lzma)
@@ -1524,11 +1512,8 @@ namespace DiscImageChef.DiscImages
offset = (ulong)imageStream.Position offset = (ulong)imageStream.Position
}); });
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(currentBlockHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref currentBlockHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
structureBytes = null; structureBytes = null;
if(currentBlockHeader.compression == CompressionType.Lzma) if(currentBlockHeader.compression == CompressionType.Lzma)
@@ -1596,11 +1581,8 @@ namespace DiscImageChef.DiscImages
blockStream.Close(); blockStream.Close();
blockStream = null; blockStream = null;
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(tagBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref tagBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(tagBlock.compression == CompressionType.Lzma) if(tagBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -1624,11 +1606,8 @@ namespace DiscImageChef.DiscImages
DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing geometry block to position {0}", DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing geometry block to position {0}",
idxEntry.offset); idxEntry.offset);
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<GeometryBlock>());
structureBytes = new byte[Marshal.SizeOf<GeometryBlock>()]; structureBytes = new byte[Marshal.SizeOf<GeometryBlock>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(geometryBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref geometryBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
index.RemoveAll(t => t.blockType == BlockType.GeometryBlock && t.dataType == DataType.NoData); index.RemoveAll(t => t.blockType == BlockType.GeometryBlock && t.dataType == DataType.NoData);
@@ -1680,13 +1659,8 @@ namespace DiscImageChef.DiscImages
extents = (uint)dump.Extents.Length extents = (uint)dump.Extents.Length
}; };
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<DumpHardwareEntry>());
structureBytes = new byte[Marshal.SizeOf<DumpHardwareEntry>()]; structureBytes = new byte[Marshal.SizeOf<DumpHardwareEntry>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(dumpEntry, structurePointer, true); MemoryMarshal.Write(structureBytes, ref dumpEntry);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
dumpMs.Write(structureBytes, 0, structureBytes.Length); dumpMs.Write(structureBytes, 0, structureBytes.Length);
if(dumpManufacturer != null) if(dumpManufacturer != null)
@@ -1763,12 +1737,8 @@ namespace DiscImageChef.DiscImages
length = (uint)dumpMs.Length length = (uint)dumpMs.Length
}; };
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<DumpHardwareHeader>());
structureBytes = new byte[Marshal.SizeOf<DumpHardwareHeader>()]; structureBytes = new byte[Marshal.SizeOf<DumpHardwareHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(dumpBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref dumpBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
imageStream.Write(dumpMs.ToArray(), 0, (int)dumpMs.Length); imageStream.Write(dumpMs.ToArray(), 0, (int)dumpMs.Length);
@@ -1796,12 +1766,8 @@ namespace DiscImageChef.DiscImages
CicmMetadataBlock cicmBlock = CicmMetadataBlock cicmBlock =
new CicmMetadataBlock {identifier = BlockType.CicmBlock, length = (uint)cicmMs.Length}; new CicmMetadataBlock {identifier = BlockType.CicmBlock, length = (uint)cicmMs.Length};
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<CicmMetadataBlock>());
structureBytes = new byte[Marshal.SizeOf<CicmMetadataBlock>()]; structureBytes = new byte[Marshal.SizeOf<CicmMetadataBlock>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(cicmBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref cicmBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
imageStream.Write(cicmMs.ToArray(), 0, (int)cicmMs.Length); imageStream.Write(cicmMs.ToArray(), 0, (int)cicmMs.Length);
@@ -1821,13 +1787,8 @@ namespace DiscImageChef.DiscImages
byte[] md5 = md5Provider.Final(); byte[] md5 = md5Provider.Final();
ChecksumEntry md5Entry = ChecksumEntry md5Entry =
new ChecksumEntry {type = ChecksumAlgorithm.Md5, length = (uint)md5.Length}; new ChecksumEntry {type = ChecksumAlgorithm.Md5, length = (uint)md5.Length};
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<ChecksumEntry>());
structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()]; structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(md5Entry, structurePointer, true); MemoryMarshal.Write(structureBytes, ref md5Entry);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(structureBytes, 0, structureBytes.Length);
chkMs.Write(md5, 0, md5.Length); chkMs.Write(md5, 0, md5.Length);
chkHeader.entries++; chkHeader.entries++;
@@ -1838,13 +1799,8 @@ namespace DiscImageChef.DiscImages
byte[] sha1 = sha1Provider.Final(); byte[] sha1 = sha1Provider.Final();
ChecksumEntry sha1Entry = ChecksumEntry sha1Entry =
new ChecksumEntry {type = ChecksumAlgorithm.Sha1, length = (uint)sha1.Length}; new ChecksumEntry {type = ChecksumAlgorithm.Sha1, length = (uint)sha1.Length};
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<ChecksumEntry>());
structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()]; structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(sha1Entry, structurePointer, true); MemoryMarshal.Write(structureBytes, ref sha1Entry);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(structureBytes, 0, structureBytes.Length);
chkMs.Write(sha1, 0, sha1.Length); chkMs.Write(sha1, 0, sha1.Length);
chkHeader.entries++; chkHeader.entries++;
@@ -1855,13 +1811,8 @@ namespace DiscImageChef.DiscImages
byte[] sha256 = sha256Provider.Final(); byte[] sha256 = sha256Provider.Final();
ChecksumEntry sha256Entry = ChecksumEntry sha256Entry =
new ChecksumEntry {type = ChecksumAlgorithm.Sha256, length = (uint)sha256.Length}; new ChecksumEntry {type = ChecksumAlgorithm.Sha256, length = (uint)sha256.Length};
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<ChecksumEntry>());
structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()]; structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(sha256Entry, structurePointer, true); MemoryMarshal.Write(structureBytes, ref sha256Entry);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(structureBytes, 0, structureBytes.Length);
chkMs.Write(sha256, 0, sha256.Length); chkMs.Write(sha256, 0, sha256.Length);
chkHeader.entries++; chkHeader.entries++;
@@ -1872,13 +1823,8 @@ namespace DiscImageChef.DiscImages
byte[] spamsum = Encoding.ASCII.GetBytes(spamsumProvider.End()); byte[] spamsum = Encoding.ASCII.GetBytes(spamsumProvider.End());
ChecksumEntry spamsumEntry = ChecksumEntry spamsumEntry =
new ChecksumEntry {type = ChecksumAlgorithm.SpamSum, length = (uint)spamsum.Length}; new ChecksumEntry {type = ChecksumAlgorithm.SpamSum, length = (uint)spamsum.Length};
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<ChecksumEntry>());
structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()]; structureBytes = new byte[Marshal.SizeOf<ChecksumEntry>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(spamsumEntry, structurePointer, true); MemoryMarshal.Write(structureBytes, ref spamsumEntry);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
chkMs.Write(structureBytes, 0, structureBytes.Length); chkMs.Write(structureBytes, 0, structureBytes.Length);
chkMs.Write(spamsum, 0, spamsum.Length); chkMs.Write(spamsum, 0, spamsum.Length);
chkHeader.entries++; chkHeader.entries++;
@@ -1897,13 +1843,8 @@ namespace DiscImageChef.DiscImages
DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing checksum block to position {0}", DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing checksum block to position {0}",
idxEntry.offset); idxEntry.offset);
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<ChecksumHeader>());
structureBytes = new byte[Marshal.SizeOf<ChecksumHeader>()]; structureBytes = new byte[Marshal.SizeOf<ChecksumHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(chkHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref chkHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
imageStream.Write(chkMs.ToArray(), 0, (int)chkMs.Length); imageStream.Write(chkMs.ToArray(), 0, (int)chkMs.Length);
@@ -1939,12 +1880,9 @@ namespace DiscImageChef.DiscImages
blockStream = new MemoryStream(); blockStream = new MemoryStream();
MemoryStream userDataDdtStream = new MemoryStream(); MemoryStream userDataDdtStream = new MemoryStream();
crc64 = new Crc64Context(); crc64 = new Crc64Context();
for(ulong i = 0; i < (ulong)userDataDdt.LongLength; i++) byte[] ddtEntries = MemoryMarshal.Cast<ulong, byte>(userDataDdt).ToArray();
{ crc64.Update(ddtEntries);
byte[] ddtEntry = BitConverter.GetBytes(userDataDdt[i]); userDataDdtStream.Write(ddtEntries, 0, ddtEntries.Length);
crc64.Update(ddtEntry);
userDataDdtStream.Write(ddtEntry, 0, ddtEntry.Length);
}
byte[] lzmaProperties = byte[] lzmaProperties =
CompressDataToStreamWithLZMA(userDataDdtStream.ToArray(), lzmaEncoderProperties, blockStream, CompressDataToStreamWithLZMA(userDataDdtStream.ToArray(), lzmaEncoderProperties, blockStream,
@@ -1956,11 +1894,8 @@ namespace DiscImageChef.DiscImages
cmpCrc64Context.Update(blockStream.ToArray()); cmpCrc64Context.Update(blockStream.ToArray());
ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0);
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<DdtHeader>());
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref ddtHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
structureBytes = null; structureBytes = null;
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2033,13 +1968,8 @@ namespace DiscImageChef.DiscImages
(endCompress - startCompress).TotalSeconds); (endCompress - startCompress).TotalSeconds);
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(prefixBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref prefixBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(prefixBlock.compression == CompressionType.Lzma) if(prefixBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2101,13 +2031,8 @@ namespace DiscImageChef.DiscImages
(endCompress - startCompress).TotalSeconds); (endCompress - startCompress).TotalSeconds);
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(prefixBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref prefixBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(prefixBlock.compression == CompressionType.Lzma) if(prefixBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2194,12 +2119,9 @@ namespace DiscImageChef.DiscImages
blockStream = new MemoryStream(); blockStream = new MemoryStream();
MemoryStream sectorPrefixDdtStream = new MemoryStream(); MemoryStream sectorPrefixDdtStream = new MemoryStream();
crc64 = new Crc64Context(); crc64 = new Crc64Context();
for(ulong i = 0; i < (ulong)sectorPrefixDdt.LongLength; i++) byte[] ddtEntries = MemoryMarshal.Cast<uint, byte>(sectorPrefixDdt).ToArray();
{ crc64.Update(ddtEntries);
byte[] ddtEntry = BitConverter.GetBytes(sectorPrefixDdt[i]); sectorPrefixDdtStream.Write(ddtEntries, 0, ddtEntries.Length);
crc64.Update(ddtEntry);
sectorPrefixDdtStream.Write(ddtEntry, 0, ddtEntry.Length);
}
byte[] lzmaProperties = byte[] lzmaProperties =
CompressDataToStreamWithLZMA(sectorPrefixDdtStream.ToArray(), lzmaEncoderProperties, CompressDataToStreamWithLZMA(sectorPrefixDdtStream.ToArray(), lzmaEncoderProperties,
@@ -2211,13 +2133,8 @@ namespace DiscImageChef.DiscImages
cmpCrc64Context.Update(blockStream.ToArray()); cmpCrc64Context.Update(blockStream.ToArray());
ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0);
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<DdtHeader>());
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref ddtHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
structureBytes = null; structureBytes = null;
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2253,12 +2170,9 @@ namespace DiscImageChef.DiscImages
blockStream = new MemoryStream(); blockStream = new MemoryStream();
MemoryStream sectorSuffixDdtStream = new MemoryStream(); MemoryStream sectorSuffixDdtStream = new MemoryStream();
crc64 = new Crc64Context(); crc64 = new Crc64Context();
for(ulong i = 0; i < (ulong)sectorSuffixDdt.LongLength; i++) ddtEntries = MemoryMarshal.Cast<uint, byte>(sectorSuffixDdt).ToArray();
{ crc64.Update(ddtEntries);
byte[] ddtEntry = BitConverter.GetBytes(sectorSuffixDdt[i]); sectorSuffixDdtStream.Write(ddtEntries, 0, ddtEntries.Length);
crc64.Update(ddtEntry);
sectorSuffixDdtStream.Write(ddtEntry, 0, ddtEntry.Length);
}
lzmaProperties = lzmaProperties =
CompressDataToStreamWithLZMA(sectorSuffixDdtStream.ToArray(), lzmaEncoderProperties, CompressDataToStreamWithLZMA(sectorSuffixDdtStream.ToArray(), lzmaEncoderProperties,
@@ -2269,13 +2183,8 @@ namespace DiscImageChef.DiscImages
cmpCrc64Context.Update(blockStream.ToArray()); cmpCrc64Context.Update(blockStream.ToArray());
ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0);
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<DdtHeader>());
structureBytes = new byte[Marshal.SizeOf<DdtHeader>()]; structureBytes = new byte[Marshal.SizeOf<DdtHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(ddtHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref ddtHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
structureBytes = null; structureBytes = null;
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2341,13 +2250,8 @@ namespace DiscImageChef.DiscImages
(endCompress - startCompress).TotalSeconds); (endCompress - startCompress).TotalSeconds);
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(prefixBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref prefixBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(prefixBlock.compression == CompressionType.Lzma) if(prefixBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2413,13 +2317,8 @@ namespace DiscImageChef.DiscImages
(endCompress - startCompress).TotalSeconds); (endCompress - startCompress).TotalSeconds);
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(suffixBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref suffixBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(suffixBlock.compression == CompressionType.Lzma) if(suffixBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2487,13 +2386,8 @@ namespace DiscImageChef.DiscImages
(endCompress - startCompress).TotalSeconds); (endCompress - startCompress).TotalSeconds);
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(subheaderBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref subheaderBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(subheaderBlock.compression == CompressionType.Lzma) if(subheaderBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2562,13 +2456,8 @@ namespace DiscImageChef.DiscImages
(endCompress - startCompress).TotalSeconds); (endCompress - startCompress).TotalSeconds);
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(subchannelBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref subchannelBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(subchannelBlock.compression == CompressionType.Lzma || subchannelBlock.compression == if(subchannelBlock.compression == CompressionType.Lzma || subchannelBlock.compression ==
CompressionType.LzmaClauniaSubchannelTransform) CompressionType.LzmaClauniaSubchannelTransform)
@@ -2642,13 +2531,8 @@ namespace DiscImageChef.DiscImages
offset = (ulong)imageStream.Position offset = (ulong)imageStream.Position
}); });
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<TracksHeader>());
structureBytes = new byte[Marshal.SizeOf<TracksHeader>()]; structureBytes = new byte[Marshal.SizeOf<TracksHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(trkHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref trkHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length); imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length);
blockStream.Close(); blockStream.Close();
@@ -2743,13 +2627,8 @@ namespace DiscImageChef.DiscImages
subchannelBlock.compression = CompressionType.Lzma; subchannelBlock.compression = CompressionType.Lzma;
} }
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<BlockHeader>());
structureBytes = new byte[Marshal.SizeOf<BlockHeader>()]; structureBytes = new byte[Marshal.SizeOf<BlockHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(subchannelBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref subchannelBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0,
structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
if(subchannelBlock.compression == CompressionType.Lzma) if(subchannelBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
@@ -2905,12 +2784,8 @@ namespace DiscImageChef.DiscImages
DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing metadata to position {0}", DicConsole.DebugWriteLine("DiscImageChef format plugin", "Writing metadata to position {0}",
imageStream.Position); imageStream.Position);
metadataBlock.blockSize = (uint)blockStream.Length; metadataBlock.blockSize = (uint)blockStream.Length;
structurePointer =
System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<MetadataBlock>());
structureBytes = new byte[Marshal.SizeOf<MetadataBlock>()]; structureBytes = new byte[Marshal.SizeOf<MetadataBlock>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(metadataBlock, structurePointer, true); MemoryMarshal.Write(structureBytes, ref metadataBlock);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
blockStream.Position = 0; blockStream.Position = 0;
blockStream.Write(structureBytes, 0, structureBytes.Length); blockStream.Write(structureBytes, 0, structureBytes.Length);
index.RemoveAll(t => t.blockType == BlockType.MetadataBlock && t.dataType == DataType.NoData); index.RemoveAll(t => t.blockType == BlockType.MetadataBlock && t.dataType == DataType.NoData);
@@ -2935,11 +2810,9 @@ namespace DiscImageChef.DiscImages
// Write index to memory // Write index to memory
foreach(IndexEntry entry in index) foreach(IndexEntry entry in index)
{ {
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<IndexEntry>());
structureBytes = new byte[Marshal.SizeOf<IndexEntry>()]; structureBytes = new byte[Marshal.SizeOf<IndexEntry>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(entry, structurePointer, true); IndexEntry indexEntry = entry;
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length); MemoryMarshal.Write(structureBytes, ref indexEntry);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
blockStream.Write(structureBytes, 0, structureBytes.Length); blockStream.Write(structureBytes, 0, structureBytes.Length);
} }
@@ -2953,11 +2826,8 @@ namespace DiscImageChef.DiscImages
}; };
// Write index to disk // Write index to disk
structurePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<IndexHeader>());
structureBytes = new byte[Marshal.SizeOf<IndexHeader>()]; structureBytes = new byte[Marshal.SizeOf<IndexHeader>()];
System.Runtime.InteropServices.Marshal.StructureToPtr(idxHeader, structurePointer, true); MemoryMarshal.Write(structureBytes, ref idxHeader);
System.Runtime.InteropServices.Marshal.Copy(structurePointer, structureBytes, 0, structureBytes.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(structurePointer);
imageStream.Write(structureBytes, 0, structureBytes.Length); imageStream.Write(structureBytes, 0, structureBytes.Length);
imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length); imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length);
blockStream.Close(); blockStream.Close();