2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : AppleMap.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Partitioning scheme plugins.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Manages Apple Partition Map.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-07-13 00:19:21 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.Text;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Console;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
namespace DiscImageChef.Partitions
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
// Information about structures learnt from Inside Macintosh
|
|
|
|
|
// Constants from image testing
|
2017-12-26 06:05:12 +00:00
|
|
|
public class AppleMap : IPartition
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>"ER", driver descriptor magic</summary>
|
|
|
|
|
const ushort DDM_MAGIC = 0x4552;
|
|
|
|
|
/// <summary>"PM", new entry magic</summary>
|
|
|
|
|
const ushort APM_MAGIC = 0x504D;
|
|
|
|
|
/// <summary>"TS", old map magic</summary>
|
|
|
|
|
const ushort APM_MAGIC_OLD = 0x5453;
|
|
|
|
|
/// <summary>Old indicator for HFS partition, "TFS1"</summary>
|
|
|
|
|
const uint HFS_MAGIC_OLD = 0x54465331;
|
2012-08-05 03:02:55 +00:00
|
|
|
|
2018-08-29 22:15:43 +01:00
|
|
|
public string Name => "Apple Partition Map";
|
|
|
|
|
public Guid Id => new Guid("36405F8D-4F1A-07F5-209C-223D735D6D22");
|
|
|
|
|
public string Author => "Natalia Portillo";
|
2014-04-14 02:29:13 +00:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
uint sectorSize;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imagePlugin.Info.SectorSize == 2352 || imagePlugin.Info.SectorSize == 2448) sectorSize = 2048;
|
2018-06-22 08:08:38 +01:00
|
|
|
else
|
|
|
|
|
sectorSize =
|
|
|
|
|
imagePlugin.Info.SectorSize;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
partitions = new List<Partition>();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(sectorOffset + 2 >= imagePlugin.Info.Sectors) return false;
|
2017-11-08 17:05:00 +00:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
byte[] ddmSector = imagePlugin.ReadSector(sectorOffset);
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
ushort maxDrivers = 61;
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
if(sectorSize == 256)
|
2014-08-28 18:26:14 +01:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
byte[] tmp = new byte[512];
|
2017-12-22 16:53:11 +00:00
|
|
|
Array.Copy(ddmSector, 0, tmp, 0, 256);
|
2018-06-22 08:08:38 +01:00
|
|
|
ddmSector = tmp;
|
2017-12-22 16:53:11 +00:00
|
|
|
maxDrivers = 29;
|
2017-07-13 00:19:21 +01:00
|
|
|
}
|
2017-12-22 16:53:11 +00:00
|
|
|
else if(sectorSize < 256) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-24 03:11:33 +00:00
|
|
|
AppleDriverDescriptorMap ddm =
|
|
|
|
|
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleDriverDescriptorMap>(ddmSector);
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbSig = 0x{0:X4}", ddm.sbSig);
|
2017-07-13 00:19:21 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbBlockSize = {0}", ddm.sbBlockSize);
|
2018-06-22 08:08:38 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbBlocks = {0}", ddm.sbBlocks);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbDevType = {0}", ddm.sbDevType);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbDevId = {0}", ddm.sbDevId);
|
2017-07-13 00:19:21 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbData = 0x{0:X8}", ddm.sbData);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbDrvrCount = {0}", ddm.sbDrvrCount);
|
|
|
|
|
|
|
|
|
|
uint sequence = 0;
|
|
|
|
|
|
2017-07-15 01:36:13 +01:00
|
|
|
if(ddm.sbSig == DDM_MAGIC)
|
2017-12-22 16:53:11 +00:00
|
|
|
if(ddm.sbDrvrCount < maxDrivers)
|
2014-08-28 18:26:14 +01:00
|
|
|
{
|
2017-07-15 01:36:13 +01:00
|
|
|
ddm.sbMap = new AppleDriverEntry[ddm.sbDrvrCount];
|
|
|
|
|
for(int i = 0; i < ddm.sbDrvrCount; i++)
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
2017-07-15 01:36:13 +01:00
|
|
|
byte[] tmp = new byte[8];
|
2017-12-22 16:53:11 +00:00
|
|
|
Array.Copy(ddmSector, 18 + i * 8, tmp, 0, 8);
|
2017-07-15 01:36:13 +01:00
|
|
|
ddm.sbMap[i] = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleDriverEntry>(tmp);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddBlock = {0}",
|
|
|
|
|
ddm.sbMap[i].ddBlock, i);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddSize = {0}", ddm.sbMap[i].ddSize,
|
|
|
|
|
i);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddType = {0}", ddm.sbMap[i].ddType,
|
|
|
|
|
i);
|
|
|
|
|
|
|
|
|
|
if(ddm.sbMap[i].ddSize == 0) continue;
|
2017-07-15 01:36:13 +01:00
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
Partition part = new Partition
|
2017-07-15 01:36:13 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = (ulong)(ddm.sbMap[i].ddSize * 512),
|
|
|
|
|
Length = (ulong)(ddm.sbMap[i].ddSize * 512 / sectorSize),
|
2017-07-19 16:37:11 +01:00
|
|
|
Sequence = sequence,
|
2018-06-22 08:08:38 +01:00
|
|
|
Offset = ddm.sbMap[i].ddBlock * sectorSize,
|
|
|
|
|
Start = ddm.sbMap[i].ddBlock + sectorOffset,
|
|
|
|
|
Type = "Apple_Driver"
|
2017-07-15 01:36:13 +01:00
|
|
|
};
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
if(ddm.sbMap[i].ddSize * 512 % sectorSize > 0) part.Length++;
|
2017-07-20 13:12:36 +01:00
|
|
|
|
2017-07-15 01:36:13 +01:00
|
|
|
partitions.Add(part);
|
2014-08-28 18:26:14 +01:00
|
|
|
|
2017-07-15 01:36:13 +01:00
|
|
|
sequence++;
|
|
|
|
|
}
|
2014-08-28 18:26:14 +01:00
|
|
|
}
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
byte[] partSector = imagePlugin.ReadSector(1 + sectorOffset);
|
|
|
|
|
AppleOldDevicePartitionMap oldMap =
|
|
|
|
|
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleOldDevicePartitionMap>(partSector);
|
2017-07-13 00:19:21 +01:00
|
|
|
|
|
|
|
|
// This is the easy one, no sector size mixing
|
2017-12-22 16:53:11 +00:00
|
|
|
if(oldMap.pdSig == APM_MAGIC_OLD)
|
2014-08-28 18:26:14 +01:00
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
for(int i = 2; i < partSector.Length; i += 12)
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
|
|
|
|
byte[] tmp = new byte[12];
|
2017-12-22 16:53:11 +00:00
|
|
|
Array.Copy(partSector, i, tmp, 0, 12);
|
|
|
|
|
AppleMapOldPartitionEntry oldEntry =
|
2017-12-19 20:33:03 +00:00
|
|
|
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapOldPartitionEntry>(tmp);
|
2017-12-22 16:53:11 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdStart = {0}", oldEntry.pdStart,
|
2017-12-19 20:33:03 +00:00
|
|
|
(i - 2) / 12);
|
2017-12-22 16:53:11 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdSize = {0}", oldEntry.pdSize,
|
2017-12-19 20:33:03 +00:00
|
|
|
(i - 2) / 12);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdFSID = 0x{0:X8}",
|
2017-12-22 16:53:11 +00:00
|
|
|
oldEntry.pdFSID, (i - 2) / 12);
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
if(oldEntry.pdSize == 0 && oldEntry.pdFSID == 0)
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
if(oldEntry.pdStart == 0) break;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2014-08-28 18:26:14 +01:00
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
Partition part = new Partition
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = oldEntry.pdStart * ddm.sbBlockSize,
|
|
|
|
|
Length = oldEntry.pdStart * ddm.sbBlockSize / sectorSize,
|
2017-07-19 16:37:11 +01:00
|
|
|
Sequence = sequence,
|
2018-06-22 08:08:38 +01:00
|
|
|
Offset = oldEntry.pdSize * ddm.sbBlockSize,
|
|
|
|
|
Start = oldEntry.pdSize * ddm.sbBlockSize / sectorSize,
|
|
|
|
|
Scheme = Name,
|
|
|
|
|
Type = oldEntry.pdFSID == HFS_MAGIC_OLD ? "Apple_HFS" : $"0x{oldEntry.pdFSID:X8}"
|
2017-07-13 00:19:21 +01:00
|
|
|
};
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
partitions.Add(part);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
sequence++;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-15 01:36:13 +01:00
|
|
|
return partitions.Count > 0;
|
2017-07-13 00:19:21 +01:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
AppleMapPartitionEntry entry;
|
2018-06-22 08:08:38 +01:00
|
|
|
uint entrySize;
|
|
|
|
|
uint entryCount;
|
|
|
|
|
uint sectorsToRead;
|
|
|
|
|
uint skipDdm;
|
2017-07-13 00:19:21 +01:00
|
|
|
|
|
|
|
|
// If sector is bigger than 512
|
2017-12-22 16:53:11 +00:00
|
|
|
if(sectorSize > 512)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
byte[] tmp = new byte[512];
|
2017-12-22 16:53:11 +00:00
|
|
|
Array.Copy(ddmSector, 512, tmp, 0, 512);
|
2017-07-13 00:19:21 +01:00
|
|
|
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
|
|
|
|
|
// Check for a partition entry that's 512-byte aligned
|
|
|
|
|
if(entry.signature == APM_MAGIC)
|
2016-08-09 15:31:44 +01:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "Found misaligned entry.");
|
2018-06-22 08:08:38 +01:00
|
|
|
entrySize = 512;
|
|
|
|
|
entryCount = entry.entries;
|
|
|
|
|
skipDdm = 512;
|
2017-12-22 16:53:11 +00:00
|
|
|
sectorsToRead = (entryCount + 1) * 512 / sectorSize + 1;
|
2016-08-09 15:31:44 +01:00
|
|
|
}
|
2014-08-28 18:26:14 +01:00
|
|
|
else
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(partSector);
|
2017-07-13 00:19:21 +01:00
|
|
|
if(entry.signature == APM_MAGIC)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "Found aligned entry.");
|
2018-06-22 08:08:38 +01:00
|
|
|
entrySize = sectorSize;
|
|
|
|
|
entryCount = entry.entries;
|
|
|
|
|
skipDdm = sectorSize;
|
2017-12-22 16:53:11 +00:00
|
|
|
sectorsToRead = entryCount + 2;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else return partitions.Count > 0;
|
2017-07-13 00:19:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(partSector);
|
2017-07-13 00:19:21 +01:00
|
|
|
if(entry.signature == APM_MAGIC)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "Found aligned entry.");
|
2018-06-22 08:08:38 +01:00
|
|
|
entrySize = sectorSize;
|
|
|
|
|
entryCount = entry.entries;
|
|
|
|
|
skipDdm = sectorSize;
|
2017-12-22 16:53:11 +00:00
|
|
|
sectorsToRead = entryCount + 2;
|
2017-07-13 00:19:21 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else return partitions.Count > 0;
|
2017-07-13 00:19:21 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
byte[] entries = imagePlugin.ReadSectors(sectorOffset, sectorsToRead);
|
2018-06-22 08:08:38 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "entry_size = {0}", entrySize);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "entry_count = {0}", entryCount);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "skip_ddm = {0}", skipDdm);
|
2017-12-22 16:53:11 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "sectors_to_read = {0}", sectorsToRead);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
byte[] copy = new byte[entries.Length - skipDdm];
|
|
|
|
|
Array.Copy(entries, skipDdm, copy, 0, copy.Length);
|
2017-07-13 00:19:21 +01:00
|
|
|
entries = copy;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
for(int i = 0; i < entryCount; i++)
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
byte[] tmp = new byte[entrySize];
|
|
|
|
|
Array.Copy(entries, i * entrySize, tmp, 0, entrySize);
|
2017-07-13 00:19:21 +01:00
|
|
|
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
|
2017-12-21 06:06:19 +00:00
|
|
|
if(entry.signature != APM_MAGIC) continue;
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].signature = 0x{1:X4}", i, entry.signature);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].reserved1 = 0x{1:X4}", i, entry.reserved1);
|
2018-06-22 08:08:38 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entries = {1}", i, entry.entries);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].start = {1}", i, entry.start);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].sectors = {1}", i, entry.sectors);
|
2017-12-21 06:06:19 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i,
|
|
|
|
|
StringHandlers.CToString(entry.name));
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i,
|
|
|
|
|
StringHandlers.CToString(entry.type));
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i,
|
|
|
|
|
entry.first_data_block);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].data_sectors = {1}", i, entry.data_sectors);
|
2018-06-22 08:08:38 +01:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i,
|
|
|
|
|
(AppleMapFlags)entry.flags);
|
2017-12-21 06:06:19 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i,
|
|
|
|
|
entry.first_boot_block);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].boot_size = {1}", i, entry.boot_size);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i,
|
|
|
|
|
entry.load_address);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i,
|
|
|
|
|
entry.load_address2);
|
2017-12-24 03:11:33 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i, entry.entry_point);
|
2017-12-21 06:06:19 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i,
|
|
|
|
|
entry.entry_point2);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum);
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i,
|
|
|
|
|
StringHandlers.CToString(entry.processor));
|
|
|
|
|
|
|
|
|
|
AppleMapFlags flags = (AppleMapFlags)entry.flags;
|
|
|
|
|
|
|
|
|
|
// BeOS doesn't mark its partitions as valid
|
|
|
|
|
//if(flags.HasFlag(AppleMapFlags.Valid) &&
|
|
|
|
|
if(StringHandlers.CToString(entry.type) == "Apple_partition_map" || entry.sectors <= 0) continue;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
Partition partition = new Partition
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
Sequence = sequence,
|
2018-06-22 08:08:38 +01:00
|
|
|
Type = StringHandlers.CToString(entry.type),
|
|
|
|
|
Name = StringHandlers.CToString(entry.name),
|
|
|
|
|
Offset = entry.start * entrySize,
|
|
|
|
|
Size = entry.sectors * entrySize,
|
|
|
|
|
Start = entry.start * entrySize / sectorSize + sectorOffset,
|
|
|
|
|
Length = entry.sectors * entrySize / sectorSize,
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
|
|
|
|
sb.AppendLine("Partition flags:");
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.Valid)) sb.AppendLine("Partition is valid.");
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.Allocated)) sb.AppendLine("Partition entry is allocated.");
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.InUse)) sb.AppendLine("Partition is in use.");
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.Bootable)) sb.AppendLine("Partition is bootable.");
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.Readable)) sb.AppendLine("Partition is readable.");
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.Writable)) sb.AppendLine("Partition is writable.");
|
|
|
|
|
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.Bootable))
|
|
|
|
|
{
|
2017-12-24 03:11:33 +00:00
|
|
|
sb.AppendFormat("First boot sector: {0}", entry.first_boot_block * entrySize / sectorSize)
|
|
|
|
|
.AppendLine();
|
2017-12-21 06:06:19 +00:00
|
|
|
sb.AppendFormat("Boot is {0} bytes.", entry.boot_size).AppendLine();
|
|
|
|
|
sb.AppendFormat("Boot load address: 0x{0:X8}", entry.load_address).AppendLine();
|
|
|
|
|
sb.AppendFormat("Boot entry point: 0x{0:X8}", entry.entry_point).AppendLine();
|
|
|
|
|
sb.AppendFormat("Boot code checksum: 0x{0:X8}", entry.checksum).AppendLine();
|
|
|
|
|
sb.AppendFormat("Processor: {0}", StringHandlers.CToString(entry.processor)).AppendLine();
|
|
|
|
|
|
|
|
|
|
if(flags.HasFlag(AppleMapFlags.PicCode))
|
|
|
|
|
sb.AppendLine("Partition's boot code is position independent.");
|
|
|
|
|
}
|
2017-07-13 00:19:21 +01:00
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
partition.Description = sb.ToString();
|
|
|
|
|
if(partition.Start < imagePlugin.Info.Sectors && partition.End < imagePlugin.Info.Sectors)
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2018-06-20 22:22:21 +01:00
|
|
|
partitions.Add(partition);
|
2017-12-21 06:06:19 +00:00
|
|
|
sequence++;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
// Some CD and DVDs end with an Apple_Free that expands beyond the disc size...
|
2018-06-20 22:22:21 +01:00
|
|
|
else if(partition.Start < imagePlugin.Info.Sectors)
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2017-12-24 03:11:33 +00:00
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin", "Cutting last partition end ({0}) to media size ({1})",
|
2018-06-20 22:22:21 +01:00
|
|
|
partition.End, imagePlugin.Info.Sectors - 1);
|
|
|
|
|
partition.Length = imagePlugin.Info.Sectors - partition.Start;
|
|
|
|
|
partitions.Add(partition);
|
2017-12-21 06:06:19 +00:00
|
|
|
sequence++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DicConsole.DebugWriteLine("AppleMap Plugin",
|
|
|
|
|
"Not adding partition becaus start ({0}) is outside media size ({1})",
|
2018-06-20 22:22:21 +01:00
|
|
|
partition.Start, imagePlugin.Info.Sectors - 1);
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2017-07-15 01:36:13 +01:00
|
|
|
return partitions.Count > 0;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2017-12-20 02:08:37 +00:00
|
|
|
struct AppleDriverDescriptorMap
|
2014-08-28 18:26:14 +01:00
|
|
|
{
|
2017-12-24 03:11:33 +00:00
|
|
|
/// <summary>Signature <see cref="DDM_MAGIC" /></summary>
|
2017-07-13 00:19:21 +01:00
|
|
|
public ushort sbSig;
|
|
|
|
|
/// <summary>Byter per sector</summary>
|
|
|
|
|
public ushort sbBlockSize;
|
|
|
|
|
/// <summary>Sectors of the disk</summary>
|
|
|
|
|
public uint sbBlocks;
|
|
|
|
|
/// <summary>Device type</summary>
|
|
|
|
|
public ushort sbDevType;
|
|
|
|
|
/// <summary>Device ID</summary>
|
|
|
|
|
public ushort sbDevId;
|
|
|
|
|
/// <summary>Reserved</summary>
|
|
|
|
|
public uint sbData;
|
|
|
|
|
/// <summary>Number of entries of the driver descriptor</summary>
|
|
|
|
|
public ushort sbDrvrCount;
|
|
|
|
|
/// <summary>Entries of the driver descriptor</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 61)]
|
|
|
|
|
public AppleDriverEntry[] sbMap;
|
2017-07-13 00:19:21 +01:00
|
|
|
}
|
2014-08-28 18:26:14 +01:00
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2017-12-20 02:08:37 +00:00
|
|
|
struct AppleDriverEntry
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>First sector of the driver</summary>
|
|
|
|
|
public uint ddBlock;
|
|
|
|
|
/// <summary>Size in 512bytes sectors of the driver</summary>
|
|
|
|
|
public ushort ddSize;
|
|
|
|
|
/// <summary>Operating system (MacOS = 1)</summary>
|
|
|
|
|
public ushort ddType;
|
|
|
|
|
}
|
2014-08-28 18:26:14 +01:00
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2017-12-20 02:08:37 +00:00
|
|
|
struct AppleOldDevicePartitionMap
|
2017-07-13 00:19:21 +01:00
|
|
|
{
|
2017-12-24 03:11:33 +00:00
|
|
|
/// <summary>Signature <see cref="APM_MAGIC_OLD" /></summary>
|
2017-07-13 00:19:21 +01:00
|
|
|
public ushort pdSig;
|
|
|
|
|
/// <summary>Entries of the driver descriptor</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 42)]
|
|
|
|
|
public AppleMapOldPartitionEntry[] pdMap;
|
2014-08-28 18:26:14 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2017-12-20 02:08:37 +00:00
|
|
|
struct AppleMapOldPartitionEntry
|
2014-08-28 18:26:14 +01:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>First sector of the partition</summary>
|
|
|
|
|
public uint pdStart;
|
|
|
|
|
/// <summary>Number of sectors of the partition</summary>
|
|
|
|
|
public uint pdSize;
|
|
|
|
|
/// <summary>Partition type</summary>
|
|
|
|
|
public uint pdFSID;
|
2014-08-28 18:26:14 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
[Flags]
|
2017-12-20 02:08:37 +00:00
|
|
|
enum AppleMapFlags : uint
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Partition is valid</summary>
|
|
|
|
|
Valid = 0x01,
|
|
|
|
|
/// <summary>Partition is allocated</summary>
|
|
|
|
|
Allocated = 0x02,
|
|
|
|
|
/// <summary>Partition is in use</summary>
|
|
|
|
|
InUse = 0x04,
|
|
|
|
|
/// <summary>Partition is bootable</summary>
|
|
|
|
|
Bootable = 0x08,
|
|
|
|
|
/// <summary>Partition is readable</summary>
|
|
|
|
|
Readable = 0x10,
|
|
|
|
|
/// <summary>Partition is writable</summary>
|
|
|
|
|
Writable = 0x20,
|
|
|
|
|
/// <summary>Partition boot code is position independent</summary>
|
|
|
|
|
PicCode = 0x40,
|
|
|
|
|
/// <summary>OS specific flag</summary>
|
|
|
|
|
Specific1 = 0x80,
|
|
|
|
|
/// <summary>OS specific flag</summary>
|
|
|
|
|
Specific2 = 0x100,
|
|
|
|
|
/// <summary>Unknown, seen in the wild</summary>
|
|
|
|
|
Unknown = 0x200,
|
|
|
|
|
/// <summary>Unknown, seen in the wild</summary>
|
|
|
|
|
Unknown2 = 0x40000000,
|
|
|
|
|
/// <summary>Reserved, not seen in the wild</summary>
|
2017-12-21 02:52:12 +00:00
|
|
|
Reserved = 0xBFFFFC00
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-13 00:19:21 +01:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2017-12-20 02:08:37 +00:00
|
|
|
struct AppleMapPartitionEntry
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2017-12-24 03:11:33 +00:00
|
|
|
/// <summary>Signature <see cref="APM_MAGIC" /></summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort signature;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Reserved</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort reserved1;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Number of entries on the partition map, each one sector</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint entries;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>First sector of the partition</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint start;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Number of sectos of the partition</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint sectors;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Partition name, 32 bytes, null-padded</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
public byte[] name;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Partition type. 32 bytes, null-padded</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
public byte[] type;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>First sector of the data area</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint first_data_block;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Number of sectors of the data area</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint data_sectors;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Partition flags</summary>
|
|
|
|
|
public uint flags;
|
|
|
|
|
/// <summary>First sector of the boot code</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint first_boot_block;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Size in bytes of the boot code</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint boot_size;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Load address of the boot code</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint load_address;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Load address of the boot code</summary>
|
|
|
|
|
public uint load_address2;
|
|
|
|
|
/// <summary>Entry point of the boot code</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint entry_point;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Entry point of the boot code</summary>
|
|
|
|
|
public uint entry_point2;
|
|
|
|
|
/// <summary>Boot code checksum</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint checksum;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Processor type, 16 bytes, null-padded</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
public byte[] processor;
|
2017-07-13 00:19:21 +01:00
|
|
|
/// <summary>Boot arguments</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
public uint[] boot_arguments;
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|