SceneGate / Ekona

.NET implementation of DS and DSi file formats
https://scenegate.github.io/Ekona/
MIT License
28 stars 1 forks source link

:sparkles: Read and write DS extended header including validate and regenerate HMAC #17

Closed pleonex closed 2 years ago

pleonex commented 2 years ago

Description

Example

The Binary2NitroRom converter accepts the optional parameter DsiKeyStore. If provided, the HMAC and Signature will be validated while reading the ROM.

DsiKeyStore keys = ...; // Create in code or deserialize from YAML/JSON.

using Node node = NodeFactory.FromFile(romPath, FileOpenMode.Read);
node.TransformWith<Binary2NitroRom, DsiKeyStore>(keys);

NitroRom rom = node.GetFormatAs<NitroRom>();
ProgramInfo programInfo = rom.Information;
bool isDsi = programInfo.UnitCode != DeviceUnitKind.DS;

if (isDsi || programInfo.ProgramFeatures.HasFlag(DsiRomFeatures.BannerSigned)) {
    programInfo.BannerMac.Status.Should().Be(HashStatus.Valid);
}

if (programInfo.ProgramFeatures.HasFlag(DsiRomFeatures.ProgramSigned)) {
    programInfo.OverlaysMac.Status.Should().Be(HashStatus.Valid);
    programInfo.Signature.Status.Should().Be(HashStatus.Valid);
}

if (isDsi) {
    programInfo.OverlaysMac.IsNull.Should().BeTrue();
    programInfo.ProgramMac.IsNull.Should().BeTrue();
    programInfo.Signature.Status.Should().Be(HashStatus.Valid);
}

The NitroRom2Binary converter accepts the optional parameter NitroRom2BinaryParams. If provided with keys, it will re-generate the above HMACs.

Related to #9, #12