NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsSecureAreaValidator.cs
1namespace NdsForge;
2
4internal static class NdsSecureAreaValidator
5{
10 public static void Validate(
11 NdsImage image,
12 List<NdsDiagnostic> diagnostics,
13 NdsKey1KeyTable? keyTable)
14 {
15 NdsSecureAreaInspection inspection;
16 try
17 {
18 inspection = NdsSecureArea.Inspect(image, keyTable);
19 }
20 catch (ArgumentException exception)
21 {
22 diagnostics.Add(new(
23 "NDS1401",
25 $"The product code cannot initialize KEY1 validation: {exception.Message}",
26 new(0x0C, 4)));
27 return;
28 }
29
30 if (inspection.State == NdsSecureAreaState.Malformed)
31 {
32 diagnostics.Add(new(
33 "NDS1402",
35 "The header places ARM9 in the secure-area interval, but the physical image does not contain all 16 KiB.",
36 inspection.Region));
37 }
38 else if (inspection.State == NdsSecureAreaState.Unrecognized && keyTable is not null)
39 {
40 diagnostics.Add(new(
41 "NDS1403",
43 "The supplied KEY1 table and product code do not recover a recognized secure-area identifier.",
44 inspection.Region));
45 }
46
47 if (inspection.IsCrcValid == false)
48 {
49 diagnostics.Add(new(
50 "NDS1404",
52 $"The secure-area CRC stores 0x{inspection.StoredCrc:X4}, but the encrypted representation calculates 0x{inspection.CalculatedCrc:X4}.",
53 inspection.Region));
54 }
55 }
56}
NdsSecureAreaState
Classifies the cartridge security interval without conflating encrypted bytes with malformed metadata...
NdsDiagnosticSeverity
Indicates the impact of a validation finding.