2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-08-18 00:05:24 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : BlindWrite5.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2016-08-18 00:07:16 +01:00
|
|
|
// Component : Disc image plugins.
|
2016-08-18 00:05:24 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-08-18 00:07:16 +01:00
|
|
|
// Manages BlindWrite 5 disc images.
|
2016-08-18 00:05:24 +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-18 00:05:24 +01:00
|
|
|
// ****************************************************************************/
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2016-08-18 00:05:24 +01:00
|
|
|
using System;
|
2016-08-18 00:07:16 +01:00
|
|
|
using System.Collections.Generic;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.Globalization;
|
2016-08-18 00:07:16 +01:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
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-18 00:07:16 +01:00
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
using DiscImageChef.Console;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.Decoders.CD;
|
|
|
|
|
using DiscImageChef.Decoders.DVD;
|
|
|
|
|
using DiscImageChef.Decoders.SCSI;
|
2016-08-18 00:07:16 +01:00
|
|
|
using DiscImageChef.Decoders.SCSI.MMC;
|
2016-09-05 17:37:31 +01:00
|
|
|
using DiscImageChef.Filters;
|
2018-01-28 20:29:46 +00:00
|
|
|
using Schemas;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DMI = DiscImageChef.Decoders.Xbox.DMI;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
namespace DiscImageChef.DiscImages
|
2016-08-18 00:05:24 +01:00
|
|
|
{
|
2018-01-08 21:16:22 +00:00
|
|
|
// TODO: Too many unknowns to make this writable
|
2017-12-26 06:05:12 +00:00
|
|
|
public class BlindWrite5 : IMediaImage
|
2016-08-18 00:05:24 +01:00
|
|
|
{
|
2016-08-18 00:07:16 +01:00
|
|
|
/// <summary>"BWT5 STREAM FOOT"</summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
readonly byte[] bw5Footer =
|
2017-12-19 20:33:03 +00:00
|
|
|
{0x42, 0x57, 0x54, 0x35, 0x20, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4D, 0x20, 0x46, 0x4F, 0x4F, 0x54};
|
2017-12-24 00:12:31 +00:00
|
|
|
/// <summary>"BWT5 STREAM SIGN"</summary>
|
|
|
|
|
readonly byte[] bw5Signature =
|
|
|
|
|
{0x42, 0x57, 0x54, 0x35, 0x20, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4D, 0x20, 0x53, 0x49, 0x47, 0x4E};
|
2018-01-28 20:29:46 +00:00
|
|
|
byte[] atip;
|
|
|
|
|
byte[] bca;
|
|
|
|
|
List<Bw5SessionDescriptor> bwSessions;
|
|
|
|
|
byte[] cdtext;
|
|
|
|
|
List<Bw5DataFile> dataFiles;
|
|
|
|
|
string dataPath;
|
|
|
|
|
byte[] discInformation;
|
|
|
|
|
byte[] dmi;
|
|
|
|
|
byte[] dpm;
|
2016-08-18 00:07:16 +01:00
|
|
|
List<DataFileCharacteristics> filePaths;
|
2018-01-28 20:29:46 +00:00
|
|
|
byte[] fullToc;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
Bw5Header header;
|
|
|
|
|
ImageInfo imageInfo;
|
|
|
|
|
Stream imageStream;
|
|
|
|
|
byte[] mode2A;
|
2016-08-18 00:07:16 +01:00
|
|
|
Dictionary<uint, ulong> offsetmap;
|
2018-01-28 20:29:46 +00:00
|
|
|
byte[] pfi;
|
|
|
|
|
byte[] pma;
|
|
|
|
|
Dictionary<uint, byte> trackFlags;
|
|
|
|
|
byte[] unkBlock;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2016-08-18 00:05:24 +01:00
|
|
|
public BlindWrite5()
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo = new ImageInfo
|
2017-12-22 06:55:04 +00:00
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
ReadableSectorTags = new List<SectorTagType>(),
|
|
|
|
|
ReadableMediaTags = new List<MediaTagType>(),
|
|
|
|
|
HasPartitions = true,
|
|
|
|
|
HasSessions = true,
|
|
|
|
|
Version = null,
|
|
|
|
|
ApplicationVersion = null,
|
|
|
|
|
MediaTitle = null,
|
|
|
|
|
Creator = null,
|
|
|
|
|
MediaManufacturer = null,
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
DriveSerialNumber = null,
|
2017-12-22 06:55:04 +00:00
|
|
|
DriveFirmwareRevision = null
|
|
|
|
|
};
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public ImageInfo Info => imageInfo;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public string Name => "BlindWrite 5";
|
2018-01-28 20:29:46 +00:00
|
|
|
public Guid Id => new Guid("9CB7A381-0509-4F9F-B801-3F65434BC3EE");
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
public string Format => "BlindWrite 5 TOC file";
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
public List<Partition> Partitions { get; private set; }
|
2017-12-26 02:51:10 +00:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
public List<Track> Tracks { get; private set; }
|
2017-12-26 06:05:12 +00:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
public List<Session> Sessions { get; private set; }
|
2017-12-26 06:05:12 +00:00
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
public bool Identify(IFilter imageFilter)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2016-08-18 00:07:16 +01:00
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(stream.Length < 276) return false;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
byte[] signature = new byte[16];
|
|
|
|
|
stream.Read(signature, 0, 16);
|
|
|
|
|
|
|
|
|
|
byte[] footer = new byte[16];
|
|
|
|
|
stream.Seek(-16, SeekOrigin.End);
|
|
|
|
|
stream.Read(footer, 0, 16);
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return bw5Signature.SequenceEqual(signature) && bw5Footer.SequenceEqual(footer);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
public bool Open(IFilter imageFilter)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2016-08-18 00:07:16 +01:00
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(stream.Length < 276) return false;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
byte[] hdr = new byte[260];
|
|
|
|
|
stream.Read(hdr, 0, 260);
|
2018-06-22 08:08:38 +01:00
|
|
|
header = new Bw5Header();
|
2016-08-18 00:07:16 +01:00
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(260);
|
|
|
|
|
Marshal.Copy(hdr, 0, hdrPtr, 260);
|
2017-12-20 17:15:26 +00:00
|
|
|
header = (Bw5Header)Marshal.PtrToStructure(hdrPtr, typeof(Bw5Header));
|
2016-08-18 00:07:16 +01:00
|
|
|
Marshal.FreeHGlobal(hdrPtr);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.signature = {0}",
|
|
|
|
|
StringHandlers.CToString(header.signature));
|
2016-08-18 00:07:16 +01:00
|
|
|
for(int i = 0; i < header.unknown1.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown1[{1}] = 0x{0:X8}", header.unknown1[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.profile = {0}", header.profile);
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.sessions = {0}", header.sessions);
|
|
|
|
|
for(int i = 0; i < header.unknown2.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown2[{1}] = 0x{0:X8}", header.unknown2[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.mcnIsValid = {0}", header.mcnIsValid);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.mcn = {0}",
|
|
|
|
|
StringHandlers.CToString(header.mcn));
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown3 = 0x{0:X4}", header.unknown3);
|
|
|
|
|
for(int i = 0; i < header.unknown4.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown4[{1}] = 0x{0:X8}", header.unknown4[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.pmaLen = {0}", header.pmaLen);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.atipLen = {0}", header.atipLen);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.cdtLen = {0}", header.cdtLen);
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.cdInfoLen = {0}", header.cdInfoLen);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.bcaLen = {0}", header.bcaLen);
|
2016-08-18 00:07:16 +01:00
|
|
|
for(int i = 0; i < header.unknown5.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown5[{1}] = 0x{0:X8}", header.unknown5[i],
|
|
|
|
|
i);
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.dvdStrLen = {0}", header.dvdStrLen);
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.dvdInfoLen = {0}", header.dvdInfoLen);
|
|
|
|
|
for(int i = 0; i < header.unknown6.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown6[{1}] = 0x{0:X2}", header.unknown6[i],
|
|
|
|
|
i);
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.manufacturer = {0}",
|
|
|
|
|
StringHandlers.CToString(header.manufacturer));
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.product = {0}",
|
|
|
|
|
StringHandlers.CToString(header.product));
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.revision = {0}",
|
|
|
|
|
StringHandlers.CToString(header.revision));
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.vendor = {0}",
|
|
|
|
|
StringHandlers.CToString(header.vendor));
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.volumeId = {0}",
|
|
|
|
|
StringHandlers.CToString(header.volumeId));
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.mode2ALen = {0}", header.mode2ALen);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.unkBlkLen = {0}", header.unkBlkLen);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.dataLen = {0}", header.dataLen);
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.sessionsLen = {0}", header.sessionsLen);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "header.dpmLen = {0}", header.dpmLen);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
mode2A = new byte[header.mode2ALen];
|
|
|
|
|
if(mode2A.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
stream.Read(mode2A, 0, mode2A.Length);
|
2018-06-22 08:08:38 +01:00
|
|
|
mode2A[1] -= 2;
|
2017-12-21 14:30:38 +00:00
|
|
|
Modes.ModePage_2A? decoded2A = Modes.DecodeModePage_2A(mode2A);
|
2016-08-18 00:07:16 +01:00
|
|
|
if(decoded2A.HasValue)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "mode page 2A: {0}",
|
2017-12-21 14:30:38 +00:00
|
|
|
Modes.PrettifyModePage_2A(decoded2A));
|
2017-12-19 20:33:03 +00:00
|
|
|
else mode2A = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unkBlock = new byte[header.unkBlkLen];
|
2017-12-19 20:33:03 +00:00
|
|
|
if(unkBlock.Length > 0) stream.Read(unkBlock, 0, unkBlock.Length);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
byte[] temp = new byte[header.pmaLen];
|
|
|
|
|
if(temp.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
byte[] tushort = BitConverter.GetBytes((ushort)(temp.Length + 2));
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2018-01-28 20:29:46 +00:00
|
|
|
pma = new byte[temp.Length + 4];
|
2016-08-18 00:07:16 +01:00
|
|
|
pma[0] = tushort[1];
|
|
|
|
|
pma[1] = tushort[0];
|
|
|
|
|
Array.Copy(temp, 0, pma, 4, temp.Length);
|
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
PMA.CDPMA? decodedPma = PMA.Decode(pma);
|
2016-08-18 00:07:16 +01:00
|
|
|
if(decodedPma.HasValue)
|
2017-12-21 14:30:38 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "PMA: {0}", PMA.Prettify(decodedPma));
|
2017-12-19 20:33:03 +00:00
|
|
|
else pma = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
temp = new byte[header.atipLen];
|
|
|
|
|
if(temp.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
byte[] tushort = BitConverter.GetBytes((ushort)(temp.Length + 2));
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2018-01-28 20:29:46 +00:00
|
|
|
atip = new byte[temp.Length + 4];
|
2016-08-18 00:07:16 +01:00
|
|
|
atip[0] = tushort[1];
|
|
|
|
|
atip[1] = tushort[0];
|
|
|
|
|
Array.Copy(temp, 0, atip, 4, temp.Length);
|
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
ATIP.CDATIP? decodedAtip = ATIP.Decode(atip);
|
2016-08-18 00:07:16 +01:00
|
|
|
if(decodedAtip.HasValue)
|
2017-12-24 00:12:31 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "ATIP: {0}", ATIP.Prettify(decodedAtip));
|
2017-12-19 20:33:03 +00:00
|
|
|
else atip = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
temp = new byte[header.cdtLen];
|
|
|
|
|
if(temp.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
byte[] tushort = BitConverter.GetBytes((ushort)(temp.Length + 2));
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2018-01-28 20:29:46 +00:00
|
|
|
cdtext = new byte[temp.Length + 4];
|
2016-08-18 00:07:16 +01:00
|
|
|
cdtext[0] = tushort[1];
|
|
|
|
|
cdtext[1] = tushort[0];
|
|
|
|
|
Array.Copy(temp, 0, cdtext, 4, temp.Length);
|
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
CDTextOnLeadIn.CDText? decodedCdText = CDTextOnLeadIn.Decode(cdtext);
|
2016-08-18 00:07:16 +01:00
|
|
|
if(decodedCdText.HasValue)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "CD-Text: {0}",
|
2017-12-21 14:30:38 +00:00
|
|
|
CDTextOnLeadIn.Prettify(decodedCdText));
|
2017-12-19 20:33:03 +00:00
|
|
|
else cdtext = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bca = new byte[header.bcaLen];
|
2017-12-19 20:33:03 +00:00
|
|
|
if(bca.Length > 0) stream.Read(bca, 0, bca.Length);
|
|
|
|
|
else bca = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
temp = new byte[header.dvdStrLen];
|
|
|
|
|
if(temp.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
|
|
|
|
dmi = new byte[2052];
|
|
|
|
|
pfi = new byte[2052];
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
Array.Copy(temp, 0, dmi, 0, 2050);
|
2016-08-18 00:07:16 +01:00
|
|
|
Array.Copy(temp, 0x802, 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? decodedPfi = PFI.Decode(pfi);
|
2016-08-18 00:07:16 +01:00
|
|
|
if(decodedPfi.HasValue)
|
2017-12-21 14:30:38 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "PFI: {0}", PFI.Prettify(decodedPfi));
|
2016-08-18 00:07:16 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pfi = null;
|
|
|
|
|
dmi = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(header.profile)
|
|
|
|
|
{
|
|
|
|
|
case ProfileNumber.CDR:
|
|
|
|
|
case ProfileNumber.CDROM:
|
|
|
|
|
case ProfileNumber.CDRW:
|
|
|
|
|
case ProfileNumber.DDCDR:
|
|
|
|
|
case ProfileNumber.DDCDROM:
|
|
|
|
|
case ProfileNumber.DDCDRW:
|
|
|
|
|
case ProfileNumber.HDBURNROM:
|
|
|
|
|
case ProfileNumber.HDBURNR:
|
|
|
|
|
case ProfileNumber.HDBURNRW:
|
|
|
|
|
discInformation = new byte[header.cdInfoLen];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
discInformation = new byte[header.dvdInfoLen];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(discInformation.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
stream.Read(discInformation, 0, discInformation.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Disc information: {0}",
|
|
|
|
|
PrintHex.ByteArrayToHexArrayString(discInformation, 40));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else discInformation = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
// How many data blocks
|
|
|
|
|
byte[] tmpArray = new byte[4];
|
|
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
|
|
|
|
uint dataBlockCount = BitConverter.ToUInt32(tmpArray, 0);
|
|
|
|
|
|
|
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
2018-01-28 20:29:46 +00:00
|
|
|
uint dataPathLen = BitConverter.ToUInt32(tmpArray, 0);
|
2016-08-18 00:07:16 +01:00
|
|
|
byte[] dataPathBytes = new byte[dataPathLen];
|
|
|
|
|
stream.Read(dataPathBytes, 0, dataPathBytes.Length);
|
|
|
|
|
dataPath = Encoding.Unicode.GetString(dataPathBytes);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Data path: {0}", dataPath);
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFiles = new List<Bw5DataFile>();
|
2016-08-18 00:07:16 +01:00
|
|
|
for(int cD = 0; cD < dataBlockCount; cD++)
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
tmpArray = new byte[52];
|
2017-12-22 06:55:04 +00:00
|
|
|
Bw5DataFile dataFile = new Bw5DataFile {Unknown1 = new uint[4], Unknown2 = new uint[3]};
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
2018-01-28 20:29:46 +00:00
|
|
|
dataFile.Type = BitConverter.ToUInt32(tmpArray, 0);
|
|
|
|
|
dataFile.Length = BitConverter.ToUInt32(tmpArray, 4);
|
|
|
|
|
dataFile.Unknown1[0] = BitConverter.ToUInt32(tmpArray, 8);
|
|
|
|
|
dataFile.Unknown1[1] = BitConverter.ToUInt32(tmpArray, 12);
|
|
|
|
|
dataFile.Unknown1[2] = BitConverter.ToUInt32(tmpArray, 16);
|
|
|
|
|
dataFile.Unknown1[3] = BitConverter.ToUInt32(tmpArray, 20);
|
|
|
|
|
dataFile.Offset = BitConverter.ToUInt32(tmpArray, 24);
|
|
|
|
|
dataFile.Unknown2[0] = BitConverter.ToUInt32(tmpArray, 28);
|
|
|
|
|
dataFile.Unknown2[1] = BitConverter.ToUInt32(tmpArray, 32);
|
|
|
|
|
dataFile.Unknown2[2] = BitConverter.ToUInt32(tmpArray, 36);
|
|
|
|
|
dataFile.StartLba = BitConverter.ToInt32(tmpArray, 40);
|
|
|
|
|
dataFile.Sectors = BitConverter.ToInt32(tmpArray, 44);
|
|
|
|
|
dataFile.FilenameLen = BitConverter.ToUInt32(tmpArray, 48);
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.FilenameBytes = new byte[dataFile.FilenameLen];
|
|
|
|
|
|
|
|
|
|
tmpArray = new byte[dataFile.FilenameLen];
|
2016-08-18 00:07:16 +01:00
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.FilenameBytes = tmpArray;
|
2018-01-28 20:29:46 +00:00
|
|
|
tmpArray = new byte[4];
|
2016-08-18 00:07:16 +01:00
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Unknown3 = BitConverter.ToUInt32(tmpArray, 0);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename = Encoding.Unicode.GetString(dataFile.FilenameBytes);
|
2016-08-18 00:07:16 +01:00
|
|
|
dataFiles.Add(dataFile);
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.type = 0x{0:X8}", dataFile.Type);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.length = {0}", dataFile.Length);
|
2017-12-20 17:15:26 +00:00
|
|
|
for(int i = 0; i < dataFile.Unknown1.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.unknown1[{1}] = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Unknown1[i], i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.offset = {0}", dataFile.Offset);
|
|
|
|
|
for(int i = 0; i < dataFile.Unknown2.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.unknown2[{1}] = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Unknown2[i], i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.startLba = {0}", dataFile.StartLba);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.sectors = {0}", dataFile.Sectors);
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.filenameLen = {0}", dataFile.FilenameLen);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.filename = {0}", dataFile.Filename);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.unknown3 = {0}", dataFile.Unknown3);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
bwSessions = new List<Bw5SessionDescriptor>();
|
2016-08-18 00:07:16 +01:00
|
|
|
for(int ses = 0; ses < header.sessions; ses++)
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
Bw5SessionDescriptor session = new Bw5SessionDescriptor();
|
2018-06-22 08:08:38 +01:00
|
|
|
tmpArray = new byte[16];
|
2016-08-18 00:07:16 +01:00
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
2018-01-28 20:29:46 +00:00
|
|
|
session.Sequence = BitConverter.ToUInt16(tmpArray, 0);
|
|
|
|
|
session.Entries = tmpArray[2];
|
|
|
|
|
session.Unknown = tmpArray[3];
|
|
|
|
|
session.Start = BitConverter.ToInt32(tmpArray, 4);
|
|
|
|
|
session.End = BitConverter.ToInt32(tmpArray, 8);
|
2017-12-20 17:15:26 +00:00
|
|
|
session.FirstTrack = BitConverter.ToUInt16(tmpArray, 12);
|
2018-01-28 20:29:46 +00:00
|
|
|
session.LastTrack = BitConverter.ToUInt16(tmpArray, 14);
|
|
|
|
|
session.Tracks = new Bw5TrackDescriptor[session.Entries];
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].filename = {1}", ses, session.Sequence);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].entries = {1}", ses, session.Entries);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].unknown = {1}", ses, session.Unknown);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].start = {1}", ses, session.Start);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].end = {1}", ses, session.End);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].firstTrack = {1}", ses,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.FirstTrack);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].lastTrack = {1}", ses, session.LastTrack);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
for(int tSeq = 0; tSeq < session.Entries; tSeq++)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
byte[] trk = new byte[72];
|
|
|
|
|
stream.Read(trk, 0, 72);
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq] = new Bw5TrackDescriptor();
|
2018-06-22 08:08:38 +01:00
|
|
|
IntPtr trkPtr = Marshal.AllocHGlobal(72);
|
2016-08-18 00:07:16 +01:00
|
|
|
Marshal.Copy(trk, 0, trkPtr, 72);
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq] =
|
|
|
|
|
(Bw5TrackDescriptor)Marshal.PtrToStructure(trkPtr, typeof(Bw5TrackDescriptor));
|
2016-08-18 00:07:16 +01:00
|
|
|
Marshal.FreeHGlobal(trkPtr);
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(session.Tracks[tSeq].type == Bw5TrackType.Dvd ||
|
|
|
|
|
session.Tracks[tSeq].type == Bw5TrackType.NotData)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].unknown9[0] = 0;
|
|
|
|
|
session.Tracks[tSeq].unknown9[1] = 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
stream.Seek(-8, SeekOrigin.Current);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].type = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].type);
|
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown1.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin",
|
|
|
|
|
"session[{0}].track[{1}].unknown1[{2}] = 0x{3:X2}", ses, tSeq, i,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].unknown1[i]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown2 = 0x{2:X8}", ses,
|
2017-12-20 17:15:26 +00:00
|
|
|
tSeq, session.Tracks[tSeq].unknown2);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].subchannel = {2}", ses,
|
2017-12-20 17:15:26 +00:00
|
|
|
tSeq, session.Tracks[tSeq].subchannel);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown3 = 0x{2:X2}", ses,
|
2017-12-20 17:15:26 +00:00
|
|
|
tSeq, session.Tracks[tSeq].unknown3);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].ctl = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].ctl);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].adr = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].adr);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].point = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].point);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown4 = 0x{2:X2}", ses,
|
2018-01-08 21:16:22 +00:00
|
|
|
tSeq, session.Tracks[tSeq].tno);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].min = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].min);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].sec = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].sec);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].frame = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].frame);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].zero = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].zero);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].pmin = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].pmin);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].psec = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].psec);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].pframe = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].pframe);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown5 = 0x{2:X2}", ses,
|
2017-12-20 17:15:26 +00:00
|
|
|
tSeq, session.Tracks[tSeq].unknown5);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].pregap = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].pregap);
|
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown6.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin",
|
|
|
|
|
"session[{0}].track[{1}].unknown6[{2}] = 0x{3:X8}", ses, tSeq, i,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].unknown6[i]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].startLba = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].startLba);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].sectors = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].sectors);
|
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown7.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin",
|
|
|
|
|
"session[{0}].track[{1}].unknown7[{2}] = 0x{3:X8}", ses, tSeq, i,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].unknown7[i]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].session = {2}", ses, tSeq,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].session);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown8 = 0x{2:X4}", ses,
|
2017-12-20 17:15:26 +00:00
|
|
|
tSeq, session.Tracks[tSeq].unknown8);
|
2017-12-21 06:06:19 +00:00
|
|
|
if(session.Tracks[tSeq].type == Bw5TrackType.Dvd ||
|
|
|
|
|
session.Tracks[tSeq].type == Bw5TrackType.NotData) continue;
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown9.Length; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin",
|
|
|
|
|
"session[{0}].track[{1}].unknown9[{2}] = 0x{3:X8}", ses, tSeq, i,
|
2017-12-20 17:15:26 +00:00
|
|
|
session.Tracks[tSeq].unknown9[i]);
|
2017-12-21 06:06:19 +00:00
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bwSessions.Add(session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dpm = new byte[header.dpmLen];
|
|
|
|
|
stream.Read(dpm, 0, dpm.Length);
|
|
|
|
|
|
|
|
|
|
// Unused
|
|
|
|
|
tmpArray = new byte[4];
|
|
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
|
|
|
|
|
|
|
|
|
byte[] footer = new byte[16];
|
|
|
|
|
stream.Read(footer, 0, footer.Length);
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(bw5Footer.SequenceEqual(footer))
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Correctly arrived end of image");
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole
|
2018-01-28 20:29:46 +00:00
|
|
|
.ErrorWriteLine("BlindWrite5 image ends after expected position. Probably new version with different data. Errors may occur.");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
filePaths = new List<DataFileCharacteristics>();
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(Bw5DataFile dataFile in dataFiles)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
DataFileCharacteristics chars = new DataFileCharacteristics();
|
|
|
|
|
string path = Path.Combine(dataPath, dataFile.Filename);
|
|
|
|
|
FiltersList filtersList = new FiltersList();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path)) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter = filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2018-01-28 20:29:46 +00:00
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
path = Path.Combine(dataPath, dataFile.Filename.ToLower(CultureInfo.CurrentCulture));
|
2016-09-05 17:37:31 +01:00
|
|
|
if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path)) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter = filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2018-01-28 20:29:46 +00:00
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
path = Path.Combine(dataPath, dataFile.Filename.ToUpper(CultureInfo.CurrentCulture));
|
2016-09-05 17:37:31 +01:00
|
|
|
if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path)) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter = filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2018-01-28 20:29:46 +00:00
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
path = Path.Combine(dataPath.ToLower(CultureInfo.CurrentCulture), dataFile.Filename);
|
2016-09-05 17:37:31 +01:00
|
|
|
if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path)) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
path = Path.Combine(dataPath.ToUpper(CultureInfo.CurrentCulture), dataFile.Filename);
|
2016-09-05 17:37:31 +01:00
|
|
|
if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path)) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
path = Path.Combine(dataPath, dataFile.Filename);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
|
|
|
|
path.ToLower(CultureInfo.CurrentCulture))) !=
|
|
|
|
|
null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
chars.FilePath = path.ToLower(CultureInfo.CurrentCulture);
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
|
|
|
|
path.ToLower(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture)));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
|
|
|
|
path.ToUpper(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture))) !=
|
2017-12-19 20:33:03 +00:00
|
|
|
null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
chars.FilePath = path.ToUpper(CultureInfo.CurrentCulture);
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
|
|
|
|
path.ToUpper(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture)));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename.ToLower(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture))) !=
|
2017-12-19 20:33:03 +00:00
|
|
|
null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
chars.FilePath = dataFile.Filename.ToLower(CultureInfo.CurrentCulture);
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename.ToLower(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture)));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename.ToUpper(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture))) !=
|
2017-12-19 20:33:03 +00:00
|
|
|
null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
chars.FilePath = dataFile.Filename.ToUpper(CultureInfo.CurrentCulture);
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename.ToUpper(CultureInfo
|
2018-01-28 20:29:46 +00:00
|
|
|
.CurrentCulture)));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename)) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
chars.FilePath = dataFile.Filename;
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.FileFilter =
|
2017-12-19 20:33:03 +00:00
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(),
|
2017-12-20 17:15:26 +00:00
|
|
|
dataFile.Filename));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.ErrorWriteLine("Cannot find data file {0}", dataFile.Filename);
|
2016-08-18 00:07:16 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
long sectorSize = dataFile.Length / dataFile.Sectors;
|
2016-08-18 00:07:16 +01:00
|
|
|
if(sectorSize > 2352)
|
2017-12-24 00:12:31 +00:00
|
|
|
switch(sectorSize - 2352)
|
|
|
|
|
{
|
|
|
|
|
case 16:
|
|
|
|
|
chars.Subchannel = TrackSubchannelType.Q16Interleaved;
|
2017-12-21 04:43:29 +00:00
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
case 96:
|
|
|
|
|
chars.Subchannel = TrackSubchannelType.PackedInterleaved;
|
2017-12-21 04:43:29 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-24 00:12:31 +00:00
|
|
|
DicConsole.ErrorWriteLine("BlindWrite5 found unknown subchannel size: {0}",
|
|
|
|
|
sectorSize - 2352);
|
2017-12-21 04:43:29 +00:00
|
|
|
return false;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
else chars.Subchannel = TrackSubchannelType.None;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
chars.SectorSize = sectorSize;
|
2018-01-28 20:29:46 +00:00
|
|
|
chars.StartLba = dataFile.StartLba;
|
|
|
|
|
chars.Sectors = dataFile.Sectors;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
filePaths.Add(chars);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
Sessions = new List<Session>();
|
|
|
|
|
Tracks = new List<Track>();
|
|
|
|
|
Partitions = new List<Partition>();
|
2016-08-18 00:07:16 +01:00
|
|
|
MemoryStream fullTocStream = new MemoryStream();
|
2017-12-19 20:33:03 +00:00
|
|
|
fullTocStream.Write(new byte[] {0, 0, 0, 0}, 0, 4);
|
2016-08-18 00:07:16 +01:00
|
|
|
ulong offsetBytes = 0;
|
2018-06-22 08:08:38 +01:00
|
|
|
offsetmap = new Dictionary<uint, ulong>();
|
2018-01-28 20:29:46 +00:00
|
|
|
bool isDvd = false;
|
2016-08-18 00:07:16 +01:00
|
|
|
byte firstSession = byte.MaxValue;
|
2018-01-28 20:29:46 +00:00
|
|
|
byte lastSession = 0;
|
|
|
|
|
trackFlags = new Dictionary<uint, byte>();
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.Sectors = 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Building maps");
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(Bw5SessionDescriptor ses in bwSessions)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
// TODO: This does nothing, should it?
|
|
|
|
|
/*
|
|
|
|
|
Session session = new Session {SessionSequence = ses.Sequence};
|
2017-12-20 17:15:26 +00:00
|
|
|
if(ses.Start < 0) session.StartSector = 0;
|
|
|
|
|
else session.StartSector = (ulong)ses.Start;
|
|
|
|
|
session.EndSector = (ulong)ses.End;
|
|
|
|
|
session.StartTrack = ses.FirstTrack;
|
|
|
|
|
session.EndTrack = ses.LastTrack;
|
2017-12-22 06:55:04 +00:00
|
|
|
*/
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(ses.Sequence < firstSession) firstSession = (byte)ses.Sequence;
|
2018-01-28 20:29:46 +00:00
|
|
|
if(ses.Sequence > lastSession) lastSession = (byte)ses.Sequence;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(Bw5TrackDescriptor trk in ses.Tracks)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
byte adrCtl = (byte)((trk.adr << 4) + trk.ctl);
|
|
|
|
|
fullTocStream.WriteByte((byte)trk.session);
|
|
|
|
|
fullTocStream.WriteByte(adrCtl);
|
|
|
|
|
fullTocStream.WriteByte(0x00);
|
|
|
|
|
fullTocStream.WriteByte(trk.point);
|
|
|
|
|
fullTocStream.WriteByte(trk.min);
|
|
|
|
|
fullTocStream.WriteByte(trk.sec);
|
|
|
|
|
fullTocStream.WriteByte(trk.frame);
|
|
|
|
|
fullTocStream.WriteByte(trk.zero);
|
|
|
|
|
fullTocStream.WriteByte(trk.pmin);
|
|
|
|
|
fullTocStream.WriteByte(trk.psec);
|
|
|
|
|
fullTocStream.WriteByte(trk.pframe);
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(trk.point >= 0xA0) continue;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
Track track = new Track();
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition partition = new Partition();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
trackFlags.Add(trk.point, trk.ctl);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
switch(trk.type)
|
|
|
|
|
{
|
|
|
|
|
case Bw5TrackType.Audio:
|
2018-06-22 08:08:38 +01:00
|
|
|
track.TrackBytesPerSector = 2352;
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.SectorSize < 2352) imageInfo.SectorSize = 2352;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
case Bw5TrackType.Mode1:
|
|
|
|
|
case Bw5TrackType.Mode2F1:
|
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);
|
2018-06-22 08:08:38 +01:00
|
|
|
track.TrackBytesPerSector = 2048;
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.SectorSize < 2048) imageInfo.SectorSize = 2048;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
case Bw5TrackType.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);
|
2018-06-22 08:08:38 +01:00
|
|
|
track.TrackBytesPerSector = 2336;
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.SectorSize < 2336) imageInfo.SectorSize = 2336;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
case Bw5TrackType.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);
|
2018-06-22 08:08:38 +01:00
|
|
|
track.TrackBytesPerSector = 2336;
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.SectorSize < 2324) imageInfo.SectorSize = 2324;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
case Bw5TrackType.Dvd:
|
2018-06-22 08:08:38 +01:00
|
|
|
track.TrackBytesPerSector = 2048;
|
|
|
|
|
track.TrackRawBytesPerSector = 2048;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.SectorSize < 2048) imageInfo.SectorSize = 2048;
|
2018-06-22 08:08:38 +01:00
|
|
|
isDvd = true;
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-21 17:58:51 +00:00
|
|
|
track.TrackDescription = $"Track {trk.point}";
|
2017-12-21 06:06:19 +00:00
|
|
|
track.TrackStartSector = (ulong)(trk.startLba + trk.pregap);
|
2018-01-28 20:29:46 +00:00
|
|
|
track.TrackEndSector = (ulong)(trk.sectors + trk.startLba);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
foreach(DataFileCharacteristics chars in filePaths.Where(chars => trk.startLba >= chars.StartLba &&
|
|
|
|
|
trk.startLba + trk.sectors <=
|
|
|
|
|
chars.StartLba + chars.Sectors))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2017-12-21 07:08:26 +00:00
|
|
|
track.TrackFilter = chars.FileFilter;
|
2018-01-28 20:29:46 +00:00
|
|
|
track.TrackFile = chars.FileFilter.GetFilename();
|
2017-12-21 07:08:26 +00:00
|
|
|
if(trk.startLba >= 0)
|
2018-01-28 20:29:46 +00:00
|
|
|
track.TrackFileOffset = (ulong)((trk.startLba - chars.StartLba) * chars.SectorSize);
|
2018-06-22 08:08:38 +01:00
|
|
|
else track.TrackFileOffset = (ulong)(trk.startLba * -1 * chars.SectorSize);
|
|
|
|
|
track.TrackFileType = "BINARY";
|
2017-12-21 07:08:26 +00:00
|
|
|
if(chars.Subchannel != TrackSubchannelType.None)
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2017-12-21 07:08:26 +00:00
|
|
|
track.TrackSubchannelFilter = track.TrackFilter;
|
2018-01-28 20:29:46 +00:00
|
|
|
track.TrackSubchannelFile = track.TrackFile;
|
|
|
|
|
track.TrackSubchannelType = chars.Subchannel;
|
2017-12-21 07:08:26 +00:00
|
|
|
track.TrackSubchannelOffset = track.TrackFileOffset;
|
|
|
|
|
|
|
|
|
|
if(chars.Subchannel == TrackSubchannelType.PackedInterleaved)
|
2017-12-26 06:05:12 +00:00
|
|
|
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
|
|
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
|
2017-12-21 06:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
track.TrackPregap = trk.pregap;
|
2017-12-21 06:06:19 +00:00
|
|
|
track.TrackSequence = trk.point;
|
2018-01-28 20:29:46 +00:00
|
|
|
track.TrackType = BlindWriteTrackTypeToTrackType(trk.type);
|
|
|
|
|
track.Indexes = new Dictionary<int, ulong> {{1, track.TrackStartSector}};
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
partition.Description = track.TrackDescription;
|
2018-06-22 08:08:38 +01:00
|
|
|
partition.Size = (track.TrackEndSector - track.TrackStartSector) *
|
|
|
|
|
(ulong)track.TrackRawBytesPerSector;
|
2018-01-28 20:29:46 +00:00
|
|
|
partition.Length = track.TrackEndSector - track.TrackStartSector;
|
2017-12-21 06:06:19 +00:00
|
|
|
partition.Sequence = track.TrackSequence;
|
2018-01-28 20:29:46 +00:00
|
|
|
partition.Offset = offsetBytes;
|
|
|
|
|
partition.Start = track.TrackStartSector;
|
|
|
|
|
partition.Type = track.TrackType.ToString();
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
offsetBytes += partition.Size;
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
Tracks.Add(track);
|
|
|
|
|
Partitions.Add(partition);
|
2017-12-21 06:06:19 +00:00
|
|
|
offsetmap.Add(track.TrackSequence, track.TrackStartSector);
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.Sectors += partition.Length;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "printing track map");
|
2018-01-28 20:29:46 +00:00
|
|
|
foreach(Track track in Tracks)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Partition sequence: {0}", track.TrackSequence);
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition description: {0}", track.TrackDescription);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition type: {0}", track.TrackType);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition starting sector: {0}",
|
|
|
|
|
track.TrackStartSector);
|
2016-08-18 00:07:16 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition ending sector: {0}", track.TrackEndSector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "printing partition map");
|
2018-01-28 20:29:46 +00:00
|
|
|
foreach(Partition partition in Partitions)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Partition sequence: {0}", partition.Sequence);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition name: {0}", partition.Name);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition description: {0}",
|
|
|
|
|
partition.Description);
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition type: {0}", partition.Type);
|
2017-07-19 16:37:11 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition starting sector: {0}", partition.Start);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition sectors: {0}", partition.Length);
|
2017-07-19 16:37:11 +01:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition starting offset: {0}", partition.Offset);
|
2018-01-28 20:29:46 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition size in bytes: {0}", partition.Size);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!isDvd)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "Rebuilding TOC");
|
|
|
|
|
|
|
|
|
|
fullToc = fullTocStream.ToArray();
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "TOC len {0}", fullToc.Length);
|
|
|
|
|
|
|
|
|
|
byte[] fullTocSize = BitConverter.GetBytes((short)(fullToc.Length - 2));
|
2018-06-22 08:08:38 +01:00
|
|
|
fullToc[0] = fullTocSize[1];
|
|
|
|
|
fullToc[1] = fullTocSize[0];
|
|
|
|
|
fullToc[2] = firstSession;
|
|
|
|
|
fullToc[3] = lastSession;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
FullTOC.CDFullTOC? decodedFullToc = FullTOC.Decode(fullToc);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
if(!decodedFullToc.HasValue)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "TOC not correctly rebuilt");
|
|
|
|
|
fullToc = null;
|
|
|
|
|
}
|
2017-12-20 23:07:46 +00:00
|
|
|
else DicConsole.DebugWriteLine("BlindWrite5 plugin", "TOC correctly rebuilt");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = BlindWriteProfileToMediaType(header.profile);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
if(dmi != null && pfi != null)
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
PFI.PhysicalFormatInformation? pfi0 = PFI.Decode(pfi);
|
2016-08-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.DVDROM;
|
2016-08-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case DiskCategory.Nintendo:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = pfi0.Value.DiscSize == DVDSize.Eighty ? MediaType.GOD : MediaType.WOD;
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
if(DMI.IsXbox(dmi)) imageInfo.MediaType = MediaType.XGD;
|
|
|
|
|
else if(DMI.IsXbox360(dmi)) imageInfo.MediaType = MediaType.XGD2;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-26 06:05:12 +00:00
|
|
|
else if(imageInfo.MediaType == MediaType.CD || imageInfo.MediaType == MediaType.CDROM)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
bool data = false;
|
|
|
|
|
bool mode2 = false;
|
2016-08-18 00:07:16 +01:00
|
|
|
bool firstaudio = false;
|
2018-01-28 20:29:46 +00:00
|
|
|
bool firstdata = false;
|
|
|
|
|
bool audio = false;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
foreach(Track bwTrack in Tracks)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
// First track is audio
|
2017-12-22 06:55:04 +00:00
|
|
|
firstaudio |= bwTrack.TrackSequence == 1 && bwTrack.TrackType == TrackType.Audio;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
// First track is data
|
2017-12-22 06:55:04 +00:00
|
|
|
firstdata |= bwTrack.TrackSequence == 1 && bwTrack.TrackType != TrackType.Audio;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
// Any non first track is data
|
2017-12-22 06:55:04 +00:00
|
|
|
data |= bwTrack.TrackSequence != 1 && bwTrack.TrackType != TrackType.Audio;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
// Any non first track is audio
|
2017-12-22 06:55:04 +00:00
|
|
|
audio |= bwTrack.TrackSequence != 1 && bwTrack.TrackType == TrackType.Audio;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(bwTrack.TrackType)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Formless:
|
|
|
|
|
case TrackType.CdMode2Form1:
|
|
|
|
|
case TrackType.CdMode2Form2:
|
2016-08-18 00:07:16 +01:00
|
|
|
mode2 = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 08:08:38 +01: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-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
imageInfo.DriveManufacturer = StringHandlers.CToString(header.manufacturer);
|
|
|
|
|
imageInfo.DriveModel = StringHandlers.CToString(header.product);
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.DriveFirmwareRevision = StringHandlers.CToString(header.revision);
|
2018-01-28 20:29:46 +00:00
|
|
|
imageInfo.Application = "BlindWrite";
|
2017-12-19 20:33:03 +00:00
|
|
|
if(string.Compare(Path.GetExtension(imageFilter.GetFilename()), "B5T",
|
2017-12-26 06:05:12 +00:00
|
|
|
StringComparison.OrdinalIgnoreCase) == 0) imageInfo.ApplicationVersion = "5";
|
2017-12-19 20:33:03 +00:00
|
|
|
else if(string.Compare(Path.GetExtension(imageFilter.GetFilename()), "B6T",
|
2018-06-22 08:08:38 +01:00
|
|
|
StringComparison.OrdinalIgnoreCase) == 0) imageInfo.ApplicationVersion = "6";
|
|
|
|
|
imageInfo.Version = "5";
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
imageInfo.ImageSize = (ulong)imageFilter.GetDataForkLength();
|
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
2018-01-28 20:29:46 +00:00
|
|
|
imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
if(pma != null)
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
PMA.CDPMA pma0 = PMA.Decode(pma).Value;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
foreach(uint id in from descriptor in pma0.PMADescriptors
|
|
|
|
|
where descriptor.ADR == 2
|
|
|
|
|
select (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame))
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaSerialNumber = $"{id & 0x00FFFFFF:X6}";
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(atip != null)
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
ATIP.CDATIP atip0 = ATIP.Decode(atip).Value;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = atip0.DiscType ? MediaType.CDRW : MediaType.CDR;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
if(atip0.LeadInStartMin == 97)
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
int type = atip0.LeadInStartFrame % 10;
|
|
|
|
|
int frm = atip0.LeadInStartFrame - type;
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaManufacturer = ATIP.ManufacturerFromATIP(atip0.LeadInStartSec, frm);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
bool isBd = false;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imageInfo.MediaType == MediaType.BDR || imageInfo.MediaType == MediaType.BDRE ||
|
|
|
|
|
imageInfo.MediaType == MediaType.BDROM)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
isDvd = false;
|
2018-01-28 20:29:46 +00:00
|
|
|
isBd = true;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(isBd && imageInfo.Sectors > 24438784)
|
|
|
|
|
switch(imageInfo.MediaType)
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
|
|
|
|
case MediaType.BDR:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.BDRXL;
|
2017-12-21 04:43:29 +00:00
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
case MediaType.BDRE:
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.BDREXL;
|
2017-12-21 04:43:29 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
DicConsole.DebugWriteLine("BlindWrite5 plugin", "ImageInfo.mediaType = {0}", imageInfo.MediaType);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(mode2A != null) imageInfo.ReadableMediaTags.Add(MediaTagType.SCSI_MODEPAGE_2A);
|
2018-01-28 20:29:46 +00:00
|
|
|
if(pma != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_PMA);
|
|
|
|
|
if(atip != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_ATIP);
|
2017-12-26 06:05:12 +00:00
|
|
|
if(cdtext != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_TEXT);
|
2018-06-22 08:08:38 +01:00
|
|
|
if(bca != null)
|
2018-01-28 20:29:46 +00:00
|
|
|
if(isDvd)
|
|
|
|
|
imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_BCA);
|
2018-06-22 08:08:38 +01:00
|
|
|
else if(isBd) imageInfo.ReadableMediaTags.Add(MediaTagType.BD_BCA);
|
2018-01-28 20:29:46 +00:00
|
|
|
if(dmi != null) imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_DMI);
|
|
|
|
|
if(pfi != null) imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_PFI);
|
2017-12-26 06:05:12 +00:00
|
|
|
if(fullToc != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_FullTOC);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
if(imageInfo.MediaType == MediaType.XGD2)
|
2018-01-28 20:29:46 +00:00
|
|
|
if(imageInfo.Sectors == 25063 || // Locked (or non compatible drive)
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.Sectors == 4229664 || // Xtreme unlock
|
2018-01-28 20:29:46 +00:00
|
|
|
imageInfo.Sectors == 4246304) // Wxripper unlock
|
2017-12-26 06:05:12 +00:00
|
|
|
imageInfo.MediaType = MediaType.XGD3;
|
2017-05-23 19:25:17 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
DicConsole.VerboseWriteLine("BlindWrite image describes a disc of type {0}", imageInfo.MediaType);
|
2016-08-21 17:35:35 +01:00
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
switch(tag)
|
|
|
|
|
{
|
|
|
|
|
case MediaTagType.SCSI_MODEPAGE_2A:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(mode2A != null) return (byte[])mode2A.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain SCSI MODE PAGE 2Ah.");
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case MediaTagType.CD_PMA:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(pma != null) return (byte[])pma.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain PMA information.");
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case MediaTagType.CD_ATIP:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(atip != null) return (byte[])atip.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain ATIP information.");
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case MediaTagType.CD_TEXT:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(cdtext != null) return (byte[])cdtext.Clone();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
throw new FeatureNotPresentImageException("Image does not contain CD-Text information.");
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case MediaTagType.DVD_BCA:
|
|
|
|
|
case MediaTagType.BD_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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsTag(sectorAddress, 1, tag);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2016-08-18 00:07:16 +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-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
where sectorAddress >= kvp.Value
|
2018-01-28 20:29:46 +00:00
|
|
|
from track in Tracks
|
2018-06-22 08:08:38 +01:00
|
|
|
where track.TrackSequence == kvp.Key
|
2018-01-28 20:29:46 +00:00
|
|
|
where sectorAddress - kvp.Value <
|
2017-12-24 00:12:31 +00:00
|
|
|
track.TrackEndSector - track.TrackStartSector
|
|
|
|
|
select kvp)
|
|
|
|
|
return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
where sectorAddress >= kvp.Value
|
2018-01-28 20:29:46 +00:00
|
|
|
from track in Tracks
|
2018-06-22 08:08:38 +01:00
|
|
|
where track.TrackSequence == kvp.Key
|
2018-01-28 20:29:46 +00:00
|
|
|
where sectorAddress - kvp.Value <
|
2017-12-24 00:12:31 +00:00
|
|
|
track.TrackEndSector - track.TrackStartSector
|
|
|
|
|
select kvp)
|
|
|
|
|
return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag);
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
// TODO: Cross data files
|
2018-01-28 20:29:46 +00:00
|
|
|
Track dicTrack = new Track();
|
|
|
|
|
DataFileCharacteristics chars = new DataFileCharacteristics();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack.TrackSequence = 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
foreach(Track bwTrack in Tracks.Where(bwTrack => bwTrack.TrackSequence == track))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack = bwTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(dicTrack.TrackSequence == 0)
|
2016-08-18 00:07:16 +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 > dicTrack.TrackEndSector)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2017-12-22 06:55:04 +00:00
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({dicTrack.TrackEndSector}), won't cross tracks");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
foreach(DataFileCharacteristics characteristics in filePaths.Where(characteristics =>
|
2018-06-22 08:08:38 +01:00
|
|
|
(long)sectorAddress >=
|
|
|
|
|
characteristics.StartLba &&
|
|
|
|
|
length < (ulong)characteristics
|
|
|
|
|
.Sectors - sectorAddress))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2018-06-20 22:22:21 +01:00
|
|
|
chars = characteristics;
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(string.IsNullOrEmpty(chars.FilePath) || chars.FileFilter == null)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(chars.FileFilter), "Track does not exist in disc image");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
uint sectorOffset;
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
uint sectorSkip;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(dicTrack.TrackType)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode1:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 16;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 288;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Formless:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 16;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2336;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Form1:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 24;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 280;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Form2:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 24;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2324;
|
|
|
|
|
sectorSkip = 4;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case TrackType.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2352;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case TrackType.Data:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(chars.Subchannel)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
case TrackSubchannelType.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 16;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 96;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
imageStream = chars.FileFilter.GetDataForkStream();
|
2016-09-05 17:37:31 +01:00
|
|
|
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)dicTrack.TrackFileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
SeekOrigin.Begin);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +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-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
// TODO: Cross data files
|
2018-01-28 20:29:46 +00:00
|
|
|
Track dicTrack = new Track();
|
|
|
|
|
DataFileCharacteristics chars = new DataFileCharacteristics();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack.TrackSequence = 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
foreach(Track bwTrack in Tracks.Where(bwTrack => bwTrack.TrackSequence == track))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack = bwTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(dicTrack.TrackSequence == 0)
|
2016-08-18 00:07:16 +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 > dicTrack.TrackEndSector)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2017-12-22 06:55:04 +00:00
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({dicTrack.TrackEndSector}), won't cross tracks");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
foreach(DataFileCharacteristics characteristics in filePaths.Where(characteristics =>
|
2018-06-22 08:08:38 +01:00
|
|
|
(long)sectorAddress >=
|
|
|
|
|
characteristics.StartLba &&
|
|
|
|
|
length < (ulong)characteristics
|
|
|
|
|
.Sectors - sectorAddress))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2018-06-20 22:22:21 +01:00
|
|
|
chars = characteristics;
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(string.IsNullOrEmpty(chars.FilePath) || chars.FileFilter == null)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(chars.FileFilter), "Track does not exist in disc image");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(dicTrack.TrackType == TrackType.Data)
|
2016-08-18 00:07:16 +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;
|
|
|
|
|
case SectorTagType.CdTrackFlags:
|
2017-12-22 06:55:04 +00:00
|
|
|
if(trackFlags.TryGetValue(track, out byte flag)) return new[] {flag};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
uint sectorOffset;
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
uint sectorSkip;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(dicTrack.TrackType)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode1:
|
2016-08-18 00:07:16 +01:00
|
|
|
switch(tag)
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 12;
|
|
|
|
|
sectorSkip = 2340;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 12;
|
2018-01-28 20:29:46 +00:00
|
|
|
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-18 00:07:16 +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-20 17:15:26 +00:00
|
|
|
sectorOffset = 2076;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 276;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccP:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2076;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 172;
|
|
|
|
|
sectorSkip = 104;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2248;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 104;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2064;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 4;
|
|
|
|
|
sectorSkip = 284;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2016-08-18 00:07:16 +01:00
|
|
|
throw new NotImplementedException("Packed subchannel not yet supported");
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Formless:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(tag)
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 8;
|
|
|
|
|
sectorSkip = 2328;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2332;
|
2018-01-28 20:29:46 +00:00
|
|
|
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
|
|
|
throw new NotImplementedException("Packed subchannel not yet supported");
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Form1:
|
2016-08-18 00:07:16 +01:00
|
|
|
switch(tag)
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 12;
|
|
|
|
|
sectorSkip = 2340;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 12;
|
2018-01-28 20:29:46 +00:00
|
|
|
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-20 17:15:26 +00:00
|
|
|
sectorOffset = 16;
|
2018-01-28 20:29:46 +00:00
|
|
|
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-20 17:15:26 +00:00
|
|
|
sectorOffset = 2076;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 276;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccP:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2076;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 172;
|
|
|
|
|
sectorSkip = 104;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEccQ:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2248;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 104;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2072;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 4;
|
|
|
|
|
sectorSkip = 276;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2016-08-18 00:07:16 +01:00
|
|
|
throw new NotImplementedException("Packed subchannel not yet supported");
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode2Form2:
|
2016-08-18 00:07:16 +01:00
|
|
|
switch(tag)
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSync:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 12;
|
|
|
|
|
sectorSkip = 2340;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorHeader:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 12;
|
2018-01-28 20:29:46 +00:00
|
|
|
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-20 17:15:26 +00:00
|
|
|
sectorOffset = 16;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 8;
|
|
|
|
|
sectorSkip = 2328;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorEdc:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 2348;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 4;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2016-08-18 00:07:16 +01:00
|
|
|
throw new NotImplementedException("Packed subchannel not yet supported");
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackType.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(tag)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new NotImplementedException("Packed subchannel not yet supported");
|
|
|
|
|
default: throw new ArgumentException("Unsupported tag requested", nameof(tag));
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(chars.Subchannel)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
case TrackSubchannelType.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 16;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 96;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
imageStream = dicTrack.TrackFilter.GetDataForkStream();
|
2016-09-05 17:37:31 +01:00
|
|
|
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)dicTrack.TrackFileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
SeekOrigin.Begin);
|
2017-12-20 17:15:26 +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-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
return ReadSectorsLong(sectorAddress, 1, track);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
|
|
|
|
|
where sectorAddress >= kvp.Value
|
2018-01-28 20:29:46 +00:00
|
|
|
from track in Tracks
|
2018-06-22 08:08:38 +01:00
|
|
|
where track.TrackSequence == kvp.Key
|
2018-01-28 20:29:46 +00:00
|
|
|
where sectorAddress - kvp.Value <
|
2017-12-24 00:12:31 +00:00
|
|
|
track.TrackEndSector - track.TrackStartSector
|
|
|
|
|
select kvp)
|
|
|
|
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
// TODO: Cross data files
|
2018-01-28 20:29:46 +00:00
|
|
|
Track dicTrack = new Track();
|
|
|
|
|
DataFileCharacteristics chars = new DataFileCharacteristics();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack.TrackSequence = 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
foreach(Track bwTrack in Tracks.Where(bwTrack => bwTrack.TrackSequence == track))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
dicTrack = bwTrack;
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
if(dicTrack.TrackSequence == 0)
|
2016-08-18 00:07:16 +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 > dicTrack.TrackEndSector)
|
2017-12-19 20:33:03 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2017-12-22 06:55:04 +00:00
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({dicTrack.TrackEndSector}), won't cross tracks");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
foreach(DataFileCharacteristics characteristics in filePaths.Where(characteristics =>
|
2018-06-22 08:08:38 +01:00
|
|
|
(long)sectorAddress >=
|
|
|
|
|
characteristics.StartLba &&
|
|
|
|
|
length < (ulong)characteristics
|
|
|
|
|
.Sectors - sectorAddress))
|
2017-12-24 00:12:31 +00:00
|
|
|
{
|
2018-06-20 22:22:21 +01:00
|
|
|
chars = characteristics;
|
2017-12-21 07:08:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(string.IsNullOrEmpty(chars.FilePath) || chars.FileFilter == null)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(chars.FileFilter), "Track does not exist in disc image");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
uint sectorOffset;
|
|
|
|
|
uint sectorSize;
|
|
|
|
|
uint sectorSkip;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
switch(dicTrack.TrackType)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
case TrackType.CdMode1:
|
|
|
|
|
case TrackType.CdMode2Formless:
|
|
|
|
|
case TrackType.CdMode2Form1:
|
|
|
|
|
case TrackType.CdMode2Form2:
|
2016-08-18 00:07:16 +01:00
|
|
|
case TrackType.Audio:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2352;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
case TrackType.Data:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorOffset = 0;
|
2018-01-28 20:29:46 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
sectorSkip = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(chars.Subchannel)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
case TrackSubchannelType.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 16;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
sectorSkip += 96;
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
byte[] buffer = new byte[sectorSize * length];
|
2016-08-18 00:07:16 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
imageStream = dicTrack.TrackFilter.GetDataForkStream();
|
2016-09-05 17:37:31 +01:00
|
|
|
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)dicTrack.TrackFileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
SeekOrigin.Begin);
|
2017-12-20 17:15:26 +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-18 00:07:16 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorOffset, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
byte[] sector = br.ReadBytes((int)sectorSize);
|
2017-12-20 17:15:26 +00:00
|
|
|
br.BaseStream.Seek(sectorSkip, SeekOrigin.Current);
|
|
|
|
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
if(Sessions.Contains(session)) return GetSessionTracks(session.SessionSequence);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
return Tracks.Where(dicTrack => dicTrack.TrackSession == session).ToList();
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress);
|
2017-12-21 14:30:38 +00:00
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorLong(sectorAddress, track);
|
2017-12-21 14:30:38 +00:00
|
|
|
return CdChecksums.CheckCdSector(buffer);
|
2016-08-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
|
|
|
|
out List<ulong> unknownLbas)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
2018-01-28 20:29:46 +00:00
|
|
|
int bps = (int)(buffer.Length / length);
|
2016-08-18 00:07:16 +01:00
|
|
|
byte[] sector = new byte[bps];
|
2018-06-22 08:08:38 +01:00
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
switch(sectorStatus)
|
|
|
|
|
{
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
|
|
|
|
out List<ulong> unknownLbas)
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
2018-01-28 20:29:46 +00:00
|
|
|
int bps = (int)(buffer.Length / length);
|
2016-08-18 00:07:16 +01:00
|
|
|
byte[] sector = new byte[bps];
|
2018-06-22 08:08:38 +01:00
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
switch(sectorStatus)
|
|
|
|
|
{
|
|
|
|
|
case null:
|
2017-12-20 17:15:26 +00:00
|
|
|
unknownLbas.Add((ulong)i + sectorAddress);
|
2016-08-18 00:07:16 +01:00
|
|
|
break;
|
|
|
|
|
case false:
|
2017-12-20 17:15:26 +00:00
|
|
|
failingLbas.Add((ulong)i + sectorAddress);
|
2016-08-18 00:07:16 +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-18 00:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool? VerifyMediaImage()
|
2016-08-18 00:07:16 +01:00
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-12-24 00:12:31 +00:00
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
public List<DumpHardwareType> DumpHardware => null;
|
|
|
|
|
public CICMMetadataType CicmMetadata => null;
|
|
|
|
|
|
2017-12-26 02:51:10 +00:00
|
|
|
static TrackType BlindWriteTrackTypeToTrackType(Bw5TrackType trackType)
|
|
|
|
|
{
|
|
|
|
|
switch(trackType)
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
case Bw5TrackType.Mode1: return TrackType.CdMode1;
|
2017-12-26 02:51:10 +00:00
|
|
|
case Bw5TrackType.Mode2F1: return TrackType.CdMode2Form1;
|
|
|
|
|
case Bw5TrackType.Mode2F2: return TrackType.CdMode2Form2;
|
2018-01-28 20:29:46 +00:00
|
|
|
case Bw5TrackType.Mode2: return TrackType.CdMode2Formless;
|
|
|
|
|
case Bw5TrackType.Audio: return TrackType.Audio;
|
|
|
|
|
default: return TrackType.Data;
|
2017-12-26 02:51:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MediaType BlindWriteProfileToMediaType(ProfileNumber profile)
|
|
|
|
|
{
|
|
|
|
|
switch(profile)
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
case ProfileNumber.BDRE: return MediaType.BDRE;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.BDROM: return MediaType.BDROM;
|
|
|
|
|
case ProfileNumber.BDRRdm:
|
|
|
|
|
case ProfileNumber.BDRSeq: return MediaType.BDR;
|
|
|
|
|
case ProfileNumber.CDR:
|
|
|
|
|
case ProfileNumber.HDBURNR: return MediaType.CDR;
|
|
|
|
|
case ProfileNumber.CDROM:
|
|
|
|
|
case ProfileNumber.HDBURNROM: return MediaType.CDROM;
|
|
|
|
|
case ProfileNumber.CDRW:
|
2018-06-22 08:08:38 +01:00
|
|
|
case ProfileNumber.HDBURNRW: return MediaType.CDRW;
|
2018-01-28 20:29:46 +00:00
|
|
|
case ProfileNumber.DDCDR: return MediaType.DDCDR;
|
|
|
|
|
case ProfileNumber.DDCDROM: return MediaType.DDCD;
|
|
|
|
|
case ProfileNumber.DDCDRW: return MediaType.DDCDRW;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.DVDDownload: return MediaType.DVDDownload;
|
2018-01-28 20:29:46 +00:00
|
|
|
case ProfileNumber.DVDRAM: return MediaType.DVDRAM;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.DVDRDLJump:
|
2018-06-22 08:08:38 +01:00
|
|
|
case ProfileNumber.DVDRDLSeq: return MediaType.DVDRDL;
|
2018-01-28 20:29:46 +00:00
|
|
|
case ProfileNumber.DVDRDLPlus: return MediaType.DVDPRDL;
|
|
|
|
|
case ProfileNumber.DVDROM: return MediaType.DVDROM;
|
|
|
|
|
case ProfileNumber.DVDRPlus: return MediaType.DVDPR;
|
|
|
|
|
case ProfileNumber.DVDRSeq: return MediaType.DVDR;
|
|
|
|
|
case ProfileNumber.DVDRWDL: return MediaType.DVDRWDL;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.DVDRWDLPlus: return MediaType.DVDPRWDL;
|
2018-01-28 20:29:46 +00:00
|
|
|
case ProfileNumber.DVDRWPlus: return MediaType.DVDPRW;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.DVDRWRes:
|
2018-06-22 08:08:38 +01:00
|
|
|
case ProfileNumber.DVDRWSeq: return MediaType.DVDRW;
|
2018-01-28 20:29:46 +00:00
|
|
|
case ProfileNumber.HDDVDR: return MediaType.HDDVDR;
|
|
|
|
|
case ProfileNumber.HDDVDRAM: return MediaType.HDDVDRAM;
|
|
|
|
|
case ProfileNumber.HDDVDRDL: return MediaType.HDDVDRDL;
|
|
|
|
|
case ProfileNumber.HDDVDROM: return MediaType.HDDVDROM;
|
|
|
|
|
case ProfileNumber.HDDVDRW: return MediaType.HDDVDRW;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.HDDVDRWDL: return MediaType.HDDVDRWDL;
|
|
|
|
|
case ProfileNumber.ASMO:
|
2018-06-22 08:08:38 +01:00
|
|
|
case ProfileNumber.MOErasable: return MediaType.UnknownMO;
|
2017-12-26 02:51:10 +00:00
|
|
|
case ProfileNumber.NonRemovable: return MediaType.GENERIC_HDD;
|
2018-01-28 20:29:46 +00:00
|
|
|
default: return MediaType.CD;
|
2017-12-26 02:51:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
enum Bw5TrackType : byte
|
|
|
|
|
{
|
|
|
|
|
NotData = 0,
|
2018-01-28 20:29:46 +00:00
|
|
|
Audio = 1,
|
|
|
|
|
Mode1 = 2,
|
|
|
|
|
Mode2 = 3,
|
2017-12-24 00:12:31 +00:00
|
|
|
Mode2F1 = 4,
|
|
|
|
|
Mode2F2 = 5,
|
2018-01-28 20:29:46 +00:00
|
|
|
Dvd = 6
|
2017-12-24 00:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Bw5TrackSubchannel : byte
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
None = 0,
|
|
|
|
|
Q16 = 2,
|
2017-12-24 00:12:31 +00:00
|
|
|
Linear = 4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct Bw5Header
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
public byte[] signature;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
2018-06-22 08:08:38 +01:00
|
|
|
public uint[] unknown1;
|
2017-12-24 00:12:31 +00:00
|
|
|
public ProfileNumber profile;
|
2018-01-28 20:29:46 +00:00
|
|
|
public ushort sessions;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
|
|
|
|
public uint[] unknown2;
|
|
|
|
|
[MarshalAs(UnmanagedType.U1, SizeConst = 3)]
|
|
|
|
|
public bool mcnIsValid;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)]
|
|
|
|
|
public byte[] mcn;
|
2017-12-24 00:12:31 +00:00
|
|
|
public ushort unknown3;
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
public uint[] unknown4;
|
2017-12-24 00:12:31 +00:00
|
|
|
public ushort pmaLen;
|
|
|
|
|
public ushort atipLen;
|
|
|
|
|
public ushort cdtLen;
|
|
|
|
|
public ushort cdInfoLen;
|
2018-01-28 20:29:46 +00:00
|
|
|
public uint bcaLen;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
|
|
|
|
public uint[] unknown5;
|
2018-06-22 08:08:38 +01:00
|
|
|
public uint dvdStrLen;
|
|
|
|
|
public uint dvdInfoLen;
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
public byte[] unknown6;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
public byte[] manufacturer;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
public byte[] product;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
public byte[] revision;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
|
|
|
|
|
public byte[] vendor;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
public byte[] volumeId;
|
2018-06-22 08:08:38 +01:00
|
|
|
public uint mode2ALen;
|
|
|
|
|
public uint unkBlkLen;
|
|
|
|
|
public uint dataLen;
|
|
|
|
|
public uint sessionsLen;
|
|
|
|
|
public uint dpmLen;
|
2017-12-24 00:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Bw5DataFile
|
|
|
|
|
{
|
|
|
|
|
public uint Type;
|
|
|
|
|
public uint Length;
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
|
|
|
|
public uint[] Unknown1;
|
2018-06-22 08:08:38 +01:00
|
|
|
public uint Offset;
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
public uint[] Unknown2;
|
|
|
|
|
public int StartLba;
|
|
|
|
|
public int Sectors;
|
|
|
|
|
public uint FilenameLen;
|
2017-12-24 00:12:31 +00:00
|
|
|
public byte[] FilenameBytes;
|
2018-01-28 20:29:46 +00:00
|
|
|
public uint Unknown3;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
public string Filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct Bw5TrackDescriptor
|
|
|
|
|
{
|
|
|
|
|
public Bw5TrackType type;
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
2018-06-22 08:08:38 +01:00
|
|
|
public byte[] unknown1;
|
2018-01-28 20:29:46 +00:00
|
|
|
public uint unknown2;
|
2017-12-24 00:12:31 +00:00
|
|
|
public Bw5TrackSubchannel subchannel;
|
2018-01-28 20:29:46 +00:00
|
|
|
public byte unknown3;
|
|
|
|
|
public byte ctl;
|
|
|
|
|
public byte adr;
|
|
|
|
|
public byte point;
|
|
|
|
|
public byte tno;
|
|
|
|
|
public byte min;
|
|
|
|
|
public byte sec;
|
|
|
|
|
public byte frame;
|
|
|
|
|
public byte zero;
|
|
|
|
|
public byte pmin;
|
|
|
|
|
public byte psec;
|
|
|
|
|
public byte pframe;
|
|
|
|
|
public byte unknown5;
|
|
|
|
|
public uint pregap;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
public uint[] unknown6;
|
2018-06-22 08:08:38 +01:00
|
|
|
public int startLba;
|
|
|
|
|
public int sectors;
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
public uint[] unknown7;
|
|
|
|
|
public uint session;
|
2017-12-24 00:12:31 +00:00
|
|
|
public ushort unknown8;
|
|
|
|
|
// Seems to be only on non DVD track descriptors
|
2018-01-28 20:29:46 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
public uint[] unknown9;
|
2017-12-24 00:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Bw5SessionDescriptor
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
public ushort Sequence;
|
|
|
|
|
public byte Entries;
|
|
|
|
|
public byte Unknown;
|
|
|
|
|
public int Start;
|
|
|
|
|
public int End;
|
|
|
|
|
public ushort FirstTrack;
|
|
|
|
|
public ushort LastTrack;
|
2017-12-24 00:12:31 +00:00
|
|
|
public Bw5TrackDescriptor[] Tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DataFileCharacteristics
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
public IFilter FileFilter;
|
|
|
|
|
public string FilePath;
|
2017-12-24 00:12:31 +00:00
|
|
|
public TrackSubchannelType Subchannel;
|
2018-01-28 20:29:46 +00:00
|
|
|
public long SectorSize;
|
|
|
|
|
public int StartLba;
|
|
|
|
|
public int Sectors;
|
2017-12-24 00:12:31 +00:00
|
|
|
}
|
2016-08-18 00:05:24 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|