2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-08-22 00:49:48 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Human68k.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Component : Partitioning scheme plugins.
|
2016-08-22 00:49:48 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Manages Human68k (Sharp X68000) partitions.
|
2016-08-22 00:49:48 +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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2016-08-22 00:49:48 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes;
|
2025-10-21 11:20:54 +01:00
|
|
|
using Aaru.CommonTypes.Attributes;
|
2021-09-19 21:16:47 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-07-20 15:43:52 +01:00
|
|
|
using Aaru.Helpers;
|
2025-08-17 05:50:25 +01:00
|
|
|
using Aaru.Logging;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Partitions;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>Implements decoding of Sharp's Human68K partitions</summary>
|
2025-10-21 11:20:54 +01:00
|
|
|
public sealed partial class Human68K : IPartition
|
2016-08-22 00:49:48 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
// ReSharper disable once InconsistentNaming
|
2023-10-03 18:46:31 +01:00
|
|
|
const uint X68K_MAGIC = 0x5836384B;
|
|
|
|
|
const string MODULE_NAME = "Human68k partitions plugin";
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2025-10-22 14:28:58 +01:00
|
|
|
#region Nested type: Entry
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
[SwapEndian]
|
|
|
|
|
partial struct Entry
|
|
|
|
|
{
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
public byte[] name;
|
|
|
|
|
public uint stateStart;
|
|
|
|
|
public uint length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Nested type: Table
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
[SwapEndian]
|
|
|
|
|
partial struct Table
|
|
|
|
|
{
|
|
|
|
|
public uint magic;
|
|
|
|
|
public uint size;
|
|
|
|
|
public uint size2;
|
|
|
|
|
public uint unknown;
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
public Entry[] entries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
#region IPartition Members
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-29 03:13:21 +00:00
|
|
|
public string Name => Localization.Human68K_Name;
|
2023-10-03 23:36:49 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Guid Id => new("246A6D93-4F1A-1F8A-344D-50187A5513A9");
|
2023-10-03 23:36:49 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2023-10-05 01:52:48 +01:00
|
|
|
public string Author => Authors.NATALIA_PORTILLO;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2021-08-17 14:25:12 +01:00
|
|
|
/// <inheritdoc />
|
2022-03-06 13:29:38 +00:00
|
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2016-08-22 00:49:48 +01:00
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
partitions = [];
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
byte[] sector;
|
|
|
|
|
ulong sectsPerUnit;
|
|
|
|
|
ErrorNumber errno;
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, "sectorSize = {0}", imagePlugin.Info.SectorSize);
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(sectorOffset + 4 >= imagePlugin.Info.Sectors) return false;
|
2017-07-24 23:35:33 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
switch(imagePlugin.Info.SectorSize)
|
|
|
|
|
{
|
|
|
|
|
case 256:
|
2025-10-23 03:07:43 +01:00
|
|
|
errno = imagePlugin.ReadSector(4 + sectorOffset, false, out sector, out _);
|
2022-03-06 13:29:38 +00:00
|
|
|
sectsPerUnit = 1;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 512:
|
2025-10-23 03:07:43 +01:00
|
|
|
errno = imagePlugin.ReadSector(4 + sectorOffset, false, out sector, out _);
|
2022-03-06 13:29:38 +00:00
|
|
|
sectsPerUnit = 2;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 1024:
|
2025-10-23 03:07:43 +01:00
|
|
|
errno = imagePlugin.ReadSector(2 + sectorOffset, false, out sector, out _);
|
2022-03-06 13:29:38 +00:00
|
|
|
sectsPerUnit = 1;
|
|
|
|
|
|
|
|
|
|
break;
|
2023-10-03 23:36:49 +01:00
|
|
|
default:
|
|
|
|
|
return false;
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2025-10-21 11:43:05 +01:00
|
|
|
Table table = Marshal.ByteArrayToStructureBigEndian<Table>(sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, "table.magic = {0:X4}", table.magic);
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(table.magic != X68K_MAGIC) return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, "table.size = {0:X4}", table.size);
|
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "table.size2 = {0:X4}", table.size2);
|
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "table.unknown = {0:X4}", table.unknown);
|
2017-07-24 23:35:33 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong counter = 0;
|
2017-07-24 04:51:08 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
foreach(Entry entry in table.entries)
|
|
|
|
|
{
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-10-21 11:20:54 +01:00
|
|
|
"entry.name = {0}",
|
|
|
|
|
StringHandlers.CToString(entry.name, Encoding.GetEncoding(932)));
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, "entry.stateStart = {0}", entry.stateStart);
|
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "entry.length = {0}", entry.length);
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2025-10-21 11:20:54 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, "sectsPerUnit = {0} {1}", sectsPerUnit, imagePlugin.Info.SectorSize);
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var part = new Partition
|
2016-08-22 00:49:48 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Start = (entry.stateStart & 0xFFFFFF) * sectsPerUnit,
|
|
|
|
|
Length = entry.length * sectsPerUnit,
|
|
|
|
|
Type = StringHandlers.CToString(entry.name, Encoding.GetEncoding(932)),
|
|
|
|
|
Sequence = counter,
|
|
|
|
|
Scheme = Name
|
|
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
part.Offset = part.Start * (ulong)sector.Length;
|
|
|
|
|
part.Size = part.Length * (ulong)sector.Length;
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(entry.length <= 0) continue;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
partitions.Add(part);
|
|
|
|
|
counter++;
|
2016-08-22 00:49:48 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
#endregion
|
2016-08-22 00:49:48 +01:00
|
|
|
}
|