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;
|
|
|
|
|
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-19 20:33:03 +00:00
|
|
|
public class Alcohol120 : ImagePlugin
|
2016-08-09 15:31:44 +01:00
|
|
|
{
|
2016-08-09 15:33:41 +01:00
|
|
|
#region Internal Structures
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct AlcoholHeader
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string signature;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] version;
|
2016-08-09 15:33:41 +01:00
|
|
|
public AlcoholMediumType type;
|
|
|
|
|
public ushort sessions;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public ushort[] unknown1;
|
2016-08-09 15:33:41 +01:00
|
|
|
public ushort bcaLength;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public uint[] unknown2;
|
2016-08-09 15:33:41 +01:00
|
|
|
public uint bcaOffset;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public uint[] unknown3;
|
2016-08-09 15:33:41 +01:00
|
|
|
public uint structuresOffset;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public uint[] unknown4;
|
2016-08-09 15:33:41 +01:00
|
|
|
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;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)] public byte[] unknown;
|
2016-08-09 15:33:41 +01:00
|
|
|
public uint startLba;
|
|
|
|
|
public ulong startOffset;
|
|
|
|
|
public uint files;
|
|
|
|
|
public uint footerOffset;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] public byte[] unknown2;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
#endregion Internal Structures
|
|
|
|
|
|
|
|
|
|
#region Internal enumerations
|
|
|
|
|
enum AlcoholMediumType : ushort
|
|
|
|
|
{
|
|
|
|
|
CD = 0x00,
|
|
|
|
|
CDR = 0x01,
|
|
|
|
|
CDRW = 0x02,
|
|
|
|
|
DVD = 0x10,
|
|
|
|
|
DVDR = 0x12
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum AlcoholTrackMode : byte
|
|
|
|
|
{
|
|
|
|
|
NoData = 0x00,
|
|
|
|
|
DVD = 0x02,
|
|
|
|
|
Audio = 0xA9,
|
|
|
|
|
Mode1 = 0xAA,
|
|
|
|
|
Mode2 = 0xAB,
|
|
|
|
|
Mode2F1 = 0xAC,
|
2017-11-08 17:34:02 +00:00
|
|
|
Mode2F2 = 0xAD,
|
2017-12-19 20:33:03 +00:00
|
|
|
Mode2F1Alt = 0xEC
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum AlcoholSubchannelMode : byte
|
|
|
|
|
{
|
|
|
|
|
None = 0x00,
|
|
|
|
|
Interleaved = 0x08
|
|
|
|
|
}
|
|
|
|
|
#endregion Internal enumerations
|
|
|
|
|
|
|
|
|
|
#region Internal variables
|
|
|
|
|
Dictionary<uint, ulong> offsetmap;
|
|
|
|
|
List<Partition> partitions;
|
|
|
|
|
Dictionary<int, AlcoholSession> alcSessions;
|
|
|
|
|
Dictionary<int, AlcoholTrack> alcTracks;
|
|
|
|
|
Dictionary<int, Dictionary<int, AlcoholTrack>> alcToc;
|
|
|
|
|
Dictionary<int, AlcoholTrackExtra> alcTrackExtras;
|
|
|
|
|
AlcoholFooter alcFooter;
|
2016-09-05 17:37:31 +01:00
|
|
|
Filter alcImage;
|
2016-08-09 15:33:41 +01:00
|
|
|
byte[] bca;
|
|
|
|
|
List<Session> sessions;
|
2016-09-05 17:37:31 +01:00
|
|
|
Stream imageStream;
|
2016-08-09 15:33:41 +01:00
|
|
|
byte[] fullToc;
|
|
|
|
|
bool isDvd;
|
|
|
|
|
byte[] dmi;
|
|
|
|
|
byte[] pfi;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public Methods
|
2016-08-09 15:31:44 +01:00
|
|
|
public Alcohol120()
|
|
|
|
|
{
|
2016-08-09 15:33:41 +01:00
|
|
|
Name = "Alcohol 120% Media Descriptor Structure";
|
2017-12-20 17:15:26 +00:00
|
|
|
PluginUuid = new Guid("A78FBEBA-0307-4915-BDE3-B8A3B57F843F");
|
2016-08-09 15:33:41 +01:00
|
|
|
ImageInfo = new ImageInfo();
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.ReadableSectorTags = new List<SectorTagType>();
|
|
|
|
|
ImageInfo.ReadableMediaTags = new List<MediaTagType>();
|
|
|
|
|
ImageInfo.ImageHasPartitions = false;
|
|
|
|
|
ImageInfo.ImageHasSessions = false;
|
|
|
|
|
ImageInfo.ImageVersion = null;
|
|
|
|
|
ImageInfo.ImageApplication = null;
|
|
|
|
|
ImageInfo.ImageApplicationVersion = null;
|
|
|
|
|
ImageInfo.ImageCreator = null;
|
|
|
|
|
ImageInfo.ImageComments = null;
|
|
|
|
|
ImageInfo.MediaManufacturer = null;
|
|
|
|
|
ImageInfo.MediaModel = null;
|
|
|
|
|
ImageInfo.MediaSerialNumber = null;
|
|
|
|
|
ImageInfo.MediaBarcode = null;
|
|
|
|
|
ImageInfo.MediaPartNumber = null;
|
|
|
|
|
ImageInfo.MediaSequence = 0;
|
|
|
|
|
ImageInfo.LastMediaSequence = 0;
|
|
|
|
|
ImageInfo.DriveManufacturer = null;
|
|
|
|
|
ImageInfo.DriveModel = null;
|
|
|
|
|
ImageInfo.DriveSerialNumber = null;
|
|
|
|
|
ImageInfo.DriveFirmwareRevision = null;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
public override bool IdentifyImage(Filter 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);
|
2017-12-21 16:07:20 +00:00
|
|
|
AlcoholHeader header;
|
2016-08-09 15:33:41 +01:00
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(88);
|
|
|
|
|
Marshal.Copy(hdr, 0, hdrPtr, 88);
|
|
|
|
|
header = (AlcoholHeader)Marshal.PtrToStructure(hdrPtr, typeof(AlcoholHeader));
|
|
|
|
|
Marshal.FreeHGlobal(hdrPtr);
|
|
|
|
|
|
|
|
|
|
return header.signature == "MEDIA DESCRIPTO";
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
public override bool OpenImage(Filter 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);
|
2017-12-21 16:07:20 +00:00
|
|
|
AlcoholHeader header;
|
2016-08-09 15:33:41 +01:00
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(88);
|
|
|
|
|
Marshal.Copy(hdr, 0, hdrPtr, 88);
|
|
|
|
|
header = (AlcoholHeader)Marshal.PtrToStructure(hdrPtr, typeof(AlcoholHeader));
|
|
|
|
|
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++)
|
|
|
|
|
{
|
|
|
|
|
byte[] trkHdr;
|
|
|
|
|
AlcoholTrack track;
|
|
|
|
|
IntPtr trkPtr;
|
|
|
|
|
|
|
|
|
|
trkHdr = new byte[80];
|
|
|
|
|
stream.Read(trkHdr, 0, 80);
|
|
|
|
|
trkPtr = Marshal.AllocHGlobal(80);
|
|
|
|
|
Marshal.Copy(trkHdr, 0, trkPtr, 80);
|
|
|
|
|
track = (AlcoholTrack)Marshal.PtrToStructure(trkPtr, typeof(AlcoholTrack));
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrackExtra extra = new AlcoholTrackExtra();
|
|
|
|
|
extra.sectors = track.extraOffset;
|
|
|
|
|
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);
|
|
|
|
|
byte[] filename;
|
2017-12-19 20:33:03 +00:00
|
|
|
if(header.dpmOffset == 0) filename = new byte[stream.Length - stream.Position];
|
|
|
|
|
else filename = 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-19 20:33:03 +00:00
|
|
|
if(alcFooter.widechar == 1) alcFile = Encoding.Unicode.GetString(filename);
|
|
|
|
|
else alcFile = 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-20 17:15:26 +00:00
|
|
|
ImageInfo.ReadableMediaTags.Add(MediaTagType.DVD_BCA);
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.MediaType = AlcoholMediumTypeToMediaType(header.type);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
if(isDvd)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Second layer
|
|
|
|
|
if(header.structuresOffset >= 0)
|
|
|
|
|
{
|
|
|
|
|
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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +00:00
|
|
|
if(pfi0.Value.PartVersion == 6) ImageInfo.MediaType = MediaType.DVDRDL;
|
|
|
|
|
else ImageInfo.MediaType = MediaType.DVDR;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.DVDRAM:
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.MediaType = MediaType.DVDRAM;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-20 17:15:26 +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-20 17:15:26 +00:00
|
|
|
if(pfi0.Value.PartVersion == 3) ImageInfo.MediaType = MediaType.DVDRWDL;
|
|
|
|
|
else ImageInfo.MediaType = MediaType.DVDRW;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.HDDVDR:
|
2017-12-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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:
|
|
|
|
|
if(pfi0.Value.DiscSize == DVDSize.Eighty)
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.MediaType = MediaType.GOD;
|
|
|
|
|
else ImageInfo.MediaType = MediaType.WOD;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.UMD:
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.MediaType = MediaType.UMD;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 14:30:38 +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-20 17:15:26 +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;
|
|
|
|
|
|
|
|
|
|
foreach(AlcoholTrack _track in alcTracks.Values)
|
|
|
|
|
{
|
|
|
|
|
// First track is audio
|
2016-08-17 01:32:20 +01:00
|
|
|
firstaudio |= _track.point == 1 && _track.mode == AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// First track is data
|
2016-08-17 01:32:20 +01:00
|
|
|
firstdata |= _track.point == 1 && _track.mode != AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// Any non first track is data
|
2016-08-17 01:32:20 +01:00
|
|
|
data |= _track.point != 1 && _track.mode != AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
// Any non first track is audio
|
2016-08-17 01:32:20 +01:00
|
|
|
audio |= _track.point != 1 && _track.mode == AlcoholTrackMode.Audio;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
switch(_track.mode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode2:
|
|
|
|
|
case AlcoholTrackMode.Mode2F1:
|
|
|
|
|
case AlcoholTrackMode.Mode2F2:
|
|
|
|
|
mode2 = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(!data && !firstdata) ImageInfo.MediaType = MediaType.CDDA;
|
|
|
|
|
else if(firstaudio && data && sessions.Count > 1 && mode2) ImageInfo.MediaType = MediaType.CDPLUS;
|
2017-12-20 17:26:28 +00:00
|
|
|
else if(firstdata && audio || mode2) ImageInfo.MediaType = MediaType.CDROMXA;
|
2017-12-20 17:15:26 +00:00
|
|
|
else if(!audio) ImageInfo.MediaType = MediaType.CDROM;
|
|
|
|
|
else ImageInfo.MediaType = MediaType.CD;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +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();
|
|
|
|
|
AlcoholTrack stTrk;
|
|
|
|
|
AlcoholTrack enTrk;
|
|
|
|
|
AlcoholTrackExtra enTrkExt;
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!alcTracks.TryGetValue(alcSes.firstTrack, out stTrk)) break;
|
|
|
|
|
if(!alcTracks.TryGetValue(alcSes.lastTrack, out enTrk)) break;
|
|
|
|
|
if(!alcTrackExtras.TryGetValue(alcSes.lastTrack, out enTrkExt)) break;
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
session.StartSector = stTrk.startLba;
|
|
|
|
|
session.StartTrack = alcSes.firstTrack;
|
|
|
|
|
session.SessionSequence = alcSes.sessionSequence;
|
|
|
|
|
session.EndSector = enTrk.startLba + enTrkExt.sectors - 1;
|
|
|
|
|
session.EndTrack = alcSes.lastTrack;
|
|
|
|
|
|
|
|
|
|
sessions.Add(session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
offsetmap = new Dictionary<uint, ulong>();
|
|
|
|
|
ulong byte_offset = 0;
|
|
|
|
|
|
|
|
|
|
foreach(AlcoholTrack trk in alcTracks.Values)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrackExtra extra;
|
|
|
|
|
if(alcTrackExtras.TryGetValue(trk.point, out extra))
|
|
|
|
|
{
|
|
|
|
|
Partition partition = new Partition();
|
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
partition.Description = string.Format("Track {0}.", trk.point);
|
|
|
|
|
partition.Start = trk.startLba;
|
|
|
|
|
partition.Size = extra.sectors * trk.sectorSize;
|
|
|
|
|
partition.Length = extra.sectors;
|
|
|
|
|
partition.Sequence = trk.point;
|
|
|
|
|
partition.Offset = byte_offset;
|
|
|
|
|
partition.Type = trk.mode.ToString();
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
partitions.Add(partition);
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.Sectors += extra.sectors;
|
2017-07-19 16:37:11 +01:00
|
|
|
byte_offset += 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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +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-20 17:15:26 +00:00
|
|
|
ImageInfo.SectorSize = 2048;
|
2016-08-09 15:33:41 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-20 17:15:26 +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-20 17:15:26 +00:00
|
|
|
ImageInfo.ImageApplication = "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-20 17:15:26 +00:00
|
|
|
ImageInfo.ImageSize = (ulong)alcImage.GetDataForkLength();
|
|
|
|
|
ImageInfo.ImageCreationTime = alcImage.GetCreationTime();
|
|
|
|
|
ImageInfo.ImageLastModificationTime = alcImage.GetLastWriteTime();
|
|
|
|
|
ImageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
|
|
|
|
ImageInfo.ImageVersion = string.Format("{0}.{1}", 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-20 17:15:26 +00:00
|
|
|
else ImageInfo.ReadableMediaTags.Add(MediaTagType.CD_FullTOC);
|
2016-08-09 15:33:41 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +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-20 17:15:26 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool ImageHasPartitions()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageHasPartitions;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ulong GetImageSize()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageSize;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ulong GetSectors()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.Sectors;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override uint GetSectorSize()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.SectorSize;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadDiskTag(MediaTagType tag)
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSector(ulong sectorAddress)
|
|
|
|
|
{
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
|
|
|
|
{
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSector(ulong sectorAddress, uint track)
|
|
|
|
|
{
|
|
|
|
|
return ReadSectors(sectorAddress, 1, track);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
|
|
|
|
{
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, track, tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectors(ulong sectorAddress, uint length)
|
|
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
|
|
|
|
if(sectorAddress >= kvp.Value)
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrackExtra extra;
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(track.point != kvp.Key || !alcTrackExtras.TryGetValue(track.point, out extra)) continue;
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
|
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
|
|
|
|
if(sectorAddress >= kvp.Value)
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrackExtra extra;
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(track.point != kvp.Key || !alcTrackExtras.TryGetValue(track.point, out extra)) continue;
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrack _track;
|
|
|
|
|
AlcoholTrackExtra _extra;
|
|
|
|
|
|
|
|
|
|
if(!alcTracks.TryGetValue((int)track, out _track) || !alcTrackExtras.TryGetValue((int)track, out _extra))
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
|
|
|
if(length + sectorAddress > _extra.sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
string
|
|
|
|
|
.Format("Requested more sectors ({0}) than present in track ({1}), won't cross tracks",
|
|
|
|
|
length + sectorAddress, _extra.sectors));
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
uint sector_offset;
|
|
|
|
|
uint sector_size;
|
|
|
|
|
uint sector_skip;
|
|
|
|
|
|
|
|
|
|
switch(_track.mode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholTrackMode.Mode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 16;
|
|
|
|
|
sector_size = 2048;
|
|
|
|
|
sector_skip = 288;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 16;
|
|
|
|
|
sector_size = 2336;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F1:
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholTrackMode.Mode2F1Alt:
|
|
|
|
|
{
|
|
|
|
|
sector_offset = 24;
|
|
|
|
|
sector_size = 2048;
|
|
|
|
|
sector_skip = 280;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Mode2F2:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 24;
|
|
|
|
|
sector_size = 2324;
|
|
|
|
|
sector_skip = 4;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = 2352;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
case AlcoholTrackMode.DVD:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = 2048;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(_track.subMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
|
|
|
|
sector_skip += 0;
|
|
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
sector_skip += 96;
|
|
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[sector_size * length];
|
|
|
|
|
|
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
|
|
|
|
|
.Seek((long)_track.startOffset + (long)(sectorAddress * (sector_offset + sector_size + sector_skip)),
|
|
|
|
|
SeekOrigin.Begin);
|
|
|
|
|
if(sector_offset == 0 && sector_skip == 0) buffer = br.ReadBytes((int)(sector_size * 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
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
byte[] sector;
|
|
|
|
|
br.BaseStream.Seek(sector_offset, SeekOrigin.Current);
|
|
|
|
|
sector = br.ReadBytes((int)sector_size);
|
|
|
|
|
br.BaseStream.Seek(sector_skip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sector_size, sector_size);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrack _track;
|
|
|
|
|
AlcoholTrackExtra _extra;
|
|
|
|
|
|
|
|
|
|
if(!alcTracks.TryGetValue((int)track, out _track) || !alcTrackExtras.TryGetValue((int)track, out _extra))
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
|
|
|
if(length + sectorAddress > _extra.sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
string
|
|
|
|
|
.Format("Requested more sectors ({0}) than present in track ({1}), won't cross tracks",
|
|
|
|
|
length, _extra.sectors));
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
uint sector_offset;
|
|
|
|
|
uint sector_size;
|
|
|
|
|
uint sector_skip;
|
|
|
|
|
|
|
|
|
|
if(_track.mode == AlcoholTrackMode.DVD)
|
|
|
|
|
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-21 14:30:38 +00:00
|
|
|
case SectorTagType.CdTrackFlags: return new[] {(byte)(_track.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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(_track.mode)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = 12;
|
|
|
|
|
sector_skip = 2340;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 12;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 2336;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
sector_offset = 2076;
|
|
|
|
|
sector_size = 276;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccP:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2076;
|
|
|
|
|
sector_size = 172;
|
|
|
|
|
sector_skip = 104;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2248;
|
|
|
|
|
sector_size = 104;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2064;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 284;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(_track.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
|
|
|
|
sector_offset = 2352;
|
|
|
|
|
sector_size = 96;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
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-19 20:33:03 +00:00
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = 8;
|
|
|
|
|
sector_skip = 2328;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2332;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(_track.subMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
|
|
|
|
sector_offset = 2352;
|
|
|
|
|
sector_size = 96;
|
2016-08-09 15:33:41 +01:00
|
|
|
sector_skip = 0;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = 12;
|
|
|
|
|
sector_skip = 2340;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 12;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 2336;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 16;
|
|
|
|
|
sector_size = 8;
|
|
|
|
|
sector_skip = 2328;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEcc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2076;
|
|
|
|
|
sector_size = 276;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccP:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2076;
|
|
|
|
|
sector_size = 172;
|
|
|
|
|
sector_skip = 104;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2248;
|
|
|
|
|
sector_size = 104;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2072;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 276;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(_track.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
|
|
|
|
sector_offset = 2352;
|
|
|
|
|
sector_size = 96;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = 12;
|
|
|
|
|
sector_skip = 2340;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 12;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 2336;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 16;
|
|
|
|
|
sector_size = 8;
|
|
|
|
|
sector_skip = 2328;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
sector_offset = 2348;
|
|
|
|
|
sector_size = 4;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(_track.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
|
|
|
|
sector_offset = 2352;
|
|
|
|
|
sector_size = 96;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
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-19 20:33:03 +00:00
|
|
|
switch(_track.subMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
|
|
|
|
|
sector_offset = 2352;
|
|
|
|
|
sector_size = 96;
|
|
|
|
|
sector_skip = 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(_track.subMode)
|
|
|
|
|
{
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
|
|
|
|
sector_skip += 0;
|
|
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
if(tag != SectorTagType.CdSectorSubchannel) sector_skip += 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[sector_size * length];
|
|
|
|
|
|
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
|
|
|
|
|
.Seek((long)_track.startOffset + (long)(sectorAddress * (sector_offset + sector_size + sector_skip)),
|
|
|
|
|
SeekOrigin.Begin);
|
|
|
|
|
if(sector_offset == 0 && sector_skip == 0) buffer = br.ReadBytes((int)(sector_size * 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
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
byte[] sector;
|
|
|
|
|
br.BaseStream.Seek(sector_offset, SeekOrigin.Current);
|
|
|
|
|
sector = br.ReadBytes((int)sector_size);
|
|
|
|
|
br.BaseStream.Seek(sector_skip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sector_size, sector_size);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorLong(ulong sectorAddress)
|
|
|
|
|
{
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
|
|
|
|
{
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1, track);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
|
|
|
|
{
|
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in offsetmap)
|
|
|
|
|
if(sectorAddress >= kvp.Value)
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrackExtra extra;
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(track.point != kvp.Key || !alcTrackExtras.TryGetValue(track.point, out extra)) continue;
|
|
|
|
|
|
|
|
|
|
if(sectorAddress - kvp.Value < extra.sectors)
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
|
|
|
|
{
|
|
|
|
|
AlcoholTrack _track;
|
|
|
|
|
AlcoholTrackExtra _extra;
|
|
|
|
|
|
|
|
|
|
if(!alcTracks.TryGetValue((int)track, out _track) || !alcTrackExtras.TryGetValue((int)track, out _extra))
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
|
|
|
if(length + sectorAddress > _extra.sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
|
|
|
|
string
|
|
|
|
|
.Format("Requested more sectors ({0}) than present in track ({1}), won't cross tracks",
|
|
|
|
|
length, _extra.sectors));
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
uint sector_offset;
|
|
|
|
|
uint sector_size;
|
|
|
|
|
uint sector_skip;
|
|
|
|
|
|
|
|
|
|
switch(_track.mode)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
sector_offset = 0;
|
|
|
|
|
sector_size = _track.sectorSize;
|
|
|
|
|
sector_skip = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-21 16:07:20 +00:00
|
|
|
byte[] buffer;
|
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
|
|
|
|
|
.Seek((long)_track.startOffset + (long)(sectorAddress * (sector_offset + sector_size + sector_skip)),
|
|
|
|
|
SeekOrigin.Begin);
|
2016-09-05 17:37:31 +01:00
|
|
|
buffer = br.ReadBytes((int)(sector_size * length));
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetImageFormat()
|
|
|
|
|
{
|
|
|
|
|
return "Alcohol 120% Media Descriptor Structure";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetImageVersion()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageVersion;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetImageApplication()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageApplication;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override MediaType GetMediaType()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaType;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Partition> GetPartitions()
|
|
|
|
|
{
|
|
|
|
|
return partitions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Track> GetTracks()
|
|
|
|
|
{
|
|
|
|
|
List<Track> tracks = new List<Track>();
|
|
|
|
|
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
2017-12-21 07:08:26 +00:00
|
|
|
ushort sessionNo = (from session in sessions where track.point >= session.StartTrack || track.point <= session.EndTrack select session.SessionSequence).FirstOrDefault();
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
AlcoholTrackExtra extra;
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!alcTrackExtras.TryGetValue(track.point, out extra)) continue;
|
|
|
|
|
|
|
|
|
|
Track _track = new Track();
|
|
|
|
|
|
|
|
|
|
_track.Indexes = new Dictionary<int, ulong>();
|
|
|
|
|
_track.Indexes.Add(1, track.startLba);
|
|
|
|
|
_track.TrackStartSector = track.startLba;
|
|
|
|
|
_track.TrackEndSector = extra.sectors - 1;
|
|
|
|
|
_track.TrackPregap = extra.pregap;
|
|
|
|
|
_track.TrackSession = sessionNo;
|
|
|
|
|
_track.TrackSequence = track.point;
|
|
|
|
|
_track.TrackType = AlcoholTrackTypeToTrackType(track.mode);
|
|
|
|
|
_track.TrackFilter = alcImage;
|
|
|
|
|
_track.TrackFile = alcImage.GetFilename();
|
|
|
|
|
_track.TrackFileOffset = track.startOffset;
|
|
|
|
|
_track.TrackFileType = "BINARY";
|
|
|
|
|
_track.TrackRawBytesPerSector = track.sectorSize;
|
|
|
|
|
_track.TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(track.mode);
|
|
|
|
|
switch(track.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
_track.TrackSubchannelFilter = alcImage;
|
|
|
|
|
_track.TrackSubchannelFile = alcImage.GetFilename();
|
|
|
|
|
_track.TrackSubchannelOffset = track.startOffset;
|
|
|
|
|
_track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
_track.TrackRawBytesPerSector += 96;
|
|
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
|
|
|
|
_track.TrackSubchannelType = TrackSubchannelType.None;
|
|
|
|
|
break;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
tracks.Add(_track);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Track> GetSessionTracks(Session session)
|
|
|
|
|
{
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Track> GetSessionTracks(ushort session)
|
|
|
|
|
{
|
|
|
|
|
List<Track> tracks = new List<Track>();
|
|
|
|
|
|
|
|
|
|
foreach(AlcoholTrack track in alcTracks.Values)
|
|
|
|
|
{
|
2017-12-21 07:08:26 +00:00
|
|
|
ushort sessionNo = (from ses in sessions where track.point >= ses.StartTrack || track.point <= ses.EndTrack select ses.SessionSequence).FirstOrDefault();
|
2016-08-09 15:33:41 +01:00
|
|
|
|
|
|
|
|
AlcoholTrackExtra extra;
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!alcTrackExtras.TryGetValue(track.point, out extra) || session != sessionNo) continue;
|
|
|
|
|
|
|
|
|
|
Track _track = new Track();
|
|
|
|
|
|
|
|
|
|
_track.Indexes = new Dictionary<int, ulong>();
|
|
|
|
|
_track.Indexes.Add(1, track.startLba);
|
|
|
|
|
_track.TrackStartSector = track.startLba;
|
|
|
|
|
_track.TrackEndSector = extra.sectors - 1;
|
|
|
|
|
_track.TrackPregap = extra.pregap;
|
|
|
|
|
_track.TrackSession = sessionNo;
|
|
|
|
|
_track.TrackSequence = track.point;
|
|
|
|
|
_track.TrackType = AlcoholTrackTypeToTrackType(track.mode);
|
|
|
|
|
_track.TrackFilter = alcImage;
|
|
|
|
|
_track.TrackFile = alcImage.GetFilename();
|
|
|
|
|
_track.TrackFileOffset = track.startOffset;
|
|
|
|
|
_track.TrackFileType = "BINARY";
|
|
|
|
|
_track.TrackRawBytesPerSector = track.sectorSize;
|
|
|
|
|
_track.TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(track.mode);
|
|
|
|
|
switch(track.subMode)
|
2016-08-09 15:33:41 +01:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
case AlcoholSubchannelMode.Interleaved:
|
|
|
|
|
_track.TrackSubchannelFilter = alcImage;
|
|
|
|
|
_track.TrackSubchannelFile = alcImage.GetFilename();
|
|
|
|
|
_track.TrackSubchannelOffset = track.startOffset;
|
|
|
|
|
_track.TrackSubchannelType = TrackSubchannelType.RawInterleaved;
|
|
|
|
|
_track.TrackRawBytesPerSector += 96;
|
|
|
|
|
break;
|
|
|
|
|
case AlcoholSubchannelMode.None:
|
|
|
|
|
_track.TrackSubchannelType = TrackSubchannelType.None;
|
|
|
|
|
break;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
tracks.Add(_track);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<Session> GetSessions()
|
|
|
|
|
{
|
|
|
|
|
return sessions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool? VerifySector(ulong sectorAddress)
|
|
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-21 14:30:38 +00:00
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool? VerifySector(ulong sectorAddress, uint track)
|
|
|
|
|
{
|
|
|
|
|
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-20 17:15:26 +00:00
|
|
|
public override bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
|
|
|
|
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;
|
|
|
|
|
if(failingLbas.Count > 0) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
public override bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
|
|
|
|
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;
|
|
|
|
|
if(failingLbas.Count > 0) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-09 15:33:41 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool? VerifyMediaImage()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
#endregion Public Methods
|
|
|
|
|
|
|
|
|
|
#region Private methods
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion Private methods
|
|
|
|
|
|
|
|
|
|
#region Unsupported features
|
|
|
|
|
public override string GetImageApplicationVersion()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageApplicationVersion;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DateTime GetImageCreationTime()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageCreationTime;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DateTime GetImageLastModificationTime()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageLastModificationTime;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetImageComments()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageComments;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetMediaSerialNumber()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaSerialNumber;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetMediaBarcode()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaBarcode;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetMediaSequence()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaSequence;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetLastDiskSequence()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.LastMediaSequence;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDriveManufacturer()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.DriveManufacturer;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDriveModel()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.DriveModel;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetDriveSerialNumber()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.DriveSerialNumber;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetMediaPartNumber()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaPartNumber;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetMediaManufacturer()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaManufacturer;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetMediaModel()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.MediaModel;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetImageName()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageName;
|
2016-08-09 15:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetImageCreator()
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
return ImageInfo.ImageCreator;
|
2016-08-09 15:31:44 +01:00
|
|
|
}
|
2016-08-09 15:33:41 +01:00
|
|
|
#endregion Unsupported features
|
2016-08-09 15:31:44 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|