// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Read.cs // Author(s) : Natalia Portillo // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // // Reads SuperCardPro flux 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; using System.IO; using System.Linq; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; using Aaru.Console; using Aaru.Helpers; namespace Aaru.DiscImages { public sealed partial class SuperCardPro { /// public ErrorNumber Open(IFilter imageFilter) { Header = new ScpHeader(); _scpStream = imageFilter.GetDataForkStream(); _scpStream.Seek(0, SeekOrigin.Begin); if(_scpStream.Length < Marshal.SizeOf()) return ErrorNumber.InvalidArgument; byte[] hdr = new byte[Marshal.SizeOf()]; _scpStream.Read(hdr, 0, Marshal.SizeOf()); Header = Marshal.ByteArrayToStructureLittleEndian(hdr); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.signature = \"{0}\"", StringHandlers.CToString(Header.signature)); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.version = {0}.{1}", (Header.version & 0xF0) >> 4, Header.version & 0xF); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.type = {0}", Header.type); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.revolutions = {0}", Header.revolutions); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.start = {0}", Header.start); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.end = {0}", Header.end); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.flags = {0}", Header.flags); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.bitCellEncoding = {0}", Header.bitCellEncoding); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.heads = {0}", Header.heads); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.reserved = {0}", Header.reserved); AaruConsole.DebugWriteLine("SuperCardPro plugin", "header.checksum = 0x{0:X8}", Header.checksum); if(!_scpSignature.SequenceEqual(Header.signature)) return ErrorNumber.InvalidArgument; ScpTracks = new Dictionary(); for(byte t = Header.start; t <= Header.end; t++) { if(t >= Header.offsets.Length) break; _scpStream.Position = Header.offsets[t]; var trk = new TrackHeader { Signature = new byte[3], Entries = new TrackEntry[Header.revolutions] }; _scpStream.Read(trk.Signature, 0, trk.Signature.Length); trk.TrackNumber = (byte)_scpStream.ReadByte(); if(!trk.Signature.SequenceEqual(_trkSignature)) { AaruConsole.DebugWriteLine("SuperCardPro plugin", "Track header at {0} contains incorrect signature.", Header.offsets[t]); continue; } if(trk.TrackNumber != t) { AaruConsole.DebugWriteLine("SuperCardPro plugin", "Track number at {0} should be {1} but is {2}.", Header.offsets[t], t, trk.TrackNumber); continue; } AaruConsole.DebugWriteLine("SuperCardPro plugin", "Found track {0} at {1}.", t, Header.offsets[t]); for(byte r = 0; r < Header.revolutions; r++) { byte[] rev = new byte[Marshal.SizeOf()]; _scpStream.Read(rev, 0, Marshal.SizeOf()); trk.Entries[r] = Marshal.ByteArrayToStructureLittleEndian(rev); // De-relative offsets trk.Entries[r].dataOffset += Header.offsets[t]; } ScpTracks.Add(t, trk); } if(Header.flags.HasFlag(ScpFlags.HasFooter)) { long position = _scpStream.Position; _scpStream.Seek(-4, SeekOrigin.End); while(_scpStream.Position >= position) { byte[] footerSig = new byte[4]; _scpStream.Read(footerSig, 0, 4); uint footerMagic = BitConverter.ToUInt32(footerSig, 0); if(footerMagic == FOOTER_SIGNATURE) { _scpStream.Seek(-Marshal.SizeOf