Add layouts for some Nitro models

This commit is contained in:
Matt Nadareski
2024-04-23 17:15:15 -04:00
parent f60afd6368
commit a422ec7e6d
4 changed files with 163 additions and 100 deletions

View File

@@ -1,214 +1,232 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.Nitro
{
/// <summary>
/// Nintendo DS / DSi cartridge header
/// </summary>
/// <see href="https://dsibrew.org/wiki/DSi_cartridge_header"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class CommonHeader
{
/// <summary>
/// Game Title
/// </summary>
public string? GameTitle { get; set; }
/// <remarks>12 bytes</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
public string? GameTitle;
/// <summary>
/// Gamecode
/// </summary>
public uint GameCode { get; set; }
public uint GameCode;
/// <summary>
/// Makercode
/// </summary>
public string? MakerCode { get; set; }
/// <remarks>2 bytes</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
public string? MakerCode;
/// <summary>
/// Unitcode
/// </summary>
public Unitcode UnitCode { get; set; }
[MarshalAs(UnmanagedType.U1)]
public Unitcode UnitCode;
/// <summary>
/// Encryption seed select (device code. 0 = normal)
/// </summary>
public byte EncryptionSeedSelect { get; set; }
public byte EncryptionSeedSelect;
/// <summary>
/// Devicecapacity
/// </summary>
public byte DeviceCapacity { get; set; }
public byte DeviceCapacity;
/// <summary>
/// Reserved
/// </summary>
public byte[]? Reserved1 { get; set; }
/// <remarks>7 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
public byte[]? Reserved1;
/// <summary>
/// Game Revision (used by DSi titles)
/// </summary>
public ushort GameRevision { get; set; }
public ushort GameRevision;
/// <summary>
/// ROM Version
/// </summary>
public byte RomVersion { get; set; }
public byte RomVersion;
/// <summary>
/// Internal flags, (Bit2: Autostart)
/// </summary>
public byte InternalFlags { get; set; }
public byte InternalFlags;
/// <summary>
/// ARM9 rom offset
/// </summary>
public uint ARM9RomOffset { get; set; }
public uint ARM9RomOffset;
/// <summary>
/// ARM9 entry address
/// </summary>
public uint ARM9EntryAddress { get; set; }
public uint ARM9EntryAddress;
/// <summary>
/// ARM9 load address
/// </summary>
public uint ARM9LoadAddress { get; set; }
public uint ARM9LoadAddress;
/// <summary>
/// ARM9 size
/// </summary>
public uint ARM9Size { get; set; }
public uint ARM9Size;
/// <summary>
/// ARM7 rom offset
/// </summary>
public uint ARM7RomOffset { get; set; }
public uint ARM7RomOffset;
/// <summary>
/// ARM7 entry address
/// </summary>
public uint ARM7EntryAddress { get; set; }
public uint ARM7EntryAddress;
/// <summary>
/// ARM7 load address
/// </summary>
public uint ARM7LoadAddress { get; set; }
public uint ARM7LoadAddress;
/// <summary>
/// ARM7 size
/// </summary>
public uint ARM7Size { get; set; }
public uint ARM7Size;
/// <summary>
/// File Name Table (FNT) offset
/// </summary>
public uint FileNameTableOffset { get; set; }
public uint FileNameTableOffset;
/// <summary>
/// File Name Table (FNT) length
/// </summary>
public uint FileNameTableLength { get; set; }
public uint FileNameTableLength;
/// <summary>
/// File Allocation Table (FNT) offset
/// </summary>
public uint FileAllocationTableOffset { get; set; }
public uint FileAllocationTableOffset;
/// <summary>
/// File Allocation Table (FNT) length
/// </summary>
public uint FileAllocationTableLength { get; set; }
public uint FileAllocationTableLength;
/// <summary>
/// File Name Table (FNT) offset
/// </summary>
public uint ARM9OverlayOffset { get; set; }
public uint ARM9OverlayOffset;
/// <summary>
/// File Name Table (FNT) length
/// </summary>
public uint ARM9OverlayLength { get; set; }
public uint ARM9OverlayLength;
/// <summary>
/// File Name Table (FNT) offset
/// </summary>
public uint ARM7OverlayOffset { get; set; }
public uint ARM7OverlayOffset;
/// <summary>
/// File Name Table (FNT) length
/// </summary>
public uint ARM7OverlayLength { get; set; }
public uint ARM7OverlayLength;
/// <summary>
/// Normal card control register settings (0x00416657 for OneTimePROM)
/// </summary>
public uint NormalCardControlRegisterSettings { get; set; }
public uint NormalCardControlRegisterSettings;
/// <summary>
/// Secure card control register settings (0x081808F8 for OneTimePROM)
/// </summary>
public uint SecureCardControlRegisterSettings { get; set; }
public uint SecureCardControlRegisterSettings;
/// <summary>
/// Icon Banner offset (NDSi same as NDS, but with new extra entries)
/// </summary>
public uint IconBannerOffset { get; set; }
public uint IconBannerOffset;
/// <summary>
/// Secure area (2K) CRC
/// </summary>
public ushort SecureAreaCRC { get; set; }
public ushort SecureAreaCRC;
/// <summary>
/// Secure transfer timeout (0x0D7E for OneTimePROM)
/// </summary>
public ushort SecureTransferTimeout { get; set; }
public ushort SecureTransferTimeout;
/// <summary>
/// ARM9 autoload
/// </summary>
public uint ARM9Autoload { get; set; }
public uint ARM9Autoload;
/// <summary>
/// ARM7 autoload
/// </summary>
public uint ARM7Autoload { get; set; }
public uint ARM7Autoload;
/// <summary>
/// Secure disable
/// </summary>
public byte[]? SecureDisable { get; set; }
/// <remarks>8 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[]? SecureDisable;
/// <summary>
/// NTR region ROM size (excluding DSi area)
/// </summary>
public uint NTRRegionRomSize { get; set; }
public uint NTRRegionRomSize;
/// <summary>
/// Header size
/// </summary>
public uint HeaderSize { get; set; }
public uint HeaderSize;
/// <summary>
///Reserved (0x88, 0x8C, 0x90 = Unknown, used by DSi)
/// Reserved (0x88, 0x8C, 0x90 = Unknown, used by DSi)
/// </summary>
public byte[]? Reserved2 { get; set; }
/// <remarks>56 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 56)]
public byte[]? Reserved2;
/// <summary>
/// Nintendo Logo
/// </summary>
public byte[]? NintendoLogo { get; set; }
/// <remarks>156 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 156)]
public byte[]? NintendoLogo;
/// <summary>
/// Nintendo Logo CRC
/// </summary>
public ushort NintendoLogoCRC { get; set; }
public ushort NintendoLogoCRC;
/// <summary>
/// Header CRC
/// </summary>
public ushort HeaderCRC { get; set; }
public ushort HeaderCRC;
/// <summary>
/// Debugger reserved
/// </summary>
public byte[]? DebuggerReserved { get; set; }
/// <remarks>0x20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x20)]
public byte[]? DebuggerReserved;
}
}

