2017-06-06 21:23:20 +01:00
|
|
|
|
// /***************************************************************************
|
2016-10-10 02:05:49 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : DiscJuggler.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disc image plugins.
|
2016-10-10 02:05:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages DiscJuggler disc images.
|
2016-10-10 02:05:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-10-10 02:05:49 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-10-10 02:06:52 +01:00
|
|
|
|
|
2016-10-10 02:05:49 +01:00
|
|
|
|
using System;
|
2016-10-10 02:06:52 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
using System.Linq;
|
2016-10-10 02:06:52 +01:00
|
|
|
|
using System.Text;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Checksums;
|
2016-10-10 02:06:52 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
using DiscImageChef.Filters;
|
|
|
|
|
|
|
2016-10-10 02:05:49 +01:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
// Support separate data files? Never seen a DiscJuggler image using them anyways...
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class DiscJuggler : IMediaImage
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] cdtext;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ImageInfo imageInfo;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Stream imageStream;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Dictionary<uint, ulong> offsetmap;
|
|
|
|
|
|
List<Partition> partitions;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
List<Session> sessions;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Dictionary<uint, byte> trackFlags;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
List<Track> tracks;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
public DiscJuggler()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo = new ImageInfo
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
|
|
|
|
|
ReadableSectorTags = new List<SectorTagType>(),
|
|
|
|
|
|
ReadableMediaTags = new List<MediaTagType>(),
|
2017-12-26 02:51:10 +00:00
|
|
|
|
HasPartitions = true,
|
|
|
|
|
|
HasSessions = true,
|
|
|
|
|
|
Version = null,
|
|
|
|
|
|
ApplicationVersion = null,
|
|
|
|
|
|
MediaTitle = null,
|
|
|
|
|
|
Creator = null,
|
2017-12-22 06:55:04 +00:00
|
|
|
|
MediaManufacturer = null,
|
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
|
DriveSerialNumber = null,
|
|
|
|
|
|
DriveFirmwareRevision = null
|
|
|
|
|
|
};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string Name => "DiscJuggler";
|
|
|
|
|
|
public Guid Id => new Guid("2444DBC6-CD35-424C-A227-39B0C4DB01B2");
|
|
|
|
|
|
public ImageInfo Info => imageInfo;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string ImageFormat => "DiscJuggler";
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Partition> Partitions => partitions;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> Tracks => tracks;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Session> Sessions => sessions;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool IdentifyImage(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
imageStream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
|
|
|
|
|
|
imageStream.Seek(-4, SeekOrigin.End);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] dscLenB = new byte[4];
|
|
|
|
|
|
imageStream.Read(dscLenB, 0, 4);
|
|
|
|
|
|
int dscLen = BitConverter.ToInt32(dscLenB, 0);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "dscLen = {0}", dscLen);
|
|
|
|
|
|
|
|
|
|
|
|
if(dscLen >= imageStream.Length) return false;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] descriptor = new byte[dscLen];
|
|
|
|
|
|
imageStream.Seek(-dscLen, SeekOrigin.End);
|
|
|
|
|
|
imageStream.Read(descriptor, 0, dscLen);
|
|
|
|
|
|
|
|
|
|
|
|
// Sessions
|
|
|
|
|
|
if(descriptor[0] > 99 || descriptor[0] == 0) return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Seems all sessions start with this data
|
|
|
|
|
|
if(descriptor[1] != 0x00 || descriptor[3] != 0x00 || descriptor[4] != 0x00 || descriptor[5] != 0x00 ||
|
|
|
|
|
|
descriptor[6] != 0x00 || descriptor[7] != 0x00 || descriptor[8] != 0x00 || descriptor[9] != 0x00 ||
|
|
|
|
|
|
descriptor[10] != 0x01 || descriptor[11] != 0x00 || descriptor[12] != 0x00 || descriptor[13] != 0x00 ||
|
|
|
|
|
|
descriptor[14] != 0xFF || descriptor[15] != 0xFF) return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Too many tracks
|
2017-12-24 00:12:31 +00:00
|
|
|
|
return descriptor[2] <= 99;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool OpenImage(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
imageStream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
|
|
|
|
|
|
imageStream.Seek(-4, SeekOrigin.End);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] dscLenB = new byte[4];
|
|
|
|
|
|
imageStream.Read(dscLenB, 0, 4);
|
|
|
|
|
|
int dscLen = BitConverter.ToInt32(dscLenB, 0);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
if(dscLen >= imageStream.Length) return false;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] descriptor = new byte[dscLen];
|
|
|
|
|
|
imageStream.Seek(-dscLen, SeekOrigin.End);
|
|
|
|
|
|
imageStream.Read(descriptor, 0, dscLen);
|
|
|
|
|
|
|
|
|
|
|
|
// Sessions
|
|
|
|
|
|
if(descriptor[0] > 99 || descriptor[0] == 0) return false;
|
|
|
|
|
|
|
|
|
|
|
|
int position = 1;
|
|
|
|
|
|
|
|
|
|
|
|
ushort sessionSequence = 0;
|
|
|
|
|
|
sessions = new List<Session>();
|
|
|
|
|
|
tracks = new List<Track>();
|
|
|
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
|
offsetmap = new Dictionary<uint, ulong>();
|
|
|
|
|
|
trackFlags = new Dictionary<uint, byte>();
|
|
|
|
|
|
ushort mediumType;
|
|
|
|
|
|
byte maxS = descriptor[0];
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "maxS = {0}", maxS);
|
|
|
|
|
|
uint lastSessionTrack = 0;
|
|
|
|
|
|
ulong currentOffset = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Read sessions
|
|
|
|
|
|
for(byte s = 0; s <= maxS; s++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "s = {0}", s);
|
|
|
|
|
|
|
|
|
|
|
|
// Seems all sessions start with this data
|
|
|
|
|
|
if(descriptor[position + 0] != 0x00 || descriptor[position + 2] != 0x00 ||
|
|
|
|
|
|
descriptor[position + 3] != 0x00 || descriptor[position + 4] != 0x00 ||
|
|
|
|
|
|
descriptor[position + 5] != 0x00 || descriptor[position + 6] != 0x00 ||
|
|
|
|
|
|
descriptor[position + 7] != 0x00 || descriptor[position + 8] != 0x00 ||
|
|
|
|
|
|
descriptor[position + 9] != 0x01 || descriptor[position + 10] != 0x00 ||
|
|
|
|
|
|
descriptor[position + 11] != 0x00 || descriptor[position + 12] != 0x00 ||
|
|
|
|
|
|
descriptor[position + 13] != 0xFF || descriptor[position + 14] != 0xFF) return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Too many tracks
|
|
|
|
|
|
if(descriptor[position + 1] > 99) return false;
|
|
|
|
|
|
|
|
|
|
|
|
byte maxT = descriptor[position + 1];
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "maxT = {0}", maxT);
|
|
|
|
|
|
|
|
|
|
|
|
sessionSequence++;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Session session = new Session
|
|
|
|
|
|
{
|
|
|
|
|
|
SessionSequence = sessionSequence,
|
|
|
|
|
|
EndTrack = uint.MinValue,
|
|
|
|
|
|
StartTrack = uint.MaxValue
|
|
|
|
|
|
};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
position += 15;
|
|
|
|
|
|
bool addedATrack = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Read track
|
|
|
|
|
|
for(byte t = 0; t < maxT; t++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "t = {0}", t);
|
|
|
|
|
|
Track track = new Track();
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 16;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] trackFilenameB = new byte[descriptor[position]];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
position++;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Array.Copy(descriptor, position, trackFilenameB, 0, trackFilenameB.Length);
|
|
|
|
|
|
position += trackFilenameB.Length;
|
|
|
|
|
|
track.TrackFile = Path.GetFileName(Encoding.Default.GetString(trackFilenameB));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tfilename = {0}", track.TrackFile);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 29;
|
|
|
|
|
|
|
|
|
|
|
|
mediumType = BitConverter.ToUInt16(descriptor, position);
|
|
|
|
|
|
position += 2;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tmediumType = {0}", mediumType);
|
|
|
|
|
|
|
|
|
|
|
|
// Read indices
|
|
|
|
|
|
track.Indexes = new Dictionary<int, ulong>();
|
|
|
|
|
|
ushort maxI = BitConverter.ToUInt16(descriptor, position);
|
|
|
|
|
|
position += 2;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tmaxI = {0}", maxI);
|
|
|
|
|
|
for(ushort i = 0; i < maxI; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint index = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
track.Indexes.Add(i, index);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tindex[{1}] = {0}", index, i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read CD-Text
|
|
|
|
|
|
uint maxC = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tmaxC = {0}", maxC);
|
|
|
|
|
|
for(uint c = 0; c < maxC; c++)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int cb = 0; cb < 18; cb++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int bLen = descriptor[position];
|
|
|
|
|
|
position++;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tc[{1}][{2}].Length = {0}", bLen, c, cb);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(bLen <= 0) continue;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] textBlk = new byte[bLen];
|
|
|
|
|
|
Array.Copy(descriptor, position, textBlk, 0, bLen);
|
|
|
|
|
|
position += bLen;
|
|
|
|
|
|
// Track title
|
|
|
|
|
|
if(cb != 10) continue;
|
|
|
|
|
|
|
|
|
|
|
|
track.TrackDescription = Encoding.Default.GetString(textBlk, 0, bLen);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tTrack title = {0}",
|
|
|
|
|
|
track.TrackDescription);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
position += 2;
|
|
|
|
|
|
uint trackMode = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\ttrackMode = {0}", trackMode);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
session.SessionSequence = (ushort)(BitConverter.ToUInt32(descriptor, position) + 1);
|
|
|
|
|
|
track.TrackSession = (ushort)(session.SessionSequence + 1);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tsession = {0}", session.SessionSequence);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
track.TrackSequence = BitConverter.ToUInt32(descriptor, position) + lastSessionTrack + 1;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\ttrack = {1} + {2} + 1 = {0}",
|
|
|
|
|
|
track.TrackSequence, BitConverter.ToUInt32(descriptor, position),
|
|
|
|
|
|
lastSessionTrack);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
track.TrackStartSector = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\ttrackStart = {0}", track.TrackStartSector);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
uint trackLen = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
track.TrackEndSector = track.TrackStartSector + trackLen - 1;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\ttrackEnd = {0}", track.TrackEndSector);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
if(track.TrackSequence > session.EndTrack)
|
|
|
|
|
|
{
|
|
|
|
|
|
session.EndTrack = track.TrackSequence;
|
|
|
|
|
|
session.EndSector = track.TrackEndSector;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(track.TrackSequence < session.StartTrack)
|
|
|
|
|
|
{
|
|
|
|
|
|
session.StartTrack = track.TrackSequence;
|
|
|
|
|
|
session.StartSector = track.TrackStartSector;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 16;
|
|
|
|
|
|
|
|
|
|
|
|
uint readMode = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\treadMode = {0}", readMode);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
uint trackCtl = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\ttrackCtl = {0}", trackCtl);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 9;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] isrc = new byte[12];
|
|
|
|
|
|
Array.Copy(descriptor, position, isrc, 0, 12);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tisrc = {0}", StringHandlers.CToString(isrc));
|
|
|
|
|
|
position += 12;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint isrcValid = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tisrc_valid = {0}", isrcValid);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 87;
|
|
|
|
|
|
|
|
|
|
|
|
byte sessionType = descriptor[position];
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tsessionType = {0}", sessionType);
|
|
|
|
|
|
position++;
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 5;
|
|
|
|
|
|
|
|
|
|
|
|
byte trackFollows = descriptor[position];
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\ttrackFollows = {0}", trackFollows);
|
|
|
|
|
|
position += 2;
|
|
|
|
|
|
|
|
|
|
|
|
uint endAddress = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "\tendAddress = {0}", endAddress);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
// As to skip the lead-in
|
|
|
|
|
|
bool firstTrack = currentOffset == 0;
|
|
|
|
|
|
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.None;
|
|
|
|
|
|
|
|
|
|
|
|
switch(trackMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Audio
|
|
|
|
|
|
case 0:
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imageInfo.SectorSize < 2352) imageInfo.SectorSize = 2352;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
track.TrackType = TrackType.Audio;
|
|
|
|
|
|
track.TrackBytesPerSector = 2352;
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
switch(readMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)track.TrackRawBytesPerSector;
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)track.TrackRawBytesPerSector;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)(track.TrackRawBytesPerSector + 16);
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
|
track.TrackSubchannelOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.Q16Interleaved;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)(track.TrackRawBytesPerSector + 16);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)(track.TrackRawBytesPerSector + 96);
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
|
track.TrackSubchannelOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)(track.TrackRawBytesPerSector + 96);
|
|
|
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
default: throw new ImageNotSupportedException($"Unknown read mode {readMode}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
// Mode 1 or DVD
|
|
|
|
|
|
case 1:
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imageInfo.SectorSize < 2048) imageInfo.SectorSize = 2048;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
track.TrackType = TrackType.CdMode1;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
track.TrackBytesPerSector = 2048;
|
|
|
|
|
|
switch(readMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2048;
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)track.TrackRawBytesPerSector;
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)track.TrackRawBytesPerSector;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw
|
|
|
|
|
|
new ImageNotSupportedException($"Invalid read mode {readMode} for this track");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
case 2:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)track.TrackRawBytesPerSector;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)(track.TrackRawBytesPerSector + 16);
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
|
track.TrackSubchannelOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.Q16Interleaved;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)(track.TrackRawBytesPerSector + 16);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)(track.TrackRawBytesPerSector + 96);
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
|
track.TrackSubchannelOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)(track.TrackRawBytesPerSector + 96);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
default: throw new ImageNotSupportedException($"Unknown read mode {readMode}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
// Mode 2
|
|
|
|
|
|
case 2:
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imageInfo.SectorSize < 2336) imageInfo.SectorSize = 2336;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
track.TrackType = TrackType.CdMode2Formless;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
track.TrackBytesPerSector = 2336;
|
|
|
|
|
|
switch(readMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
throw
|
|
|
|
|
|
new ImageNotSupportedException($"Invalid read mode {readMode} for this track");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
case 1:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2336;
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)track.TrackRawBytesPerSector;
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)track.TrackRawBytesPerSector;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)track.TrackRawBytesPerSector;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)(track.TrackRawBytesPerSector + 16);
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
|
track.TrackSubchannelOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.Q16Interleaved;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)(track.TrackRawBytesPerSector + 16);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
|
|
|
|
|
if(firstTrack) currentOffset += 150 * (ulong)(track.TrackRawBytesPerSector + 96);
|
|
|
|
|
|
track.TrackFileOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
|
track.TrackSubchannelOffset = currentOffset;
|
|
|
|
|
|
track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
|
currentOffset += trackLen * (ulong)(track.TrackRawBytesPerSector + 96);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
default: throw new ImageNotSupportedException($"Unknown read mode {readMode}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
default: throw new ImageNotSupportedException($"Unknown track mode {trackMode}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
track.TrackFile = imageFilter.GetFilename();
|
|
|
|
|
|
track.TrackFilter = imageFilter;
|
|
|
|
|
|
if(track.TrackSubchannelType != TrackSubchannelType.None)
|
|
|
|
|
|
{
|
|
|
|
|
|
track.TrackSubchannelFile = imageFilter.GetFilename();
|
|
|
|
|
|
track.TrackSubchannelFilter = imageFilter;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
|
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Partition partition = new Partition
|
|
|
|
|
|
{
|
|
|
|
|
|
Description = track.TrackDescription,
|
|
|
|
|
|
Size = (ulong)(trackLen * track.TrackBytesPerSector),
|
|
|
|
|
|
Length = trackLen,
|
|
|
|
|
|
Sequence = track.TrackSequence,
|
|
|
|
|
|
Offset = track.TrackFileOffset,
|
|
|
|
|
|
Start = track.TrackStartSector,
|
|
|
|
|
|
Type = track.TrackType.ToString()
|
|
|
|
|
|
};
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Sectors += partition.Length;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
partitions.Add(partition);
|
|
|
|
|
|
offsetmap.Add(track.TrackSequence, track.TrackStartSector);
|
|
|
|
|
|
tracks.Add(track);
|
|
|
|
|
|
trackFlags.Add(track.TrackSequence, (byte)(trackCtl & 0xFF));
|
|
|
|
|
|
addedATrack = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(!addedATrack) continue;
|
|
|
|
|
|
|
|
|
|
|
|
lastSessionTrack = session.EndTrack;
|
|
|
|
|
|
sessions.Add(session);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "session.StartTrack = {0}", session.StartTrack);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "session.StartSector = {0}", session.StartSector);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "session.EndTrack = {0}", session.EndTrack);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "session.EndSector = {0}", session.EndSector);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "session.SessionSequence = {0}",
|
|
|
|
|
|
session.SessionSequence);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 16;
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "Current position = {0}", position);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] filenameB = new byte[descriptor[position]];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
position++;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Array.Copy(descriptor, position, filenameB, 0, filenameB.Length);
|
|
|
|
|
|
position += filenameB.Length;
|
|
|
|
|
|
string filename = Path.GetFileName(Encoding.Default.GetString(filenameB));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "filename = {0}", filename);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 29;
|
|
|
|
|
|
|
|
|
|
|
|
mediumType = BitConverter.ToUInt16(descriptor, position);
|
|
|
|
|
|
position += 2;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "mediumType = {0}", mediumType);
|
|
|
|
|
|
|
|
|
|
|
|
uint discSize = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "discSize = {0}", discSize);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] volidB = new byte[descriptor[position]];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
position++;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Array.Copy(descriptor, position, volidB, 0, volidB.Length);
|
|
|
|
|
|
position += volidB.Length;
|
|
|
|
|
|
string volid = Path.GetFileName(Encoding.Default.GetString(volidB));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "volid = {0}", volid);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 9;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] mcn = new byte[13];
|
|
|
|
|
|
Array.Copy(descriptor, position, mcn, 0, 13);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "mcn = {0}", StringHandlers.CToString(mcn));
|
|
|
|
|
|
position += 13;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint mcnValid = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "mcn_valid = {0}", mcnValid);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
position += 4;
|
|
|
|
|
|
|
|
|
|
|
|
uint cdtextLen = BitConverter.ToUInt32(descriptor, position);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "cdtextLen = {0}", cdtextLen);
|
|
|
|
|
|
position += 4;
|
|
|
|
|
|
if(cdtextLen > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
cdtext = new byte[cdtextLen];
|
|
|
|
|
|
Array.Copy(descriptor, position, cdtext, 0, cdtextLen);
|
|
|
|
|
|
position += (int)cdtextLen;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.ReadableMediaTags.Add(MediaTagType.CD_TEXT);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Skip unknown
|
|
|
|
|
|
position += 12;
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscJuggler plugin", "End position = {0}", position);
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imageInfo.MediaType == MediaType.CDROM)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
bool data = false;
|
|
|
|
|
|
bool mode2 = false;
|
|
|
|
|
|
bool firstaudio = false;
|
|
|
|
|
|
bool firstdata = false;
|
|
|
|
|
|
bool audio = false;
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < tracks.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// First track is audio
|
|
|
|
|
|
firstaudio |= i == 0 && tracks[i].TrackType == TrackType.Audio;
|
|
|
|
|
|
|
|
|
|
|
|
// First track is data
|
|
|
|
|
|
firstdata |= i == 0 && tracks[i].TrackType != TrackType.Audio;
|
|
|
|
|
|
|
|
|
|
|
|
// Any non first track is data
|
|
|
|
|
|
data |= i != 0 && tracks[i].TrackType != TrackType.Audio;
|
|
|
|
|
|
|
|
|
|
|
|
// Any non first track is audio
|
|
|
|
|
|
audio |= i != 0 && tracks[i].TrackType == TrackType.Audio;
|
|
|
|
|
|
|
|
|
|
|
|
switch(tracks[i].TrackType)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode2Form1:
|
|
|
|
|
|
case TrackType.CdMode2Form2:
|
|
|
|
|
|
case TrackType.CdMode2Formless:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
mode2 = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(!data && !firstdata) imageInfo.MediaType = MediaType.CDDA;
|
|
|
|
|
|
else if(firstaudio && data && sessions.Count > 1 && mode2) imageInfo.MediaType = MediaType.CDPLUS;
|
|
|
|
|
|
else if(firstdata && audio || mode2) imageInfo.MediaType = MediaType.CDROMXA;
|
|
|
|
|
|
else if(!audio) imageInfo.MediaType = MediaType.CDROM;
|
|
|
|
|
|
else imageInfo.MediaType = MediaType.CD;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Application = "DiscJuggler";
|
|
|
|
|
|
imageInfo.ImageSize = (ulong)imageFilter.GetDataForkLength();
|
|
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
|
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
|
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
static MediaType DecodeCdiMediumType(ushort type)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch(type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 56: return MediaType.DVDROM;
|
|
|
|
|
|
case 152: return MediaType.CDROM;
|
|
|
|
|
|
default: return MediaType.Unknown;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
case MediaTagType.CD_TEXT:
|
|
|
|
|
|
{
|
|
|
|
|
|
if(cdtext != null && cdtext.Length > 0) return cdtext;
|
|
|
|
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain CD-TEXT information.");
|
|
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1, track);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, track, tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
|
where sectorAddress >= kvp.Value
|
|
|
|
|
|
from track in tracks
|
|
|
|
|
|
where track.TrackSequence == kvp.Key
|
|
|
|
|
|
where sectorAddress < track.TrackEndSector
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-21 17:58:51 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap
|
|
|
|
|
|
.Where(kvp => sectorAddress >= kvp.Value)
|
|
|
|
|
|
.Where(kvp => tracks.Where(track => track.TrackSequence == kvp.Key)
|
|
|
|
|
|
.Any(track => sectorAddress < track.TrackEndSector)))
|
|
|
|
|
|
return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-21 17:58:51 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Track dicTrack = new Track {TrackSequence = 0};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(Track linqTrack in tracks.Where(linqTrack => linqTrack.TrackSequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = linqTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackSequence == 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(length + sectorAddress > dicTrack.TrackEndSector)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2017-12-22 06:55:04 +00:00
|
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({dicTrack.TrackEndSector}), won't cross tracks");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.TrackType)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
case TrackType.Audio:
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
|
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode1:
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackRawBytesPerSector == 2352)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 16;
|
|
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 288;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
|
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode2Formless:
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackRawBytesPerSector == 2352)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 16;
|
|
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
|
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.TrackSubchannelType)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 16;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 96;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
imageStream.Seek((long)(dicTrack.TrackFileOffset + sectorAddress * (ulong)dicTrack.TrackRawBytesPerSector),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) imageStream.Read(buffer, 0, buffer.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] sector = new byte[sectorSize];
|
|
|
|
|
|
imageStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
imageStream.Read(sector, 0, sector.Length);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
imageStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Track dicTrack = new Track {TrackSequence = 0};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(Track linqTrack in tracks.Where(linqTrack => linqTrack.TrackSequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = linqTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackSequence == 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(length + sectorAddress > dicTrack.TrackEndSector)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2017-12-22 06:55:04 +00:00
|
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({dicTrack.TrackEndSector}), won't cross tracks");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackType == TrackType.Data)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
|
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEcc:
|
|
|
|
|
|
case SectorTagType.CdSectorEccP:
|
|
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
|
|
|
|
|
case SectorTagType.CdSectorEdc:
|
|
|
|
|
|
case SectorTagType.CdSectorHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
|
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorSync: break;
|
|
|
|
|
|
case SectorTagType.CdTrackFlags:
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(trackFlags.TryGetValue(track, out byte flag)) return new[] {flag};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorOffset;
|
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
|
uint sectorSkip;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.TrackType)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode1:
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackRawBytesPerSector != 2352)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
|
|
|
|
|
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
|
|
|
|
|
sectorSize = 12;
|
|
|
|
|
|
sectorSkip = 2340;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 12;
|
|
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 2336;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEcc:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2076;
|
|
|
|
|
|
sectorSize = 276;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEccP:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2076;
|
|
|
|
|
|
sectorSize = 172;
|
|
|
|
|
|
sectorSkip = 104;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2248;
|
|
|
|
|
|
sectorSize = 104;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2064;
|
|
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 284;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
switch(dicTrack.TrackSubchannelType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
|
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track",
|
|
|
|
|
|
nameof(tag));
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
throw new ArgumentException("Q16 subchannel not yet supported");
|
2017-12-21 04:43:29 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode2Formless:
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackRawBytesPerSector != 2352)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSync:
|
|
|
|
|
|
case SectorTagType.CdSectorHeader:
|
|
|
|
|
|
case SectorTagType.CdSectorEcc:
|
|
|
|
|
|
case SectorTagType.CdSectorEccP:
|
|
|
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track", nameof(tag));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 0;
|
|
|
|
|
|
sectorSize = 8;
|
|
|
|
|
|
sectorSkip = 2328;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2332;
|
|
|
|
|
|
sectorSize = 4;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
switch(dicTrack.TrackSubchannelType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
|
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track",
|
|
|
|
|
|
nameof(tag));
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
throw new ArgumentException("Q16 subchannel not yet supported");
|
2017-12-21 04:43:29 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case TrackType.Audio:
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(tag)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-24 00:12:31 +00:00
|
|
|
|
switch(dicTrack.TrackSubchannelType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
|
|
|
|
|
throw new ArgumentException("Unsupported tag requested for this track",
|
|
|
|
|
|
nameof(tag));
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
throw new ArgumentException("Q16 subchannel not yet supported");
|
2017-12-21 04:43:29 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.TrackSubchannelType)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 16;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 96;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
imageStream.Seek((long)(dicTrack.TrackFileOffset + sectorAddress * (ulong)dicTrack.TrackRawBytesPerSector),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) imageStream.Read(buffer, 0, buffer.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] sector = new byte[sectorSize];
|
|
|
|
|
|
imageStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
imageStream.Read(sector, 0, sector.Length);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
imageStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1, track);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
|
where sectorAddress >= kvp.Value
|
|
|
|
|
|
from track in tracks
|
|
|
|
|
|
where track.TrackSequence == kvp.Key
|
|
|
|
|
|
where sectorAddress - kvp.Value <
|
|
|
|
|
|
track.TrackEndSector - track.TrackStartSector
|
|
|
|
|
|
select kvp)
|
|
|
|
|
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-21 17:58:51 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
Track dicTrack = new Track {TrackSequence = 0};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(Track linqTrack in tracks.Where(linqTrack => linqTrack.TrackSequence == track))
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
dicTrack = linqTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(dicTrack.TrackSequence == 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(length + sectorAddress > dicTrack.TrackEndSector)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2017-12-22 06:55:04 +00:00
|
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({dicTrack.TrackEndSector}), won't cross tracks");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
uint sectorSize = (uint)dicTrack.TrackRawBytesPerSector;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
uint sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(dicTrack.TrackSubchannelType)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 16;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 96;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
imageStream.Seek((long)(dicTrack.TrackFileOffset + sectorAddress * (ulong)dicTrack.TrackRawBytesPerSector),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(sectorSkip == 0) imageStream.Read(buffer, 0, buffer.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] sector = new byte[sectorSize];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
imageStream.Read(sector, 0, sector.Length);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
imageStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
|
if(sessions.Contains(session)) return GetSessionTracks(session.SessionSequence);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
throw new ImageNotSupportedException("Session does not exist in disc image");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
return tracks.Where(track => track.TrackSession == session).ToList();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress, track);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
|
|
|
|
|
int bps = (int)(buffer.Length / length);
|
|
|
|
|
|
byte[] sector = new byte[bps];
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
switch(sectorStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(unknownLbas.Count > 0) return null;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
return failingLbas.Count <= 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
|
|
|
|
int bps = (int)(buffer.Length / length);
|
|
|
|
|
|
byte[] sector = new byte[bps];
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
switch(sectorStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(unknownLbas.Count > 0) return null;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
return failingLbas.Count <= 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifyMediaImage()
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|