2020-06-17 23:14:20 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-08-18 00:05:24 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Filename : Read.cs
|
2016-08-18 00:05:24 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Component : Disk image plugins.
|
2016-08-18 00:05:24 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 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;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Exceptions;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs.Devices.SCSI.Modes;
|
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
|
using Aaru.Decoders.CD;
|
|
|
|
|
|
using Aaru.Decoders.DVD;
|
|
|
|
|
|
using Aaru.Decoders.SCSI;
|
|
|
|
|
|
using Aaru.Decoders.SCSI.MMC;
|
|
|
|
|
|
using Aaru.Helpers;
|
|
|
|
|
|
using DMI = Aaru.Decoders.Xbox.DMI;
|
|
|
|
|
|
using Session = Aaru.CommonTypes.Structs.Session;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.DiscImages
|
2016-08-18 00:05:24 +01:00
|
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed partial class BlindWrite5
|
2016-08-18 00:05:24 +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);
|
2020-01-11 20:55:54 +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);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_header = Marshal.ByteArrayToStructureLittleEndian<Bw5Header>(hdr);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.signature = {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
StringHandlers.CToString(_header.signature));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
for(int i = 0; i < _header.unknown1.Length; i++)
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown1[{1}] = 0x{0:X8}", _header.unknown1[i],
|
2020-02-29 18:03:35 +00:00
|
|
|
|
i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.profile = {0}", _header.profile);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.sessions = {0}", _header.sessions);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
for(int i = 0; i < _header.unknown2.Length; i++)
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown2[{1}] = 0x{0:X8}", _header.unknown2[i],
|
2020-02-29 18:03:35 +00:00
|
|
|
|
i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.mcnIsValid = {0}", _header.mcnIsValid);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.mcn = {0}", StringHandlers.CToString(_header.mcn));
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown3 = 0x{0:X4}", _header.unknown3);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
for(int i = 0; i < _header.unknown4.Length; i++)
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown4[{1}] = 0x{0:X8}", _header.unknown4[i],
|
2020-02-29 18:03:35 +00:00
|
|
|
|
i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.pmaLen = {0}", _header.pmaLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.atipLen = {0}", _header.atipLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.cdtLen = {0}", _header.cdtLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.cdInfoLen = {0}", _header.cdInfoLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.bcaLen = {0}", _header.bcaLen);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
for(int i = 0; i < _header.unknown5.Length; i++)
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown5[{1}] = 0x{0:X8}", _header.unknown5[i],
|
2020-02-29 18:03:35 +00:00
|
|
|
|
i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.dvdStrLen = {0}", _header.dvdStrLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.dvdInfoLen = {0}", _header.dvdInfoLen);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
for(int i = 0; i < _header.unknown6.Length; i++)
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unknown6[{1}] = 0x{0:X2}", _header.unknown6[i],
|
2020-02-29 18:03:35 +00:00
|
|
|
|
i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.manufacturer = {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
StringHandlers.CToString(_header.manufacturer));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.product = {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
StringHandlers.CToString(_header.product));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.revision = {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
StringHandlers.CToString(_header.revision));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.vendor = {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
StringHandlers.CToString(_header.vendor));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.volumeId = {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
StringHandlers.CToString(_header.volumeId));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.mode2ALen = {0}", _header.mode2ALen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.unkBlkLen = {0}", _header.unkBlkLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.dataLen = {0}", _header.dataLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.sessionsLen = {0}", _header.sessionsLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "header.dpmLen = {0}", _header.dpmLen);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_mode2A = new byte[_header.mode2ALen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_mode2A.Length > 0)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
stream.Read(_mode2A, 0, _mode2A.Length);
|
|
|
|
|
|
_mode2A[1] -= 2;
|
|
|
|
|
|
var decoded2A = ModePage_2A.Decode(_mode2A);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
if(!(decoded2A is null))
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "mode page 2A: {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Modes.PrettifyModePage_2A(decoded2A));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_mode2A = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_unkBlock = new byte[_header.unkBlkLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_unkBlock.Length > 0)
|
|
|
|
|
|
stream.Read(_unkBlock, 0, _unkBlock.Length);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
byte[] temp = new byte[_header.pmaLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
if(temp.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] tushort = BitConverter.GetBytes((ushort)(temp.Length + 2));
|
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_pma = new byte[temp.Length + 4];
|
|
|
|
|
|
_pma[0] = tushort[1];
|
|
|
|
|
|
_pma[1] = tushort[0];
|
|
|
|
|
|
Array.Copy(temp, 0, _pma, 4, temp.Length);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
PMA.CDPMA? decodedPma = PMA.Decode(_pma);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
if(decodedPma.HasValue)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "PMA: {0}", PMA.Prettify(decodedPma));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_pma = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_atip = new byte[_header.atipLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_atip.Length > 0)
|
|
|
|
|
|
stream.Read(_atip, 0, _atip.Length);
|
2020-03-11 14:01:01 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_atip = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_cdtext = new byte[_header.cdtLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_cdtext.Length > 0)
|
|
|
|
|
|
stream.Read(_cdtext, 0, _cdtext.Length);
|
2020-03-11 14:01:01 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_cdtext = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_bca = new byte[_header.bcaLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_bca.Length > 0)
|
|
|
|
|
|
stream.Read(_bca, 0, _bca.Length);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_bca = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
temp = new byte[_header.dvdStrLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
if(temp.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dmi = new byte[2052];
|
|
|
|
|
|
_pfi = new byte[2052];
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-03-11 14:01:01 +00:00
|
|
|
|
// TODO: CMI
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(temp, 2, _dmi, 4, 2048);
|
|
|
|
|
|
Array.Copy(temp, 0x802, _pfi, 4, 2048);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_pfi[0] = 0x08;
|
|
|
|
|
|
_pfi[1] = 0x02;
|
|
|
|
|
|
_dmi[0] = 0x08;
|
|
|
|
|
|
_dmi[1] = 0x02;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
PFI.PhysicalFormatInformation? decodedPfi = PFI.Decode(_pfi);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
if(decodedPfi.HasValue)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "PFI: {0}", PFI.Prettify(decodedPfi));
|
2016-08-18 00:07:16 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_pfi = null;
|
|
|
|
|
|
_dmi = null;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
switch(_header.profile)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
|
|
|
|
|
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:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_discInformation = new byte[_header.cdInfoLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_discInformation = new byte[_header.dvdInfoLen];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_discInformation.Length > 0)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
stream.Read(_discInformation, 0, _discInformation.Length);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Disc information: {0}",
|
2020-07-20 21:11:32 +01:00
|
|
|
|
PrintHex.ByteArrayToHexArrayString(_discInformation, 40));
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_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);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dataPath = Encoding.Unicode.GetString(dataPathBytes);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Data path: {0}", _dataPath);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dataFiles = new List<Bw5DataFile>();
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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];
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
|
|
|
|
|
var dataFile = new Bw5DataFile
|
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Unknown1 = new uint[4],
|
|
|
|
|
|
Unknown2 = new uint[3]
|
2020-01-11 20:55:54 +00:00
|
|
|
|
};
|
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);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dataFiles.Add(dataFile);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.type = 0x{0:X8}", dataFile.Type);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.length = {0}", dataFile.Length);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < dataFile.Unknown1.Length; i++)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.unknown1[{1}] = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
dataFile.Unknown1[i], i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.offset = {0}", dataFile.Offset);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < dataFile.Unknown2.Length; i++)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.unknown2[{1}] = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
dataFile.Unknown2[i], i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.startLba = {0}", dataFile.StartLba);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.sectors = {0}", dataFile.Sectors);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.filenameLen = {0}", dataFile.FilenameLen);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.filename = {0}", dataFile.Filename);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "dataFile.unknown3 = {0}", dataFile.Unknown3);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_bwSessions = new List<Bw5SessionDescriptor>();
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
for(int ses = 0; ses < _header.sessions; ses++)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-01-11 20:55:54 +00:00
|
|
|
|
var 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
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].filename = {1}", ses, session.Sequence);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].entries = {1}", ses, session.Entries);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].unknown = {1}", ses, session.Unknown);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].start = {1}", ses, session.Start);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].end = {1}", ses, session.End);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].firstTrack = {1}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.FirstTrack);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.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);
|
2019-02-27 23:57:52 +00:00
|
|
|
|
session.Tracks[tSeq] = Marshal.ByteArrayToStructureLittleEndian<Bw5TrackDescriptor>(trk);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].type = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].type);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown1.Length; i++)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
"session[{0}].track[{1}].unknown1[{2}] = 0x{3:X2}", ses, tSeq, i,
|
|
|
|
|
|
session.Tracks[tSeq].unknown1[i]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown2 = 0x{2:X8}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
tSeq, session.Tracks[tSeq].unknown2);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].subchannel = {2}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
tSeq, session.Tracks[tSeq].subchannel);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown3 = 0x{2:X2}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
tSeq, session.Tracks[tSeq].unknown3);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].ctl = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].ctl);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].adr = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].adr);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].point = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].point);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown4 = 0x{2:X2}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
tSeq, session.Tracks[tSeq].tno);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].min = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].min);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].sec = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].sec);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].frame = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].frame);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].zero = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].zero);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].pmin = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].pmin);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].psec = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].psec);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].pframe = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].pframe);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown5 = 0x{2:X2}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
tSeq, session.Tracks[tSeq].unknown5);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].pregap = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].pregap);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown6.Length; i++)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
"session[{0}].track[{1}].unknown6[{2}] = 0x{3:X8}", ses, tSeq, i,
|
|
|
|
|
|
session.Tracks[tSeq].unknown6[i]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].startLba = {2}", ses,
|
|
|
|
|
|
tSeq, session.Tracks[tSeq].startLba);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].sectors = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].sectors);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown7.Length; i++)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
"session[{0}].track[{1}].unknown7[{2}] = 0x{3:X8}", ses, tSeq, i,
|
|
|
|
|
|
session.Tracks[tSeq].unknown7[i]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].session = {2}", ses, tSeq,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
session.Tracks[tSeq].session);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown8 = 0x{2:X4}", ses,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
tSeq, session.Tracks[tSeq].unknown8);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(session.Tracks[tSeq].type == Bw5TrackType.Dvd ||
|
2020-01-11 20:55:54 +00:00
|
|
|
|
session.Tracks[tSeq].type == Bw5TrackType.NotData)
|
|
|
|
|
|
continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(int i = 0; i < session.Tracks[tSeq].unknown9.Length; i++)
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
"session[{0}].track[{1}].unknown9[{2}] = 0x{3:X8}", ses, tSeq, i,
|
|
|
|
|
|
session.Tracks[tSeq].unknown9[i]);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_bwSessions.Add(session);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dpm = new byte[_header.dpmLen];
|
|
|
|
|
|
stream.Read(_dpm, 0, _dpm.Length);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
|
|
|
|
|
// Unused
|
|
|
|
|
|
tmpArray = new byte[4];
|
|
|
|
|
|
stream.Read(tmpArray, 0, tmpArray.Length);
|
|
|
|
|
|
|
|
|
|
|
|
byte[] footer = new byte[16];
|
|
|
|
|
|
stream.Read(footer, 0, footer.Length);
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_bw5Footer.SequenceEqual(footer))
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Correctly arrived end of image");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
else
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.
|
2020-01-11 20:55:54 +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
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_filePaths = new List<DataFileCharacteristics>();
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
foreach(Bw5DataFile dataFile in _dataFiles)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-01-11 20:55:54 +00:00
|
|
|
|
var chars = new DataFileCharacteristics();
|
2020-07-20 21:11:32 +01:00
|
|
|
|
string path = Path.Combine(_dataPath, dataFile.Filename);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
var 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
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
path = Path.Combine(_dataPath, dataFile.Filename.ToLower(CultureInfo.CurrentCulture));
|
2020-01-11 20:55:54 +00: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
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
path = Path.Combine(_dataPath, dataFile.Filename.ToUpper(CultureInfo.CurrentCulture));
|
2020-01-11 20:55:54 +00: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
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
path = Path.Combine(_dataPath.ToLower(CultureInfo.CurrentCulture), dataFile.Filename);
|
2020-01-11 20:55:54 +00: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 =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
path = Path.Combine(_dataPath.ToUpper(CultureInfo.CurrentCulture), dataFile.Filename);
|
2020-01-11 20:55:54 +00: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 =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
filtersList.GetFilter(Path.Combine(imageFilter.GetParentFolder(), path));
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
chars.FilePath = path;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
path = Path.Combine(_dataPath, dataFile.Filename);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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);
|
2020-01-11 20:55:54 +00: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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
path.ToLower(CultureInfo.
|
2020-11-01 18:02:29 +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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
path.ToUpper(CultureInfo.
|
2020-11-01 18:02:29 +00:00
|
|
|
|
CurrentCulture))) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
chars.FilePath = path.ToUpper(CultureInfo.CurrentCulture);
|
2020-01-11 20:55:54 +00: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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
path.ToUpper(CultureInfo.
|
2020-11-01 18:02:29 +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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
dataFile.Filename.ToLower(CultureInfo.
|
2020-11-01 18:02:29 +00:00
|
|
|
|
CurrentCulture))) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
chars.FilePath = dataFile.Filename.ToLower(CultureInfo.CurrentCulture);
|
2020-01-11 20:55:54 +00: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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
dataFile.Filename.ToLower(CultureInfo.
|
2020-11-01 18:02:29 +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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
dataFile.Filename.ToUpper(CultureInfo.
|
2020-11-01 18:02:29 +00:00
|
|
|
|
CurrentCulture))) != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
chars.FilePath = dataFile.Filename.ToUpper(CultureInfo.CurrentCulture);
|
2020-01-11 20:55:54 +00: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(),
|
2020-01-11 20:55:54 +00:00
|
|
|
|
dataFile.Filename.ToUpper(CultureInfo.
|
2020-11-01 18:02:29 +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;
|
2020-01-11 20:55:54 +00: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(),
|
2017-12-20 17:15:26 +00:00
|
|
|
|
dataFile.Filename));
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.ErrorWriteLine("Cannot find data file {0}", dataFile.Filename);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-06-17 23:13:55 +01:00
|
|
|
|
continue;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
long sectorSize = dataFile.Length / dataFile.Sectors;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
case 96:
|
|
|
|
|
|
chars.Subchannel = TrackSubchannelType.PackedInterleaved;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.ErrorWriteLine("BlindWrite5 found unknown subchannel size: {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sectorSize - 2352);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
return false;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
2020-01-11 20:55:54 +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;
|
2020-06-18 02:03:19 +01:00
|
|
|
|
chars.Offset = dataFile.Offset;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_filePaths.Add(chars);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Sessions = new List<Session>();
|
|
|
|
|
|
Tracks = new List<Track>();
|
|
|
|
|
|
Partitions = new List<Partition>();
|
2020-01-11 20:55:54 +00:00
|
|
|
|
var fullTocStream = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
|
|
fullTocStream.Write(new byte[]
|
|
|
|
|
|
{
|
2020-03-11 14:01:01 +00:00
|
|
|
|
0, 0
|
|
|
|
|
|
}, 0, 2);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
ulong offsetBytes = 0;
|
2020-07-20 21:11:32 +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;
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_trackFlags = new Dictionary<uint, byte>();
|
|
|
|
|
|
_imageInfo.Sectors = 0;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Building maps");
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01: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
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
if(ses.Sequence < firstSession)
|
|
|
|
|
|
firstSession = (byte)ses.Sequence;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
if(trk.point >= 0xA0)
|
|
|
|
|
|
continue;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
var track = new Track();
|
|
|
|
|
|
var partition = new Partition();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01: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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_imageInfo.SectorSize < 2352)
|
|
|
|
|
|
_imageInfo.SectorSize = 2352;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case Bw5TrackType.Mode1:
|
|
|
|
|
|
case Bw5TrackType.Mode2F1:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
track.TrackBytesPerSector = 2048;
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_imageInfo.SectorSize < 2048)
|
|
|
|
|
|
_imageInfo.SectorSize = 2048;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case Bw5TrackType.Mode2:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
track.TrackBytesPerSector = 2336;
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_imageInfo.SectorSize < 2336)
|
|
|
|
|
|
_imageInfo.SectorSize = 2336;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case Bw5TrackType.Mode2F2:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
|
|
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
track.TrackBytesPerSector = 2336;
|
|
|
|
|
|
track.TrackRawBytesPerSector = 2352;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_imageInfo.SectorSize < 2324)
|
|
|
|
|
|
_imageInfo.SectorSize = 2324;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_imageInfo.SectorSize < 2048)
|
|
|
|
|
|
_imageInfo.SectorSize = 2048;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
isDvd = true;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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);
|
2020-11-03 23:22:18 +00:00
|
|
|
|
track.TrackEndSector = (ulong)(trk.sectors + trk.startLba) - 1;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
foreach(DataFileCharacteristics chars in _filePaths.Where(chars => trk.startLba >= chars.StartLba &&
|
2020-11-01 18:02:29 +00:00
|
|
|
|
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();
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
if(trk.startLba >= 0)
|
2020-06-18 02:03:19 +01:00
|
|
|
|
track.TrackFileOffset =
|
|
|
|
|
|
(ulong)((trk.startLba - chars.StartLba) * chars.SectorSize) + chars.Offset;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else
|
|
|
|
|
|
track.TrackFileOffset = (ulong)(trk.startLba * -1 * chars.SectorSize);
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
track.TrackFileType = "BINARY";
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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)
|
2020-07-20 21:11:32 +01: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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 23:13:55 +01:00
|
|
|
|
if(track.TrackFilter is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
AaruConsole.ErrorWriteLine("Could not find image for track {0}", trk.point);
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-06-17 21:32:19 +01:00
|
|
|
|
if(trk.pregap > 0)
|
|
|
|
|
|
track.Indexes.Add(0, (int)(track.TrackStartSector - trk.pregap));
|
|
|
|
|
|
|
|
|
|
|
|
track.Indexes.Add(1, (int)track.TrackStartSector);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
|
|
partition.Description = track.TrackDescription;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
partition.Size = (track.TrackEndSector - track.TrackStartSector) *
|
|
|
|
|
|
(ulong)track.TrackRawBytesPerSector;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-11-03 23:22:18 +00:00
|
|
|
|
partition.Length = (track.TrackEndSector - track.TrackStartSector) + 1;
|
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;
|
|
|
|
|
|
|
2020-06-18 02:03:19 +01:00
|
|
|
|
if(track.TrackStartSector >= trk.pregap)
|
|
|
|
|
|
track.TrackStartSector -= trk.pregap;
|
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
Tracks.Add(track);
|
|
|
|
|
|
Partitions.Add(partition);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_offsetmap.Add(track.TrackSequence, track.TrackStartSector);
|
|
|
|
|
|
_imageInfo.Sectors += partition.Length;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "printing track map");
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
foreach(Track track in Tracks)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Partition sequence: {0}", track.TrackSequence);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition description: {0}",
|
|
|
|
|
|
track.TrackDescription);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition type: {0}", track.TrackType);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition starting sector: {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
track.TrackStartSector);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition ending sector: {0}",
|
|
|
|
|
|
track.TrackEndSector);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "printing partition map");
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
foreach(Partition partition in Partitions)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Partition sequence: {0}", partition.Sequence);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition name: {0}", partition.Name);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition description: {0}", partition.Description);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition type: {0}", partition.Type);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition starting sector: {0}", partition.Start);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition sectors: {0}", partition.Length);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition starting offset: {0}", partition.Offset);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "\tPartition size in bytes: {0}", partition.Size);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!isDvd)
|
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "Rebuilding TOC");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_fullToc = fullTocStream.ToArray();
|
|
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "TOC len {0}", _fullToc.Length);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_fullToc[0] = firstSession;
|
|
|
|
|
|
_fullToc[1] = lastSession;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = BlindWriteProfileToMediaType(_header.profile);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_dmi != null &&
|
|
|
|
|
|
_pfi != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.DVDPR;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.DVDPRDL:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.DVDPRDL;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.DVDPRW:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.DVDPRW;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.DVDPRWDL:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.DVDPRWDL;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.DVDR:
|
2020-11-01 18:02:29 +00:00
|
|
|
|
_imageInfo.MediaType = pfi0.Value.PartVersion >= 6 ? MediaType.DVDRDL : MediaType.DVDR;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.DVDRAM:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.DVDRAM;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.DVDROM;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.DVDRW:
|
2020-11-01 18:02:29 +00:00
|
|
|
|
_imageInfo.MediaType = pfi0.Value.PartVersion >= 3 ? MediaType.DVDRWDL : MediaType.DVDRW;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.HDDVDR:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.HDDVDR;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.HDDVDRAM:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.HDDVDRAM;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.HDDVDROM:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.HDDVDROM;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.HDDVDRW:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.HDDVDRW;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.Nintendo:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType =
|
|
|
|
|
|
pfi0.Value.DiscSize == DVDSize.Eighty ? MediaType.GOD : MediaType.WOD;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
case DiskCategory.UMD:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.UMD;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +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
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-20 21:11:32 +01: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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
if(!data &&
|
|
|
|
|
|
!firstdata)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.CDDA;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else if(firstaudio &&
|
|
|
|
|
|
data &&
|
|
|
|
|
|
Sessions.Count > 1 &&
|
|
|
|
|
|
mode2)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.CDPLUS;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else if((firstdata && audio) || mode2)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.CDROMXA;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else if(!audio)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.CDROM;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.CD;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.DriveManufacturer = StringHandlers.CToString(_header.manufacturer);
|
|
|
|
|
|
_imageInfo.DriveModel = StringHandlers.CToString(_header.product);
|
|
|
|
|
|
_imageInfo.DriveFirmwareRevision = StringHandlers.CToString(_header.revision);
|
|
|
|
|
|
_imageInfo.Application = "BlindWrite";
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-06-17 23:14:10 +01:00
|
|
|
|
if(string.Compare(Path.GetExtension(imageFilter.GetFilename()), ".B5T",
|
2020-01-11 20:55:54 +00:00
|
|
|
|
StringComparison.OrdinalIgnoreCase) == 0)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ApplicationVersion = "5";
|
2020-06-17 23:14:10 +01:00
|
|
|
|
else if(string.Compare(Path.GetExtension(imageFilter.GetFilename()), ".B6T",
|
2020-01-11 20:55:54 +00:00
|
|
|
|
StringComparison.OrdinalIgnoreCase) == 0)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ApplicationVersion = "6";
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Version = "5";
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ImageSize = (ulong)imageFilter.GetDataForkLength();
|
|
|
|
|
|
_imageInfo.CreationTime = imageFilter.GetCreationTime();
|
|
|
|
|
|
_imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
|
|
|
|
|
_imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_pma != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
PMA.CDPMA pma0 = PMA.Decode(_pma).Value;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
foreach(uint id in from descriptor in pma0.PMADescriptors where descriptor.ADR == 2
|
2017-12-24 00:12:31 +00:00
|
|
|
|
select (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame))
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaSerialNumber = $"{id & 0x00FFFFFF:X6}";
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_atip != null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
byte[] atipTmp = new byte[_atip.Length + 4];
|
|
|
|
|
|
Array.Copy(_atip, 0, atipTmp, 4, _atip.Length);
|
|
|
|
|
|
atipTmp[0] = (byte)((_atip.Length & 0xFF00) >> 8);
|
|
|
|
|
|
atipTmp[1] = (byte)(_atip.Length & 0xFF);
|
2020-06-17 23:14:20 +01:00
|
|
|
|
|
2020-11-01 20:10:20 +00:00
|
|
|
|
ATIP.CDATIP atip0 = ATIP.Decode(atipTmp);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-11-01 20:10:20 +00:00
|
|
|
|
_imageInfo.MediaType = atip0?.DiscType ?? false ? 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;
|
2020-07-20 21:11:32 +01: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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01: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
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(isBd && _imageInfo.Sectors > 24438784)
|
|
|
|
|
|
switch(_imageInfo.MediaType)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
case MediaType.BDR:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.BDRXL;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
case MediaType.BDRE:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.MediaType = MediaType.BDREXL;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("BlindWrite5 plugin", "ImageInfo.mediaType = {0}", _imageInfo.MediaType);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_mode2A != null)
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.SCSI_MODEPAGE_2A);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_pma != null)
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.CD_PMA);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_atip != null)
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.CD_ATIP);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_cdtext != null)
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.CD_TEXT);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_bca != null)
|
2018-01-28 20:29:46 +00:00
|
|
|
|
if(isDvd)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_BCA);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
else if(isBd)
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.BD_BCA);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-03-11 14:01:01 +00:00
|
|
|
|
byte[] tmp;
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_dmi != null)
|
2020-03-11 14:01:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
tmp = new byte[2048];
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(_dmi, 4, tmp, 0, 2048);
|
|
|
|
|
|
_dmi = tmp;
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_DMI);
|
2020-03-11 14:01:01 +00:00
|
|
|
|
}
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_pfi != null)
|
2020-03-11 14:01:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
tmp = new byte[2048];
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(_pfi, 4, tmp, 0, 2048);
|
|
|
|
|
|
_pfi = tmp;
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.DVD_PFI);
|
2020-03-11 14:01:01 +00:00
|
|
|
|
}
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_fullToc != null)
|
|
|
|
|
|
_imageInfo.ReadableMediaTags.Add(MediaTagType.CD_FullTOC);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_imageInfo.MediaType == MediaType.XGD2)
|
|
|
|
|
|
if(_imageInfo.Sectors == 25063 || // Locked (or non compatible drive)
|
|
|
|
|
|
_imageInfo.Sectors == 4229664 || // Xtreme unlock
|
|
|
|
|
|
_imageInfo.Sectors == 4246304) // Wxripper unlock
|
|
|
|
|
|
_imageInfo.MediaType = MediaType.XGD3;
|
2017-05-23 19:25:17 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.VerboseWriteLine("BlindWrite image describes a disc of type {0}", _imageInfo.MediaType);
|
2016-08-21 17:35:35 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_header.profile != ProfileNumber.CDR &&
|
|
|
|
|
|
_header.profile != ProfileNumber.CDRW &&
|
|
|
|
|
|
_header.profile != ProfileNumber.CDROM)
|
2020-07-12 23:13:05 +01:00
|
|
|
|
foreach(Track track in Tracks)
|
|
|
|
|
|
{
|
|
|
|
|
|
track.TrackPregap = 0;
|
|
|
|
|
|
track.Indexes?.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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
|
|
|
|
{
|
2020-07-20 21:11:32 +01: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");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track) => ReadSectors(sectorAddress, 1, track);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag) =>
|
|
|
|
|
|
ReadSectorsTag(sectorAddress, 1, track, tag);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetmap where sectorAddress >= kvp.Value
|
2020-01-11 20:55:54 +00:00
|
|
|
|
from track in Tracks where track.TrackSequence == kvp.Key
|
2020-11-03 23:22:39 +00:00
|
|
|
|
where sectorAddress - kvp.Value <
|
|
|
|
|
|
(track.TrackEndSector - track.TrackStartSector) + 1
|
|
|
|
|
|
select kvp)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
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
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetmap where sectorAddress >= kvp.Value
|
2020-01-11 20:55:54 +00:00
|
|
|
|
from track in Tracks where track.TrackSequence == kvp.Key
|
2020-11-03 23:22:39 +00:00
|
|
|
|
where sectorAddress - kvp.Value <
|
|
|
|
|
|
(track.TrackEndSector - track.TrackStartSector) + 1
|
|
|
|
|
|
select kvp)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
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
|
2020-07-22 13:20:25 +01:00
|
|
|
|
var aaruTrack = new Track
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
aaruTrack = bwTrack;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-06-21 14:49:25 +01:00
|
|
|
|
if(aaruTrack is null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
2020-11-03 23:22:39 +00:00
|
|
|
|
if(length + sectorAddress > (aaruTrack.TrackEndSector - aaruTrack.TrackStartSector) + 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2020-11-03 23:22:39 +00:00
|
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({(aaruTrack.TrackEndSector - aaruTrack.TrackStartSector) + 1}), won't cross tracks");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
DataFileCharacteristics chars = (from characteristics in _filePaths let firstSector =
|
2020-06-18 02:03:19 +01:00
|
|
|
|
characteristics.StartLba let lastSector =
|
|
|
|
|
|
(firstSector + characteristics.Sectors) - 1 let wantedSector =
|
|
|
|
|
|
(int)(sectorAddress + aaruTrack.TrackStartSector)
|
|
|
|
|
|
where wantedSector >= firstSector && wantedSector <= lastSector
|
|
|
|
|
|
select characteristics).FirstOrDefault();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
if(string.IsNullOrEmpty(chars.FilePath) ||
|
|
|
|
|
|
chars.FileFilter == null)
|
2017-12-20 17:15:26 +00:00
|
|
|
|
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;
|
2020-01-11 22:44:25 +00:00
|
|
|
|
bool mode2 = false;
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
switch(aaruTrack.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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case TrackType.CdMode2Formless:
|
|
|
|
|
|
case TrackType.CdMode2Form1:
|
|
|
|
|
|
case TrackType.CdMode2Form2:
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-01-11 22:44:25 +00:00
|
|
|
|
mode2 = true;
|
|
|
|
|
|
sectorOffset = 0;
|
|
|
|
|
|
sectorSize = 2352;
|
|
|
|
|
|
sectorSkip = 0;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 16;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 96;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageStream = chars.FileFilter.GetDataForkStream();
|
|
|
|
|
|
var br = new BinaryReader(_imageStream);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
|
|
|
|
|
br.BaseStream.
|
2020-02-28 00:19:50 +00:00
|
|
|
|
Seek((long)aaruTrack.TrackFileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-01-11 22:44:25 +00:00
|
|
|
|
if(mode2)
|
|
|
|
|
|
{
|
|
|
|
|
|
var mode2Ms = new MemoryStream((int)(sectorSize * length));
|
|
|
|
|
|
|
2020-01-12 01:00:26 +00:00
|
|
|
|
buffer = br.ReadBytes((int)((sectorSize + sectorSkip) * length));
|
2020-01-11 22:44:25 +00:00
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] sector = new byte[sectorSize];
|
2020-01-12 01:00:26 +00:00
|
|
|
|
Array.Copy(buffer, (sectorSize + sectorSkip) * i, sector, 0, sectorSize);
|
2020-01-11 22:44:25 +00:00
|
|
|
|
sector = Sector.GetUserDataFromMode2(sector);
|
|
|
|
|
|
mode2Ms.Write(sector, 0, sector.Length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buffer = mode2Ms.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(sectorOffset == 0 &&
|
|
|
|
|
|
sectorSkip == 0)
|
2020-01-11 20:55:54 +00:00
|
|
|
|
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
|
2020-07-22 13:20:25 +01:00
|
|
|
|
var aaruTrack = new Track
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
aaruTrack = bwTrack;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-06-21 14:49:25 +01:00
|
|
|
|
if(aaruTrack is null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
2020-11-03 23:22:39 +00:00
|
|
|
|
if(length + sectorAddress > (aaruTrack.TrackEndSector - aaruTrack.TrackStartSector) + 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2020-11-03 23:22:39 +00:00
|
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({(aaruTrack.TrackEndSector - aaruTrack.TrackStartSector) + 1}), won't cross tracks");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
DataFileCharacteristics chars = (from characteristics in _filePaths let firstSector =
|
2020-06-18 02:03:19 +01:00
|
|
|
|
characteristics.StartLba let lastSector =
|
|
|
|
|
|
(firstSector + characteristics.Sectors) - 1 let wantedSector =
|
|
|
|
|
|
(int)(sectorAddress + aaruTrack.TrackStartSector)
|
|
|
|
|
|
where wantedSector >= firstSector && wantedSector <= lastSector
|
|
|
|
|
|
select characteristics).FirstOrDefault();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
if(string.IsNullOrEmpty(chars.FilePath) ||
|
|
|
|
|
|
chars.FileFilter == null)
|
2017-12-20 17:15:26 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(chars.FileFilter), "Track does not exist in disc image");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
if(aaruTrack.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:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_trackFlags.TryGetValue((uint)sectorAddress, out byte flag))
|
2020-01-11 20:55:54 +00:00
|
|
|
|
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
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
switch(aaruTrack.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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2020-06-18 02:11:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
switch(chars.Subchannel)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 16;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default: throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2020-06-18 02:11:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
switch(chars.Subchannel)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 16;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default: throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SectorTagType.CdSectorSubchannel:
|
2020-06-18 02:11:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
switch(chars.Subchannel)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 16;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default: throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
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:
|
2020-06-18 02:11:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
switch(chars.Subchannel)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 96;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorOffset = 2352;
|
|
|
|
|
|
sectorSize = 16;
|
|
|
|
|
|
sectorSkip = 0;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default: throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
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
|
|
|
|
}
|
2020-06-18 02:11:55 +01:00
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-18 02:11:55 +01:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
switch(chars.Subchannel)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TrackSubchannelType.None:
|
|
|
|
|
|
sectorSkip += 0;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-06-18 02:11:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
|
|
|
|
|
sectorSkip += 16;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-06-18 02:11:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
|
|
|
|
|
sectorSkip += 96;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2020-06-18 02:11:55 +01:00
|
|
|
|
break;
|
|
|
|
|
|
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
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
|
|
|
|
|
var br = new BinaryReader(_imageStream);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
|
|
|
|
|
br.BaseStream.
|
2020-02-28 00:19:50 +00:00
|
|
|
|
Seek((long)aaruTrack.TrackFileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2020-01-11 20:55:54 +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
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-18 02:11:55 +01:00
|
|
|
|
if(tag != SectorTagType.CdSectorSubchannel)
|
|
|
|
|
|
return buffer;
|
2020-05-05 15:46:32 +01:00
|
|
|
|
|
2020-06-18 02:11:55 +01:00
|
|
|
|
return chars.Subchannel switch
|
|
|
|
|
|
{
|
|
|
|
|
|
TrackSubchannelType.Q16Interleaved => Subchannel.ConvertQToRaw(buffer),
|
|
|
|
|
|
TrackSubchannelType.PackedInterleaved => Subchannel.Interleave(buffer),
|
|
|
|
|
|
_ => buffer
|
|
|
|
|
|
};
|
2016-08-18 00:07:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2018-11-26 23:16:54 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetmap where sectorAddress >= kvp.Value
|
2020-01-11 20:55:54 +00:00
|
|
|
|
from track in Tracks where track.TrackSequence == kvp.Key
|
2020-11-03 23:22:39 +00:00
|
|
|
|
where sectorAddress - kvp.Value <
|
|
|
|
|
|
(track.TrackEndSector - track.TrackStartSector) + 1
|
|
|
|
|
|
select kvp)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
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
|
2020-07-22 13:20:25 +01:00
|
|
|
|
var aaruTrack = new Track
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-02-28 00:19:50 +00:00
|
|
|
|
aaruTrack = bwTrack;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2017-12-21 07:08:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-06-21 14:49:25 +01:00
|
|
|
|
if(aaruTrack is null)
|
2016-08-18 00:07:16 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
|
|
|
|
|
2020-11-03 23:22:39 +00:00
|
|
|
|
if(length + sectorAddress > (aaruTrack.TrackEndSector - aaruTrack.TrackStartSector) + 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length),
|
2020-11-03 23:22:39 +00:00
|
|
|
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({(aaruTrack.TrackEndSector - aaruTrack.TrackStartSector) + 1}), won't cross tracks");
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
DataFileCharacteristics chars = (from characteristics in _filePaths let firstSector =
|
2020-06-18 02:03:19 +01:00
|
|
|
|
characteristics.StartLba let lastSector =
|
|
|
|
|
|
(firstSector + characteristics.Sectors) - 1 let wantedSector =
|
|
|
|
|
|
(int)(sectorAddress + aaruTrack.TrackStartSector)
|
|
|
|
|
|
where wantedSector >= firstSector && wantedSector <= lastSector
|
|
|
|
|
|
select characteristics).FirstOrDefault();
|
2016-08-18 00:07:16 +01:00
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
if(string.IsNullOrEmpty(chars.FilePath) ||
|
|
|
|
|
|
chars.FileFilter == null)
|
2017-12-20 17:15:26 +00:00
|
|
|
|
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
|
|
|
|
|
2020-02-28 00:19:50 +00:00
|
|
|
|
switch(aaruTrack.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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.Q16Interleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 16;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2016-08-18 00:07:16 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case TrackSubchannelType.PackedInterleaved:
|
2017-12-20 17:15:26 +00:00
|
|
|
|
sectorSkip += 96;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
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
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
|
|
|
|
|
var br = new BinaryReader(_imageStream);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
|
|
|
|
|
br.BaseStream.
|
2020-02-28 00:19:50 +00:00
|
|
|
|
Seek((long)aaruTrack.TrackFileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
2017-12-19 20:33:03 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2020-01-11 20:55:54 +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
|
|
|
|
{
|
2020-01-11 20:55:54 +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");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-11 20:55:54 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session) =>
|
2020-02-28 00:19:50 +00:00
|
|
|
|
Tracks.Where(aaruTrack => aaruTrack.TrackSession == session).ToList();
|
2016-08-18 00:05:24 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|