2018-02-08 21:13:23 +00:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2018-02-08 21:13:23 +00:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : PCEngine.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : NEC PC-FX plugin.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the NEC PC-FX track header and shows information.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2018-02-08 21:13:23 +00:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2018-02-08 21:13:23 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2018-02-08 21:13:23 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2018-02-08 21:13:23 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// Not a filesystem, more like an executable header
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection of NEC PC-FX headers</summary>
|
|
|
|
|
|
public sealed class PCFX : IFilesystem
|
2018-02-08 21:13:23 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
const string IDENTIFIER = "PC-FX:Hu_CD-ROM ";
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public string Name => "PC-FX Plugin";
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Guid Id => new("8BC27CCE-D9E9-48F8-BA93-C66A86EB565A");
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public string Author => "Natalia Portillo";
|
|
|
|
|
|
|
2021-08-17 14:25:12 +01:00
|
|
|
|
/// <inheritdoc />
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2018-02-08 21:13:23 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(2 + partition.Start >= partition.End ||
|
|
|
|
|
|
imagePlugin.Info.XmlMediaType != XmlMediaType.OpticalDisc)
|
|
|
|
|
|
return false;
|
2018-02-08 21:13:23 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2018-02-08 21:13:23 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var encoding = Encoding.GetEncoding("shift_jis");
|
2018-02-08 21:13:23 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return encoding.GetString(sector, 0, 16) == IDENTIFIER;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
// Always Shift-JIS
|
|
|
|
|
|
Encoding = Encoding.GetEncoding("shift_jis");
|
|
|
|
|
|
information = "";
|
|
|
|
|
|
|
|
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] sector);
|
2018-02-08 21:13:23 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
Header header = Marshal.ByteArrayToStructureLittleEndian<Header>(sector);
|
|
|
|
|
|
|
|
|
|
|
|
string date;
|
|
|
|
|
|
DateTime dateTime = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2018-02-08 21:13:23 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
date = Encoding.GetString(header.date);
|
2022-11-14 01:15:06 +00:00
|
|
|
|
var year = int.Parse(date[..4]);
|
2022-03-07 07:36:44 +00:00
|
|
|
|
var month = int.Parse(date.Substring(4, 2));
|
|
|
|
|
|
var day = int.Parse(date.Substring(6, 2));
|
2022-03-06 13:29:38 +00:00
|
|
|
|
dateTime = new DateTime(year, month, day);
|
2018-02-08 21:13:23 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
catch
|
2018-02-08 21:13:23 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
date = null;
|
2018-02-08 21:13:23 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
sb.AppendLine("PC-FX executable:");
|
|
|
|
|
|
sb.AppendFormat("Identifier: {0}", StringHandlers.CToString(header.signature, Encoding)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Copyright: {0}", StringHandlers.CToString(header.copyright, Encoding)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Title: {0}", StringHandlers.CToString(header.title, Encoding)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Maker ID: {0}", StringHandlers.CToString(header.makerId, Encoding)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Maker name: {0}", StringHandlers.CToString(header.makerName, Encoding)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Volume number: {0}", header.volumeNumber).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Country code: {0}", header.country).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Version: {0}.{1}", header.minorVersion, header.majorVersion).AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
if(date != null)
|
|
|
|
|
|
sb.AppendFormat("Dated {0}", dateTime).AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("Load {0} sectors from sector {1}", header.loadCount, header.loadOffset).AppendLine();
|
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
sb.AppendFormat("Load at 0x{0:X8} and jump to 0x{1:X8}", header.loadAddress, header.entryPoint).AppendLine();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
XmlFsType = new FileSystemType
|
|
|
|
|
|
{
|
|
|
|
|
|
Type = "PC-FX",
|
|
|
|
|
|
Clusters = partition.Length,
|
|
|
|
|
|
ClusterSize = 2048,
|
|
|
|
|
|
Bootable = true,
|
|
|
|
|
|
CreationDate = dateTime,
|
|
|
|
|
|
CreationDateSpecified = date != null,
|
|
|
|
|
|
PublisherIdentifier = StringHandlers.CToString(header.makerName, Encoding),
|
|
|
|
|
|
VolumeName = StringHandlers.CToString(header.title, Encoding),
|
|
|
|
|
|
SystemIdentifier = "PC-FX"
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
readonly struct Header
|
|
|
|
|
|
{
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public readonly byte[] signature;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0xE0)]
|
|
|
|
|
|
public readonly byte[] copyright;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x710)]
|
|
|
|
|
|
public readonly byte[] unknown;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public readonly byte[] title;
|
|
|
|
|
|
public readonly uint loadOffset;
|
|
|
|
|
|
public readonly uint loadCount;
|
|
|
|
|
|
public readonly uint loadAddress;
|
|
|
|
|
|
public readonly uint entryPoint;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
|
|
|
|
public readonly byte[] makerId;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
|
|
|
|
|
|
public readonly byte[] makerName;
|
|
|
|
|
|
public readonly uint volumeNumber;
|
|
|
|
|
|
public readonly byte majorVersion;
|
|
|
|
|
|
public readonly byte minorVersion;
|
|
|
|
|
|
public readonly ushort country;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
|
public readonly byte[] date;
|
2018-02-08 21:13:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|