mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-04 05:36:12 +00:00
Update Models to 1.5.1
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.5.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Extended Headers
|
||||
|
||||
// Create the extended header table
|
||||
cart.ExtendedHeaders = new NCCHExtendedHeader[8];
|
||||
cart.ExtendedHeaders = new NCCHExtendedHeader?[8];
|
||||
|
||||
// Iterate and build the extended headers
|
||||
for (int i = 0; i < 8; i++)
|
||||
@@ -115,7 +115,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region ExeFS Headers
|
||||
|
||||
// Create the ExeFS header table
|
||||
cart.ExeFSHeaders = new ExeFSHeader[8];
|
||||
cart.ExeFSHeaders = new ExeFSHeader?[8];
|
||||
|
||||
// Iterate and build the ExeFS headers
|
||||
for (int i = 0; i < 8; i++)
|
||||
@@ -149,7 +149,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region RomFS Headers
|
||||
|
||||
// Create the RomFS header table
|
||||
cart.RomFSHeaders = new RomFSHeader[8];
|
||||
cart.RomFSHeaders = new RomFSHeader?[8];
|
||||
|
||||
// Iterate and build the RomFS headers
|
||||
for (int i = 0; i < 8; i++)
|
||||
@@ -305,25 +305,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <returns>Filled development card info header on success, null on error</returns>
|
||||
public static DevelopmentCardInfoHeader? ParseDevelopmentCardInfoHeader(Stream data)
|
||||
{
|
||||
// TODO: Go back to `data.ReadType<DevelopmentCardInfoHeader>();` when Models is fixed
|
||||
var header = new DevelopmentCardInfoHeader();
|
||||
|
||||
header.CardDeviceReserved1 = data.ReadBytes(0x200);
|
||||
header.TitleKey = data.ReadBytes(0x10);
|
||||
header.CardDeviceReserved2 = data.ReadBytes(0x1BF0);
|
||||
header.TestData = ParseTestData(data);
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into test data
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled test data on success, null on error</returns>
|
||||
public static TestData? ParseTestData(Stream data)
|
||||
{
|
||||
return data.ReadType<TestData>();
|
||||
return data.ReadType<DevelopmentCardInfoHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<PackageReference Include="SabreTools.ASN1" Version="1.4.0" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.4.0" />
|
||||
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.5.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,7 +4,7 @@ using SabreTools.Models.N3DS;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
public class N3DS : WrapperBase<Models.N3DS.Cart>
|
||||
public class N3DS : WrapperBase<Cart>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
@@ -179,14 +179,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public N3DS(Models.N3DS.Cart? model, byte[]? data, int offset)
|
||||
public N3DS(Cart? model, byte[]? data, int offset)
|
||||
: base(model, data, offset)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public N3DS(Models.N3DS.Cart? model, Stream? data)
|
||||
public N3DS(Cart? model, Stream? data)
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
@@ -251,7 +251,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
return false;
|
||||
if (fsIndex < 0 || fsIndex >= Model.ExeFSHeaders.Length)
|
||||
return false;
|
||||
|
||||
|
||||
var fsHeader = Model.ExeFSHeaders[fsIndex];
|
||||
if (fsHeader?.FileHeaders == null)
|
||||
return false;
|
||||
@@ -289,5 +289,170 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Offsets
|
||||
|
||||
/// <summary>
|
||||
/// Get the offset of a partition ExeFS
|
||||
/// </summary>
|
||||
/// <returns>Offset to the ExeFS of the partition, 0 on error</returns>
|
||||
public uint GetExeFSOffset(int index)
|
||||
{
|
||||
// Empty partitions table means no size is available
|
||||
var partitionsTable = Model.Header?.PartitionsTable;
|
||||
if (partitionsTable == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition table entry means no size is available
|
||||
var entry = partitionsTable[index];
|
||||
if (entry == null)
|
||||
return 0;
|
||||
|
||||
// Empty partitions array means no size is available
|
||||
var partitions = Model.Partitions;
|
||||
if (partitions == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition means no size is available
|
||||
var header = partitions[index];
|
||||
if (header == null)
|
||||
return 0;
|
||||
|
||||
// If the offset is 0, return 0
|
||||
uint exeFsOffsetMU = header.ExeFSOffsetInMediaUnits;
|
||||
if (exeFsOffsetMU == 0)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted offset
|
||||
uint partitionOffsetMU = entry.Offset;
|
||||
return (partitionOffsetMU + exeFsOffsetMU) * MediaUnitSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the offset of a partition
|
||||
/// </summary>
|
||||
/// <returns>Offset to the partition, 0 on error</returns>
|
||||
public uint GetPartitionOffset(int index)
|
||||
{
|
||||
// Empty partitions table means no size is available
|
||||
var partitionsTable = Model.Header?.PartitionsTable;
|
||||
if (partitionsTable == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition table entry means no size is available
|
||||
var entry = partitionsTable[index];
|
||||
if (entry == null)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted offset
|
||||
uint partitionOffsetMU = entry.Offset;
|
||||
if (entry.Offset == 0)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted offset
|
||||
return partitionOffsetMU * MediaUnitSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the offset of a partition RomFS
|
||||
/// </summary>
|
||||
/// <returns>Offset to the RomFS of the partition, 0 on error</returns>
|
||||
public uint GetRomFSOffset(int index)
|
||||
{
|
||||
// Empty partitions table means no size is available
|
||||
var partitionsTable = Model.Header?.PartitionsTable;
|
||||
if (partitionsTable == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition table entry means no size is available
|
||||
var entry = partitionsTable[index];
|
||||
if (entry == null)
|
||||
return 0;
|
||||
|
||||
// Empty partitions array means no size is available
|
||||
var partitions = Model.Partitions;
|
||||
if (partitions == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition means no size is available
|
||||
var header = partitions[index];
|
||||
if (header == null)
|
||||
return 0;
|
||||
|
||||
// If the offset is 0, return 0
|
||||
uint romFsOffsetMU = header.RomFSOffsetInMediaUnits;
|
||||
if (romFsOffsetMU == 0)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted offset
|
||||
uint partitionOffsetMU = entry.Offset;
|
||||
return (partitionOffsetMU + romFsOffsetMU) * MediaUnitSize;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sizes
|
||||
|
||||
/// <summary>
|
||||
/// Get the size of a partition ExeFS
|
||||
/// </summary>
|
||||
/// <returns>Size of the partition ExeFS in bytes, 0 on error</returns>
|
||||
public uint GetExeFSSize(int index)
|
||||
{
|
||||
// Empty partitions array means no size is available
|
||||
var partitions = Model.Partitions;
|
||||
if (partitions == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition header means no size is available
|
||||
var header = partitions[index];
|
||||
if (header == null)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted size
|
||||
return header.ExeFSSizeInMediaUnits * MediaUnitSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the size of a partition extended header
|
||||
/// </summary>
|
||||
/// <returns>Size of the partition extended header in bytes, 0 on error</returns>
|
||||
public uint GetExtendedHeaderSize(int index)
|
||||
{
|
||||
// Empty partitions array means no size is available
|
||||
var partitions = Model.Partitions;
|
||||
if (partitions == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition header means no size is available
|
||||
var header = partitions[index];
|
||||
if (header == null)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted size
|
||||
return header.ExtendedHeaderSizeInBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the size of a partition RomFS
|
||||
/// </summary>
|
||||
/// <returns>Size of the partition RomFS in bytes, 0 on error</returns>
|
||||
public uint GetRomFSSize(int index)
|
||||
{
|
||||
// Empty partitions array means no size is available
|
||||
var partitions = Model.Partitions;
|
||||
if (partitions == null)
|
||||
return 0;
|
||||
|
||||
// Invalid partition header means no size is available
|
||||
var header = partitions[index];
|
||||
if (header == null)
|
||||
return 0;
|
||||
|
||||
// Return the adjusted size
|
||||
return header.RomFSSizeInMediaUnits * MediaUnitSize;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user