2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-09-17 21:23:01 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Xbox.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2016-09-17 21:25:14 +01:00
|
|
|
// Component : Partitioning scheme plugins.
|
2016-09-17 21:23:01 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-09-17 21:25:14 +01:00
|
|
|
// Manages Xbox partitions.
|
2016-09-17 21:23:01 +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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2016-09-17 21:23:01 +01:00
|
|
|
// ****************************************************************************/
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2016-09-17 21:23:01 +01:00
|
|
|
using System;
|
2016-09-17 21:25:14 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
namespace DiscImageChef.Partitions
|
2016-09-17 21:23:01 +01:00
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
public class Xbox : IPartition
|
2016-09-17 21:23:01 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
const uint XboxCigam = 0x46415458;
|
|
|
|
|
const uint XboxMagic = 0x58544146;
|
|
|
|
|
const long MemoryUnitDataOff = 0x7FF000;
|
2016-09-17 21:25:14 +01:00
|
|
|
const long Xbox360SecuritySectorOff = 0x2000;
|
2018-06-22 08:08:38 +01:00
|
|
|
const long Xbox360SystemCacheOff = 0x80000;
|
|
|
|
|
const long Xbox360GameCacheOff = 0x8008000;
|
|
|
|
|
const long Xbox368SysExtOff = 0x10C080000;
|
|
|
|
|
const long Xbox360SysExt2Off = 0x118EB0000;
|
|
|
|
|
const long Xbox360CompatOff = 0x120EB0000;
|
|
|
|
|
const long Xbox360DataOff = 0x130EB0000;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
|
|
|
const long Xbox360SecuritySectorLen = 0x80000;
|
2018-06-22 08:08:38 +01:00
|
|
|
const long Xbox360SystemCacheLen = 0x80000000;
|
|
|
|
|
const long Xbox360GameCacheLen = 0xA0E30000;
|
|
|
|
|
const long Xbox368SysExtLen = 0xCE30000;
|
|
|
|
|
const long Xbox360SysExt2Len = 0x8000000;
|
|
|
|
|
const long Xbox360CompatLen = 0x10000000;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
const uint XBOX360_DEVKIT_MAGIC = 0x00020000;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2018-08-29 22:15:43 +01:00
|
|
|
public string Name => "Xbox partitioning";
|
|
|
|
|
public Guid Id => new Guid("E3F6FB91-D358-4F22-A550-81E92D50EB78");
|
|
|
|
|
public string Author => "Natalia Portillo";
|
2016-09-17 21:23:01 +01:00
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2016-09-17 21:25:14 +01:00
|
|
|
{
|
|
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
|
2017-07-24 23:35:33 +01:00
|
|
|
// Xbox partitions always start on 0
|
2017-12-19 20:33:03 +00:00
|
|
|
if(sectorOffset != 0) return false;
|
2017-07-24 23:35:33 +01:00
|
|
|
|
2016-09-17 21:25:14 +01:00
|
|
|
byte[] sector = imagePlugin.ReadSector(0);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(sector.Length < 512) return false;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
Xbox360DevKitPartitionTable table =
|
|
|
|
|
BigEndianMarshal.ByteArrayToStructureBigEndian<Xbox360DevKitPartitionTable>(sector);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
if(table.magic == XBOX360_DEVKIT_MAGIC &&
|
|
|
|
|
table.contentOff + table.contentLen <= imagePlugin.Info.Sectors &&
|
2017-12-26 06:05:12 +00:00
|
|
|
table.dashboardOff + table.dashboardLen <= imagePlugin.Info.Sectors)
|
2016-09-17 21:25:14 +01:00
|
|
|
{
|
2017-07-23 22:54:36 +01:00
|
|
|
Partition contentPart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "Content volume",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = (ulong)table.contentLen * imagePlugin.Info.SectorSize,
|
|
|
|
|
Length = table.contentLen,
|
|
|
|
|
Sequence = 1,
|
|
|
|
|
Offset = (ulong)table.contentOff * imagePlugin.Info.SectorSize,
|
|
|
|
|
Start = table.contentOff,
|
|
|
|
|
Scheme = Name
|
2017-07-23 22:54:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Partition dashboardPart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "Dashboard volume",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = (ulong)table.dashboardLen * imagePlugin.Info.SectorSize,
|
|
|
|
|
Length = table.dashboardLen,
|
|
|
|
|
Sequence = 2,
|
|
|
|
|
Offset = (ulong)table.dashboardOff * imagePlugin.Info.SectorSize,
|
|
|
|
|
Start = table.dashboardOff,
|
|
|
|
|
Scheme = Name
|
2017-07-23 22:54:36 +01:00
|
|
|
};
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
|
|
|
partitions.Add(contentPart);
|
|
|
|
|
partitions.Add(dashboardPart);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 16:07:20 +00:00
|
|
|
uint temp;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imagePlugin.Info.Sectors > (ulong)(MemoryUnitDataOff / imagePlugin.Info.SectorSize))
|
2016-09-17 21:25:14 +01:00
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
sector = imagePlugin.ReadSector((ulong)(MemoryUnitDataOff / imagePlugin.Info.SectorSize));
|
2018-06-22 08:08:38 +01:00
|
|
|
temp = BitConverter.ToUInt32(sector, 0);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
|
|
|
if(temp == XboxCigam)
|
|
|
|
|
{
|
2017-07-23 22:54:36 +01:00
|
|
|
Partition sysCachePart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "System cache",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = MemoryUnitDataOff,
|
|
|
|
|
Length = (ulong)(MemoryUnitDataOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 1,
|
|
|
|
|
Offset = 0,
|
|
|
|
|
Start = 0,
|
|
|
|
|
Scheme = Name
|
2017-07-23 22:54:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Partition dataPart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "Data volume",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = imagePlugin.Info.Sectors * imagePlugin.Info.SectorSize - MemoryUnitDataOff,
|
|
|
|
|
Length = imagePlugin.Info.Sectors - sysCachePart.Length,
|
|
|
|
|
Sequence = 2,
|
|
|
|
|
Offset = MemoryUnitDataOff,
|
|
|
|
|
Start = sysCachePart.Length,
|
|
|
|
|
Scheme = Name
|
2017-07-23 22:54:36 +01:00
|
|
|
};
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
|
|
|
partitions.Add(sysCachePart);
|
|
|
|
|
partitions.Add(dataPart);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(imagePlugin.Info.Sectors <= (ulong)(Xbox360DataOff / imagePlugin.Info.SectorSize)) return false;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2016-09-17 21:25:14 +01:00
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
sector = imagePlugin.ReadSector((ulong)(Xbox360DataOff / imagePlugin.Info.SectorSize));
|
2018-06-22 08:08:38 +01:00
|
|
|
temp = BitConverter.ToUInt32(sector, 0);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(temp != XboxCigam) return false;
|
|
|
|
|
|
|
|
|
|
Partition securityPart = new Partition
|
2016-09-17 21:25:14 +01:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
Description = "Security sectors",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = Xbox360SecuritySectorLen,
|
|
|
|
|
Length = (ulong)(Xbox360SecuritySectorLen / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 1,
|
|
|
|
|
Offset = Xbox360SecuritySectorOff,
|
|
|
|
|
Start = (ulong)(Xbox360SecuritySectorOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-07-23 22:54:36 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition sysCachePart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "System cache",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = Xbox360SystemCacheLen,
|
|
|
|
|
Length = (ulong)(Xbox360SystemCacheLen / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 2,
|
|
|
|
|
Offset = Xbox360SystemCacheOff,
|
|
|
|
|
Start = (ulong)(Xbox360SystemCacheOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-07-23 22:54:36 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition gameCachePart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "Game cache",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = Xbox360GameCacheLen,
|
|
|
|
|
Length = (ulong)(Xbox360GameCacheLen / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 3,
|
|
|
|
|
Offset = Xbox360GameCacheOff,
|
|
|
|
|
Start = (ulong)(Xbox360GameCacheOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-07-23 22:54:36 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition sysExtPart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "System volume",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = Xbox368SysExtLen,
|
|
|
|
|
Length = (ulong)(Xbox368SysExtLen / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 4,
|
|
|
|
|
Offset = Xbox368SysExtOff,
|
|
|
|
|
Start = (ulong)(Xbox368SysExtOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-07-23 22:54:36 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition sysExt2Part = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "System volume 2",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = Xbox360SysExt2Len,
|
|
|
|
|
Length = (ulong)(Xbox360SysExt2Len / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 5,
|
|
|
|
|
Offset = Xbox360SysExt2Off,
|
|
|
|
|
Start = (ulong)(Xbox360SysExt2Off / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-07-23 22:54:36 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition xbox1Part = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "Xbox backwards compatibility",
|
2018-06-22 08:08:38 +01:00
|
|
|
Size = Xbox360CompatLen,
|
|
|
|
|
Length = (ulong)(Xbox360CompatLen / imagePlugin.Info.SectorSize),
|
|
|
|
|
Sequence = 6,
|
|
|
|
|
Offset = Xbox360CompatOff,
|
|
|
|
|
Start = (ulong)(Xbox360CompatOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-07-23 22:54:36 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Partition dataPart = new Partition
|
|
|
|
|
{
|
|
|
|
|
Description = "Data volume",
|
2018-06-22 08:08:38 +01:00
|
|
|
Sequence = 7,
|
|
|
|
|
Offset = Xbox360DataOff,
|
|
|
|
|
Start = (ulong)(Xbox360DataOff / imagePlugin.Info.SectorSize),
|
|
|
|
|
Scheme = Name
|
2017-12-21 06:06:19 +00:00
|
|
|
};
|
2017-12-26 06:05:12 +00:00
|
|
|
dataPart.Length = imagePlugin.Info.Sectors - dataPart.Start;
|
2018-06-22 08:08:38 +01:00
|
|
|
dataPart.Size = dataPart.Length * imagePlugin.Info.SectorSize;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
partitions.Add(securityPart);
|
|
|
|
|
partitions.Add(sysCachePart);
|
|
|
|
|
partitions.Add(gameCachePart);
|
|
|
|
|
partitions.Add(sysExtPart);
|
|
|
|
|
partitions.Add(sysExt2Part);
|
|
|
|
|
partitions.Add(xbox1Part);
|
|
|
|
|
partitions.Add(dataPart);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
return true;
|
2016-09-17 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-24 03:11:33 +00:00
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct Xbox360DevKitPartitionTable
|
|
|
|
|
{
|
|
|
|
|
public uint magic;
|
|
|
|
|
public uint unknown;
|
|
|
|
|
public uint contentOff;
|
|
|
|
|
public uint contentLen;
|
|
|
|
|
public uint dashboardOff;
|
|
|
|
|
public uint dashboardLen;
|
|
|
|
|
}
|
2016-09-17 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
}
|