2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Read.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Disk image plugins.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Reads Apple DiskCopy 4.2 disk images.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Exceptions;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.Console;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
using Claunia.Encoding;
|
|
|
|
|
|
using Claunia.RsrcFork;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
using Version = Resources.Version;
|
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.DiscImages
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
public partial class DiskCopy42
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Open(IFilter imageFilter)
|
|
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
byte[] buffer = new byte[0x58];
|
|
|
|
|
|
byte[] pString = new byte[64];
|
|
|
|
|
|
stream.Read(buffer, 0, 0x58);
|
|
|
|
|
|
IsWriting = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Incorrect pascal string length, not DC42
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(buffer[0] > 63)
|
|
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2019-05-11 20:49:32 +01:00
|
|
|
|
header = new Dc42Header();
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
Array.Copy(buffer, 0, pString, 0, 64);
|
|
|
|
|
|
header.DiskName = StringHandlers.PascalToString(pString, Encoding.GetEncoding("macintosh"));
|
|
|
|
|
|
header.DataSize = BigEndianBitConverter.ToUInt32(buffer, 0x40);
|
|
|
|
|
|
header.TagSize = BigEndianBitConverter.ToUInt32(buffer, 0x44);
|
|
|
|
|
|
header.DataChecksum = BigEndianBitConverter.ToUInt32(buffer, 0x48);
|
|
|
|
|
|
header.TagChecksum = BigEndianBitConverter.ToUInt32(buffer, 0x4C);
|
|
|
|
|
|
header.Format = buffer[0x50];
|
|
|
|
|
|
header.FmtByte = buffer[0x51];
|
|
|
|
|
|
header.Valid = buffer[0x52];
|
|
|
|
|
|
header.Reserved = buffer[0x53];
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.diskName = \"{0}\"", header.DiskName);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.dataSize = {0} bytes", header.DataSize);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.tagSize = {0} bytes", header.TagSize);
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.dataChecksum = 0x{0:X8}", header.DataChecksum);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.tagChecksum = 0x{0:X8}", header.TagChecksum);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.format = 0x{0:X2}", header.Format);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.fmtByte = 0x{0:X2}", header.FmtByte);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.valid = {0}", header.Valid);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "header.reserved = {0}", header.Reserved);
|
|
|
|
|
|
|
|
|
|
|
|
if(header.Valid != 1 ||
|
|
|
|
|
|
header.Reserved != 0)
|
|
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
// Some versions seem to incorrectly create little endian fields
|
|
|
|
|
|
if(header.DataSize + header.TagSize + 0x54 != imageFilter.GetDataForkLength() &&
|
|
|
|
|
|
header.Format != kSigmaFormatTwiggy)
|
|
|
|
|
|
{
|
|
|
|
|
|
header.DataSize = BitConverter.ToUInt32(buffer, 0x40);
|
|
|
|
|
|
header.TagSize = BitConverter.ToUInt32(buffer, 0x44);
|
|
|
|
|
|
header.DataChecksum = BitConverter.ToUInt32(buffer, 0x48);
|
|
|
|
|
|
header.TagChecksum = BitConverter.ToUInt32(buffer, 0x4C);
|
|
|
|
|
|
|
|
|
|
|
|
if(header.DataSize + header.TagSize + 0x54 != imageFilter.GetDataForkLength() &&
|
2020-02-29 18:03:35 +00:00
|
|
|
|
header.Format != kSigmaFormatTwiggy)
|
|
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.Format != kSonyFormat400K &&
|
|
|
|
|
|
header.Format != kSonyFormat800K &&
|
|
|
|
|
|
header.Format != kSonyFormat720K &&
|
|
|
|
|
|
header.Format != kSonyFormat1440K &&
|
|
|
|
|
|
header.Format != kSonyFormat1680K &&
|
|
|
|
|
|
header.Format != kSigmaFormatTwiggy &&
|
2018-07-23 23:25:43 +01:00
|
|
|
|
header.Format != kNotStandardFormat)
|
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Unknown header.format = 0x{0:X2} value", header.Format);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.FmtByte != kSonyFmtByte400K &&
|
|
|
|
|
|
header.FmtByte != kSonyFmtByte800K &&
|
|
|
|
|
|
header.FmtByte != kSonyFmtByte800KIncorrect &&
|
|
|
|
|
|
header.FmtByte != kSonyFmtByteProDos &&
|
|
|
|
|
|
header.FmtByte != kInvalidFmtByte &&
|
|
|
|
|
|
header.FmtByte != kSigmaFmtByteTwiggy &&
|
|
|
|
|
|
header.FmtByte != kFmtNotStandard &&
|
|
|
|
|
|
header.FmtByte != kMacOSXFmtByte)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Unknown tmp_header.fmtByte = 0x{0:X2} value",
|
|
|
|
|
|
header.FmtByte);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(header.FmtByte == kInvalidFmtByte)
|
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Image says it's unformatted");
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataOffset = 0x54;
|
|
|
|
|
|
tagOffset = header.TagSize != 0 ? 0x54 + header.DataSize : 0;
|
|
|
|
|
|
imageInfo.SectorSize = 512;
|
|
|
|
|
|
bptag = (uint)(header.TagSize != 0 ? 12 : 0);
|
|
|
|
|
|
dc42ImageFilter = imageFilter;
|
|
|
|
|
|
|
|
|
|
|
|
imageInfo.Sectors = header.DataSize / 512;
|
|
|
|
|
|
|
|
|
|
|
|
if(header.TagSize != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
bptag = (uint)(header.TagSize / imageInfo.Sectors);
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "bptag = {0} bytes", bptag);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(bptag != 12 &&
|
|
|
|
|
|
bptag != 20 &&
|
|
|
|
|
|
bptag != 24)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Unknown tag size");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.AppleSectorTag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
imageInfo.ImageSize = (imageInfo.Sectors * imageInfo.SectorSize) + (imageInfo.Sectors * bptag);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
|
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
|
|
|
|
|
imageInfo.MediaTitle = header.DiskName;
|
|
|
|
|
|
|
|
|
|
|
|
switch(header.Format)
|
|
|
|
|
|
{
|
|
|
|
|
|
case kSonyFormat400K:
|
|
|
|
|
|
imageInfo.MediaType = imageInfo.Sectors == 1600 ? MediaType.AppleSonyDS : MediaType.AppleSonySS;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case kSonyFormat800K:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.AppleSonyDS;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case kSonyFormat720K:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.DOS_35_DS_DD_9;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case kSonyFormat1440K:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.DOS_35_HD;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case kSonyFormat1680K:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.DMF;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case kSigmaFormatTwiggy:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.AppleFileWare;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case kNotStandardFormat:
|
|
|
|
|
|
switch(imageInfo.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 9728:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.AppleProfile;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 19456:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.AppleProfile;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 38912:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.AppleWidget;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 39040:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.AppleHD20;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.Unknown;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.Unknown;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(imageInfo.MediaType == MediaType.AppleFileWare)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] data = new byte[header.DataSize];
|
|
|
|
|
|
byte[] tags = new byte[header.TagSize];
|
|
|
|
|
|
|
|
|
|
|
|
twiggyCache = new byte[header.DataSize];
|
|
|
|
|
|
twiggyCacheTags = new byte[header.TagSize];
|
|
|
|
|
|
twiggy = true;
|
|
|
|
|
|
|
|
|
|
|
|
Stream datastream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
datastream.Seek(dataOffset, SeekOrigin.Begin);
|
|
|
|
|
|
datastream.Read(data, 0, (int)header.DataSize);
|
|
|
|
|
|
|
|
|
|
|
|
Stream tagstream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
tagstream.Seek(tagOffset, SeekOrigin.Begin);
|
|
|
|
|
|
tagstream.Read(tags, 0, (int)header.TagSize);
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
ushort mfsMagic = BigEndianBitConverter.ToUInt16(data, (data.Length / 2) + 0x400);
|
|
|
|
|
|
ushort mfsAllBlocks = BigEndianBitConverter.ToUInt16(data, (data.Length / 2) + 0x412);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
// Detect a Macintosh Twiggy
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(mfsMagic == 0xD2D7 &&
|
|
|
|
|
|
mfsAllBlocks == 422)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Macintosh Twiggy detected, reversing disk sides");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Array.Copy(data, header.DataSize / 2, twiggyCache, 0, header.DataSize / 2);
|
|
|
|
|
|
Array.Copy(tags, header.TagSize / 2, twiggyCacheTags, 0, header.TagSize / 2);
|
|
|
|
|
|
Array.Copy(data, 0, twiggyCache, header.DataSize / 2, header.DataSize / 2);
|
|
|
|
|
|
Array.Copy(tags, 0, twiggyCacheTags, header.TagSize / 2, header.TagSize / 2);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Lisa Twiggy detected, reversing second half of disk");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Array.Copy(data, 0, twiggyCache, 0, header.DataSize / 2);
|
|
|
|
|
|
Array.Copy(tags, 0, twiggyCacheTags, 0, header.TagSize / 2);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
int copiedSectors = 0;
|
|
|
|
|
|
int sectorsToCopy = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 46; i++)
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(i >= 0 &&
|
|
|
|
|
|
i <= 3)
|
|
|
|
|
|
sectorsToCopy = 22;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 4 &&
|
|
|
|
|
|
i <= 10)
|
|
|
|
|
|
sectorsToCopy = 21;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 11 &&
|
|
|
|
|
|
i <= 16)
|
|
|
|
|
|
sectorsToCopy = 20;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 17 &&
|
|
|
|
|
|
i <= 22)
|
|
|
|
|
|
sectorsToCopy = 19;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 23 &&
|
|
|
|
|
|
i <= 28)
|
|
|
|
|
|
sectorsToCopy = 18;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 29 &&
|
|
|
|
|
|
i <= 34)
|
|
|
|
|
|
sectorsToCopy = 17;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 35 &&
|
|
|
|
|
|
i <= 41)
|
|
|
|
|
|
sectorsToCopy = 16;
|
|
|
|
|
|
|
|
|
|
|
|
if(i >= 42 &&
|
|
|
|
|
|
i <= 45)
|
|
|
|
|
|
sectorsToCopy = 15;
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(data, (header.DataSize / 2) + (copiedSectors * 512), twiggyCache,
|
|
|
|
|
|
twiggyCache.Length - (copiedSectors * 512) - (sectorsToCopy * 512),
|
|
|
|
|
|
sectorsToCopy * 512);
|
|
|
|
|
|
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Array.Copy(tags, (header.TagSize / 2) + (copiedSectors * bptag), twiggyCacheTags,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
twiggyCacheTags.Length - (copiedSectors * bptag) - (sectorsToCopy * bptag),
|
2018-07-23 23:25:43 +01:00
|
|
|
|
sectorsToCopy * bptag);
|
|
|
|
|
|
|
|
|
|
|
|
copiedSectors += sectorsToCopy;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if(imageFilter.HasResourceFork())
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var rsrcFork = new ResourceFork(imageFilter.GetResourceForkStream());
|
|
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
if(rsrcFork.ContainsKey(0x76657273))
|
|
|
|
|
|
{
|
|
|
|
|
|
Resource versRsrc = rsrcFork.GetResource(0x76657273);
|
|
|
|
|
|
|
|
|
|
|
|
byte[] vers = versRsrc?.GetResource(versRsrc.GetIds()[0]);
|
|
|
|
|
|
|
|
|
|
|
|
if(vers != null)
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var version = new Version(vers);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
string release = null;
|
|
|
|
|
|
string dev = null;
|
|
|
|
|
|
string pre = null;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
string major = $"{version.MajorVersion}";
|
|
|
|
|
|
string minor = $".{version.MinorVersion / 10}";
|
|
|
|
|
|
|
|
|
|
|
|
if(version.MinorVersion % 10 > 0)
|
|
|
|
|
|
release = $".{version.MinorVersion % 10}";
|
|
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
switch(version.DevStage)
|
|
|
|
|
|
{
|
|
|
|
|
|
case Version.DevelopmentStage.Alpha:
|
|
|
|
|
|
dev = "a";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case Version.DevelopmentStage.Beta:
|
|
|
|
|
|
dev = "b";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case Version.DevelopmentStage.PreAlpha:
|
|
|
|
|
|
dev = "d";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(dev == null &&
|
|
|
|
|
|
version.PreReleaseVersion > 0)
|
|
|
|
|
|
dev = "f";
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(dev != null)
|
|
|
|
|
|
pre = $"{version.PreReleaseVersion}";
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
|
|
|
|
|
|
imageInfo.Application = version.VersionString;
|
|
|
|
|
|
imageInfo.Comments = version.VersionMessage;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(rsrcFork.ContainsKey(0x64437079))
|
|
|
|
|
|
{
|
|
|
|
|
|
Resource dCpyRsrc = rsrcFork.GetResource(0x64437079);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
if(dCpyRsrc != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dCpy = StringHandlers.PascalToString(dCpyRsrc.GetResource(dCpyRsrc.GetIds()[0]),
|
|
|
|
|
|
Encoding.GetEncoding("macintosh"));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
var dCpyEx = new Regex(REGEX_DCPY);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
Match dCpyMatch = dCpyEx.Match(dCpy);
|
|
|
|
|
|
|
|
|
|
|
|
if(dCpyMatch.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
imageInfo.Application = dCpyMatch.Groups["application"].Value;
|
|
|
|
|
|
imageInfo.ApplicationVersion = dCpyMatch.Groups["version"].Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
catch(InvalidCastException) {}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("DC42 plugin", "Image application = {0} version {1}", imageInfo.Application,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
imageInfo.ApplicationVersion);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.VerboseWriteLine("DiskCopy 4.2 image contains a disk of type {0}", imageInfo.MediaType);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
switch(imageInfo.MediaType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case MediaType.AppleSonySS:
|
|
|
|
|
|
imageInfo.Cylinders = 80;
|
|
|
|
|
|
imageInfo.Heads = 1;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 10;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.AppleSonyDS:
|
|
|
|
|
|
imageInfo.Cylinders = 80;
|
|
|
|
|
|
imageInfo.Heads = 2;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 10;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.DOS_35_DS_DD_9:
|
|
|
|
|
|
imageInfo.Cylinders = 80;
|
|
|
|
|
|
imageInfo.Heads = 2;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 9;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.DOS_35_HD:
|
|
|
|
|
|
imageInfo.Cylinders = 80;
|
|
|
|
|
|
imageInfo.Heads = 2;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 18;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.DMF:
|
|
|
|
|
|
imageInfo.Cylinders = 80;
|
|
|
|
|
|
imageInfo.Heads = 2;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 21;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.AppleProfile:
|
|
|
|
|
|
switch(imageInfo.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 9728:
|
|
|
|
|
|
imageInfo.Cylinders = 152;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case 19456:
|
|
|
|
|
|
imageInfo.Cylinders = 304;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
imageInfo.Heads = 4;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 16;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.AppleWidget:
|
|
|
|
|
|
imageInfo.Cylinders = 608;
|
|
|
|
|
|
imageInfo.Heads = 2;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 16;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case MediaType.AppleHD20:
|
|
|
|
|
|
imageInfo.Cylinders = 610;
|
|
|
|
|
|
imageInfo.Heads = 2;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 16;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
imageInfo.Cylinders = (uint)(imageInfo.Sectors / 16 / 63);
|
|
|
|
|
|
imageInfo.Heads = 16;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = 63;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[length * imageInfo.SectorSize];
|
|
|
|
|
|
|
|
|
|
|
|
if(twiggy)
|
|
|
|
|
|
Array.Copy(twiggyCache, (int)sectorAddress * imageInfo.SectorSize, buffer, 0,
|
|
|
|
|
|
length * imageInfo.SectorSize);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Stream stream = dc42ImageFilter.GetDataForkStream();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
stream.Seek((long)(dataOffset + (sectorAddress * imageInfo.SectorSize)), SeekOrigin.Begin);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
stream.Read(buffer, 0, (int)(length * imageInfo.SectorSize));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(tag != SectorTagType.AppleSectorTag)
|
|
|
|
|
|
throw new FeatureUnsupportedImageException($"Tag {tag} not supported by image format");
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.TagSize == 0)
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Disk image does not have tags");
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[length * bptag];
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(twiggy)
|
|
|
|
|
|
Array.Copy(twiggyCacheTags, (int)sectorAddress * bptag, buffer, 0, length * bptag);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Stream stream = dc42ImageFilter.GetDataForkStream();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
stream.Seek((long)(tagOffset + (sectorAddress * bptag)), SeekOrigin.Begin);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
stream.Read(buffer, 0, (int)(length * bptag));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
|
|
|
|
|
byte[] data = ReadSectors(sectorAddress, length);
|
|
|
|
|
|
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
|
|
|
|
|
byte[] buffer = new byte[data.Length + tags.Length];
|
|
|
|
|
|
|
|
|
|
|
|
for(uint i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(data, i * imageInfo.SectorSize, buffer, i * (imageInfo.SectorSize + bptag),
|
|
|
|
|
|
imageInfo.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
Array.Copy(tags, i * bptag, buffer, (i * (imageInfo.SectorSize + bptag)) + imageInfo.SectorSize, bptag);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|