diff --git a/armsrc/Standalone/hf_tmudford.c b/armsrc/Standalone/hf_tmudford.c index 661c1887b..aa986aba0 100644 --- a/armsrc/Standalone/hf_tmudford.c +++ b/armsrc/Standalone/hf_tmudford.c @@ -75,7 +75,7 @@ void RunMod(void) { } else if (state == STATE_EMUL) { Iso15693InitTag(); Dbprintf("Starting simulation, press " _GREEN_("pm3 button") " to stop and go back to search state."); - // default block size is 4.. + // default block size is 4.. // iceman: which can be 4,8 all the way to 32 SimTagIso15693(card.uid, 4); diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 4e5bb15ae..e0471fe10 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1323,19 +1323,19 @@ static void PacketReceived(PacketCommandNG *packet) { uint32_t offset; uint16_t length; } PACKED; - struct p *payload = (struct p *) packet->data.asBytes; + struct p *payload = (struct p *) packet->data.asBytes; if (payload->length > PM3_CMD_DATA_SIZE) { reply_ng(CMD_HF_ISO15693_EML_GETMEM, PM3_EMALLOC, NULL, 0); return; } - uint8_t *buf = BigBuf_malloc(payload->length); + uint8_t *buf = BigBuf_malloc(payload->length); emlGet(buf, payload->offset, payload->length); LED_B_ON(); reply_ng(CMD_HF_ISO15693_EML_GETMEM, PM3_SUCCESS, buf, payload->length); LED_B_OFF(); - BigBuf_free_keep_EM(); + BigBuf_free_keep_EM(); break; } case CMD_HF_ISO15693_SIMULATE: { diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index f75c2ecdc..b7c07e0ea 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -2139,7 +2139,7 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { } if (uid != NULL) { - + uint8_t empty[8] = { 0 }; // User supplied not empty? @@ -2168,9 +2168,9 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { } if ((tag->pagesCount > ISO15693_TAG_MAX_PAGES) || - ((tag->pagesCount * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) || - (tag->pagesCount == 0) || - (tag->bytesPerPage == 0)) { + ((tag->pagesCount * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) || + (tag->pagesCount == 0) || + (tag->bytesPerPage == 0)) { Dbprintf("Tag size error: pagesCount = %d, bytesPerPage=%d", tag->pagesCount, tag->bytesPerPage); reply_ng(CMD_HF_ISO15693_SIMULATE, PM3_EOPABORTED, NULL, 0); return; @@ -2182,17 +2182,17 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { if (g_dbglevel >= DBG_DEBUG) { Dbprintf("ISO-15963 Simulating uid: %02X%02X%02X%02X%02X%02X%02X%02X, %u bytes/blocks x %u blocks" - , tag->uid[7] - , tag->uid[6] - , tag->uid[5] - , tag->uid[4] - , tag->uid[3] - , tag->uid[2] - , tag->uid[1] - , tag->uid[0] - , tag->bytesPerPage - , tag->pagesCount - ); + , tag->uid[7] + , tag->uid[6] + , tag->uid[5] + , tag->uid[4] + , tag->uid[3] + , tag->uid[2] + , tag->uid[1] + , tag->uid[0] + , tag->bytesPerPage + , tag->pagesCount + ); } LED_C_ON(); diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index 47e71abcc..aca7ed989 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -637,11 +637,11 @@ bool emlCheckValBl(int blockNum) { uint8_t *d = mem + (blockNum * 16); if ((d[0] != (d[4] ^ 0xff)) || (d[0] != d[8]) || - (d[1] != (d[5] ^ 0xff)) || (d[1] != d[9]) || - (d[2] != (d[6] ^ 0xff)) || (d[2] != d[10]) || - (d[3] != (d[7] ^ 0xff)) || (d[3] != d[11]) || - (d[12] != (d[13] ^ 0xff)) || (d[12] != d[14]) || - (d[12] != (d[15] ^ 0xff))) { + (d[1] != (d[5] ^ 0xff)) || (d[1] != d[9]) || + (d[2] != (d[6] ^ 0xff)) || (d[2] != d[10]) || + (d[3] != (d[7] ^ 0xff)) || (d[3] != d[11]) || + (d[12] != (d[13] ^ 0xff)) || (d[12] != d[14]) || + (d[12] != (d[15] ^ 0xff))) { return false; } return true; diff --git a/client/deps/amiitool/amiibo.c b/client/deps/amiitool/amiibo.c index 6aa4aeeed..1d1b1ccff 100644 --- a/client/deps/amiitool/amiibo.c +++ b/client/deps/amiitool/amiibo.c @@ -86,25 +86,25 @@ bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys_t *amiiboKeys, const uint8_t *t nfc3d_amiibo_cipher(&dataKeys, internal, plain); // Regenerate tag HMAC. Note: order matters, data HMAC depends on tag HMAC! - mbedtls_md_hmac( mbedtls_md_info_from_type(MBEDTLS_MD_SHA256) - , tagKeys.hmacKey - , sizeof(tagKeys.hmacKey) - , plain + 0x1D4 - , 0x34 - , plain + HMAC_POS_TAG - ); + mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256) + , tagKeys.hmacKey + , sizeof(tagKeys.hmacKey) + , plain + 0x1D4 + , 0x34 + , plain + HMAC_POS_TAG + ); // Regenerate data HMAC mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256) - , dataKeys.hmacKey - , sizeof(dataKeys.hmacKey) - , plain + 0x029 - , 0x1DF - , plain + HMAC_POS_DATA - ); + , dataKeys.hmacKey + , sizeof(dataKeys.hmacKey) + , plain + 0x029 + , 0x1DF + , plain + HMAC_POS_DATA + ); return ((memcmp(plain + HMAC_POS_DATA, internal + HMAC_POS_DATA, 32) == 0) && - (memcmp(plain + HMAC_POS_TAG, internal + HMAC_POS_TAG, 32) == 0)); + (memcmp(plain + HMAC_POS_TAG, internal + HMAC_POS_TAG, 32) == 0)); } void nfc3d_amiibo_pack(const nfc3d_amiibo_keys_t *amiiboKeys, const uint8_t *plain, uint8_t *tag) { @@ -118,12 +118,12 @@ void nfc3d_amiibo_pack(const nfc3d_amiibo_keys_t *amiiboKeys, const uint8_t *pla // Generate tag HMAC mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256) - , tagKeys.hmacKey - , sizeof(tagKeys.hmacKey) - , plain + 0x1D4 - , 0x34 - , cipher + HMAC_POS_TAG - ); + , tagKeys.hmacKey + , sizeof(tagKeys.hmacKey) + , plain + 0x1D4 + , 0x34 + , cipher + HMAC_POS_TAG + ); // Init mbedtls HMAC context mbedtls_md_context_t ctx; diff --git a/client/deps/amiitool/keygen.c b/client/deps/amiitool/keygen.c index 236edd210..150eb769b 100644 --- a/client/deps/amiitool/keygen.c +++ b/client/deps/amiitool/keygen.c @@ -20,7 +20,7 @@ static void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys_t *baseKeys, // 1: Copy whole type string // output = (uint8_t *)strcpy((char *)output, baseKeys->typeString); - output = memccpy(output, baseKeys->typeString, '\0', sizeof(baseKeys->typeString)); + output = memccpy(output, baseKeys->typeString, '\0', sizeof(baseKeys->typeString)); // 2: Append (16 - magicBytesSize) from the input seed size_t leadingSeedBytes = 16 - baseKeys->magicBytesSize; diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index ae8ffd92b..dba707330 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -1309,11 +1309,11 @@ static int mfu_dump_tag(uint16_t pages, void **pdata, uint16_t *len) { } // UL_EV1/NTAG auth - uint8_t keytype = 2; + uint8_t keytype = 2; // generate PWD uint8_t key[4] = {0}; num_to_bytes(ul_ev1_pwdgenB(card.uid), 4, key); - + clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFAREU_READCARD, 0, pages, keytype, key, 4); PacketResponseNG resp; @@ -4834,7 +4834,7 @@ static int CmdHF14AMfuList(const char *Cmd) { return CmdTraceListAlias(Cmd, "hf 14a", "14a -c"); } -static int CmdHF14AAmiibo(const char *Cmd){ +static int CmdHF14AAmiibo(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfu amiibo", @@ -4888,7 +4888,7 @@ static int CmdHF14AAmiibo(const char *Cmd){ // load dump file if available if (infnlen > 0) { uint8_t *dump = NULL; - size_t dumplen = 0; + size_t dumplen = 0; res = loadFile_safe(infilename, "", (void **)&dump, &dumplen); if (res != PM3_SUCCESS) { free(dump); @@ -4914,7 +4914,7 @@ static int CmdHF14AAmiibo(const char *Cmd){ } else { uint16_t dlen = 0; uint8_t *dump = NULL; - res = mfu_dump_tag( MAX_NTAG_215, (void **)&dump, &dlen); + res = mfu_dump_tag(MAX_NTAG_215, (void **)&dump, &dlen); if (res != PM3_SUCCESS) { PrintAndLogEx(FAILED, "Failed to dump memory from tag"); free(dump); @@ -4925,7 +4925,7 @@ static int CmdHF14AAmiibo(const char *Cmd){ } - uint8_t decrypted[NFC3D_AMIIBO_SIZE] = {0}; + uint8_t decrypted[NFC3D_AMIIBO_SIZE] = {0}; if (shall_decrypt) { if (nfc3d_amiibo_unpack(&amiibo_keys, original, decrypted) == false) { PrintAndLogEx(INFO, "Tag signature ( " _RED_("fail") " )"); @@ -4933,7 +4933,7 @@ static int CmdHF14AAmiibo(const char *Cmd){ } // print if (verbose) { - for (uint8_t i = 0; i < (NFC3D_AMIIBO_SIZE / 16); i++ ) { + for (uint8_t i = 0; i < (NFC3D_AMIIBO_SIZE / 16); i++) { PrintAndLogEx(INFO, "[%d] %s", i, sprint_hex_ascii(decrypted + (i * 16), 16)); } } @@ -4944,7 +4944,7 @@ static int CmdHF14AAmiibo(const char *Cmd){ nfc3d_amiibo_pack(&amiibo_keys, decrypted, encrypted); // print if (verbose) { - for (uint8_t i = 0; i < (NFC3D_AMIIBO_SIZE / 16); i++ ) { + for (uint8_t i = 0; i < (NFC3D_AMIIBO_SIZE / 16); i++) { PrintAndLogEx(INFO, "[%d] %s", i, sprint_hex_ascii(encrypted + (i * 16), 16)); } } diff --git a/client/src/fileutils.c b/client/src/fileutils.c index bf3478362..5cf6d6e34 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -544,10 +544,10 @@ int saveFileJSONex(const char *preferredName, JSONFileType ftype, uint8_t *data, snprintf(path, sizeof(path), "$.blocks.%u", i); JsonSaveBufAsHexCompact(root - , path - , &tag->data[i * tag->bytesPerPage] - , tag->bytesPerPage - ); + , path + , &tag->data[i * tag->bytesPerPage] + , tag->bytesPerPage + ); } break; } @@ -1691,13 +1691,13 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz if (sptr + 8 > maxdatalen) { PrintAndLogEx(ERR, "loadFileJSONex: maxdatalen=%zu (%04zx) block (i)=%4d (%04x) sptr=%zu (%04zx) -- exceeded maxdatalen" - , maxdatalen - , maxdatalen - , i - , i - , sptr - , sptr - ); + , maxdatalen + , maxdatalen + , i + , i + , sptr + , sptr + ); retval = PM3_EMALLOC; goto out; @@ -1735,13 +1735,13 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz if (((i + 1) * tag->bytesPerPage) > ISO15693_TAG_MAX_SIZE) { PrintAndLogEx(ERR, "loadFileJSONex: maxdatalen=%zu (%04zx) block (i)=%4d (%04x) sptr=%zu (%04zx) -- exceeded maxdatalen" - , maxdatalen - , maxdatalen - , i - , i - , sptr - , sptr - ); + , maxdatalen + , maxdatalen + , i + , i + , sptr + , sptr + ); retval = PM3_EMALLOC; goto out; diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 1e085bd3b..cb79af350 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -423,6 +423,7 @@ const static vocabulary_t vocabulary[] = { { 0, "hf mfu sim" }, { 0, "hf mfu setpwd" }, { 0, "hf mfu setuid" }, + { 0, "hf mfu amiibo" }, { 1, "hf mfdes help" }, { 0, "hf mfdes info" }, { 0, "hf mfdes getuid" }, diff --git a/doc/commands.json b/doc/commands.json index 529a3f7cb..723b69ebe 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -6668,6 +6668,24 @@ ], "usage": "hf mfp wrp [-hv] -a [-d ]" }, + "hf mfu amiibo": { + "command": "hf mfu amiibo", + "description": "Tries to read all memory from amiibo tag and decrypt it", + "notes": [ + "hf mfu amiiboo --dec -f hf-mfu-04579DB27C4880-dump.bin -> decrypt file", + "hf mfu amiiboo -v --dec -> decrypt tag" + ], + "offline": false, + "options": [ + "-h, --help This help", + "--dec Decrypt memory", + "--enc Encrypt memory", + "-i, --in Specify a filename for input dump file", + "-o, --out Specify a filename for output dump file", + "-v, --verbose Verbose output" + ], + "usage": "hf mfu amiibo [-hv] [--dec] [--enc] [-i ] [-o ]" + }, "hf mfu cauth": { "command": "hf mfu cauth", "description": "Tests 3DES password on Mifare Ultralight-C tag. If password is not specified, a set of known defaults will be tested.", @@ -12336,8 +12354,8 @@ } }, "metadata": { - "commands_extracted": 711, + "commands_extracted": 712, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2024-01-24T17:12:09" + "extracted_on": "2024-01-25T00:53:56" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 87643a2c3..066d9f6c3 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -602,6 +602,7 @@ Check column "offline" for their availability. |`hf mfu sim `|N |`Simulate MIFARE Ultralight from emulator memory` |`hf mfu setpwd `|N |`Set 3DES key - Ultralight-C` |`hf mfu setuid `|N |`Set UID - MAGIC tags only` +|`hf mfu amiibo `|N |`Amiibo tag operations` ### hf mfdes