diff --git a/README.md b/README.md index 9f9544f..8378e64 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi | PP | | [`patterns/selinuxpp.hexpat`](patterns/selinuxpp.pat) | SE Linux package | | PFS0 | | [`patterns/pfs0.hexpat`](patterns/pfs0.hexpat) | Nintendo Switch PFS0 archive (NSP files) | | PIF | `image/pif` | [`patterns/pif.hexpat`](patterns/pif.hexpat) | PIF Image Format | +| PKM | | [`patterns/pkm.hexpat`](patterns/pkm.hexpat) | PKM texture format | | PNG | `image/png` | [`patterns/png.hexpat`](patterns/png.hexpat) | PNG image files | | PRODINFO | | [`patterns/prodinfo.hexpat`](patterns/prodinfo.hexpat) | Nintendo Switch PRODINFO | | Protobuf | | [`patterns/protobuf.hexpat`](patterns/protobuf.hexpat) | Google Protobuf encoding | diff --git a/patterns/ntag.hexpat b/patterns/ntag.hexpat index 9aadc15..831acd1 100644 --- a/patterns/ntag.hexpat +++ b/patterns/ntag.hexpat @@ -2,6 +2,7 @@ #pragma description NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC import std.core; +import std.io; using BitfieldOrder = std::core::BitfieldOrder; @@ -147,6 +148,38 @@ bitfield ACCESS { AUTHLIM : 3; }; +fn validate_ntag_checksum(ManufacturerData mdata) { + + /* + 0x88 is the CT/cascade digit. + This is XOR'd with the first 3 bytes of the serial to calculate BCC0. + */ + + u8 bcc0 = 0x88 ^ + mdata.serial1[0] ^ + mdata.serial1[1] ^ + mdata.serial1[2]; + + if (bcc0 == mdata.checkByte0) { + std::print("NTAG BCC0 checksum OK. Value: {}", bcc0); + } else { + std::warning(std::format("NTAG BCC0 checksum failed! Value: {}", bcc0)); + } + + // BCC1 is the XOR of the last 4 serial bytes. + + u8 bcc1 = mdata.serial2[0] ^ + mdata.serial2[1] ^ + mdata.serial2[2] ^ + mdata.serial2[3]; + + if (bcc1 == mdata.checkByte1) { + std::print("NTAG BCC1 checksum OK. Value: {}", bcc1); + } else { + std::warning(std::format("NTAG BCC1 checksum failed! Value: {}", bcc1)); + } +}; + struct Config { MIRROR MIRROR; u8 MIRROR_PAGE; @@ -166,3 +199,5 @@ struct NTAG { }; NTAG ntag @ 0x00; + +validate_ntag_checksum(ntag.manufacturerData); diff --git a/patterns/pkm.hexpat b/patterns/pkm.hexpat new file mode 100644 index 0000000..2ce2180 --- /dev/null +++ b/patterns/pkm.hexpat @@ -0,0 +1,27 @@ +#pragma description PKM (PacKMan) files containing ETC (Ericsson Texture Compression) +#pragma author applecuckoo +#pragma endian big + +enum PKMFormat : u16 { + ETC1_RGB_NO_MIPMAPS, + ETC2PACKAGE_RGB_NO_MIPMAPS, + ETC2PACKAGE_RGBA_NO_MIPMAPS_OLD, + ETC2PACKAGE_RGBA_NO_MIPMAPS, + ETC2PACKAGE_RGBA1_NO_MIPMAPS, + ETC2PACKAGE_R_NO_MIPMAPS, + ETC2PACKAGE_RG_NO_MIPMAPS, + ETC2PACKAGE_R_SIGNED_NO_MIPMAPS, + ETC2PACKAGE_RG_SIGNED_NO_MIPMAPS +}; + +struct PKMHeader { + char id[4]; + char version[2]; + PKMFormat pkm_format; + u16 width; + u16 height; + u16 original_width; + u16 original_height; +}; + +PKMHeader pkm_header @ 0x00 [[comment("PKM file header"), name("Header")]]; \ No newline at end of file diff --git a/tests/patterns/test_data/pkm.hexpat.pkm b/tests/patterns/test_data/pkm.hexpat.pkm new file mode 100644 index 0000000..32479c0 Binary files /dev/null and b/tests/patterns/test_data/pkm.hexpat.pkm differ