2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-08-09 15:31:44 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Alcohol120.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2016-08-17 01:32:20 +01:00
|
|
|
// Component : Disc image plugins.
|
2016-08-09 15:31:44 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-08-17 01:32:20 +01:00
|
|
|
// Manages Alcohol 120% disc images.
|
2016-08-09 15:31:44 +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-08-09 15:31:44 +01:00
|
|
|
// ****************************************************************************/
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2016-08-09 15:31:44 +01:00
|
|
|
using System;
|
2016-08-09 15:33:41 +01:00
|
|
|
using System.Collections.Generic;
|
2017-12-22 06:55:04 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-08-09 15:33:41 +01:00
|
|
|
using System.IO;
|
2017-12-21 07:08:26 +00:00
|
|
|
using System.Linq;
|
2016-08-09 15:33:41 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.Text;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.Checksums;
|
2016-08-09 15:33:41 +01:00
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
using DiscImageChef.Console;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.Decoders.CD;
|
|
|
|
|
using DiscImageChef.Decoders.DVD;
|
2016-09-05 17:37:31 +01:00
|
|
|
using DiscImageChef.Filters;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DMI = DiscImageChef.Decoders.Xbox.DMI;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
namespace DiscImageChef.DiscImages
|
2016-08-09 15:31:44 +01:00
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
public class Alcohol120 : IMediaImage
|
2016-08-09 15:31:44 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
AlcoholFooter alcFooter;
|
2017-12-26 06:05:12 +00:00
|
|
|
IFilter alcImage;
|
2016-08-09 15:33:41 +01:00
|
|
|
Dictionary<int, AlcoholSession> alcSessions;
|
|
|
|
|
Dictionary<int, Dictionary<int, AlcoholTrack>> alcToc;
|
|
|
|
|
Dictionary<int, AlcoholTrackExtra> alcTrackExtras;
|
2017-12-24 00:12:31 +00:00
|
|
|
Dictionary<int, AlcoholTrack> alcTracks;
|
2016-08-09 15:33:41 +01:00
|
|
|
byte[] bca;
|
2017-12-24 00:12:31 +00:00
|
|
|
byte[] dmi;
|
2016-08-09 15:33:41 +01:00
|
|
|
byte[] fullToc;
|
2017-12-26 06:05:12 +00:00
|
|
|
ImageInfo imageInfo;
|
2017-12-24 00:12:31 +00:00
|
|
|
Stream imageStream;
|
2016-08-09 15:33:41 +01:00
|
|
|
bool isDvd;
|
2017-12-24 00:12:31 +00:00
|
|
|
Dictionary<uint, ulong> offsetmap;
|
|
|
|
|
List<Partition> partitions;
|
2016-08-09 15:33:41 +01:00
|
|
|
byte[] pfi;
|
2017-12-24 00:12:31 +00:00
|
|
|
List<Session> sessions;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2016-08-09 15:31:44 +01:00
|
|
|
public Alcohol120()
|
|
|
|
|
{
|
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,
|
|
|
|
|
Application = null,
|
|
|
|
|
ApplicationVersion = null,
|
|
|
|
|
Creator = null,
|
|
|
|
|
Comments = null,
|
2017-12-22 06:55:04 +00:00
|
|
|
MediaManufacturer = null,
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
MediaSerialNumber = null,
|
|
|
|
|
MediaBarcode = null,
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
DriveSerialNumber = null,
|
|
|
|
|
DriveFirmwareRevision = null
|
|
|
|
|
};
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public ImageInfo Info => imageInfo;
|
|
|
|
|
public string Name => "Alcohol 120% Media Descriptor Structure";
|
|
|
|
|
public Guid Id => new Guid("A78FBEBA-0307-4915-BDE3-B8A3B57F843F");
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
public string Format => "Alcohol 120% Media Descriptor Structure";
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public List<Partition> Partitions => partitions;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public List<Track> Tracks
|
2017-12-26 02:51:10 +00:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Track> tracks = new List<Track>();
|
|
|
|
|
|
|
|
|
|
foreach(AlcoholTrack alcTrack in alcTracks.Values)
|
|
|
|
|
{
|
|
|
|
|
ushort sessionNo =
|
|
|
|
|
(from session in sessions
|
|
|
|
|
where alcTrack.point >= session.StartTrack || alcTrack.point <= session.EndTrack
|
|
|
|
|
select session.SessionSequence).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if(!alcTrackExtras.TryGetValue(alcTrack.point, out AlcoholTrackExtra alcExtra)) continue;
|
|
|
|
|
|
|
|
|
|
Track dicTrack = new Track
|
|
|
|
|
{
|
|
|
|
|
Indexes = new Dictionary<int, ulong> {{1, alcTrack.startLba}},
|
|
|
|
|
TrackStartSector = alcTrack.startLba,
|
|
|
|
|
TrackEndSector = alcExtra.sectors - 1,
|
|
|
|
|
TrackPregap = alcExtra.pregap,
|
|
|
|
|
TrackSession = sessionNo,
|
|
|
|
|
TrackSequence = alcTrack.point,
|
|
|
|
|
TrackType = AlcoholTrackTypeToTrackType(alcTrack.mode),
|
|
|
|
|
TrackFilter = alcImage,
|
|
|
|
|
TrackFile = alcImage.GetFilename(),
|
|
|
|
|
TrackFileOffset = alcTrack.startOffset,
|
|
|
|
|
TrackFileType = "BINARY",
|
|
|
|
|
TrackRawBytesPerSector = alcTrack.sectorSize,
|
|
|
|
|
TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(alcTrack.mode)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch(alcTrack.subMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
dicTrack.TrackSubchannelFilter = alcImage;
|
|
|
|
|
dicTrack.TrackSubchannelFile = alcImage.GetFilename();
|
|
|
|
|
dicTrack.TrackSubchannelOffset = alcTrack.startOffset;
|
|
|
|
|
dicTrack.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
dicTrack.TrackRawBytesPerSector += 96;
|
|
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
|
|
|
|
dicTrack.TrackSubchannelType = TrackSubchannelType.None;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tracks.Add(dicTrack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public List<Session> Sessions => sessions;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
public bool Identify(IFilter imageFilter)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2016-08-09 15:33:41 +01:00
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(stream.Length < 88) return false;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
byte[] hdr = new byte[88];
|
|
|
|
|
stream.Read(hdr, 0, 88);
|
|
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(88);
|
|
|
|
|
Marshal.Copy(hdr, 0, hdrPtr, 88);
|
2017-12-22 06:55:04 +00:00
|
|
|
AlcoholHeader header = (AlcoholHeader)Marshal.PtrToStructure(hdrPtr, typeof(AlcoholHeader));
|
2016-08-09 15:33:41 +01:00
|
|
|
Marshal.FreeHGlobal(hdrPtr);
|
|
|
|
|
|
|
|
|
|
return header.signature == "MEDIA DESCRIPTO";
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
public bool Open(IFilter imageFilter)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2016-08-09 15:33:41 +01:00
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(stream.Length < 88) return false;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
isDvd = false;
|
|
|
|
|
byte[] hdr = new byte[88];
|
|
|
|
|
stream.Read(hdr, 0, 88);
|
|
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(88);
|
|
|
|
|
Marshal.Copy(hdr, 0, hdrPtr, 88);
|
2017-12-22 06:55:04 +00:00
|
|
|
AlcoholHeader header = (AlcoholHeader)Marshal.PtrToStructure(hdrPtr, typeof(AlcoholHeader));
|
2016-08-09 15:33:41 +01:00
|
|
|
Marshal.FreeHGlobal(hdrPtr);
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.signature = {0}", header.signature);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.version = {0}.{1}", header.version[0],
|
|
|
|
|
header.version[1]);
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.type = {0}", header.type);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.sessions = {0}", header.sessions);
|
|
|
|
|
for(int i = 0; i < header.unknown1.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.unknown1[{1}] = 0x{0:X4}", header.unknown1[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.bcaLength = {0}", header.bcaLength);
|
|
|
|
|
for(int i = 0; i < header.unknown2.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.unknown2[{1}] = 0x{0:X8}", header.unknown2[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.bcaOffset = {0}", header.bcaOffset);
|
|
|
|
|
for(int i = 0; i < header.unknown3.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.unknown3[{1}] = 0x{0:X8}", header.unknown3[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.structuresOffset = {0}", header.structuresOffset);
|
|
|
|
|
for(int i = 0; i < header.unknown4.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.unknown4[{1}] = 0x{0:X8}", header.unknown4[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.sessionOffset = {0}", header.sessionOffset);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "header.dpmOffset = {0}", header.dpmOffset);
|
|
|
|
|
|
|
|
|
|
stream.Seek(header.sessionOffset, SeekOrigin.Begin);
|
|
|
|
|
alcSessions = new Dictionary<int, AlcoholSession>();
|
|
|
|
|
for(int i = 0; i < header.sessions; i++)
|
|
|
|
|
{
|
|
|
|
|
byte[] sesHdr = new byte[24];
|
|
|
|
|
stream.Read(sesHdr, 0, 24);
|
2017-12-21 16:07:20 +00:00
|
|
|
AlcoholSession session;
|
2016-08-09 15:33:41 +01:00
|
|
|
IntPtr sesPtr = Marshal.AllocHGlobal(24);
|
|
|
|
|
Marshal.Copy(sesHdr, 0, sesPtr, 24);
|
|
|
|
|
session = (AlcoholSession)Marshal.PtrToStructure(sesPtr, typeof(AlcoholSession));
|
|
|
|
|
Marshal.FreeHGlobal(sesPtr);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].sessionStart = {0}",
|
|
|
|
|
session.sessionStart, i);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].sessionEnd = {0}", session.sessionEnd,
|
|
|
|
|
i);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].sessionSequence = {0}",
|
|
|
|
|
session.sessionSequence, i);
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].allBlocks = {0}", session.allBlocks, i);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].nonTrackBlocks = {0}",
|
|
|
|
|
session.nonTrackBlocks, i);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].firstTrack = {0}", session.firstTrack,
|
|
|
|
|
i);
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].lastTrack = {0}", session.lastTrack, i);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].unknown = 0x{0:X8}", session.unknown, i);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{1}].trackOffset = {0}", session.trackOffset,
|
|
|
|
|
i);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
alcSessions.Add(session.sessionSequence, session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long footerOff = 0;
|
|
|
|
|
|
|
|
|
|
alcTracks = new Dictionary<int, AlcoholTrack>();
|
|
|
|
|
alcToc = new Dictionary<int, Dictionary<int, AlcoholTrack>>();
|
|
|
|
|
foreach(AlcoholSession session in alcSessions.Values)
|
|
|
|
|
{
|
|
|
|
|
stream.Seek(session.trackOffset, SeekOrigin.Begin);
|
|
|
|
|
Dictionary<int, AlcoholTrack> sesToc = new Dictionary<int, AlcoholTrack>();
|
|
|
|
|
for(int i = 0; i < session.allBlocks; i++)
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] trkHdr = new byte[80];
|
2016-08-09 15:33:41 +01:00
|
|
|
stream.Read(trkHdr, 0, 80);
|
2017-12-22 06:55:04 +00:00
|
|
|
IntPtr trkPtr = Marshal.AllocHGlobal(80);
|
2016-08-09 15:33:41 +01:00
|
|
|
Marshal.Copy(trkHdr, 0, trkPtr, 80);
|
2017-12-22 06:55:04 +00:00
|
|
|
AlcoholTrack track = (AlcoholTrack)Marshal.PtrToStructure(trkPtr, typeof(AlcoholTrack));
|
2016-08-09 15:33:41 +01:00
|
|
|
Marshal.FreeHGlobal(trkPtr);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].mode = {0}", track.mode,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].subMode = {0}",
|
|
|
|
|
track.subMode, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].adrCtl = {0}",
|
|
|
|
|
track.adrCtl, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].tno = {0}", track.tno,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].point = {0:X2}",
|
|
|
|
|
track.point, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].min = {0}", track.min,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].sec = {0}", track.sec,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].frame = {0}", track.frame,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].zero = {0}", track.zero,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].pmin = {0}", track.pmin,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].psec = {0}", track.psec,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].pframe = {0}",
|
|
|
|
|
track.pframe, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].extraOffset = {0}",
|
|
|
|
|
track.extraOffset, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].sectorSize = {0}",
|
|
|
|
|
track.sectorSize, track.point, session.sessionSequence);
|
2016-08-09 15:33:41 +01:00
|
|
|
//for(int j = 0; j < track.unknown.Length; j++)
|
|
|
|
|
// DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].unknown[{2}] = {0}", track.unknown[j], i, j, session.sessionSequence);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].startLba = {0}",
|
|
|
|
|
track.startLba, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].startOffset = {0}",
|
|
|
|
|
track.startOffset, track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].files = {0}", track.files,
|
|
|
|
|
track.point, session.sessionSequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].footerOffset = {0}",
|
|
|
|
|
track.footerOffset, track.point, session.sessionSequence);
|
2016-08-09 15:33:41 +01:00
|
|
|
//for(int j = 0; j < track.unknown2.Length; j++)
|
|
|
|
|
// DicConsole.DebugWriteLine("Alcohol 120% plugin", "session[{2}].track[{1}].unknown2[{2}] = {0}", track.unknown2[j], i, j, session.sessionSequence);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!sesToc.ContainsKey(track.point)) sesToc.Add(track.point, track);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(track.point < 0xA0) alcTracks.Add(track.point, track);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(footerOff == 0) footerOff = track.footerOffset;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
isDvd |= track.mode == AlcoholTrackMode.DVD;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
alcToc.Add(session.sessionSequence, sesToc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alcTrackExtras = new Dictionary<int, AlcoholTrackExtra>();
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
if(track.extraOffset > 0 && !isDvd)
|
|
|
|
|
{
|
|
|
|
|
byte[] extHdr = new byte[8];
|
|
|
|
|
stream.Seek(track.extraOffset, SeekOrigin.Begin);
|
|
|
|
|
stream.Read(extHdr, 0, 8);
|
2017-12-21 16:07:20 +00:00
|
|
|
AlcoholTrackExtra extra;
|
2016-08-09 15:33:41 +01:00
|
|
|
IntPtr extPtr = Marshal.AllocHGlobal(8);
|
|
|
|
|
Marshal.Copy(extHdr, 0, extPtr, 8);
|
|
|
|
|
extra = (AlcoholTrackExtra)Marshal.PtrToStructure(extPtr, typeof(AlcoholTrackExtra));
|
|
|
|
|
Marshal.FreeHGlobal(extPtr);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "track[{1}].extra.pregap = {0}", extra.pregap,
|
|
|
|
|
track.point);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "track[{1}].extra.sectors = {0}", extra.sectors,
|
|
|
|
|
track.point);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
alcTrackExtras.Add(track.point, extra);
|
|
|
|
|
}
|
|
|
|
|
else if(isDvd)
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
AlcoholTrackExtra extra = new AlcoholTrackExtra {sectors = track.extraOffset};
|
2016-08-09 15:33:41 +01:00
|
|
|
alcTrackExtras.Add(track.point, extra);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(footerOff > 0)
|
|
|
|
|
{
|
|
|
|
|
byte[] footer = new byte[16];
|
|
|
|
|
stream.Seek(footerOff, SeekOrigin.Begin);
|
|
|
|
|
stream.Read(footer, 0, 16);
|
|
|
|
|
alcFooter = new AlcoholFooter();
|
|
|
|
|
IntPtr footPtr = Marshal.AllocHGlobal(16);
|
|
|
|
|
Marshal.Copy(footer, 0, footPtr, 16);
|
|
|
|
|
alcFooter = (AlcoholFooter)Marshal.PtrToStructure(footPtr, typeof(AlcoholFooter));
|
|
|
|
|
Marshal.FreeHGlobal(footPtr);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "footer.filenameOffset = {0}",
|
|
|
|
|
alcFooter.filenameOffset);
|
2016-08-09 15:33:41 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "footer.widechar = {0}", alcFooter.widechar);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "footer.unknown1 = 0x{0:X8}", alcFooter.unknown1);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "footer.unknown2 = 0x{0:X8}", alcFooter.unknown2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
string alcFile = "*.mdf";
|
|
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
if(alcFooter.filenameOffset > 0)
|
|
|
|
|
{
|
|
|
|
|
stream.Seek(alcFooter.filenameOffset, SeekOrigin.Begin);
|
2017-12-24 00:12:31 +00:00
|
|
|
byte[] filename = header.dpmOffset == 0
|
|
|
|
|
? new byte[stream.Length - stream.Position]
|
|
|
|
|
: new byte[header.dpmOffset - stream.Position];
|
2016-08-09 17:12:17 +01:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
stream.Read(filename, 0, filename.Length);
|
2017-12-24 00:12:31 +00:00
|
|
|
alcFile = alcFooter.widechar == 1
|
|
|
|
|
? Encoding.Unicode.GetString(filename)
|
|
|
|
|
: Encoding.Default.GetString(filename);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "footer.filename = {0}", alcFile);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(alcFooter.filenameOffset == 0 ||
|
|
|
|
|
string.Compare(alcFile, "*.mdf", StringComparison.InvariantCultureIgnoreCase) == 0)
|
2016-09-05 17:37:31 +01:00
|
|
|
alcFile = Path.GetFileNameWithoutExtension(imageFilter.GetBasePath()) + ".mdf";
|
2016-08-09 17:12:17 +01:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
if(header.bcaLength > 0 && header.bcaOffset > 0 && isDvd)
|
|
|
|
|
{
|
|
|
|
|
bca = new byte[header.bcaLength];
|
|
|
|
|
stream.Seek(header.bcaOffset, SeekOrigin.Begin);
|
|
|
|
|
int readBytes = stream.Read(bca, 0, bca.Length);
|
|
|
|
|
|
|
|
|
|
if(readBytes == bca.Length)
|
|
|
|
|
switch(header.type)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholMediumType.DVD:
|
|
|
|
|
case AlcoholMediumType.DVDR:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_BCA);
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = AlcoholMediumTypeToMediaType(header.type);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
if(isDvd)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Second layer
|
2017-12-21 17:34:47 +00:00
|
|
|
if(header.structuresOffset > 0)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
byte[] structures = new byte[4100];
|
|
|
|
|
stream.Seek(header.structuresOffset, SeekOrigin.Begin);
|
|
|
|
|
stream.Read(structures, 0, 4100);
|
|
|
|
|
dmi = new byte[2052];
|
|
|
|
|
pfi = new byte[2052];
|
|
|
|
|
|
|
|
|
|
Array.Copy(structures, 0, dmi, 0, 2052);
|
|
|
|
|
Array.Copy(structures, 0x804, pfi, 4, 2048);
|
|
|
|
|
|
|
|
|
|
pfi[0] = 0x08;
|
|
|
|
|
pfi[1] = 0x02;
|
|
|
|
|
dmi[0] = 0x08;
|
|
|
|
|
dmi[1] = 0x02;
|
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
PFI.PhysicalFormatInformation? pfi0 = PFI.Decode(pfi);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// All discs I tested the disk category and part version (as well as the start PSN for DVD-RAM) where modified by Alcohol
|
|
|
|
|
// So much for archival value
|
|
|
|
|
if(pfi0.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch(pfi0.Value.DiskCategory)
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDPR:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDPR;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDPRDL:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDPRDL;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDPRW:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDPRW;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDPRWDL:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDPRWDL;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDR:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = pfi0.Value.PartVersion == 6 ? MediaType.DVDRDL : MediaType.DVDR;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDRAM:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDRAM;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDROM;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDRW:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = pfi0.Value.PartVersion == 3 ? MediaType.DVDRWDL : MediaType.DVDRW;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.HDDVDR:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.HDDVDR;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.HDDVDRAM:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.HDDVDRAM;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.HDDVDROM:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.HDDVDROM;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.HDDVDRW:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.HDDVDRW;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.Nintendo:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType =
|
2017-12-24 00:12:31 +00:00
|
|
|
pfi0.Value.DiscSize == DVDSize.Eighty ? MediaType.GOD : MediaType.WOD;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.UMD:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.UMD;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(DMI.IsXbox(dmi)) imageInfo.MediaType = MediaType.XGD;
|
|
|
|
|
else if(DMI.IsXbox360(dmi)) imageInfo.MediaType = MediaType.XGD2;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_PFI);
|
|
|
|
|
imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_DMI);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(header.type == AlcoholMediumType.CD)
|
|
|
|
|
{
|
|
|
|
|
bool data = false;
|
|
|
|
|
bool mode2 = false;
|
|
|
|
|
bool firstaudio = false;
|
|
|
|
|
bool firstdata = false;
|
|
|
|
|
bool audio = false;
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
foreach(AlcoholTrack alcoholTrack in alcTracks.Values)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
// First track is audio
|
2017-12-22 06:55:04 +00:00
|
|
|
firstaudio |= alcoholTrack.point == 1 && alcoholTrack.mode == AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// First track is data
|
2017-12-22 06:55:04 +00:00
|
|
|
firstdata |= alcoholTrack.point == 1 && alcoholTrack.mode != AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// Any non first track is data
|
2017-12-22 06:55:04 +00:00
|
|
|
data |= alcoholTrack.point != 1 && alcoholTrack.mode != AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// Any non first track is audio
|
2017-12-22 06:55:04 +00:00
|
|
|
audio |= alcoholTrack.point != 1 && alcoholTrack.mode == AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcoholTrack.mode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode2:
|
|
|
|
|
case AlcoholTrackMode.Mode2F1:
|
|
|
|
|
case AlcoholTrackMode.Mode2F2:
|
|
|
|
|
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;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "ImageInfo.mediaType = {0}", imageInfo.MediaType);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
sessions = new List<Session>();
|
|
|
|
|
foreach(AlcoholSession alcSes in alcSessions.Values)
|
|
|
|
|
{
|
|
|
|
|
Session session = new Session();
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(!alcTracks.TryGetValue(alcSes.firstTrack, out AlcoholTrack startingTrack)) break;
|
|
|
|
|
if(!alcTracks.TryGetValue(alcSes.lastTrack, out AlcoholTrack endingTrack)) break;
|
|
|
|
|
if(!alcTrackExtras.TryGetValue(alcSes.lastTrack, out AlcoholTrackExtra endingTrackExtra)) break;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
session.StartSector = startingTrack.startLba;
|
2016-08-09 15:33:41 +01:00
|
|
|
session.StartTrack = alcSes.firstTrack;
|
|
|
|
|
session.SessionSequence = alcSes.sessionSequence;
|
2017-12-22 06:55:04 +00:00
|
|
|
session.EndSector = endingTrack.startLba + endingTrackExtra.sectors - 1;
|
2016-08-09 15:33:41 +01:00
|
|
|
session.EndTrack = alcSes.lastTrack;
|
|
|
|
|
|
|
|
|
|
sessions.Add(session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
offsetmap = new Dictionary<uint, ulong>();
|
2017-12-22 06:55:04 +00:00
|
|
|
ulong byteOffset = 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
foreach(AlcoholTrack trk in alcTracks.Values)
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
if(alcTrackExtras.TryGetValue(trk.point, out AlcoholTrackExtra extra))
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
Partition partition = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = $"Track {trk.point}.",
|
|
|
|
|
Start = trk.startLba,
|
|
|
|
|
Size = extra.sectors * trk.sectorSize,
|
|
|
|
|
Length = extra.sectors,
|
|
|
|
|
Sequence = trk.point,
|
|
|
|
|
Offset = byteOffset,
|
|
|
|
|
Type = trk.mode.ToString()
|
|
|
|
|
};
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
partitions.Add(partition);
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.Sectors += extra.sectors;
|
2017-12-22 06:55:04 +00:00
|
|
|
byteOffset += partition.Size;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!offsetmap.ContainsKey(trk.point)) offsetmap.Add(trk.point, trk.startLba);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
switch(trk.mode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
|
|
|
|
case AlcoholTrackMode.Mode2F1Alt:
|
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.CdSectorSubHeader))
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
|
|
|
|
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);
|
|
|
|
|
if(imageInfo.SectorSize < 2048) imageInfo.SectorSize = 2048;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholTrackMode.Mode2:
|
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.SectorSize < 2336) imageInfo.SectorSize = 2336;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholTrackMode.Mode2F2:
|
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.CdSectorSubHeader))
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
|
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
|
|
|
|
if(imageInfo.SectorSize < 2324) imageInfo.SectorSize = 2324;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholTrackMode.DVD:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.SectorSize = 2048;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.SectorSize = 2352;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "printing partition map");
|
|
|
|
|
foreach(Partition partition in partitions)
|
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "Partition sequence: {0}", partition.Sequence);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition name: {0}", partition.Name);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition description: {0}", partition.Description);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition type: {0}", partition.Type);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition starting sector: {0}", partition.Start);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition sectors: {0}", partition.Length);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition starting offset: {0}", partition.Offset);
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "\tPartition size in bytes: {0}", partition.Size);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.Application = "Alcohol 120%";
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "Data filename: {0}", alcFile);
|
|
|
|
|
|
|
|
|
|
FiltersList filtersList = new FiltersList();
|
|
|
|
|
alcImage = filtersList.GetFilter(alcFile);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(alcImage == null) throw new Exception("Cannot open data file");
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.ImageSize = (ulong)alcImage.GetDataForkLength();
|
|
|
|
|
imageInfo.CreationTime = alcImage.GetCreationTime();
|
|
|
|
|
imageInfo.LastModificationTime = alcImage.GetLastWriteTime();
|
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
|
|
|
|
imageInfo.Version = $"{header.version[0]}.{header.version[1]}";
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
if(!isDvd)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "Rebuilding TOC");
|
|
|
|
|
byte firstSession = byte.MaxValue;
|
|
|
|
|
byte lastSession = 0;
|
|
|
|
|
MemoryStream tocMs = new MemoryStream();
|
2017-12-19 20:33:03 +00:00
|
|
|
tocMs.Write(new byte[] {0, 0, 0, 0}, 0, 4); // Reserved for TOC response size and session numbers
|
2016-08-09 15:33:41 +01:00
|
|
|
foreach(KeyValuePair<int, Dictionary<int, AlcoholTrack>> sessionToc in alcToc)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(sessionToc.Key < firstSession) firstSession = (byte)sessionToc.Key;
|
|
|
|
|
if(sessionToc.Key > lastSession) lastSession = (byte)sessionToc.Key;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
foreach(AlcoholTrack sessionTrack in sessionToc.Value.Values)
|
|
|
|
|
{
|
|
|
|
|
tocMs.WriteByte((byte)sessionToc.Key);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.adrCtl);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.tno);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.point);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.min);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.sec);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.frame);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.zero);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.pmin);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.psec);
|
|
|
|
|
tocMs.WriteByte(sessionTrack.pframe);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
fullToc = tocMs.ToArray();
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
byte[] fullTocSize = BigEndianBitConverter.GetBytes((short)(fullToc.Length - 2));
|
|
|
|
|
fullToc[0] = fullTocSize[0];
|
|
|
|
|
fullToc[1] = fullTocSize[1];
|
|
|
|
|
fullToc[2] = firstSession;
|
|
|
|
|
fullToc[3] = lastSession;
|
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
FullTOC.CDFullTOC? decodedFullToc = FullTOC.Decode(fullToc);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
if(!decodedFullToc.HasValue)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Alcohol 120% plugin", "TOC not correctly rebuilt");
|
|
|
|
|
fullToc = null;
|
|
|
|
|
}
|
2017-12-26 06:05:12 +00:00
|
|
|
else imageInfo.ReadableMediaTags.Add(MediaTagType.CD_FullTOC);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.MediaType == MediaType.XGD2)
|
|
|
|
|
if(imageInfo.Sectors == 25063 || // Locked (or non compatible drive)
|
|
|
|
|
imageInfo.Sectors == 4229664 || // Xtreme unlock
|
|
|
|
|
imageInfo.Sectors == 4246304) // Wxripper unlock
|
|
|
|
|
imageInfo.MediaType = MediaType.XGD3;
|
2017-05-23 19:25:17 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
DicConsole.VerboseWriteLine("Alcohol 120% image describes a disc of type {0}", imageInfo.MediaType);
|
2016-08-21 17:35:35 +01:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
switch(tag)
|
|
|
|
|
{
|
|
|
|
|
case MediaTagType.DVD_BCA:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(bca != null) return (byte[])bca.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain BCA information.");
|
|
|
|
|
}
|
2016-08-09 17:12:17 +01:00
|
|
|
case MediaTagType.DVD_PFI:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(pfi != null) return (byte[])pfi.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain PFI.");
|
|
|
|
|
}
|
2016-08-09 17:12:17 +01:00
|
|
|
case MediaTagType.DVD_DMI:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(dmi != null) return (byte[])dmi.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain DMI.");
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case MediaTagType.CD_FullTOC:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(fullToc != null) return (byte[])fullToc.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain TOC information.");
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
default:
|
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Feature not supported by image format");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, tag);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectors(sectorAddress, 1, track);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, track, tag);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
|
|
|
|
if(sectorAddress >= kvp.Value)
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
if(track.point != kvp.Key ||
|
|
|
|
|
!alcTrackExtras.TryGetValue(track.point, out AlcoholTrackExtra extra)) continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
if(sectorAddress - kvp.Value < extra.sectors)
|
|
|
|
|
return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
|
|
|
|
if(sectorAddress >= kvp.Value)
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
if(track.point != kvp.Key ||
|
|
|
|
|
!alcTrackExtras.TryGetValue(track.point, out AlcoholTrackExtra extra)) continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
if(sectorAddress - kvp.Value < extra.sectors)
|
|
|
|
|
return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
if(!alcTracks.TryGetValue((int)track, out AlcoholTrack alcTrack) ||
|
|
|
|
|
!alcTrackExtras.TryGetValue((int)track, out AlcoholTrackExtra alcExtra))
|
2016-08-09 15:33:41 +01:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(length + sectorAddress > alcExtra.sectors)
|
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 ({alcExtra.sectors}), won't cross tracks");
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
uint sectorOffset;
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
uint sectorSkip;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.mode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 16;
|
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 288;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 16;
|
|
|
|
|
sectorSize = 2336;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1Alt:
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 24;
|
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 280;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F2:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 24;
|
|
|
|
|
sectorSize = 2324;
|
|
|
|
|
sectorSkip = 4;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 0;
|
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.DVD:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 0;
|
|
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorSkip += 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorSkip += 96;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
imageStream = alcImage.GetDataForkStream();
|
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
2017-12-19 20:33:03 +00:00
|
|
|
br.BaseStream
|
2017-12-22 06:55:04 +00:00
|
|
|
.Seek((long)alcTrack.startOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
SeekOrigin.Begin);
|
2017-12-22 06:55:04 +00:00
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) buffer = br.ReadBytes((int)(sectorSize * length));
|
2016-09-05 17:37:31 +01:00
|
|
|
else
|
|
|
|
|
for(int i = 0; i < length; i++)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
|
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
|
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
if(!alcTracks.TryGetValue((int)track, out AlcoholTrack alcTrack) ||
|
|
|
|
|
!alcTrackExtras.TryGetValue((int)track, out AlcoholTrackExtra alcExtra))
|
2016-08-09 15:33:41 +01:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(length + sectorAddress > alcExtra.sectors)
|
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}) than present in track ({alcExtra.sectors}), won't cross tracks");
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
uint sectorOffset;
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
uint sectorSkip;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(alcTrack.mode == AlcoholTrackMode.DVD)
|
2016-08-09 15:33:41 +01: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;
|
2017-12-22 06:55:04 +00:00
|
|
|
case SectorTagType.CdTrackFlags: return new[] {(byte)(alcTrack.adrCtl & 0x0F)};
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.mode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
switch(tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +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-22 06:55:04 +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:
|
2016-08-09 15:33:41 +01: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-22 06:55:04 +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-22 06:55:04 +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-22 06:55:04 +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-22 06:55:04 +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-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
2017-12-22 06:55:04 +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));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholTrackMode.Mode2:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
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:
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-22 06:55:04 +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-22 06:55:04 +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-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 2352;
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
sectorSkip = 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1Alt:
|
|
|
|
|
switch(tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +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-22 06:55:04 +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
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 16;
|
|
|
|
|
sectorSize = 8;
|
|
|
|
|
sectorSkip = 2328;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEcc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +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-22 06:55:04 +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-22 06:55:04 +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-22 06:55:04 +00:00
|
|
|
sectorOffset = 2072;
|
|
|
|
|
sectorSize = 4;
|
|
|
|
|
sectorSkip = 276;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
2017-12-22 06:55:04 +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));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholTrackMode.Mode2F2:
|
|
|
|
|
switch(tag)
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +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-22 06:55:04 +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
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 16;
|
|
|
|
|
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-22 06:55:04 +00:00
|
|
|
sectorOffset = 2348;
|
|
|
|
|
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-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
2017-12-22 06:55:04 +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));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholTrackMode.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(tag)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 2352;
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
sectorSkip = 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorSkip += 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
2017-12-22 06:55:04 +00:00
|
|
|
if(tag != SectorTagType.CdSectorSubchannel) sectorSkip += 96;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
imageStream = alcImage.GetDataForkStream();
|
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
2017-12-19 20:33:03 +00:00
|
|
|
br.BaseStream
|
2017-12-22 06:55:04 +00:00
|
|
|
.Seek((long)alcTrack.startOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
SeekOrigin.Begin);
|
2017-12-22 06:55:04 +00:00
|
|
|
if(sectorOffset == 0 && sectorSkip == 0) buffer = br.ReadBytes((int)(sectorSize * length));
|
2016-09-05 17:37:31 +01:00
|
|
|
else
|
|
|
|
|
for(int i = 0; i < length; i++)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
|
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
|
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1, track);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
|
|
|
|
if(sectorAddress >= kvp.Value)
|
2017-12-22 06:55:04 +00:00
|
|
|
foreach(AlcoholTrack alcTrack in alcTracks.Values)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
if(alcTrack.point != kvp.Key ||
|
|
|
|
|
!alcTrackExtras.TryGetValue(alcTrack.point, out AlcoholTrackExtra alcExtra)) continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(sectorAddress - kvp.Value < alcExtra.sectors)
|
2017-12-21 06:06:19 +00:00
|
|
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
if(!alcTracks.TryGetValue((int)track, out AlcoholTrack alcTrack) ||
|
|
|
|
|
!alcTrackExtras.TryGetValue((int)track, out AlcoholTrackExtra alcExtra))
|
2016-08-09 15:33:41 +01:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(length + sectorAddress > alcExtra.sectors)
|
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}) than present in track ({alcExtra.sectors}), won't cross tracks");
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
uint sectorOffset;
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
uint sectorSkip;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(alcTrack.mode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2:
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1Alt:
|
|
|
|
|
case AlcoholTrackMode.Mode2F2:
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Audio:
|
|
|
|
|
case AlcoholTrackMode.DVD:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
sectorOffset = 0;
|
|
|
|
|
sectorSize = alcTrack.sectorSize;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
imageStream = alcImage.GetDataForkStream();
|
|
|
|
|
BinaryReader br = new BinaryReader(imageStream);
|
2017-12-19 20:33:03 +00:00
|
|
|
br.BaseStream
|
2017-12-22 06:55:04 +00:00
|
|
|
.Seek((long)alcTrack.startOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
SeekOrigin.Begin);
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] buffer = br.ReadBytes((int)(sectorSize * length));
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2016-08-09 15:33:41 +01: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
|
|
|
|
2016-08-09 15:33:41 +01: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)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
List<Track> tracks = new List<Track>();
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
foreach(AlcoholTrack alcTrack in alcTracks.Values)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
ushort sessionNo =
|
|
|
|
|
(from ses in sessions
|
|
|
|
|
where alcTrack.point >= ses.StartTrack || alcTrack.point <= ses.EndTrack
|
|
|
|
|
select ses.SessionSequence).FirstOrDefault();
|
2017-12-22 06:55:04 +00:00
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
if(!alcTrackExtras.TryGetValue(alcTrack.point, out AlcoholTrackExtra alcExtra) ||
|
|
|
|
|
session != sessionNo) continue;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
|
|
|
Track dicTrack = new Track
|
|
|
|
|
{
|
|
|
|
|
Indexes = new Dictionary<int, ulong> {{1, alcTrack.startLba}},
|
|
|
|
|
TrackStartSector = alcTrack.startLba,
|
|
|
|
|
TrackEndSector = alcExtra.sectors - 1,
|
|
|
|
|
TrackPregap = alcExtra.pregap,
|
|
|
|
|
TrackSession = sessionNo,
|
|
|
|
|
TrackSequence = alcTrack.point,
|
|
|
|
|
TrackType = AlcoholTrackTypeToTrackType(alcTrack.mode),
|
|
|
|
|
TrackFilter = alcImage,
|
|
|
|
|
TrackFile = alcImage.GetFilename(),
|
|
|
|
|
TrackFileOffset = alcTrack.startOffset,
|
|
|
|
|
TrackFileType = "BINARY",
|
|
|
|
|
TrackRawBytesPerSector = alcTrack.sectorSize,
|
|
|
|
|
TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(alcTrack.mode)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch(alcTrack.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack.TrackSubchannelFilter = alcImage;
|
|
|
|
|
dicTrack.TrackSubchannelFile = alcImage.GetFilename();
|
|
|
|
|
dicTrack.TrackSubchannelOffset = alcTrack.startOffset;
|
|
|
|
|
dicTrack.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
dicTrack.TrackRawBytesPerSector += 96;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack.TrackSubchannelType = TrackSubchannelType.None;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
tracks.Add(dicTrack);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-21 14:30:38 +00:00
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress, track);
|
2017-12-21 14:30:38 +00:00
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2016-08-09 15:33:41 +01: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)
|
2016-08-09 15:33:41 +01: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>();
|
2016-08-09 15:33:41 +01: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);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
switch(sectorStatus)
|
|
|
|
|
{
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2016-08-09 15:33:41 +01: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-22 06:55:04 +00:00
|
|
|
return failingLbas.Count <= 0;
|
2016-08-09 15:33:41 +01: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)
|
2016-08-09 15:33:41 +01: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>();
|
2016-08-09 15:33:41 +01: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);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
switch(sectorStatus)
|
|
|
|
|
{
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2016-08-09 15:33:41 +01: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;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool? VerifyMediaImage()
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ushort AlcoholTrackModeToBytesPerSector(AlcoholTrackMode trackMode)
|
|
|
|
|
{
|
|
|
|
|
switch(trackMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Audio:
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2:
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F2:
|
|
|
|
|
case AlcoholTrackMode.Mode2F1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1Alt: return 2352;
|
|
|
|
|
case AlcoholTrackMode.DVD: return 2048;
|
|
|
|
|
default: return 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ushort AlcoholTrackModeToCookedBytesPerSector(AlcoholTrackMode trackMode)
|
|
|
|
|
{
|
|
|
|
|
switch(trackMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
|
|
|
|
case AlcoholTrackMode.Mode2F1Alt: return 2048;
|
|
|
|
|
case AlcoholTrackMode.Mode2F2: return 2324;
|
|
|
|
|
case AlcoholTrackMode.Mode2: return 2336;
|
|
|
|
|
case AlcoholTrackMode.Audio: return 2352;
|
|
|
|
|
case AlcoholTrackMode.DVD: return 2048;
|
|
|
|
|
default: return 0;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static TrackType AlcoholTrackTypeToTrackType(AlcoholTrackMode trackType)
|
|
|
|
|
{
|
|
|
|
|
switch(trackType)
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case AlcoholTrackMode.Mode1: return TrackType.CdMode1;
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
2017-12-20 17:15:26 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1Alt: return TrackType.CdMode2Form1;
|
|
|
|
|
case AlcoholTrackMode.Mode2F2: return TrackType.CdMode2Form2;
|
|
|
|
|
case AlcoholTrackMode.Mode2: return TrackType.CdMode2Formless;
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Audio: return TrackType.Audio;
|
|
|
|
|
default: return TrackType.Data;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MediaType AlcoholMediumTypeToMediaType(AlcoholMediumType discType)
|
|
|
|
|
{
|
|
|
|
|
switch(discType)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholMediumType.CD: return MediaType.CD;
|
|
|
|
|
case AlcoholMediumType.CDR: return MediaType.CDR;
|
|
|
|
|
case AlcoholMediumType.CDRW: return MediaType.CDRW;
|
|
|
|
|
case AlcoholMediumType.DVD: return MediaType.DVDROM;
|
|
|
|
|
case AlcoholMediumType.DVDR: return MediaType.DVDR;
|
|
|
|
|
default: return MediaType.Unknown;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct AlcoholHeader
|
|
|
|
|
{
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string signature;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] version;
|
|
|
|
|
public AlcoholMediumType type;
|
|
|
|
|
public ushort sessions;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public ushort[] unknown1;
|
|
|
|
|
public ushort bcaLength;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public uint[] unknown2;
|
|
|
|
|
public uint bcaOffset;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public uint[] unknown3;
|
|
|
|
|
public uint structuresOffset;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public uint[] unknown4;
|
|
|
|
|
public uint sessionOffset;
|
|
|
|
|
public uint dpmOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct AlcoholSession
|
|
|
|
|
{
|
|
|
|
|
public int sessionStart;
|
|
|
|
|
public int sessionEnd;
|
|
|
|
|
public ushort sessionSequence;
|
|
|
|
|
public byte allBlocks;
|
|
|
|
|
public byte nonTrackBlocks;
|
|
|
|
|
public ushort firstTrack;
|
|
|
|
|
public ushort lastTrack;
|
|
|
|
|
public uint unknown;
|
|
|
|
|
public uint trackOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct AlcoholTrack
|
|
|
|
|
{
|
|
|
|
|
public AlcoholTrackMode mode;
|
|
|
|
|
public AlcoholSubchannelMode subMode;
|
|
|
|
|
public byte adrCtl;
|
|
|
|
|
public byte tno;
|
|
|
|
|
public byte point;
|
|
|
|
|
public byte min;
|
|
|
|
|
public byte sec;
|
|
|
|
|
public byte frame;
|
|
|
|
|
public byte zero;
|
|
|
|
|
public byte pmin;
|
|
|
|
|
public byte psec;
|
|
|
|
|
public byte pframe;
|
|
|
|
|
public uint extraOffset;
|
|
|
|
|
public ushort sectorSize;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)] public byte[] unknown;
|
|
|
|
|
public uint startLba;
|
|
|
|
|
public ulong startOffset;
|
|
|
|
|
public uint files;
|
|
|
|
|
public uint footerOffset;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] public byte[] unknown2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct AlcoholTrackExtra
|
|
|
|
|
{
|
|
|
|
|
public uint pregap;
|
|
|
|
|
public uint sectors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct AlcoholFooter
|
|
|
|
|
{
|
|
|
|
|
public uint filenameOffset;
|
|
|
|
|
public uint widechar;
|
|
|
|
|
public uint unknown1;
|
|
|
|
|
public uint unknown2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
enum AlcoholMediumType : ushort
|
|
|
|
|
{
|
|
|
|
|
CD = 0x00,
|
|
|
|
|
CDR = 0x01,
|
|
|
|
|
CDRW = 0x02,
|
|
|
|
|
DVD = 0x10,
|
|
|
|
|
DVDR = 0x12
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
enum AlcoholTrackMode : byte
|
|
|
|
|
{
|
|
|
|
|
NoData = 0x00,
|
|
|
|
|
DVD = 0x02,
|
|
|
|
|
Audio = 0xA9,
|
|
|
|
|
Mode1 = 0xAA,
|
|
|
|
|
Mode2 = 0xAB,
|
|
|
|
|
Mode2F1 = 0xAC,
|
|
|
|
|
Mode2F2 = 0xAD,
|
|
|
|
|
Mode2F1Alt = 0xEC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum AlcoholSubchannelMode : byte
|
|
|
|
|
{
|
|
|
|
|
None = 0x00,
|
|
|
|
|
Interleaved = 0x08
|
|
|
|
|
}
|
2016-08-09 15:31:44 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|