Port Nitro to new printing

This commit is contained in:
Matt Nadareski
2023-09-15 00:47:44 -04:00
parent a35a9a4ab6
commit ea6b0f1ca3
6 changed files with 443 additions and 395 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Text;
namespace BinaryObjectScanner.Wrappers
@@ -650,268 +649,10 @@ namespace BinaryObjectScanner.Wrappers
public override StringBuilder PrettyPrint()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("NDS Cart Information:");
builder.AppendLine("-------------------------");
builder.AppendLine();
PrintCommonHeader(builder);
PrintExtendedDSiHeader(builder);
PrintSecureArea(builder);
PrintNameTable(builder);
PrintFileAllocationTable(builder);
Printing.Nitro.Print(builder, _model);
return builder;
}
/// <summary>
/// Print common header information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintCommonHeader(StringBuilder builder)
{
builder.AppendLine(" Common Header Information:");
builder.AppendLine(" -------------------------");
builder.AppendLine($" Game title: {GameTitle ?? "[NULL]"}");
builder.AppendLine($" Game code: {GameCode} (0x{GameCode:X})");
builder.AppendLine($" Maker code: {MakerCode ?? "[NULL]"}");
builder.AppendLine($" Unit code: {UnitCode} (0x{UnitCode:X})");
builder.AppendLine($" Encryption seed select: {EncryptionSeedSelect} (0x{EncryptionSeedSelect:X})");
builder.AppendLine($" Device capacity: {DeviceCapacity} (0x{DeviceCapacity:X})");
builder.AppendLine($" Reserved 1: {(Reserved1 == null ? "[NULL]" : BitConverter.ToString(Reserved1).Replace('-', ' '))}");
builder.AppendLine($" Game revision: {GameRevision} (0x{GameRevision:X})");
builder.AppendLine($" Rom version: {RomVersion} (0x{RomVersion:X})");
builder.AppendLine($" ARM9 rom offset: {ARM9RomOffset} (0x{ARM9RomOffset:X})");
builder.AppendLine($" ARM9 entry address: {ARM9EntryAddress} (0x{ARM9EntryAddress:X})");
builder.AppendLine($" ARM9 load address: {ARM9LoadAddress} (0x{ARM9LoadAddress:X})");
builder.AppendLine($" ARM9 size: {ARM9Size} (0x{ARM9Size:X})");
builder.AppendLine($" ARM7 rom offset: {ARM7RomOffset} (0x{ARM7RomOffset:X})");
builder.AppendLine($" ARM7 entry address: {ARM7EntryAddress} (0x{ARM7EntryAddress:X})");
builder.AppendLine($" ARM7 load address: {ARM7LoadAddress} (0x{ARM7LoadAddress:X})");
builder.AppendLine($" ARM7 size: {ARM7Size} (0x{ARM7Size:X})");
builder.AppendLine($" File name table offset: {FileNameTableOffset} (0x{FileNameTableOffset:X})");
builder.AppendLine($" File name table length: {FileNameTableLength} (0x{FileNameTableLength:X})");
builder.AppendLine($" File allocation table offset: {FileAllocationTableOffset} (0x{FileAllocationTableOffset:X})");
builder.AppendLine($" File allocation table length: {FileAllocationTableLength} (0x{FileAllocationTableLength:X})");
builder.AppendLine($" ARM9 overlay offset: {ARM9OverlayOffset} (0x{ARM9OverlayOffset:X})");
builder.AppendLine($" ARM9 overlay length: {ARM9OverlayLength} (0x{ARM9OverlayLength:X})");
builder.AppendLine($" ARM7 overlay offset: {ARM7OverlayOffset} (0x{ARM7OverlayOffset:X})");
builder.AppendLine($" ARM7 overlay length: {ARM7OverlayLength} (0x{ARM7OverlayLength:X})");
builder.AppendLine($" Normal card control register settings: {NormalCardControlRegisterSettings} (0x{NormalCardControlRegisterSettings:X})");
builder.AppendLine($" Secure card control register settings: {SecureCardControlRegisterSettings} (0x{SecureCardControlRegisterSettings:X})");
builder.AppendLine($" Icon banner offset: {IconBannerOffset} (0x{IconBannerOffset:X})");
builder.AppendLine($" Secure area CRC: {SecureAreaCRC} (0x{SecureAreaCRC:X})");
builder.AppendLine($" Secure transfer timeout: {SecureTransferTimeout} (0x{SecureTransferTimeout:X})");
builder.AppendLine($" ARM9 autoload: {ARM9Autoload} (0x{ARM9Autoload:X})");
builder.AppendLine($" ARM7 autoload: {ARM7Autoload} (0x{ARM7Autoload:X})");
builder.AppendLine($" Secure disable: {SecureDisable} (0x{SecureDisable:X})");
builder.AppendLine($" NTR region rom size: {NTRRegionRomSize} (0x{NTRRegionRomSize:X})");
builder.AppendLine($" Header size: {HeaderSize} (0x{HeaderSize:X})");
builder.AppendLine($" Reserved 2: {(Reserved2 == null ? "[NULL]" : BitConverter.ToString(Reserved2).Replace('-', ' '))}");
builder.AppendLine($" Nintendo logo: {(NintendoLogo == null ? "[NULL]" : BitConverter.ToString(NintendoLogo).Replace('-', ' '))}");
builder.AppendLine($" Nintendo logo CRC: {NintendoLogoCRC} (0x{NintendoLogoCRC:X})");
builder.AppendLine($" Header CRC: {HeaderCRC} (0x{HeaderCRC:X})");
builder.AppendLine($" Debugger reserved: {(DebuggerReserved == null ? "[NULL]" : BitConverter.ToString(DebuggerReserved).Replace('-', ' '))}");
builder.AppendLine();
}
/// <summary>
/// Print extended DSi header information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintExtendedDSiHeader(StringBuilder builder)
{
builder.AppendLine(" Extended DSi Header Information:");
builder.AppendLine(" -------------------------");
if (_model.ExtendedDSiHeader == null)
{
builder.AppendLine(" No extended DSi header");
}
else
{
builder.AppendLine($" Global MBK1..MBK5 settings: {(GlobalMBK15Settings == null ? "[NULL]" : string.Join(", ", GlobalMBK15Settings))}");
builder.AppendLine($" Local MBK6..MBK8 settings for ARM9: {(LocalMBK68SettingsARM9 == null ? "[NULL]" : string.Join(", ", LocalMBK68SettingsARM9))}");
builder.AppendLine($" Local MBK6..MBK8 settings for ARM7: {(LocalMBK68SettingsARM7 == null ? "[NULL]" : string.Join(", ", LocalMBK68SettingsARM7))}");
builder.AppendLine($" Global MBK9 setting: {GlobalMBK9Setting} (0x{GlobalMBK9Setting:X})");
builder.AppendLine($" Region flags: {RegionFlags} (0x{RegionFlags:X})");
builder.AppendLine($" Access control: {AccessControl} (0x{AccessControl:X})");
builder.AppendLine($" ARM7 SCFG EXT mask: {ARM7SCFGEXTMask} (0x{ARM7SCFGEXTMask:X})");
builder.AppendLine($" Reserved/flags?: {ReservedFlags} (0x{ReservedFlags:X})");
builder.AppendLine($" ARM9i rom offset: {ARM9iRomOffset} (0x{ARM9iRomOffset:X})");
builder.AppendLine($" Reserved 3: {Reserved3} (0x{Reserved3:X})");
builder.AppendLine($" ARM9i load address: {ARM9iLoadAddress} (0x{ARM9iLoadAddress:X})");
builder.AppendLine($" ARM9i size: {ARM9iSize} (0x{ARM9iSize:X})");
builder.AppendLine($" ARM7i rom offset: {ARM7iRomOffset} (0x{ARM7iRomOffset:X})");
builder.AppendLine($" Reserved 4: {Reserved4} (0x{Reserved4:X})");
builder.AppendLine($" ARM7i load address: {ARM7iLoadAddress} (0x{ARM7iLoadAddress:X})");
builder.AppendLine($" ARM7i size: {ARM7iSize} (0x{ARM7iSize:X})");
builder.AppendLine($" Digest NTR region offset: {DigestNTRRegionOffset} (0x{DigestNTRRegionOffset:X})");
builder.AppendLine($" Digest NTR region length: {DigestNTRRegionLength} (0x{DigestNTRRegionLength:X})");
builder.AppendLine($" Digest TWL region offset: {DigestTWLRegionOffset} (0x{DigestTWLRegionOffset:X})");
builder.AppendLine($" Digest TWL region length: {DigestTWLRegionLength} (0x{DigestTWLRegionLength:X})");
builder.AppendLine($" Digest sector hashtable region offset: {DigestSectorHashtableRegionOffset} (0x{DigestSectorHashtableRegionOffset:X})");
builder.AppendLine($" Digest sector hashtable region length: {DigestSectorHashtableRegionLength} (0x{DigestSectorHashtableRegionLength:X})");
builder.AppendLine($" Digest block hashtable region offset: {DigestBlockHashtableRegionOffset} (0x{DigestBlockHashtableRegionOffset:X})");
builder.AppendLine($" Digest block hashtable region length: {DigestBlockHashtableRegionLength} (0x{DigestBlockHashtableRegionLength:X})");
builder.AppendLine($" Digest sector size: {DigestSectorSize} (0x{DigestSectorSize:X})");
builder.AppendLine($" Digest block sector count: {DigestBlockSectorCount} (0x{DigestBlockSectorCount:X})");
builder.AppendLine($" Icon banner size: {IconBannerSize} (0x{IconBannerSize:X})");
builder.AppendLine($" Unknown 1: {Unknown1} (0x{Unknown1:X})");
builder.AppendLine($" Modcrypt area 1 offset: {ModcryptArea1Offset} (0x{ModcryptArea1Offset:X})");
builder.AppendLine($" Modcrypt area 1 size: {ModcryptArea1Size} (0x{ModcryptArea1Size:X})");
builder.AppendLine($" Modcrypt area 2 offset: {ModcryptArea2Offset} (0x{ModcryptArea2Offset:X})");
builder.AppendLine($" Modcrypt area 2 size: {ModcryptArea2Size} (0x{ModcryptArea2Size:X})");
builder.AppendLine($" Title ID: {(TitleID == null ? "[NULL]" : BitConverter.ToString(TitleID).Replace('-', ' '))}");
builder.AppendLine($" DSiWare 'public.sav' size: {DSiWarePublicSavSize} (0x{DSiWarePublicSavSize:X})");
builder.AppendLine($" DSiWare 'private.sav' size: {DSiWarePrivateSavSize} (0x{DSiWarePrivateSavSize:X})");
builder.AppendLine($" Reserved (zero): {(ReservedZero == null ? "[NULL]" : BitConverter.ToString(ReservedZero).Replace('-', ' '))}");
builder.AppendLine($" Unknown 2: {(Unknown2 == null ? "[NULL]" : BitConverter.ToString(Unknown2).Replace('-', ' '))}");
builder.AppendLine($" ARM9 (with encrypted secure area) SHA1 HMAC hash: {(ARM9WithSecureAreaSHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(ARM9WithSecureAreaSHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" ARM7 SHA1 HMAC hash: {(ARM7SHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(ARM7SHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" Digest master SHA1 HMAC hash: {(DigestMasterSHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(DigestMasterSHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" Banner SHA1 HMAC hash: {(BannerSHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(BannerSHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" ARM9i (decrypted) SHA1 HMAC hash: {(ARM9iDecryptedSHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(ARM9iDecryptedSHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" ARM7i (decrypted) SHA1 HMAC hash: {(ARM7iDecryptedSHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(ARM7iDecryptedSHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" Reserved 5: {(Reserved5 == null ? "[NULL]" : BitConverter.ToString(Reserved5).Replace('-', ' '))}");
builder.AppendLine($" ARM9 (without secure area) SHA1 HMAC hash: {(ARM9NoSecureAreaSHA1HMACHash == null ? "[NULL]" : BitConverter.ToString(ARM9NoSecureAreaSHA1HMACHash).Replace('-', ' '))}");
builder.AppendLine($" Reserved 6: {(Reserved6 == null ? "[NULL]" : BitConverter.ToString(Reserved6).Replace('-', ' '))}");
builder.AppendLine($" Reserved and unchecked region: {(ReservedAndUnchecked == null ? "[NULL]" : BitConverter.ToString(ReservedAndUnchecked).Replace('-', ' '))}");
builder.AppendLine($" RSA signature: {(RSASignature == null ? "[NULL]" : BitConverter.ToString(RSASignature).Replace('-', ' '))}");
}
builder.AppendLine();
}
/// <summary>
/// Print secure area information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintSecureArea(StringBuilder builder)
{
builder.AppendLine(" Secure Area Information:");
builder.AppendLine(" -------------------------");
builder.AppendLine($" {(SecureArea == null ? "[NULL]" : BitConverter.ToString(SecureArea).Replace('-', ' '))}");
builder.AppendLine();
}
/// <summary>
/// Print name table information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintNameTable(StringBuilder builder)
{
builder.AppendLine(" Name Table Information:");
builder.AppendLine(" -------------------------");
builder.AppendLine();
PrintFolderAllocationTable(builder);
PrintNameList(builder);
}
/// <summary>
/// Print folder allocation table information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintFolderAllocationTable(StringBuilder builder)
{
builder.AppendLine($" Folder Allocation Table:");
builder.AppendLine(" -------------------------");
if (FolderAllocationTable == null || FolderAllocationTable.Length == 0)
{
builder.AppendLine(" No folder allocation table entries");
}
else
{
for (int i = 0; i < FolderAllocationTable.Length; i++)
{
var entry = FolderAllocationTable[i];
builder.AppendLine($" Folder Allocation Table Entry {i}");
if (entry == null)
{
builder.AppendLine(" [NULL]");
continue;
}
builder.AppendLine($" Start offset: {entry.StartOffset} (0x{entry.StartOffset:X})");
builder.AppendLine($" First file index: {entry.FirstFileIndex} (0x{entry.FirstFileIndex:X})");
if (entry.Unknown == 0xF0)
{
builder.AppendLine($" Parent folder index: {entry.ParentFolderIndex} (0x{entry.ParentFolderIndex:X})");
builder.AppendLine($" Unknown: {entry.Unknown} (0x{entry.Unknown:X})");
}
else
{
ushort totalEntries = (ushort)((entry.Unknown << 8) | entry.ParentFolderIndex);
builder.AppendLine($" Total entries: {totalEntries} (0x{totalEntries:X})");
}
}
}
builder.AppendLine();
}
/// <summary>
/// Print folder allocation table information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintNameList(StringBuilder builder)
{
builder.AppendLine($" Name List:");
builder.AppendLine(" -------------------------");
if (NameList == null || NameList.Length == 0)
{
builder.AppendLine(" No name list entries");
}
else
{
for (int i = 0; i < NameList.Length; i++)
{
var entry = NameList[i];
builder.AppendLine($" Name List Entry {i}");
if (entry == null)
{
builder.AppendLine(" [NULL]");
continue;
}
builder.AppendLine($" Folder: {entry.Folder} (0x{entry.Folder:X})");
builder.AppendLine($" Name: {entry.Name ?? "[NULL]"}");
if (entry.Folder)
builder.AppendLine($" Index: {entry.Index} (0x{entry.Index:X})");
}
}
builder.AppendLine();
}
/// <summary>
/// Print file allocation table information
/// </summary>
/// <param name="builder">StringBuilder to append information to</param>
private void PrintFileAllocationTable(StringBuilder builder)
{
builder.AppendLine($" File Allocation Table:");
builder.AppendLine(" -------------------------");
if (FileAllocationTable == null || FileAllocationTable.Length == 0)
{
builder.AppendLine(" No file allocation table entries");
}
else
{
for (int i = 0; i < FileAllocationTable.Length; i++)
{
var entry = FileAllocationTable[i];
builder.AppendLine($" File Allocation Table Entry {i}");
if (entry == null)
{
builder.AppendLine(" [NULL]");
continue;
}
builder.AppendLine($" Start offset: {entry.StartOffset} (0x{entry.StartOffset:X})");
builder.AppendLine($" End offset: {entry.EndOffset} (0x{entry.EndOffset:X})");
}
}
builder.AppendLine();
}
#if NET6_0_OR_GREATER
/// <inheritdoc/>