mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Introduces constant fields for respective debug module names, replacing the hardcoded ones. This is done to standardize the naming convention, reduce redundancy and potentially avoid any typos or name mismatches across the project. This change makes the code more maintainable and easier to update in case module names need to be changed.
166 lines
5.8 KiB
C#
166 lines
5.8 KiB
C#
// /***************************************************************************
|
|
// Aaru Data Preservation Suite
|
|
// ----------------------------------------------------------------------------
|
|
//
|
|
// Filename : Human68k.cs
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
//
|
|
// Component : Partitioning scheme plugins.
|
|
//
|
|
// --[ Description ] ----------------------------------------------------------
|
|
//
|
|
// Manages Human68k (Sharp X68000) partitions.
|
|
//
|
|
// --[ 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/>.
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
// Copyright © 2011-2023 Natalia Portillo
|
|
// ****************************************************************************/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using Aaru.CommonTypes;
|
|
using Aaru.CommonTypes.Enums;
|
|
using Aaru.CommonTypes.Interfaces;
|
|
using Aaru.Console;
|
|
using Aaru.Helpers;
|
|
using Marshal = Aaru.Helpers.Marshal;
|
|
|
|
namespace Aaru.Partitions;
|
|
|
|
/// <inheritdoc />
|
|
/// <summary>Implements decoding of Sharp's Human68K partitions</summary>
|
|
public sealed class Human68K : IPartition
|
|
{
|
|
// ReSharper disable once InconsistentNaming
|
|
const uint X68K_MAGIC = 0x5836384B;
|
|
const string MODULE_NAME = "Human68k partitions plugin";
|
|
|
|
/// <inheritdoc />
|
|
public string Name => Localization.Human68K_Name;
|
|
/// <inheritdoc />
|
|
public Guid Id => new("246A6D93-4F1A-1F8A-344D-50187A5513A9");
|
|
/// <inheritdoc />
|
|
public string Author => Authors.NataliaPortillo;
|
|
|
|
/// <inheritdoc />
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
|
{
|
|
partitions = new List<Partition>();
|
|
|
|
byte[] sector;
|
|
ulong sectsPerUnit;
|
|
ErrorNumber errno;
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "sectorSize = {0}", imagePlugin.Info.SectorSize);
|
|
|
|
if(sectorOffset + 4 >= imagePlugin.Info.Sectors)
|
|
return false;
|
|
|
|
switch(imagePlugin.Info.SectorSize)
|
|
{
|
|
case 256:
|
|
errno = imagePlugin.ReadSector(4 + sectorOffset, out sector);
|
|
sectsPerUnit = 1;
|
|
|
|
break;
|
|
case 512:
|
|
errno = imagePlugin.ReadSector(4 + sectorOffset, out sector);
|
|
sectsPerUnit = 2;
|
|
|
|
break;
|
|
case 1024:
|
|
errno = imagePlugin.ReadSector(2 + sectorOffset, out sector);
|
|
sectsPerUnit = 1;
|
|
|
|
break;
|
|
default: return false;
|
|
}
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
return false;
|
|
|
|
Table table = Marshal.ByteArrayToStructureBigEndian<Table>(sector);
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.magic = {0:X4}", table.magic);
|
|
|
|
if(table.magic != X68K_MAGIC)
|
|
return false;
|
|
|
|
for(int i = 0; i < table.entries.Length; i++)
|
|
table.entries[i] = (Entry)Marshal.SwapStructureMembersEndian(table.entries[i]);
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.size = {0:X4}", table.size);
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.size2 = {0:X4}", table.size2);
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.unknown = {0:X4}", table.unknown);
|
|
|
|
ulong counter = 0;
|
|
|
|
foreach(Entry entry in table.entries)
|
|
{
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "entry.name = {0}",
|
|
StringHandlers.CToString(entry.name, Encoding.GetEncoding(932)));
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "entry.stateStart = {0}", entry.stateStart);
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "entry.length = {0}", entry.length);
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "sectsPerUnit = {0} {1}", sectsPerUnit,
|
|
imagePlugin.Info.SectorSize);
|
|
|
|
var part = new Partition
|
|
{
|
|
Start = (entry.stateStart & 0xFFFFFF) * sectsPerUnit,
|
|
Length = entry.length * sectsPerUnit,
|
|
Type = StringHandlers.CToString(entry.name, Encoding.GetEncoding(932)),
|
|
Sequence = counter,
|
|
Scheme = Name
|
|
};
|
|
|
|
part.Offset = part.Start * (ulong)sector.Length;
|
|
part.Size = part.Length * (ulong)sector.Length;
|
|
|
|
if(entry.length <= 0)
|
|
continue;
|
|
|
|
partitions.Add(part);
|
|
counter++;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
readonly struct Table
|
|
{
|
|
public readonly uint magic;
|
|
public readonly uint size;
|
|
public readonly uint size2;
|
|
public readonly uint unknown;
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
public readonly Entry[] entries;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
readonly struct Entry
|
|
{
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
public readonly byte[] name;
|
|
public readonly uint stateStart;
|
|
public readonly uint length;
|
|
}
|
|
} |