mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Code restyling.
This commit is contained in:
@@ -34,13 +34,9 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
public partial class Ndif
|
||||
{
|
||||
/// <summary>
|
||||
/// Resource OSType for NDIF is "bcem"
|
||||
/// </summary>
|
||||
/// <summary>Resource OSType for NDIF is "bcem"</summary>
|
||||
const uint NDIF_RESOURCE = 0x6263656D;
|
||||
/// <summary>
|
||||
/// Resource ID is always 128? Never found another
|
||||
/// </summary>
|
||||
/// <summary>Resource ID is always 128? Never found another</summary>
|
||||
const short NDIF_RESOURCEID = 128;
|
||||
|
||||
const byte CHUNK_TYPE_NOCOPY = 0;
|
||||
@@ -49,9 +45,7 @@ namespace Aaru.DiscImages
|
||||
const byte CHUNK_TYPE_RLE = 0x81;
|
||||
const byte CHUNK_TYPE_LZH = 0x82;
|
||||
const byte CHUNK_TYPE_ADC = 0x83;
|
||||
/// <summary>
|
||||
/// Created by ShrinkWrap 3.5, dunno which version of the StuffIt algorithm it is using
|
||||
/// </summary>
|
||||
/// <summary>Created by ShrinkWrap 3.5, dunno which version of the StuffIt algorithm it is using</summary>
|
||||
const byte CHUNK_TYPE_STUFFIT = 0xF0;
|
||||
const byte CHUNK_TYPE_END = 0xFF;
|
||||
const byte CHUNK_TYPE_COMPRESSED_MASK = 0x80;
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using Claunia.RsrcFork;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Claunia.RsrcFork;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -40,18 +40,26 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
public bool Identify(IFilter imageFilter)
|
||||
{
|
||||
if(!imageFilter.HasResourceFork() || imageFilter.GetResourceForkLength() == 0) return false;
|
||||
if(!imageFilter.HasResourceFork() ||
|
||||
imageFilter.GetResourceForkLength() == 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
ResourceFork rsrcFork = new ResourceFork(imageFilter.GetResourceForkStream());
|
||||
if(!rsrcFork.ContainsKey(NDIF_RESOURCE)) return false;
|
||||
var rsrcFork = new ResourceFork(imageFilter.GetResourceForkStream());
|
||||
|
||||
if(!rsrcFork.ContainsKey(NDIF_RESOURCE))
|
||||
return false;
|
||||
|
||||
Resource rsrc = rsrcFork.GetResource(NDIF_RESOURCE);
|
||||
|
||||
if(rsrc.ContainsId(NDIF_RESOURCEID)) return true;
|
||||
if(rsrc.ContainsId(NDIF_RESOURCEID))
|
||||
return true;
|
||||
}
|
||||
catch(InvalidCastException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(InvalidCastException) { return false; }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -53,31 +53,18 @@ namespace Aaru.DiscImages
|
||||
Stream imageStream;
|
||||
Dictionary<ulong, byte[]> sectorCache;
|
||||
|
||||
public Ndif()
|
||||
public Ndif() => imageInfo = new ImageInfo
|
||||
{
|
||||
imageInfo = new ImageInfo
|
||||
{
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false,
|
||||
HasSessions = false,
|
||||
Version = null,
|
||||
Application = null,
|
||||
ApplicationVersion = null,
|
||||
Creator = null,
|
||||
Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaSerialNumber = null,
|
||||
MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
ReadableSectorTags = new List<SectorTagType>(), ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false, HasSessions = false, Version = null,
|
||||
Application = null,
|
||||
ApplicationVersion = null, Creator = null, Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null, MediaSerialNumber = null, MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0, LastMediaSequence = 0, DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null, DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Claunia.Encoding;
|
||||
using Claunia.RsrcFork;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Exceptions;
|
||||
@@ -43,6 +41,8 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Compression;
|
||||
using Aaru.Console;
|
||||
using Aaru.Helpers;
|
||||
using Claunia.Encoding;
|
||||
using Claunia.RsrcFork;
|
||||
using SharpCompress.Compressors.ADC;
|
||||
using Version = Resources.Version;
|
||||
|
||||
@@ -52,7 +52,9 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
public bool Open(IFilter imageFilter)
|
||||
{
|
||||
if(!imageFilter.HasResourceFork() || imageFilter.GetResourceForkLength() == 0) return false;
|
||||
if(!imageFilter.HasResourceFork() ||
|
||||
imageFilter.GetResourceForkLength() == 0)
|
||||
return false;
|
||||
|
||||
ResourceFork rsrcFork;
|
||||
Resource rsrc;
|
||||
@@ -61,43 +63,54 @@ namespace Aaru.DiscImages
|
||||
try
|
||||
{
|
||||
rsrcFork = new ResourceFork(imageFilter.GetResourceForkStream());
|
||||
if(!rsrcFork.ContainsKey(NDIF_RESOURCE)) return false;
|
||||
|
||||
if(!rsrcFork.ContainsKey(NDIF_RESOURCE))
|
||||
return false;
|
||||
|
||||
rsrc = rsrcFork.GetResource(NDIF_RESOURCE);
|
||||
|
||||
bcems = rsrc.GetIds();
|
||||
|
||||
if(bcems == null || bcems.Length == 0) return false;
|
||||
if(bcems == null ||
|
||||
bcems.Length == 0)
|
||||
return false;
|
||||
}
|
||||
catch(InvalidCastException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(InvalidCastException) { return false; }
|
||||
|
||||
imageInfo.Sectors = 0;
|
||||
|
||||
foreach(byte[] bcem in bcems.Select(id => rsrc.GetResource(NDIF_RESOURCEID)))
|
||||
{
|
||||
if(bcem.Length < 128) return false;
|
||||
if(bcem.Length < 128)
|
||||
return false;
|
||||
|
||||
header = Marshal.ByteArrayToStructureBigEndian<ChunkHeader>(bcem);
|
||||
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.type = {0}", header.version);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.type = {0}", header.version);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.driver = {0}", header.driver);
|
||||
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.name = {0}",
|
||||
StringHandlers.PascalToString(header.name,
|
||||
Encoding.GetEncoding("macintosh")));
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.sectors = {0}", header.sectors);
|
||||
StringHandlers.PascalToString(header.name,
|
||||
Encoding.GetEncoding("macintosh")));
|
||||
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.sectors = {0}", header.sectors);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.maxSectorsPerChunk = {0}", header.maxSectorsPerChunk);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.dataOffset = {0}", header.dataOffset);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.crc = 0x{0:X7}", header.crc);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.segmented = {0}", header.segmented);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.p1 = 0x{0:X8}", header.p1);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.p2 = 0x{0:X8}", header.p2);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[0] = 0x{0:X8}", header.unknown[0]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[1] = 0x{0:X8}", header.unknown[1]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[2] = 0x{0:X8}", header.unknown[2]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[3] = 0x{0:X8}", header.unknown[3]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[4] = 0x{0:X8}", header.unknown[4]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.encrypted = {0}", header.encrypted);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.hash = 0x{0:X8}", header.hash);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.chunks = {0}", header.chunks);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.dataOffset = {0}", header.dataOffset);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.crc = 0x{0:X7}", header.crc);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.segmented = {0}", header.segmented);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.p1 = 0x{0:X8}", header.p1);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.p2 = 0x{0:X8}", header.p2);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[0] = 0x{0:X8}", header.unknown[0]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[1] = 0x{0:X8}", header.unknown[1]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[2] = 0x{0:X8}", header.unknown[2]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[3] = 0x{0:X8}", header.unknown[3]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.unknown[4] = 0x{0:X8}", header.unknown[4]);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.encrypted = {0}", header.encrypted);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.hash = 0x{0:X8}", header.hash);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "footer.chunks = {0}", header.chunks);
|
||||
|
||||
// Block chunks and headers
|
||||
chunks = new Dictionary<ulong, BlockChunk>();
|
||||
@@ -106,20 +119,21 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
// Obsolete read-only NDIF only prepended the header and then put the image without any kind of block references.
|
||||
// So let's falsify a block chunk
|
||||
BlockChunk bChnk = new BlockChunk();
|
||||
byte[] sector = new byte[4];
|
||||
Array.Copy(bcem, 128 + 0 + i * 12, sector, 1, 3);
|
||||
var bChnk = new BlockChunk();
|
||||
byte[] sector = new byte[4];
|
||||
Array.Copy(bcem, 128 + 0 + (i * 12), sector, 1, 3);
|
||||
bChnk.sector = BigEndianBitConverter.ToUInt32(sector, 0);
|
||||
bChnk.type = bcem[128 + 3 + i * 12];
|
||||
bChnk.offset = BigEndianBitConverter.ToUInt32(bcem, 128 + 4 + i * 12);
|
||||
bChnk.length = BigEndianBitConverter.ToUInt32(bcem, 128 + 8 + i * 12);
|
||||
bChnk.type = bcem[128 + 3 + (i * 12)];
|
||||
bChnk.offset = BigEndianBitConverter.ToUInt32(bcem, 128 + 4 + (i * 12));
|
||||
bChnk.length = BigEndianBitConverter.ToUInt32(bcem, 128 + 8 + (i * 12));
|
||||
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].type = 0x{1:X2}", i, bChnk.type);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].sector = {1}", i, bChnk.sector);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].offset = {1}", i, bChnk.offset);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].length = {1}", i, bChnk.length);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].sector = {1}", i, bChnk.sector);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].offset = {1}", i, bChnk.offset);
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "bHdr.chunk[{0}].length = {1}", i, bChnk.length);
|
||||
|
||||
if(bChnk.type == CHUNK_TYPE_END) break;
|
||||
if(bChnk.type == CHUNK_TYPE_END)
|
||||
break;
|
||||
|
||||
bChnk.offset += header.dataOffset;
|
||||
bChnk.sector += (uint)imageInfo.Sectors;
|
||||
@@ -138,9 +152,10 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
// TODO: Handle compressed chunks
|
||||
if(bChnk.type > CHUNK_TYPE_COPY && bChnk.type < CHUNK_TYPE_KENCODE ||
|
||||
bChnk.type > CHUNK_TYPE_ADC && bChnk.type < CHUNK_TYPE_STUFFIT ||
|
||||
bChnk.type > CHUNK_TYPE_STUFFIT && bChnk.type < CHUNK_TYPE_END || bChnk.type == 1)
|
||||
if((bChnk.type > CHUNK_TYPE_COPY && bChnk.type < CHUNK_TYPE_KENCODE) ||
|
||||
(bChnk.type > CHUNK_TYPE_ADC && bChnk.type < CHUNK_TYPE_STUFFIT) ||
|
||||
(bChnk.type > CHUNK_TYPE_STUFFIT && bChnk.type < CHUNK_TYPE_END) ||
|
||||
bChnk.type == 1)
|
||||
throw new ImageNotSupportedException($"Unsupported chunk type 0x{bChnk.type:X8} found");
|
||||
|
||||
chunks.Add(bChnk.sector, bChnk);
|
||||
@@ -149,73 +164,92 @@ namespace Aaru.DiscImages
|
||||
imageInfo.Sectors += header.sectors;
|
||||
}
|
||||
|
||||
if(header.segmented > 0) throw new ImageNotSupportedException("Segmented images are not yet supported.");
|
||||
if(header.segmented > 0)
|
||||
throw new ImageNotSupportedException("Segmented images are not yet supported.");
|
||||
|
||||
if(header.encrypted > 0) throw new ImageNotSupportedException("Encrypted images are not yet supported.");
|
||||
if(header.encrypted > 0)
|
||||
throw new ImageNotSupportedException("Encrypted images are not yet supported.");
|
||||
|
||||
switch(imageInfo.Sectors)
|
||||
{
|
||||
case 1440:
|
||||
imageInfo.MediaType = MediaType.DOS_35_DS_DD_9;
|
||||
|
||||
break;
|
||||
case 1600:
|
||||
imageInfo.MediaType = MediaType.AppleSonyDS;
|
||||
|
||||
break;
|
||||
case 2880:
|
||||
imageInfo.MediaType = MediaType.DOS_35_HD;
|
||||
|
||||
break;
|
||||
case 3360:
|
||||
imageInfo.MediaType = MediaType.DMF;
|
||||
|
||||
break;
|
||||
default:
|
||||
imageInfo.MediaType = MediaType.GENERIC_HDD;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(rsrcFork.ContainsKey(0x76657273))
|
||||
{
|
||||
Resource versRsrc = rsrcFork.GetResource(0x76657273);
|
||||
|
||||
if(versRsrc != null)
|
||||
{
|
||||
byte[] vers = versRsrc.GetResource(versRsrc.GetIds()[0]);
|
||||
|
||||
Version version = new Version(vers);
|
||||
var version = new Version(vers);
|
||||
|
||||
string release = null;
|
||||
string dev = null;
|
||||
string pre = null;
|
||||
|
||||
string major = $"{version.MajorVersion}";
|
||||
string minor = $".{version.MinorVersion / 10}";
|
||||
if(version.MinorVersion % 10 > 0) release = $".{version.MinorVersion % 10}";
|
||||
string major = $"{version.MajorVersion}";
|
||||
string minor = $".{version.MinorVersion / 10}";
|
||||
|
||||
if(version.MinorVersion % 10 > 0)
|
||||
release = $".{version.MinorVersion % 10}";
|
||||
|
||||
switch(version.DevStage)
|
||||
{
|
||||
case Version.DevelopmentStage.Alpha:
|
||||
dev = "a";
|
||||
|
||||
break;
|
||||
case Version.DevelopmentStage.Beta:
|
||||
dev = "b";
|
||||
|
||||
break;
|
||||
case Version.DevelopmentStage.PreAlpha:
|
||||
dev = "d";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(dev == null && version.PreReleaseVersion > 0) dev = "f";
|
||||
if(dev == null &&
|
||||
version.PreReleaseVersion > 0)
|
||||
dev = "f";
|
||||
|
||||
if(dev != null) pre = $"{version.PreReleaseVersion}";
|
||||
if(dev != null)
|
||||
pre = $"{version.PreReleaseVersion}";
|
||||
|
||||
imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
|
||||
imageInfo.Application = version.VersionString;
|
||||
imageInfo.Comments = version.VersionMessage;
|
||||
|
||||
if(version.MajorVersion == 3) imageInfo.Application = "ShrinkWrap™";
|
||||
else if(version.MajorVersion == 6) imageInfo.Application = "DiskCopy";
|
||||
if(version.MajorVersion == 3)
|
||||
imageInfo.Application = "ShrinkWrap™";
|
||||
else if(version.MajorVersion == 6)
|
||||
imageInfo.Application = "DiskCopy";
|
||||
}
|
||||
}
|
||||
|
||||
AaruConsole.DebugWriteLine("NDIF plugin", "Image application = {0} version {1}", imageInfo.Application,
|
||||
imageInfo.ApplicationVersion);
|
||||
imageInfo.ApplicationVersion);
|
||||
|
||||
sectorCache = new Dictionary<ulong, byte[]>();
|
||||
chunkCache = new Dictionary<ulong, byte[]>();
|
||||
@@ -225,8 +259,9 @@ namespace Aaru.DiscImages
|
||||
|
||||
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
||||
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
||||
imageInfo.MediaTitle =
|
||||
StringHandlers.PascalToString(header.name, Encoding.GetEncoding("macintosh"));
|
||||
|
||||
imageInfo.MediaTitle = StringHandlers.PascalToString(header.name, Encoding.GetEncoding("macintosh"));
|
||||
|
||||
imageInfo.SectorSize = SECTOR_SIZE;
|
||||
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
||||
imageInfo.ImageSize = imageInfo.Sectors * SECTOR_SIZE;
|
||||
@@ -239,27 +274,32 @@ namespace Aaru.DiscImages
|
||||
imageInfo.Cylinders = 80;
|
||||
imageInfo.Heads = 2;
|
||||
imageInfo.SectorsPerTrack = 10;
|
||||
|
||||
break;
|
||||
case MediaType.DOS_35_DS_DD_9:
|
||||
imageInfo.Cylinders = 80;
|
||||
imageInfo.Heads = 2;
|
||||
imageInfo.SectorsPerTrack = 9;
|
||||
|
||||
break;
|
||||
case MediaType.DOS_35_HD:
|
||||
imageInfo.Cylinders = 80;
|
||||
imageInfo.Heads = 2;
|
||||
imageInfo.SectorsPerTrack = 18;
|
||||
|
||||
break;
|
||||
case MediaType.DMF:
|
||||
imageInfo.Cylinders = 80;
|
||||
imageInfo.Heads = 2;
|
||||
imageInfo.SectorsPerTrack = 21;
|
||||
|
||||
break;
|
||||
default:
|
||||
imageInfo.MediaType = MediaType.GENERIC_HDD;
|
||||
imageInfo.Cylinders = (uint)(imageInfo.Sectors / 16 / 63);
|
||||
imageInfo.Heads = 16;
|
||||
imageInfo.SectorsPerTrack = 63;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -272,11 +312,12 @@ namespace Aaru.DiscImages
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
$"Sector address {sectorAddress} not found");
|
||||
|
||||
if(sectorCache.TryGetValue(sectorAddress, out byte[] sector)) return sector;
|
||||
if(sectorCache.TryGetValue(sectorAddress, out byte[] sector))
|
||||
return sector;
|
||||
|
||||
BlockChunk currentChunk = new BlockChunk();
|
||||
bool chunkFound = false;
|
||||
ulong chunkStartSector = 0;
|
||||
var currentChunk = new BlockChunk();
|
||||
bool chunkFound = false;
|
||||
ulong chunkStartSector = 0;
|
||||
|
||||
foreach(KeyValuePair<ulong, BlockChunk> kvp in chunks.Where(kvp => sectorAddress >= kvp.Key))
|
||||
{
|
||||
@@ -302,8 +343,8 @@ namespace Aaru.DiscImages
|
||||
byte[] cmpBuffer = new byte[currentChunk.length];
|
||||
imageStream.Seek(currentChunk.offset, SeekOrigin.Begin);
|
||||
imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
|
||||
MemoryStream cmpMs = new MemoryStream(cmpBuffer);
|
||||
int realSize;
|
||||
var cmpMs = new MemoryStream(cmpBuffer);
|
||||
int realSize;
|
||||
|
||||
switch(currentChunk.type)
|
||||
{
|
||||
@@ -314,6 +355,7 @@ namespace Aaru.DiscImages
|
||||
realSize = decStream.Read(tmpBuffer, 0, (int)buffersize);
|
||||
buffer = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -321,11 +363,14 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
byte[] tmpBuffer = new byte[buffersize];
|
||||
realSize = 0;
|
||||
AppleRle rle = new AppleRle(cmpMs);
|
||||
var rle = new AppleRle(cmpMs);
|
||||
|
||||
for(int i = 0; i < buffersize; i++)
|
||||
{
|
||||
int b = rle.ProduceByte();
|
||||
if(b == -1) break;
|
||||
|
||||
if(b == -1)
|
||||
break;
|
||||
|
||||
tmpBuffer[i] = (byte)b;
|
||||
realSize++;
|
||||
@@ -333,6 +378,7 @@ namespace Aaru.DiscImages
|
||||
|
||||
buffer = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -354,7 +400,8 @@ namespace Aaru.DiscImages
|
||||
sector = new byte[SECTOR_SIZE];
|
||||
Array.Copy(buffer, relOff, sector, 0, SECTOR_SIZE);
|
||||
|
||||
if(sectorCache.Count >= MAX_CACHED_SECTORS) sectorCache.Clear();
|
||||
if(sectorCache.Count >= MAX_CACHED_SECTORS)
|
||||
sectorCache.Clear();
|
||||
|
||||
sectorCache.Add(sectorAddress, sector);
|
||||
|
||||
@@ -366,18 +413,22 @@ namespace Aaru.DiscImages
|
||||
case CHUNK_TYPE_NOCOPY:
|
||||
sector = new byte[SECTOR_SIZE];
|
||||
|
||||
if(sectorCache.Count >= MAX_CACHED_SECTORS) sectorCache.Clear();
|
||||
if(sectorCache.Count >= MAX_CACHED_SECTORS)
|
||||
sectorCache.Clear();
|
||||
|
||||
sectorCache.Add(sectorAddress, sector);
|
||||
|
||||
return sector;
|
||||
case CHUNK_TYPE_COPY:
|
||||
imageStream.Seek(currentChunk.offset + relOff, SeekOrigin.Begin);
|
||||
sector = new byte[SECTOR_SIZE];
|
||||
imageStream.Read(sector, 0, sector.Length);
|
||||
|
||||
if(sectorCache.Count >= MAX_CACHED_SECTORS) sectorCache.Clear();
|
||||
if(sectorCache.Count >= MAX_CACHED_SECTORS)
|
||||
sectorCache.Clear();
|
||||
|
||||
sectorCache.Add(sectorAddress, sector);
|
||||
|
||||
return sector;
|
||||
}
|
||||
|
||||
@@ -393,7 +444,7 @@ namespace Aaru.DiscImages
|
||||
if(sectorAddress + length > imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
var ms = new MemoryStream();
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -40,106 +40,62 @@ namespace Aaru.DiscImages
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct ChunkHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// Version
|
||||
/// </summary>
|
||||
public short version;
|
||||
/// <summary>
|
||||
/// Filesystem ID
|
||||
/// </summary>
|
||||
public short driver;
|
||||
/// <summary>
|
||||
/// Disk image name, Str63 (Pascal string)
|
||||
/// </summary>
|
||||
/// <summary>Version</summary>
|
||||
public readonly short version;
|
||||
/// <summary>Filesystem ID</summary>
|
||||
public readonly short driver;
|
||||
/// <summary>Disk image name, Str63 (Pascal string)</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
||||
public byte[] name;
|
||||
/// <summary>
|
||||
/// Sectors in image
|
||||
/// </summary>
|
||||
public uint sectors;
|
||||
/// <summary>
|
||||
/// Maximum number of sectors per chunk
|
||||
/// </summary>
|
||||
public uint maxSectorsPerChunk;
|
||||
/// <summary>
|
||||
/// Offset to add to every chunk offset
|
||||
/// </summary>
|
||||
public uint dataOffset;
|
||||
/// <summary>
|
||||
/// CRC28 of whole image
|
||||
/// </summary>
|
||||
public uint crc;
|
||||
/// <summary>
|
||||
/// Set to 1 if segmented
|
||||
/// </summary>
|
||||
public uint segmented;
|
||||
/// <summary>
|
||||
/// Unknown
|
||||
/// </summary>
|
||||
public uint p1;
|
||||
/// <summary>
|
||||
/// Unknown
|
||||
/// </summary>
|
||||
public uint p2;
|
||||
/// <summary>
|
||||
/// Unknown, spare?
|
||||
/// </summary>
|
||||
public readonly byte[] name;
|
||||
/// <summary>Sectors in image</summary>
|
||||
public readonly uint sectors;
|
||||
/// <summary>Maximum number of sectors per chunk</summary>
|
||||
public readonly uint maxSectorsPerChunk;
|
||||
/// <summary>Offset to add to every chunk offset</summary>
|
||||
public readonly uint dataOffset;
|
||||
/// <summary>CRC28 of whole image</summary>
|
||||
public readonly uint crc;
|
||||
/// <summary>Set to 1 if segmented</summary>
|
||||
public readonly uint segmented;
|
||||
/// <summary>Unknown</summary>
|
||||
public readonly uint p1;
|
||||
/// <summary>Unknown</summary>
|
||||
public readonly uint p2;
|
||||
/// <summary>Unknown, spare?</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
||||
public uint[] unknown;
|
||||
/// <summary>
|
||||
/// Set to 1 by ShrinkWrap if image is encrypted
|
||||
/// </summary>
|
||||
public uint encrypted;
|
||||
/// <summary>
|
||||
/// Set by ShrinkWrap if image is encrypted, value is the same for same password
|
||||
/// </summary>
|
||||
public uint hash;
|
||||
/// <summary>
|
||||
/// How many chunks follow the header
|
||||
/// </summary>
|
||||
public uint chunks;
|
||||
public readonly uint[] unknown;
|
||||
/// <summary>Set to 1 by ShrinkWrap if image is encrypted</summary>
|
||||
public readonly uint encrypted;
|
||||
/// <summary>Set by ShrinkWrap if image is encrypted, value is the same for same password</summary>
|
||||
public readonly uint hash;
|
||||
/// <summary>How many chunks follow the header</summary>
|
||||
public readonly uint chunks;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct BlockChunk
|
||||
{
|
||||
/// <summary>
|
||||
/// Starting sector, 3 bytes
|
||||
/// </summary>
|
||||
/// <summary>Starting sector, 3 bytes</summary>
|
||||
public uint sector;
|
||||
/// <summary>
|
||||
/// Chunk type
|
||||
/// </summary>
|
||||
/// <summary>Chunk type</summary>
|
||||
public byte type;
|
||||
/// <summary>
|
||||
/// Offset in start of chunk
|
||||
/// </summary>
|
||||
/// <summary>Offset in start of chunk</summary>
|
||||
public uint offset;
|
||||
/// <summary>
|
||||
/// Length in bytes of chunk
|
||||
/// </summary>
|
||||
/// <summary>Length in bytes of chunk</summary>
|
||||
public uint length;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct SegmentHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// Segment #
|
||||
/// </summary>
|
||||
public ushort segment;
|
||||
/// <summary>
|
||||
/// How many segments
|
||||
/// </summary>
|
||||
public ushort segments;
|
||||
/// <summary>
|
||||
/// Seems to be a Guid, changes with different images, same for all segments of same image
|
||||
/// </summary>
|
||||
public Guid segmentId;
|
||||
/// <summary>
|
||||
/// Seems to be a CRC28 of this segment, unchecked
|
||||
/// </summary>
|
||||
public uint crc;
|
||||
/// <summary>Segment #</summary>
|
||||
public readonly ushort segment;
|
||||
/// <summary>How many segments</summary>
|
||||
public readonly ushort segments;
|
||||
/// <summary>Seems to be a Guid, changes with different images, same for all segments of same image</summary>
|
||||
public readonly Guid segmentId;
|
||||
/// <summary>Seems to be a CRC28 of this segment, unchecked</summary>
|
||||
public readonly uint crc;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user