diff --git a/runtime/amiibo.c b/runtime/amiibo.c index 07f30031..8b2c6a95 100644 --- a/runtime/amiibo.c +++ b/runtime/amiibo.c @@ -29,9 +29,10 @@ static bool amiibo_validate_dump(const uint8_t *data, uint64_t size) { return false; } - // NTAG215 Capability Container (CC) at page 3 (offset 0x0C). - // Byte 0x0C must be 0xE1 (NDEF Magic / Type 2 Tag CC container byte). - if (data[0x0C] != 0xE1) { + // NTAG215 Capability Container (CC) at page 3 (offset 0x0C). An amiibo's is F1 10 FF EE, not the E1 of a plain + // NDEF tag (3dbrew, "Amiibo"); the CC is not encrypted, so encrypted dumps carry it too. + static const uint8_t amiibo_cc[4] = {0xF1, 0x10, 0xFF, 0xEE}; + if (memcmp(data + 0x0C, amiibo_cc, sizeof amiibo_cc)) { return false; } diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index 42bbb52b..470e9b92 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -12,6 +12,7 @@ #include #include +#include "amiibo.h" #include "cfg.h" #include "fs.h" #include "gfx.h" @@ -398,6 +399,18 @@ static void probe_applet(void) { int reattached = event_works(activate, 0) && event_works(deactivate, 0); CHECK(reattached, "the nfp events do not work after DestroySystemEvent and a second Attach"); CHECK((uint32_t)CALL("nfp.StartDetection", U(handles)) == 0, "nfp StartDetection again"); + // An amiibo's NTAG215 header: UID with its two check bytes, static lock 0F E0, capability container F1 10 FF EE. + // The loader takes it and refuses the same file with a plain NDEF container (E1). + static const uint8_t head[16] = {0x04, 0x11, 0x22, 0x88 ^ 0x04 ^ 0x11 ^ 0x22, 0x33, 0x44, 0x55, 0x66, + 0x33 ^ 0x44 ^ 0x55 ^ 0x66, 0x48, 0x0F, 0xE0, 0xF1, 0x10, 0xFF, 0xEE}; + uint8_t dump[AMIIBO_DUMP_SIZE] = {0}; + memcpy(dump, head, sizeof head); + const char *dump_path = "probe-amiibo.bin"; + int amiibo_ok = plat_file_write(dump_path, dump, sizeof dump) && amiibo_load_file(dump_path); + dump[0x0C] = 0xE1; + amiibo_ok = amiibo_ok && plat_file_write(dump_path, dump, sizeof dump) && !amiibo_load_file(dump_path); + plat_fs_unlink(dump_path); + CHECK(amiibo_ok, "the amiibo loader refuses a dump with the amiibo capability container, or takes a plain NDEF one"); CHECK(CALL("nfp.Finalize", 0) == 0 && (uint32_t)CALL("nfp.GetState", 0) == 0, "nfp finalize"); CALL("err.ShowError", 0x2a8); CALL("nndiagStartup", 0);