From 5b46cc6db71626f47e6f0236ba322c20619578fc Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 24 Nov 2018 14:23:35 +0000 Subject: [PATCH] Fix dumping CDs in raw image format (.iso). --- .../Devices/Dumping/CompactDisc.cs | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs b/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs index 5220b6741..5f61f9346 100644 --- a/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs +++ b/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs @@ -736,6 +736,8 @@ namespace DiscImageChef.Core.Devices.Dumping } } + bool supportsLongSectors = true; + if(outputPlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) { if(tracks.Length > 1) @@ -758,6 +760,8 @@ namespace DiscImageChef.Core.Devices.Dumping dumpLog.WriteLine("Output format only supports MODE 1 tracks, not continuing..."); return; } + + supportsLongSectors = false; } // Check if something prevents from dumping the Lead-in @@ -914,7 +918,8 @@ namespace DiscImageChef.Core.Devices.Dumping MhddLog mhddLog = new MhddLog(outputPrefix + ".mhddlog.bin", dev, blocks, blockSize, blocksToRead); IbgLog ibgLog = new IbgLog(outputPrefix + ".ibg", 0x0008); - bool ret = outputPlugin.Create(outputPath, dskType, formatOptions, blocks, blockSize); + bool ret = outputPlugin.Create(outputPath, dskType, formatOptions, blocks, + supportsLongSectors ? blockSize : 2048); // Cannot create image if(!ret) @@ -1100,7 +1105,23 @@ namespace DiscImageChef.Core.Devices.Dumping outputPlugin.WriteSectorsLong(data, i, blocksToRead); outputPlugin.WriteSectorsTag(sub, i, blocksToRead, SectorTagType.CdSectorSubchannel); } - else outputPlugin.WriteSectors(readBuffer, i, blocksToRead); + else + { + if(supportsLongSectors) outputPlugin.WriteSectorsLong(readBuffer, i, blocksToRead); + else + { + if(readBuffer.Length % 2352 == 0) + { + byte[] data = new byte[2048 * blocksToRead]; + + for(int b = 0; b < blocksToRead; b++) + Array.Copy(readBuffer, (int)(16 + b * blockSize), data, 2048 * b, 2048); + + outputPlugin.WriteSectors(data, i, blocksToRead); + } + else outputPlugin.WriteSectorsLong(readBuffer, i, blocksToRead); + } + } imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds; } @@ -1119,7 +1140,16 @@ namespace DiscImageChef.Core.Devices.Dumping outputPlugin.WriteSectorsTag(new byte[subSize * skip], i, skip, SectorTagType.CdSectorSubchannel); } - else outputPlugin.WriteSectors(new byte[blockSize * skip], i, skip); + else + { + if(supportsLongSectors) outputPlugin.WriteSectorsLong(new byte[blockSize * skip], i, skip); + else + { + if(readBuffer.Length % 2352 == 0) + outputPlugin.WriteSectors(new byte[2048 * skip], i, skip); + else outputPlugin.WriteSectorsLong(new byte[blockSize * skip], i, skip); + } + } imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds; @@ -1312,7 +1342,22 @@ namespace DiscImageChef.Core.Devices.Dumping outputPlugin.WriteSectorLong(data, badSector); outputPlugin.WriteSectorTag(sub, badSector, SectorTagType.CdSectorSubchannel); } - else outputPlugin.WriteSector(readBuffer, badSector); + else + { + if(supportsLongSectors) outputPlugin.WriteSectorLong(readBuffer, badSector); + else + { + if(readBuffer.Length % 2352 == 0) + { + byte[] data = new byte[2048]; + + for(int b = 0; b < blocksToRead; b++) Array.Copy(readBuffer, 16, data, 0, 2048); + + outputPlugin.WriteSector(data, badSector); + } + else outputPlugin.WriteSectorLong(readBuffer, badSector); + } + } } DicConsole.WriteLine();