View File

@@ -1,259 +1,298 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.Nitro
{
/// <summary>
/// Nintendo DSi extended cart header
/// </summary>
/// <see href="https://dsibrew.org/wiki/DSi_cartridge_header"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ExtendedDSiHeader
{
/// <summary>
/// Global MBK1..MBK5 Settings
/// </summary>
public uint[]? GlobalMBK15Settings { get; set; }
/// <remarks>5 entries</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public uint[]? GlobalMBK15Settings;
/// <summary>
/// Local MBK6..MBK8 Settings for ARM9
/// </summary>
public uint[]? LocalMBK68SettingsARM9 { get; set; }
/// <remarks>3 entries</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public uint[]? LocalMBK68SettingsARM9;
/// <summary>
/// Local MBK6..MBK8 Settings for ARM7
/// </summary>
public uint[]? LocalMBK68SettingsARM7 { get; set; }
/// <remarks>3 entries</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public uint[]? LocalMBK68SettingsARM7;
/// <summary>
/// Global MBK9 Setting
/// </summary>
public uint GlobalMBK9Setting { get; set; }
public uint GlobalMBK9Setting;
/// <summary>
/// Region Flags
/// </summary>
public uint RegionFlags { get; set; }
public uint RegionFlags;
/// <summary>
/// Access control
/// </summary>
public uint AccessControl { get; set; }
public uint AccessControl;
/// <summary>
/// ARM7 SCFG EXT mask (controls which devices to enable)
/// </summary>
public uint ARM7SCFGEXTMask { get; set; }
public uint ARM7SCFGEXTMask;
/// <summary>
/// Reserved/flags? When bit2 of byte 0x1bf is set, usage of banner.sav from the title data dir is enabled.(additional banner data)
/// </summary>
public uint ReservedFlags { get; set; }
public uint ReservedFlags;
/// <summary>
/// ARM9i rom offset
/// </summary>
public uint ARM9iRomOffset { get; set; }
public uint ARM9iRomOffset;
/// <summary>
/// Reserved
/// </summary>
public uint Reserved3 { get; set; }
public uint Reserved3;
/// <summary>
/// ARM9i load address
/// </summary>
public uint ARM9iLoadAddress { get; set; }
public uint ARM9iLoadAddress;
/// <summary>
/// ARM9i size { get; set; }
/// ARM9i size;
/// </summary>
public uint ARM9iSize { get; set; }
public uint ARM9iSize;
/// <summary>
/// ARM7i rom offset
/// </summary>
public uint ARM7iRomOffset { get; set; }
public uint ARM7iRomOffset;
/// <summary>
/// Pointer to base address where various structures and parameters are passed to the title - what is that???
/// </summary>
public uint Reserved4 { get; set; }
public uint Reserved4;
/// <summary>
/// ARM7i load address
/// </summary>
public uint ARM7iLoadAddress { get; set; }
public uint ARM7iLoadAddress;
/// <summary>
/// ARM7i size { get; set; }
/// ARM7i size;
/// </summary>
public uint ARM7iSize { get; set; }
public uint ARM7iSize;
/// <summary>
/// Digest NTR region offset
/// </summary>
public uint DigestNTRRegionOffset { get; set; }
public uint DigestNTRRegionOffset;
/// <summary>
/// Digest NTR region length
/// </summary>
public uint DigestNTRRegionLength { get; set; }
public uint DigestNTRRegionLength;
// <summary>
/// Digest TWL region offset
/// </summary>
public uint DigestTWLRegionOffset { get; set; }
public uint DigestTWLRegionOffset;
/// <summary>
/// Digest TWL region length
/// </summary>
public uint DigestTWLRegionLength { get; set; }
public uint DigestTWLRegionLength;
// <summary>
/// Digest Sector Hashtable region offset
/// </summary>
public uint DigestSectorHashtableRegionOffset { get; set; }
public uint DigestSectorHashtableRegionOffset;
/// <summary>
/// Digest Sector Hashtable region length
/// </summary>
public uint DigestSectorHashtableRegionLength { get; set; }
public uint DigestSectorHashtableRegionLength;
// <summary>
/// Digest Block Hashtable region offset
/// </summary>
public uint DigestBlockHashtableRegionOffset { get; set; }
public uint DigestBlockHashtableRegionOffset;
/// <summary>
/// Digest Block Hashtable region length
/// </summary>
public uint DigestBlockHashtableRegionLength { get; set; }
public uint DigestBlockHashtableRegionLength;
/// <summary>
/// Digest Sector size
/// </summary>
public uint DigestSectorSize { get; set; }
public uint DigestSectorSize;
/// <summary>
/// Digeset Block Sectorount
/// </summary>
public uint DigestBlockSectorCount { get; set; }
public uint DigestBlockSectorCount;
/// <summary>
/// Icon Banner Size (usually 0x23C0)
/// </summary>
public uint IconBannerSize { get; set; }
public uint IconBannerSize;
/// <summary>
/// Unknown (used by DSi)
/// </summary>
public uint Unknown1 { get; set; }
public uint Unknown1;
/// <summary>
/// NTR+TWL region ROM size (total size including DSi area)
/// </summary>
public uint NTRTWLRegionRomSize { get; set; }
public uint NTRTWLRegionRomSize;
/// <summary>
/// Unknown (used by DSi)
/// </summary>
public byte[]? Unknown2 { get; set; }
/// <remarks>12 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[]? Unknown2;
/// <summary>
/// Modcrypt area 1 offset
/// </summary>
public uint ModcryptArea1Offset { get; set; }
public uint ModcryptArea1Offset;
/// <summary>
/// Modcrypt area 1 size
/// </summary>
public uint ModcryptArea1Size { get; set; }
public uint ModcryptArea1Size;
/// <summary>
/// Modcrypt area 2 offset
/// </summary>
public uint ModcryptArea2Offset { get; set; }
public uint ModcryptArea2Offset;
/// <summary>
/// Modcrypt area 2 size
/// </summary>
public uint ModcryptArea2Size { get; set; }
public uint ModcryptArea2Size;
/// <summary>
/// Title ID
/// </summary>
public byte[]? TitleID { get; set; }
/// <remarks>8 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[]? TitleID;
/// <summary>
/// DSiWare: "public.sav" size
/// </summary>
public uint DSiWarePublicSavSize { get; set; }
public uint DSiWarePublicSavSize;
/// <summary>
/// DSiWare: "private.sav" size
/// </summary>
public uint DSiWarePrivateSavSize { get; set; }
public uint DSiWarePrivateSavSize;
/// <summary>
/// Reserved (zero)
/// </summary>
public byte[]? ReservedZero { get; set; }
/// <remarks>176 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 176)]
public byte[]? ReservedZero;
/// <summary>
/// Unknown (used by DSi)
/// </summary>
public byte[]? Unknown3 { get; set; }
/// <remarks>16 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? Unknown3;
/// <summary>
/// ARM9 (with encrypted secure area) SHA1 HMAC hash
/// </summary>
public byte[]? ARM9WithSecureAreaSHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ARM9WithSecureAreaSHA1HMACHash;
/// <summary>
/// ARM7 SHA1 HMAC hash
/// </summary>
public byte[]? ARM7SHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ARM7SHA1HMACHash;
/// <summary>
/// Digest master SHA1 HMAC hash
/// </summary>
public byte[]? DigestMasterSHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? DigestMasterSHA1HMACHash;
/// <summary>
/// Banner SHA1 HMAC hash
/// </summary>
public byte[]? BannerSHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? BannerSHA1HMACHash;
/// <summary>
/// ARM9i (decrypted) SHA1 HMAC hash
/// </summary>
public byte[]? ARM9iDecryptedSHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ARM9iDecryptedSHA1HMACHash;
/// <summary>
/// ARM7i (decrypted) SHA1 HMAC hash
/// </summary>
public byte[]? ARM7iDecryptedSHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ARM7iDecryptedSHA1HMACHash;
/// <summary>
/// Reserved
/// </summary>
public byte[]? Reserved5 { get; set; }
/// <remarks>40 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
public byte[]? Reserved5;
/// <summary>
/// ARM9 (without secure area) SHA1 HMAC hash
/// </summary>
public byte[]? ARM9NoSecureAreaSHA1HMACHash { get; set; }
/// <remarks>20 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ARM9NoSecureAreaSHA1HMACHash;
/// <summary>
/// Reserved
/// </summary>
public byte[]? Reserved6 { get; set; }
/// <remarks>2636 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2636)]
public byte[]? Reserved6;
/// <summary>
/// Reserved and unchecked region, always zero. Used for passing arguments in debug environment.
/// </summary>
public byte[]? ReservedAndUnchecked { get; set; }
/// <remarks>0x180 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x180)]
public byte[]? ReservedAndUnchecked;
/// <summary>
/// RSA signature (the first 0xE00 bytes of the header are signed with an 1024-bit RSA signature).
/// </summary>
public byte[]? RSASignature { get; set; }
/// <remarks>0x80 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x80)]
public byte[]? RSASignature;
}
}

