mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use new little endian marshaller on media images.
This commit is contained in:
@@ -65,10 +65,7 @@ namespace DiscImageChef.DiscImages
|
||||
header = new DicHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(header)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(header));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(header));
|
||||
header = (DicHeader)Marshal.PtrToStructure(structurePointer, typeof(DicHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
header = Helpers.Marshal.ByteArrayToStructureLittleEndian<DicHeader>(structureBytes);
|
||||
|
||||
if(header.imageMajorVersion > DICF_VERSION)
|
||||
throw new FeatureUnsupportedImageException($"Image version {header.imageMajorVersion} not recognized.");
|
||||
@@ -83,10 +80,7 @@ namespace DiscImageChef.DiscImages
|
||||
IndexHeader idxHeader = new IndexHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(idxHeader)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(idxHeader));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(idxHeader));
|
||||
idxHeader = (IndexHeader)Marshal.PtrToStructure(structurePointer, typeof(IndexHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
idxHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian<IndexHeader>(structureBytes);
|
||||
|
||||
if(idxHeader.identifier != BlockType.Index) throw new FeatureUnsupportedImageException("Index not found!");
|
||||
|
||||
@@ -100,10 +94,7 @@ namespace DiscImageChef.DiscImages
|
||||
IndexEntry entry = new IndexEntry();
|
||||
structureBytes = new byte[Marshal.SizeOf(entry)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(entry));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(entry));
|
||||
entry = (IndexEntry)Marshal.PtrToStructure(structurePointer, typeof(IndexEntry));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
entry = Helpers.Marshal.ByteArrayToStructureLittleEndian<IndexEntry>(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);
|
||||
@@ -128,10 +119,8 @@ namespace DiscImageChef.DiscImages
|
||||
BlockHeader blockHeader = new BlockHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(blockHeader)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(blockHeader));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(blockHeader));
|
||||
blockHeader = (BlockHeader)Marshal.PtrToStructure(structurePointer, typeof(BlockHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
blockHeader =
|
||||
Helpers.Marshal.ByteArrayToStructureLittleEndian<BlockHeader>(structureBytes);
|
||||
imageInfo.ImageSize += blockHeader.cmpLength;
|
||||
|
||||
// Unused, skip
|
||||
@@ -296,10 +285,8 @@ namespace DiscImageChef.DiscImages
|
||||
DdtHeader ddtHeader = new DdtHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(ddtHeader)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(ddtHeader));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(ddtHeader));
|
||||
ddtHeader = (DdtHeader)Marshal.PtrToStructure(structurePointer, typeof(DdtHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
ddtHeader =
|
||||
Helpers.Marshal.ByteArrayToStructureLittleEndian<DdtHeader>(structureBytes);
|
||||
imageInfo.ImageSize += ddtHeader.cmpLength;
|
||||
|
||||
if(ddtHeader.identifier != BlockType.DeDuplicationTable) break;
|
||||
@@ -350,10 +337,8 @@ namespace DiscImageChef.DiscImages
|
||||
DdtHeader ddtHeader = new DdtHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(ddtHeader)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(ddtHeader));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(ddtHeader));
|
||||
ddtHeader = (DdtHeader)Marshal.PtrToStructure(structurePointer, typeof(DdtHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
ddtHeader =
|
||||
Helpers.Marshal.ByteArrayToStructureLittleEndian<DdtHeader>(structureBytes);
|
||||
imageInfo.ImageSize += ddtHeader.cmpLength;
|
||||
|
||||
if(ddtHeader.identifier != BlockType.DeDuplicationTable) break;
|
||||
@@ -402,10 +387,7 @@ namespace DiscImageChef.DiscImages
|
||||
geometryBlock = new GeometryBlock();
|
||||
structureBytes = new byte[Marshal.SizeOf(geometryBlock)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(geometryBlock));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(geometryBlock));
|
||||
geometryBlock = (GeometryBlock)Marshal.PtrToStructure(structurePointer, typeof(GeometryBlock));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
geometryBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian<GeometryBlock>(structureBytes);
|
||||
if(geometryBlock.identifier == BlockType.GeometryBlock)
|
||||
{
|
||||
DicConsole.DebugWriteLine("DiscImageChef format plugin",
|
||||
@@ -423,10 +405,7 @@ namespace DiscImageChef.DiscImages
|
||||
MetadataBlock metadataBlock = new MetadataBlock();
|
||||
structureBytes = new byte[Marshal.SizeOf(metadataBlock)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(metadataBlock));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(metadataBlock));
|
||||
metadataBlock = (MetadataBlock)Marshal.PtrToStructure(structurePointer, typeof(MetadataBlock));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
metadataBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian<MetadataBlock>(structureBytes);
|
||||
|
||||
if(metadataBlock.identifier != entry.blockType)
|
||||
{
|
||||
@@ -594,10 +573,7 @@ namespace DiscImageChef.DiscImages
|
||||
TracksHeader tracksHeader = new TracksHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(tracksHeader)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(tracksHeader));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(tracksHeader));
|
||||
tracksHeader = (TracksHeader)Marshal.PtrToStructure(structurePointer, typeof(TracksHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
tracksHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian<TracksHeader>(structureBytes);
|
||||
if(tracksHeader.identifier != BlockType.TracksBlock)
|
||||
{
|
||||
DicConsole.DebugWriteLine("DiscImageChef format plugin",
|
||||
@@ -631,10 +607,7 @@ namespace DiscImageChef.DiscImages
|
||||
TrackEntry trackEntry = new TrackEntry();
|
||||
structureBytes = new byte[Marshal.SizeOf(trackEntry)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(trackEntry));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(trackEntry));
|
||||
trackEntry = (TrackEntry)Marshal.PtrToStructure(structurePointer, typeof(TrackEntry));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
trackEntry = Helpers.Marshal.ByteArrayToStructureLittleEndian<TrackEntry>(structureBytes);
|
||||
|
||||
Tracks.Add(new Track
|
||||
{
|
||||
@@ -661,11 +634,7 @@ namespace DiscImageChef.DiscImages
|
||||
CicmMetadataBlock cicmBlock = new CicmMetadataBlock();
|
||||
structureBytes = new byte[Marshal.SizeOf(cicmBlock)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(cicmBlock));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(cicmBlock));
|
||||
cicmBlock = (CicmMetadataBlock)Marshal.PtrToStructure(structurePointer,
|
||||
typeof(CicmMetadataBlock));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
cicmBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian<CicmMetadataBlock>(structureBytes);
|
||||
if(cicmBlock.identifier != BlockType.CicmBlock) break;
|
||||
|
||||
DicConsole.DebugWriteLine("DiscImageChef format plugin",
|
||||
@@ -694,11 +663,8 @@ namespace DiscImageChef.DiscImages
|
||||
DumpHardwareHeader dumpBlock = new DumpHardwareHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(dumpBlock)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(dumpBlock));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(dumpBlock));
|
||||
dumpBlock = (DumpHardwareHeader)Marshal.PtrToStructure(structurePointer,
|
||||
typeof(DumpHardwareHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
dumpBlock = Helpers
|
||||
.Marshal.ByteArrayToStructureLittleEndian<DumpHardwareHeader>(structureBytes);
|
||||
if(dumpBlock.identifier != BlockType.DumpHardwareBlock) break;
|
||||
|
||||
DicConsole.DebugWriteLine("DiscImageChef format plugin",
|
||||
@@ -724,11 +690,8 @@ namespace DiscImageChef.DiscImages
|
||||
DumpHardwareEntry dumpEntry = new DumpHardwareEntry();
|
||||
structureBytes = new byte[Marshal.SizeOf(dumpEntry)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(dumpEntry));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(dumpEntry));
|
||||
dumpEntry = (DumpHardwareEntry)Marshal.PtrToStructure(structurePointer,
|
||||
typeof(DumpHardwareEntry));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
dumpEntry =
|
||||
Helpers.Marshal.ByteArrayToStructureLittleEndian<DumpHardwareEntry>(structureBytes);
|
||||
|
||||
DumpHardwareType dump = new DumpHardwareType
|
||||
{
|
||||
@@ -973,10 +936,7 @@ namespace DiscImageChef.DiscImages
|
||||
blockHeader = new BlockHeader();
|
||||
structureBytes = new byte[Marshal.SizeOf(blockHeader)];
|
||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(blockHeader));
|
||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(blockHeader));
|
||||
blockHeader = (BlockHeader)Marshal.PtrToStructure(structurePointer, typeof(BlockHeader));
|
||||
Marshal.FreeHGlobal(structurePointer);
|
||||
blockHeader = Helpers.Marshal.ByteArrayToStructureLittleEndian<BlockHeader>(structureBytes);
|
||||
|
||||
// Decompress block
|
||||
switch(blockHeader.compression)
|
||||
|
||||
Reference in New Issue
Block a user