View File

@@ -1,3 +1,5 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.Nitro
{
/// <summary>
@@ -5,16 +7,17 @@ namespace SabreTools.Models.Nitro
/// it's just a table of 8 byte entries
/// </summary>
/// <see href="https://github.com/Deijin27/RanseiLink/wiki/NDS-File-System"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class FileAllocationTableEntry
{
/// <summary>
/// Start offset of file
/// </summary>
public uint StartOffset { get; set; }
public uint StartOffset;
/// <summary>
/// End offset of file (after this is padding)
/// </summary>
public uint EndOffset { get; set; }
public uint EndOffset;
}
}

View File

@@ -1,3 +1,5 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.Nitro
{
/// <summary>
@@ -6,28 +8,29 @@ namespace SabreTools.Models.Nitro
/// point to the file system.
/// </summary>
/// <see href="https://github.com/Deijin27/RanseiLink/wiki/NDS-File-System"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class FolderAllocationTableEntry
{
/// <summary>
/// Start offset of folder contents within Name List
/// relative to start of NameTable
/// </summary>
public uint StartOffset { get; set; }
public uint StartOffset;
/// <summary>
/// Index of first file within folder in File Allocation Table
/// </summary>
public ushort FirstFileIndex { get; set; }
public ushort FirstFileIndex;
/// <summary>
/// Index of parent folder in current table; for root folder
/// this holds the number of entries in the table
/// </summary>
public byte ParentFolderIndex { get; set; }
public byte ParentFolderIndex;
/// <summary>
/// Unknown, always 0xF0 except for root folder
/// </summary>
public byte Unknown { get; set; }
public byte Unknown;
}
}