From 8bc080b3b8a38ab43d3a6661daa9f0629a8c4dfb Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Fri, 24 Jul 2026 11:53:14 +0300 Subject: [PATCH 1/7] Added support for emulating ST25TA tag (IKEA Rothult) with custom NDEF response --- armsrc/appmain.c | 8 ++- armsrc/iso14443a.c | 28 ++++++-- armsrc/iso14443a.h | 3 +- client/src/cmdhf14a.c | 3 + client/src/cmdhfst25ta.c | 142 ++++++++++++++++++++++++++++++++++++++- include/pm3_cmd.h | 3 + 6 files changed, 178 insertions(+), 9 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 82ff672e0..ddb6746b1 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -26,6 +26,9 @@ #include "bwm_uart_at32.h" #include "bwm_wifi.h" #endif +#include "clocks.h" +#include "pm3_cmd.h" +#include "usb_cdc.h" #include "proxmark3_arm.h" #include "dbprint.h" #include "pmflash.h" @@ -2144,13 +2147,16 @@ static void PacketReceived(PacketCommandNG *packet) { uint8_t ulauth_1a1[16]; uint8_t ulauth_1a2[16]; bool ulauth_1a2_mirror; + uint16_t st25ta_ndef_len; + uint8_t st25ta_ndef[ST25TA_SIM_NDEF_MAX]; } PACKED; struct p *payload = (struct p *) packet->data.asBytes; SimulateIso14443aTagEx(payload->tagtype, payload->flags, payload->uid, payload->exitAfter, payload->rats, sizeof(payload->rats), payload->ulauth_1a1, payload->ulauth_1a1_len, payload->ulauth_1a2, payload->ulauth_1a2_len, - payload->ulauth_1a2_mirror + payload->ulauth_1a2_mirror, + payload->st25ta_ndef, payload->st25ta_ndef_len ); // ## Simulate iso14443a tag - pass tag type & UID break; } diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 8e7f0afe2..30b321990 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -19,6 +19,7 @@ //----------------------------------------------------------------------------- #include "iso14443a.h" +#include "pm3_cmd.h" #include "string.h" #include "proxmark3_arm.h" #include "cmd.h" @@ -1714,14 +1715,15 @@ bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data, // 'hf 14a sim' //----------------------------------------------------------------------------- void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uint8_t exitAfterNReads) { - SimulateIso14443aTagEx(tagType, flags, useruid, exitAfterNReads, NULL, 0, NULL, 0, NULL, 0, false); + SimulateIso14443aTagEx(tagType, flags, useruid, exitAfterNReads, NULL, 0, NULL, 0, NULL, 0, false, NULL, 0); } void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, uint8_t exitAfterNReads, uint8_t *ats, size_t ats_len, uint8_t *ulauth_1a1, uint8_t ulauth_1a1_len, uint8_t *ulauth_1a2, uint8_t ulauth_1a2_len, - bool ulauth_1a2_mirror) { + bool ulauth_1a2_mirror, + const uint8_t *st25ta_ndef, uint16_t st25ta_ndef_len) { #define ATTACK_KEY_COUNT 16 #define ULC_TAG_NONCE "\x01\x02\x03\x04\x05\x06\x07\x08" @@ -1754,8 +1756,8 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u // Allocate 512 bytes for the dynamic modulation, created when the reader queries for it // Such a response is less time critical, so we can prepare them on the fly -#define DYNAMIC_RESPONSE_BUFFER_SIZE 64 -#define DYNAMIC_MODULATION_BUFFER_SIZE 512 +#define DYNAMIC_RESPONSE_BUFFER_SIZE (ST25TA_SIM_NDEF_MAX + 4) +#define DYNAMIC_MODULATION_BUFFER_SIZE 4096 uint8_t *dynamic_response_buffer = BigBuf_calloc(DYNAMIC_RESPONSE_BUFFER_SIZE); if (dynamic_response_buffer == NULL) { @@ -2429,10 +2431,24 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u if (tagType == 10) { // we replay 90 00 for all commands but the read bin and we deny the verify cmd. + static const uint8_t default_st25ta_ndef[] = { + 0x00, 0x1b, 0xd1, 0x01, 0x17, 0x54, 0x02, 0x7a, + 0x68, 0xa2, 0x34, 0xcb, 0xd0, 0xe2, 0x03, 0xc7, + 0x3e, 0x62, 0x0b, 0xe8, 0xc6, 0x3c, 0x85, 0x2c, + 0xc5, 0x31, 0x31, 0x31, 0x32, 0x90, 0x00 + }; + const uint8_t *ndef = default_st25ta_ndef; + uint16_t ndef_len = sizeof(default_st25ta_ndef); + + if (st25ta_ndef != NULL && st25ta_ndef_len > 0 && st25ta_ndef_len <= ST25TA_SIM_NDEF_MAX) { + ndef = st25ta_ndef; + ndef_len = st25ta_ndef_len; + } + if (memcmp("\x02\xa2\xb0\x00\x00\x1d\x51\x69", receivedCmd, 8) == 0) { dynamic_response_info.response[0] = receivedCmd[0]; - memcpy(dynamic_response_info.response + 1, "\x00\x1b\xd1\x01\x17\x54\x02\x7a\x68\xa2\x34\xcb\xd0\xe2\x03\xc7\x3e\x62\x0b\xe8\xc6\x3c\x85\x2c\xc5\x31\x31\x31\x32\x90\x00", 31); - dynamic_response_info.response_n = 32; + memcpy(dynamic_response_info.response + 1, ndef, ndef_len); + dynamic_response_info.response_n = ndef_len + 1; } else if (memcmp("\x02\x00\x20\x00\x01\x00\x6e\xa9", receivedCmd, 8) == 0) { dynamic_response_info.response[0] = receivedCmd[0]; dynamic_response_info.response[1] = 0x63; diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 559ca7827..a644451ea 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -148,7 +148,8 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u uint8_t *ats, size_t ats_len, uint8_t *ulauth_1a1, uint8_t ulauth_1a1_len, uint8_t *ulauth_1a2, uint8_t ulauth_1a2_len, - bool ulauth_1a2_mirror); + bool ulauth_1a2_mirror, + const uint8_t *st25ta_ndef, uint16_t st25ta_ndef_len); void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid, uint8_t *ats, size_t ats_len, uint8_t *aid, size_t aid_len, diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index a720aece4..71a71317c 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1037,8 +1037,11 @@ int CmdHF14ASim(const char *Cmd) { uint8_t ulauth_1a1[16]; uint8_t ulauth_1a2[16]; bool ulauth_1a2_mirror; + uint16_t st25ta_ndef_len; + uint8_t st25ta_ndef[ST25TA_SIM_NDEF_MAX]; } PACKED payload; + memset(&payload, 0x00, sizeof(payload)); payload.tagtype = tagtype; payload.flags = flags; payload.exitAfter = exitAfterNReads; diff --git a/client/src/cmdhfst25ta.c b/client/src/cmdhfst25ta.c index 76c32d154..ff85a3a87 100644 --- a/client/src/cmdhfst25ta.c +++ b/client/src/cmdhfst25ta.c @@ -26,6 +26,7 @@ #include "cliparser.h" #include "crc16.h" #include "cmdhf14a.h" +#include "pm3_cmd.h" #include "protocols.h" // definitions of ISO14A/7816 protocol #include "iso7816/apduinfo.h" // GetAPDUCodeDescription #include "nfc/ndef.h" // NDEFRecordsDecodeAndPrint @@ -34,6 +35,8 @@ #include "protocols.h" // ISO7816 APDU return codes #include "crypto/libpcrypto.h" // ecdsa #include "crypto/originality.h" +#include "ui.h" +#include "util.h" // kbd_enter_pressed #define TIMEOUT 2000 @@ -335,22 +338,122 @@ static int CmdHFST25TAInfo(const char *Cmd) { return infoHFST25TA(); } +static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t *dst, uint16_t *dst_len) { + if (src == NULL || src_len == 0 || dst == NULL || dst_len == NULL) { + return PM3_EINVARG; + } + + if (src_len >= 4 && src[src_len - 2] == 0x90 && src[src_len - 1] == 0x00) { + if (src_len > ST25TA_SIM_NDEF_MAX) { + PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_SIM_NDEF_MAX); + return PM3_EINVARG; + } + memcpy(dst, src, src_len); + *dst_len = src_len; + return PM3_SUCCESS; + } + + if (src_len >= 2) { + uint16_t nlen = (src[0] << 8) | src[1]; + if (nlen + 2 == src_len) { + if (src_len + 2 > ST25TA_SIM_NDEF_MAX) { + PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_SIM_NDEF_MAX); + return PM3_EINVARG; + } + memcpy(dst, src, src_len); + dst[src_len] = 0x90; + dst[src_len + 1] = 0x00; + *dst_len = src_len + 2; + return PM3_SUCCESS; + } + } + + if (src_len + 4 > ST25TA_SIM_NDEF_MAX) { + PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_SIM_NDEF_MAX); + return PM3_EINVARG; + } + + dst[0] = (src_len >> 8) & 0xff; + dst[1] = src_len & 0xff; + memcpy(dst + 2, src, src_len); + dst[src_len + 2] = 0x90; + dst[src_len + 3] = 0x00; + *dst_len = src_len + 4; + return PM3_SUCCESS; +} + +static int st25ta_simulate_with_ndef(const uint8_t *uid, const uint8_t *ndef, uint16_t ndef_len) { + struct { + uint8_t tagtype; + uint16_t flags; + uint8_t uid[10]; + uint8_t exitAfter; + uint8_t rats[20]; + uint8_t ulauth_1a1_len; + uint8_t ulauth_1a2_len; + uint8_t ulauth_1a1[16]; + uint8_t ulauth_1a2[16]; + bool ulauth_1a2_mirror; + uint16_t st25ta_ndef_len; + uint8_t st25ta_ndef[ST25TA_SIM_NDEF_MAX]; + } PACKED payload; + + memset(&payload, 0x00, sizeof(payload)); + payload.tagtype = 10; + payload.flags = 0; + FLAG_SET_UID_IN_DATA(payload.flags, 7); + memcpy(payload.uid, uid, 7); + + if (ndef != NULL && ndef_len > 0) { + payload.st25ta_ndef_len = ndef_len; + memcpy(payload.st25ta_ndef, ndef, ndef_len); + } + + clearCommandBuffer(); + SendCommandNG(CMD_HF_ISO14443A_SIMULATE, (uint8_t *)&payload, sizeof(payload)); + + PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("") " to abort simulation"); + PacketResponseNG resp = {0}; + bool keypress = kbd_enter_pressed(); + while (keypress == false) { + keypress = kbd_enter_pressed(); + + if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == false) { + continue; + } + + break; + } + + return resp.status; +} + static int CmdHFST25TASim(const char *Cmd) { int uidlen = 0; uint8_t uid[7] = {0}; + int ndef_hex_len = 0; + uint8_t ndef_hex[ST25TA_SIM_NDEF_MAX] = {0}; CLIParserContext *ctx; CLIParserInit(&ctx, "hf st25ta sim", "Emulating ST25TA512B tag with 7 byte UID", - "hf st25ta sim -u 02E2007D0FCA4C\n"); + "hf st25ta sim -u 02E2007D0FCA4C\n" + "hf st25ta sim -u 02E2007D0FCA4C --ndef 001BD1011754027A68A234CBD0E203C73E620BE8C63C852CC5313131329000\n" + "hf st25ta sim -u 02E2007D0FCA4C -f my-ndef.bin\n"); void *argtable[] = { arg_param_begin, arg_str1("u", "uid", "", "7 byte UID"), + arg_str0(NULL, "ndef", "", "NDEF data or full READ BINARY response"), + arg_str0("f", "file", "", "load NDEF data or full READ BINARY response from file"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); CLIGetHexWithReturn(ctx, 1, uid, &uidlen); + int ndef_res = CLIParamHexToBuf(arg_get_str(ctx, 2), ndef_hex, sizeof(ndef_hex), &ndef_hex_len); + int fnlen = 0; + char filename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParserFree(ctx); if (uidlen != 7) { @@ -358,6 +461,43 @@ static int CmdHFST25TASim(const char *Cmd) { return PM3_EINVARG; } + if (ndef_res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Invalid NDEF hex"); + return ndef_res; + } + + if (ndef_hex_len > 0 && fnlen > 0) { + PrintAndLogEx(ERR, "Use either --ndef or -f, not both"); + return PM3_EINVARG; + } + + uint8_t ndef[ST25TA_SIM_NDEF_MAX] = {0}; + uint16_t ndef_len = 0; + + if (ndef_hex_len > 0) { + int res = st25ta_normalize_sim_ndef(ndef_hex, ndef_hex_len, ndef, &ndef_len); + if (res != PM3_SUCCESS) { + return res; + } + } else if (fnlen > 0) { + uint8_t *file_data = NULL; + size_t file_len = 0; + int res = loadFile_safe(filename, "", (void **)&file_data, &file_len); + if (res != PM3_SUCCESS) { + return res; + } + res = st25ta_normalize_sim_ndef(file_data, file_len, ndef, &ndef_len); + free(file_data); + if (res != PM3_SUCCESS) { + return res; + } + } + + if (ndef_len > 0) { + PrintAndLogEx(SUCCESS, "Emulating ST25TA512B with supplied NDEF response (%u bytes)", ndef_len); + return st25ta_simulate_with_ndef(uid, ndef, ndef_len); + } + char param[40]; snprintf(param, sizeof(param), "-t 10 -u %s", sprint_hex_inrow(uid, uidlen)); return CmdHF14ASim(param); diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 739c6b0c4..b33f23da3 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -974,6 +974,9 @@ typedef struct { #define CMD_UNKNOWN 0xFFFF +// Max NDEF record length for ST25TA simulation +#define ST25TA_SIM_NDEF_MAX 256 + // Mifare simulation flags // In interactive mode, we are expected to finish the operation with an ACK #define FLAG_INTERACTIVE 0x0001 From 0a83751380425d3a4d6f60d8873b6854bc6535a8 Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Fri, 24 Jul 2026 12:00:52 +0300 Subject: [PATCH 2/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db02144a2..f73902d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fixed `hf_mf_uscuid_prog.lua` - corrected the script name shown in its usage text (@c-barron) - Added `hf felica seacauth1` command (@kormax) - Added `lf trovan` commands to support Trovan Animal ID (@iceman1001) +- Added support for emulating ST25TA tag (IKEA Rothult) with custom NDEF response (@sanduuz) - Added `hf mf gdmgetblk/gdmgethidblk/gdmsethidblk/gdmsetuid/gdmwipe/gdmsetsig` (@0x6r1an0y) - Changed `hf mf gdmparsecfg/gdmsetblk` (@0x6r1an0y) - Renamed `hf mf gdmcfg` (@0x6r1an0y) From 222bd04252299e62cb0b06558a78fd311b8e52de Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Fri, 24 Jul 2026 13:47:56 +0300 Subject: [PATCH 3/7] Rework ST25TA emulation to use emulator memory instead of pushing stuff to hf 14a sim --- armsrc/appmain.c | 5 +- armsrc/iso14443a.c | 40 +++++++-- armsrc/iso14443a.h | 3 +- client/src/cmdhf14a.c | 2 - client/src/cmdhfst25ta.c | 153 +++++++++++++++++++------------- client/src/pm3line_vocabulary.h | 1 + include/pm3_cmd.h | 11 ++- 7 files changed, 133 insertions(+), 82 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index ddb6746b1..f8feabe4a 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -2147,16 +2147,13 @@ static void PacketReceived(PacketCommandNG *packet) { uint8_t ulauth_1a1[16]; uint8_t ulauth_1a2[16]; bool ulauth_1a2_mirror; - uint16_t st25ta_ndef_len; - uint8_t st25ta_ndef[ST25TA_SIM_NDEF_MAX]; } PACKED; struct p *payload = (struct p *) packet->data.asBytes; SimulateIso14443aTagEx(payload->tagtype, payload->flags, payload->uid, payload->exitAfter, payload->rats, sizeof(payload->rats), payload->ulauth_1a1, payload->ulauth_1a1_len, payload->ulauth_1a2, payload->ulauth_1a2_len, - payload->ulauth_1a2_mirror, - payload->st25ta_ndef, payload->st25ta_ndef_len + payload->ulauth_1a2_mirror ); // ## Simulate iso14443a tag - pass tag type & UID break; } diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 30b321990..dd0129d22 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -1715,15 +1715,14 @@ bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data, // 'hf 14a sim' //----------------------------------------------------------------------------- void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uint8_t exitAfterNReads) { - SimulateIso14443aTagEx(tagType, flags, useruid, exitAfterNReads, NULL, 0, NULL, 0, NULL, 0, false, NULL, 0); + SimulateIso14443aTagEx(tagType, flags, useruid, exitAfterNReads, NULL, 0, NULL, 0, NULL, 0, false); } void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, uint8_t exitAfterNReads, uint8_t *ats, size_t ats_len, uint8_t *ulauth_1a1, uint8_t ulauth_1a1_len, uint8_t *ulauth_1a2, uint8_t ulauth_1a2_len, - bool ulauth_1a2_mirror, - const uint8_t *st25ta_ndef, uint16_t st25ta_ndef_len) { + bool ulauth_1a2_mirror) { #define ATTACK_KEY_COUNT 16 #define ULC_TAG_NONCE "\x01\x02\x03\x04\x05\x06\x07\x08" @@ -1756,16 +1755,23 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u // Allocate 512 bytes for the dynamic modulation, created when the reader queries for it // Such a response is less time critical, so we can prepare them on the fly -#define DYNAMIC_RESPONSE_BUFFER_SIZE (ST25TA_SIM_NDEF_MAX + 4) -#define DYNAMIC_MODULATION_BUFFER_SIZE 4096 +#define DYNAMIC_RESPONSE_BUFFER_SIZE 64 +#define DYNAMIC_MODULATION_BUFFER_SIZE 512 - uint8_t *dynamic_response_buffer = BigBuf_calloc(DYNAMIC_RESPONSE_BUFFER_SIZE); + uint16_t dynamic_response_buffer_size = DYNAMIC_RESPONSE_BUFFER_SIZE; + uint16_t dynamic_modulation_buffer_size = DYNAMIC_MODULATION_BUFFER_SIZE; + if (tagType == 10) { + dynamic_response_buffer_size = ST25TA_EML_NDEF_MAX + 4; + dynamic_modulation_buffer_size = 4096; + } + + uint8_t *dynamic_response_buffer = BigBuf_calloc(dynamic_response_buffer_size); if (dynamic_response_buffer == NULL) { BigBuf_free_keep_EM(); reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EMALLOC, NULL, 0); return; } - uint8_t *dynamic_modulation_buffer = BigBuf_calloc(DYNAMIC_MODULATION_BUFFER_SIZE); + uint8_t *dynamic_modulation_buffer = BigBuf_calloc(dynamic_modulation_buffer_size); if (dynamic_modulation_buffer == NULL) { BigBuf_free_keep_EM(); reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EMALLOC, NULL, 0); @@ -1786,6 +1792,22 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u return; } + uint8_t st25ta_ndef[ST25TA_EML_NDEF_MAX] = {0}; + uint16_t st25ta_ndef_len = 0; + if (tagType == 10) { + uint8_t st25ta_header[ST25TA_EML_DATA_OFFSET] = {0}; + emlGet(st25ta_header, 0, sizeof(st25ta_header)); + if (memcmp(st25ta_header + ST25TA_EML_MAGIC_OFFSET, ST25TA_EML_MAGIC, 4) == 0) { + st25ta_ndef_len = st25ta_header[ST25TA_EML_LEN_OFFSET] | + (st25ta_header[ST25TA_EML_LEN_OFFSET + 1] << 8); + if (st25ta_ndef_len <= ST25TA_EML_NDEF_MAX) { + emlGet(st25ta_ndef, ST25TA_EML_DATA_OFFSET, st25ta_ndef_len); + } else { + st25ta_ndef_len = 0; + } + } + } + mfu_dump_t *mfu_em_dump = NULL; if (tagType == 2 || tagType == 7) { mfu_em_dump = (mfu_dump_t *)BigBuf_get_EM_addr(); @@ -2440,7 +2462,7 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u const uint8_t *ndef = default_st25ta_ndef; uint16_t ndef_len = sizeof(default_st25ta_ndef); - if (st25ta_ndef != NULL && st25ta_ndef_len > 0 && st25ta_ndef_len <= ST25TA_SIM_NDEF_MAX) { + if (st25ta_ndef_len > 0) { ndef = st25ta_ndef; ndef_len = st25ta_ndef_len; } @@ -2543,7 +2565,7 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u AddCrc14A(dynamic_response_info.response, dynamic_response_info.response_n); dynamic_response_info.response_n += 2; - if (prepare_tag_modulation(&dynamic_response_info, DYNAMIC_MODULATION_BUFFER_SIZE) == false) { + if (prepare_tag_modulation(&dynamic_response_info, dynamic_modulation_buffer_size) == false) { if (g_dbglevel >= DBG_DEBUG) DbpString("Error preparing tag response"); LogTrace(receivedCmd, Uart.len, Uart.startTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.endTime * 16 - DELAY_AIR2ARM_AS_TAG, Uart.parity, true); break; diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index a644451ea..559ca7827 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -148,8 +148,7 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u uint8_t *ats, size_t ats_len, uint8_t *ulauth_1a1, uint8_t ulauth_1a1_len, uint8_t *ulauth_1a2, uint8_t ulauth_1a2_len, - bool ulauth_1a2_mirror, - const uint8_t *st25ta_ndef, uint16_t st25ta_ndef_len); + bool ulauth_1a2_mirror); void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid, uint8_t *ats, size_t ats_len, uint8_t *aid, size_t aid_len, diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index 71a71317c..76d490f3d 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1037,8 +1037,6 @@ int CmdHF14ASim(const char *Cmd) { uint8_t ulauth_1a1[16]; uint8_t ulauth_1a2[16]; bool ulauth_1a2_mirror; - uint16_t st25ta_ndef_len; - uint8_t st25ta_ndef[ST25TA_SIM_NDEF_MAX]; } PACKED payload; memset(&payload, 0x00, sizeof(payload)); diff --git a/client/src/cmdhfst25ta.c b/client/src/cmdhfst25ta.c index ff85a3a87..e845529d3 100644 --- a/client/src/cmdhfst25ta.c +++ b/client/src/cmdhfst25ta.c @@ -35,8 +35,8 @@ #include "protocols.h" // ISO7816 APDU return codes #include "crypto/libpcrypto.h" // ecdsa #include "crypto/originality.h" +#include "mifare/mifarehost.h" // mf_eml_set_mem_xt / mf_eml_get_mem_xt #include "ui.h" -#include "util.h" // kbd_enter_pressed #define TIMEOUT 2000 @@ -344,8 +344,8 @@ static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t } if (src_len >= 4 && src[src_len - 2] == 0x90 && src[src_len - 1] == 0x00) { - if (src_len > ST25TA_SIM_NDEF_MAX) { - PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_SIM_NDEF_MAX); + if (src_len > ST25TA_EML_NDEF_MAX) { + PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_EML_NDEF_MAX); return PM3_EINVARG; } memcpy(dst, src, src_len); @@ -356,8 +356,8 @@ static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t if (src_len >= 2) { uint16_t nlen = (src[0] << 8) | src[1]; if (nlen + 2 == src_len) { - if (src_len + 2 > ST25TA_SIM_NDEF_MAX) { - PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_SIM_NDEF_MAX); + if (src_len + 2 > ST25TA_EML_NDEF_MAX) { + PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_EML_NDEF_MAX); return PM3_EINVARG; } memcpy(dst, src, src_len); @@ -368,8 +368,8 @@ static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t } } - if (src_len + 4 > ST25TA_SIM_NDEF_MAX) { - PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_SIM_NDEF_MAX); + if (src_len + 4 > ST25TA_EML_NDEF_MAX) { + PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_EML_NDEF_MAX); return PM3_EINVARG; } @@ -382,68 +382,46 @@ static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t return PM3_SUCCESS; } -static int st25ta_simulate_with_ndef(const uint8_t *uid, const uint8_t *ndef, uint16_t ndef_len) { - struct { - uint8_t tagtype; - uint16_t flags; - uint8_t uid[10]; - uint8_t exitAfter; - uint8_t rats[20]; - uint8_t ulauth_1a1_len; - uint8_t ulauth_1a2_len; - uint8_t ulauth_1a1[16]; - uint8_t ulauth_1a2[16]; - bool ulauth_1a2_mirror; - uint16_t st25ta_ndef_len; - uint8_t st25ta_ndef[ST25TA_SIM_NDEF_MAX]; - } PACKED payload; - - memset(&payload, 0x00, sizeof(payload)); - payload.tagtype = 10; - payload.flags = 0; - FLAG_SET_UID_IN_DATA(payload.flags, 7); - memcpy(payload.uid, uid, 7); - - if (ndef != NULL && ndef_len > 0) { - payload.st25ta_ndef_len = ndef_len; - memcpy(payload.st25ta_ndef, ndef, ndef_len); +static int st25ta_upload_sim_data(const uint8_t *uid, uint8_t uid_len, const uint8_t *ndef, uint16_t ndef_len) { + uint8_t data[ST25TA_EML_DATA_OFFSET + ST25TA_EML_NDEF_MAX] = {0}; + uint16_t data_len = ST25TA_EML_DATA_OFFSET + ndef_len; + memcpy(data + ST25TA_EML_MAGIC_OFFSET, ST25TA_EML_MAGIC, 4); + data[ST25TA_EML_LEN_OFFSET] = ndef_len & 0xff; + data[ST25TA_EML_LEN_OFFSET + 1] = (ndef_len >> 8) & 0xff; + data[ST25TA_EML_UIDLEN_OFFSET] = uid_len; + if (uid_len == 7) { + memcpy(data + ST25TA_EML_UID_OFFSET, uid, uid_len); } + memcpy(data + ST25TA_EML_DATA_OFFSET, ndef, ndef_len); - clearCommandBuffer(); - SendCommandNG(CMD_HF_ISO14443A_SIMULATE, (uint8_t *)&payload, sizeof(payload)); - - PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("") " to abort simulation"); - PacketResponseNG resp = {0}; - bool keypress = kbd_enter_pressed(); - while (keypress == false) { - keypress = kbd_enter_pressed(); - - if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == false) { - continue; + for (uint16_t offset = 0; offset < data_len;) { + uint8_t chunk_len = MIN(data_len - offset, UINT8_MAX); + int res = mf_eml_set_mem_xt(data + offset, offset, chunk_len, 1); + if (res != PM3_SUCCESS) { + return res; } - - break; + offset += chunk_len; } - return resp.status; + return PM3_SUCCESS; } -static int CmdHFST25TASim(const char *Cmd) { +static int CmdHFST25TAELoad(const char *Cmd) { int uidlen = 0; uint8_t uid[7] = {0}; int ndef_hex_len = 0; - uint8_t ndef_hex[ST25TA_SIM_NDEF_MAX] = {0}; + uint8_t ndef_hex[ST25TA_EML_NDEF_MAX] = {0}; CLIParserContext *ctx; - CLIParserInit(&ctx, "hf st25ta sim", - "Emulating ST25TA512B tag with 7 byte UID", - "hf st25ta sim -u 02E2007D0FCA4C\n" - "hf st25ta sim -u 02E2007D0FCA4C --ndef 001BD1011754027A68A234CBD0E203C73E620BE8C63C852CC5313131329000\n" - "hf st25ta sim -u 02E2007D0FCA4C -f my-ndef.bin\n"); + CLIParserInit(&ctx, "hf st25ta eload", + "Load ST25TA NDEF response into emulator memory", + "hf st25ta eload --ndef 001BD1011754027A68A234CBD0E203C73E620BE8C63C852CC5313131329000\n" + "hf st25ta eload -f my-ndef.bin\n" + "hf st25ta eload -u 02E2007D0FCA4C -f my-ndef.bin\n"); void *argtable[] = { arg_param_begin, - arg_str1("u", "uid", "", "7 byte UID"), + arg_str0("u", "uid", "", "optional 7 byte UID to store for simulation"), arg_str0(NULL, "ndef", "", "NDEF data or full READ BINARY response"), arg_str0("f", "file", "", "load NDEF data or full READ BINARY response from file"), arg_param_end @@ -456,7 +434,7 @@ static int CmdHFST25TASim(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParserFree(ctx); - if (uidlen != 7) { + if (uidlen != 0 && uidlen != 7) { PrintAndLogEx(ERR, "UID must be 7 hex bytes"); return PM3_EINVARG; } @@ -466,20 +444,19 @@ static int CmdHFST25TASim(const char *Cmd) { return ndef_res; } - if (ndef_hex_len > 0 && fnlen > 0) { - PrintAndLogEx(ERR, "Use either --ndef or -f, not both"); + if ((ndef_hex_len > 0) == (fnlen > 0)) { + PrintAndLogEx(ERR, "Use exactly one of --ndef or -f"); return PM3_EINVARG; } - uint8_t ndef[ST25TA_SIM_NDEF_MAX] = {0}; + uint8_t ndef[ST25TA_EML_NDEF_MAX] = {0}; uint16_t ndef_len = 0; - if (ndef_hex_len > 0) { int res = st25ta_normalize_sim_ndef(ndef_hex, ndef_hex_len, ndef, &ndef_len); if (res != PM3_SUCCESS) { return res; } - } else if (fnlen > 0) { + } else { uint8_t *file_data = NULL; size_t file_len = 0; int res = loadFile_safe(filename, "", (void **)&file_data, &file_len); @@ -493,9 +470,58 @@ static int CmdHFST25TASim(const char *Cmd) { } } - if (ndef_len > 0) { - PrintAndLogEx(SUCCESS, "Emulating ST25TA512B with supplied NDEF response (%u bytes)", ndef_len); - return st25ta_simulate_with_ndef(uid, ndef, ndef_len); + int res = st25ta_upload_sim_data(uid, uidlen, ndef, ndef_len); + if (res != PM3_SUCCESS) { + PrintAndLogEx(FAILED, "Failed uploading ST25TA data to emulator memory"); + return res; + } + + PrintAndLogEx(SUCCESS, "Uploaded ST25TA NDEF response to emulator memory (" _YELLOW_("%u") " bytes)", ndef_len); + if (uidlen == 7) { + PrintAndLogEx(SUCCESS, "Stored UID " _YELLOW_("%s"), sprint_hex_inrow(uid, uidlen)); + } + PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`hf st25ta sim`")); + return PM3_SUCCESS; +} + +static int CmdHFST25TASim(const char *Cmd) { + int uidlen = 0; + uint8_t uid[7] = {0}; + + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf st25ta sim", + "Emulating ST25TA512B tag. Uses NDEF data from `hf st25ta eload` if loaded.", + "hf st25ta sim -u 02E2007D0FCA4C\n" + "hf st25ta sim\n"); + + void *argtable[] = { + arg_param_begin, + arg_str0("u", "uid", "", "7 byte UID"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + CLIGetHexWithReturn(ctx, 1, uid, &uidlen); + CLIParserFree(ctx); + + if (uidlen != 0 && uidlen != 7) { + PrintAndLogEx(ERR, "UID must be 7 hex bytes"); + return PM3_EINVARG; + } + + if (uidlen == 0) { + uint8_t header[ST25TA_EML_DATA_OFFSET] = {0}; + int res = mf_eml_get_mem_xt(header, 0, sizeof(header), 1); + if (res != PM3_SUCCESS) { + return res; + } + if (memcmp(header + ST25TA_EML_MAGIC_OFFSET, ST25TA_EML_MAGIC, 4) == 0 && + header[ST25TA_EML_UIDLEN_OFFSET] == 7) { + memcpy(uid, header + ST25TA_EML_UID_OFFSET, sizeof(uid)); + uidlen = sizeof(uid); + } else { + PrintAndLogEx(ERR, "No UID supplied and no UID loaded. Use " _YELLOW_("`hf st25ta sim -u `") " or " _YELLOW_("`hf st25ta eload -u ...`")); + return PM3_EINVARG; + } } char param[40]; @@ -951,6 +977,7 @@ static int CmdHFST25TAList(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"eload", CmdHFST25TAELoad, IfPm3Iso14443a, "Upload NDEF response into emulator memory"}, {"info", CmdHFST25TAInfo, IfPm3Iso14443a, "Tag information"}, {"list", CmdHFST25TAList, AlwaysAvailable, "List ISO 14443A/7816 history"}, {"ndefread", CmdHFST25TANdefRead, AlwaysAvailable, "read NDEF file on tag"}, diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 6f98e05d4..31a298b6f 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -635,6 +635,7 @@ const static vocabulary_t vocabulary[] = { { 0, "hf st25ta protect" }, { 0, "hf st25ta pwd" }, { 0, "hf st25ta sim" }, + { 0, "hf st25ta eload" }, { 1, "hf tesla help" }, { 0, "hf tesla info" }, { 1, "hf tesla list" }, diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index b33f23da3..f9444b8b1 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -974,8 +974,15 @@ typedef struct { #define CMD_UNKNOWN 0xFFFF -// Max NDEF record length for ST25TA simulation -#define ST25TA_SIM_NDEF_MAX 256 +// ST25TA simulation data in emulator memory: +// magic[4] || len_le[2] || uid_len[1] || uid[7] || READ BINARY response bytes +#define ST25TA_EML_MAGIC_OFFSET 0 +#define ST25TA_EML_LEN_OFFSET 4 +#define ST25TA_EML_UIDLEN_OFFSET 6 +#define ST25TA_EML_UID_OFFSET 7 +#define ST25TA_EML_DATA_OFFSET 14 +#define ST25TA_EML_NDEF_MAX 256 +#define ST25TA_EML_MAGIC "ST25" // Mifare simulation flags // In interactive mode, we are expected to finish the operation with an ACK From 515e76f92e4889128a19a4de5249a6809a2d8d60 Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Fri, 24 Jul 2026 16:06:55 +0300 Subject: [PATCH 4/7] Implement eview and esave commands for st25ta --- client/src/cmdhfst25ta.c | 211 +++++++++++++++++++++++++++++++- client/src/pm3line_vocabulary.h | 2 + 2 files changed, 211 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhfst25ta.c b/client/src/cmdhfst25ta.c index e845529d3..25e271118 100644 --- a/client/src/cmdhfst25ta.c +++ b/client/src/cmdhfst25ta.c @@ -338,17 +338,80 @@ static int CmdHFST25TAInfo(const char *Cmd) { return infoHFST25TA(); } +static int st25ta_ndef_records_len(const uint8_t *data, size_t data_len, size_t *records_len) { + if (data == NULL || records_len == NULL || data_len < 3) { + return PM3_EINVARG; + } + + size_t offset = 0; + for (;;) { + if (offset + 3 > data_len) { + return PM3_ESOFT; + } + + uint8_t flags = data[offset]; + uint8_t type_len = data[offset + 1]; + bool short_record = (flags & 0x10) != 0; + bool id_length_present = (flags & 0x08) != 0; + bool message_end = (flags & 0x40) != 0; + size_t header_len = short_record ? 3 : 6; + uint32_t payload_len = 0; + + if (short_record) { + payload_len = data[offset + 2]; + } else { + if (offset + 6 > data_len) { + return PM3_ESOFT; + } + payload_len = (data[offset + 2] << 24) | + (data[offset + 3] << 16) | + (data[offset + 4] << 8) | + data[offset + 5]; + } + + uint8_t id_len = 0; + if (id_length_present) { + if (offset + header_len >= data_len) { + return PM3_ESOFT; + } + id_len = data[offset + header_len]; + header_len++; + } + + size_t record_len = header_len + type_len + id_len + payload_len; + if (record_len == 0 || offset + record_len > data_len) { + return PM3_ESOFT; + } + + offset += record_len; + if (message_end) { + *records_len = offset; + return PM3_SUCCESS; + } + } +} + static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t *dst, uint16_t *dst_len) { if (src == NULL || src_len == 0 || dst == NULL || dst_len == NULL) { return PM3_EINVARG; } if (src_len >= 4 && src[src_len - 2] == 0x90 && src[src_len - 1] == 0x00) { + uint16_t nlen = (src[0] << 8) | src[1]; + if (nlen + 4 != src_len) { + nlen = src_len - 4; + } + if (src_len > ST25TA_EML_NDEF_MAX) { PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_EML_NDEF_MAX); return PM3_EINVARG; } - memcpy(dst, src, src_len); + + dst[0] = (nlen >> 8) & 0xff; + dst[1] = nlen & 0xff; + memcpy(dst + 2, src + 2, src_len - 4); + dst[src_len - 2] = 0x90; + dst[src_len - 1] = 0x00; *dst_len = src_len; return PM3_SUCCESS; } @@ -360,7 +423,10 @@ static int st25ta_normalize_sim_ndef(const uint8_t *src, size_t src_len, uint8_t PrintAndLogEx(ERR, "NDEF response too large. Max %u bytes", ST25TA_EML_NDEF_MAX); return PM3_EINVARG; } - memcpy(dst, src, src_len); + + dst[0] = (nlen >> 8) & 0xff; + dst[1] = nlen & 0xff; + memcpy(dst + 2, src + 2, nlen); dst[src_len] = 0x90; dst[src_len + 1] = 0x00; *dst_len = src_len + 2; @@ -406,6 +472,45 @@ static int st25ta_upload_sim_data(const uint8_t *uid, uint8_t uid_len, const uin return PM3_SUCCESS; } +static int st25ta_download_sim_data(uint8_t *uid, uint8_t *uid_len, uint8_t *ndef, uint16_t *ndef_len) { + uint8_t header[ST25TA_EML_DATA_OFFSET] = {0}; + int res = mf_eml_get_mem_xt(header, 0, sizeof(header), 1); + if (res != PM3_SUCCESS) { + return res; + } + + if (memcmp(header + ST25TA_EML_MAGIC_OFFSET, ST25TA_EML_MAGIC, 4) != 0) { + PrintAndLogEx(ERR, "No ST25TA data loaded in emulator memory"); + return PM3_ESOFT; + } + + uint16_t len = header[ST25TA_EML_LEN_OFFSET] | + (header[ST25TA_EML_LEN_OFFSET + 1] << 8); + if (len == 0 || len > ST25TA_EML_NDEF_MAX) { + PrintAndLogEx(ERR, "Invalid ST25TA NDEF response length in emulator memory: %u", len); + return PM3_ESOFT; + } + + if (uid_len != NULL) { + *uid_len = header[ST25TA_EML_UIDLEN_OFFSET]; + } + if (uid != NULL && header[ST25TA_EML_UIDLEN_OFFSET] == 7) { + memcpy(uid, header + ST25TA_EML_UID_OFFSET, 7); + } + + for (uint16_t offset = 0; offset < len;) { + uint8_t chunk_len = MIN(len - offset, UINT8_MAX); + res = mf_eml_get_mem_xt(ndef + offset, ST25TA_EML_DATA_OFFSET + offset, chunk_len, 1); + if (res != PM3_SUCCESS) { + return res; + } + offset += chunk_len; + } + + *ndef_len = len; + return PM3_SUCCESS; +} + static int CmdHFST25TAELoad(const char *Cmd) { int uidlen = 0; uint8_t uid[7] = {0}; @@ -484,6 +589,106 @@ static int CmdHFST25TAELoad(const char *Cmd) { return PM3_SUCCESS; } +static int CmdHFST25TAEView(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf st25ta eview", + "Display ST25TA emulator memory", + "hf st25ta eview\n" + "hf st25ta eview -v\n"); + + void *argtable[] = { + arg_param_begin, + arg_lit0("v", "verbose", "verbose NDEF output"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool verbose = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + uint8_t uid[7] = {0}; + uint8_t uid_len = 0; + uint8_t ndef[ST25TA_EML_NDEF_MAX] = {0}; + uint16_t ndef_len = 0; + int res = st25ta_download_sim_data(uid, &uid_len, ndef, &ndef_len); + if (res != PM3_SUCCESS) { + return res; + } + + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "--- " _CYAN_("ST25TA emulator memory") " ----------------"); + if (uid_len == 7) { + PrintAndLogEx(INFO, "UID................ " _YELLOW_("%s"), sprint_hex_inrow(uid, uid_len)); + } else { + PrintAndLogEx(INFO, "UID................ " _YELLOW_("not loaded")); + } + PrintAndLogEx(INFO, "NDEF response len.. " _YELLOW_("%u") " bytes", ndef_len); + PrintAndLogEx(INFO, "NDEF response raw:"); + print_buffer(ndef, ndef_len, 1); + + if (ndef_len >= 4 && ndef[ndef_len - 2] == 0x90 && ndef[ndef_len - 1] == 0x00) { + uint16_t nlen = (ndef[0] << 8) | ndef[1]; + size_t records_len = ndef_len - 4; + if (nlen <= records_len) { + records_len = nlen; + } + + size_t calculated_len = 0; + if (st25ta_ndef_records_len(ndef + 2, records_len, &calculated_len) == PM3_SUCCESS && + calculated_len < records_len) { + records_len = calculated_len; + } + + PrintAndLogEx(INFO, "--- " _CYAN_("NDEF records") " --------------------------"); + NDEFRecordsDecodeAndPrint(ndef + 2, records_len, verbose); + } + + return PM3_SUCCESS; +} + +static int CmdHFST25TAESave(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf st25ta esave", + "Save ST25TA emulator memory NDEF response to file", + "hf st25ta esave\n" + "hf st25ta esave -f hf-st25ta-ndef\n"); + + void *argtable[] = { + arg_param_begin, + arg_str0("f", "file", "", "Specify a filename for dump file"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + char filename[FILE_PATH_SIZE] = {0}; + int fnlen = 0; + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); + CLIParserFree(ctx); + + if (fnlen == 0) { + snprintf(filename, sizeof(filename), "hf-st25ta-ndef"); + } + + uint8_t ndef[ST25TA_EML_NDEF_MAX] = {0}; + uint16_t ndef_len = 0; + int res = st25ta_download_sim_data(NULL, NULL, ndef, &ndef_len); + if (res != PM3_SUCCESS) { + return res; + } + + if (ndef_len < 4 || ndef[ndef_len - 2] != 0x90 || ndef[ndef_len - 1] != 0x00) { + PrintAndLogEx(ERR, "Loaded ST25TA data is not a READ BINARY response ending in 9000"); + return PM3_ESOFT; + } + + uint16_t nlen = (ndef[0] << 8) | ndef[1]; + if (nlen == 0 || nlen + 4 > ndef_len) { + PrintAndLogEx(ERR, "Invalid ST25TA NLEN in emulator memory: %u", nlen); + return PM3_ESOFT; + } + + return pm3_save_dump(filename, ndef + 2, nlen, jsfNDEF); +} + static int CmdHFST25TASim(const char *Cmd) { int uidlen = 0; uint8_t uid[7] = {0}; @@ -978,6 +1183,8 @@ static int CmdHFST25TAList(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"eload", CmdHFST25TAELoad, IfPm3Iso14443a, "Upload NDEF response into emulator memory"}, + {"esave", CmdHFST25TAESave, IfPm3Iso14443a, "Save emulator memory to file"}, + {"eview", CmdHFST25TAEView, IfPm3Iso14443a, "View emulator memory"}, {"info", CmdHFST25TAInfo, IfPm3Iso14443a, "Tag information"}, {"list", CmdHFST25TAList, AlwaysAvailable, "List ISO 14443A/7816 history"}, {"ndefread", CmdHFST25TANdefRead, AlwaysAvailable, "read NDEF file on tag"}, diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 31a298b6f..81cd5c730 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -636,6 +636,8 @@ const static vocabulary_t vocabulary[] = { { 0, "hf st25ta pwd" }, { 0, "hf st25ta sim" }, { 0, "hf st25ta eload" }, + { 0, "hf st25ta esave" }, + { 0, "hf st25ta eview" }, { 1, "hf tesla help" }, { 0, "hf tesla info" }, { 1, "hf tesla list" }, From 4b67c017a210791debd4191de77e2054a73aa7df Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Fri, 24 Jul 2026 17:02:35 +0300 Subject: [PATCH 5/7] make style --- client/src/pm3line_vocabulary.h | 6 ++-- doc/commands.json | 56 ++++++++++++++++++++++++++++++--- doc/commands.md | 3 ++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 81cd5c730..b872b9413 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -629,15 +629,15 @@ const static vocabulary_t vocabulary[] = { { 0, "hf seos sim" }, { 1, "hf seos managekeys" }, { 1, "hf st25ta help" }, + { 0, "hf st25ta eload" }, + { 0, "hf st25ta esave" }, + { 0, "hf st25ta eview" }, { 0, "hf st25ta info" }, { 1, "hf st25ta list" }, { 1, "hf st25ta ndefread" }, { 0, "hf st25ta protect" }, { 0, "hf st25ta pwd" }, { 0, "hf st25ta sim" }, - { 0, "hf st25ta eload" }, - { 0, "hf st25ta esave" }, - { 0, "hf st25ta eview" }, { 1, "hf tesla help" }, { 0, "hf tesla info" }, { 1, "hf tesla list" }, diff --git a/doc/commands.json b/doc/commands.json index 034d60691..b7635bd09 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -10227,13 +10227,58 @@ ], "usage": "hf sniff [-h] [--sp ] [--st ] [--smode [none|drop|min|max|avg]] [--sratio ]" }, + "hf st25ta esave": { + "command": "hf st25ta esave", + "description": "Save ST25TA emulator memory NDEF response to file", + "notes": [ + "hf st25ta esave", + "hf st25ta esave -f hf-st25ta-ndef" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-f, --file Specify a filename for dump file" + ], + "usage": "hf st25ta esave [-h] [-f ]" + }, + "hf st25ta eview": { + "command": "hf st25ta eview", + "description": "Display ST25TA emulator memory", + "notes": [ + "hf st25ta eview", + "hf st25ta eview -v" + ], + "offline": false, + "options": [ + "-h, --help This help", + "-v, --verbose verbose NDEF output" + ], + "usage": "hf st25ta eview [-hv]" + }, "hf st25ta help": { "command": "hf st25ta help", - "description": "help This help list List ISO 14443A/7816 history ndefread read NDEF file on tag --------------------------------------------------------------------------------------- hf st25ta info available offline: no Get info about ST25TA tag", + "description": "help This help list List ISO 14443A/7816 history ndefread read NDEF file on tag --------------------------------------------------------------------------------------- hf st25ta eload available offline: no Load ST25TA NDEF response into emulator memory", + "notes": [ + "hf st25ta eload --ndef 001BD1011754027A68A234CBD0E203C73E620BE8C63C852CC5313131329000", + "hf st25ta eload -f my-ndef.bin", + "hf st25ta eload -u 02E2007D0FCA4C -f my-ndef.bin" + ], + "offline": true, + "options": [ + "-h, --help This help", + "-u, --uid optional 7 byte UID to store for simulation", + "--ndef NDEF data or full READ BINARY response", + "-f, --file load NDEF data or full READ BINARY response from file" + ], + "usage": "hf st25ta eload [-h] [-u ] [--ndef ] [-f ]" + }, + "hf st25ta info": { + "command": "hf st25ta info", + "description": "Get info about ST25TA tag", "notes": [ "hf st25ta info" ], - "offline": true, + "offline": false, "options": [ "-h, --help This help" ], @@ -10313,16 +10358,17 @@ }, "hf st25ta sim": { "command": "hf st25ta sim", - "description": "Emulating ST25TA512B tag with 7 byte UID", + "description": "Emulating ST25TA512B tag. Uses NDEF data from `hf st25ta eload` if loaded.", "notes": [ - "hf st25ta sim -u 02E2007D0FCA4C" + "hf st25ta sim -u 02E2007D0FCA4C", + "hf st25ta sim" ], "offline": false, "options": [ "-h, --help This help", "-u, --uid 7 byte UID" ], - "usage": "hf st25ta sim [-h] -u " + "usage": "hf st25ta sim [-h] [-u ]" }, "hf tesla help": { "command": "hf tesla help", diff --git a/doc/commands.md b/doc/commands.md index a19c0ff3f..7c281657d 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -896,6 +896,9 @@ Check column "offline" for their availability. |command |offline |description |------- |------- |----------- |`hf st25ta help `|Y |`This help` +|`hf st25ta eload `|N |`Upload NDEF response into emulator memory` +|`hf st25ta esave `|N |`Save emulator memory to file` +|`hf st25ta eview `|N |`View emulator memory` |`hf st25ta info `|N |`Tag information` |`hf st25ta list `|Y |`List ISO 14443A/7816 history` |`hf st25ta ndefread `|Y |`read NDEF file on tag` From 8006ab05da8f9cf0ffa627d443d13ed1a3cd5eed Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Thu, 20 Aug 2026 20:56:21 +0300 Subject: [PATCH 6/7] Remove nonexisting includes after HAL rebase --- armsrc/appmain.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index f8feabe4a..ad1e5673a 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -26,9 +26,7 @@ #include "bwm_uart_at32.h" #include "bwm_wifi.h" #endif -#include "clocks.h" #include "pm3_cmd.h" -#include "usb_cdc.h" #include "proxmark3_arm.h" #include "dbprint.h" #include "pmflash.h" From b9c65e2d43f49b2e7ed43130c564fb41fafdfb1f Mon Sep 17 00:00:00 2001 From: Sanduuz Date: Fri, 28 Aug 2026 19:27:50 +0300 Subject: [PATCH 7/7] Remove generated vocabulary changes --- client/src/pm3line_vocabulary.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index b872b9413..6f98e05d4 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -629,9 +629,6 @@ const static vocabulary_t vocabulary[] = { { 0, "hf seos sim" }, { 1, "hf seos managekeys" }, { 1, "hf st25ta help" }, - { 0, "hf st25ta eload" }, - { 0, "hf st25ta esave" }, - { 0, "hf st25ta eview" }, { 0, "hf st25ta info" }, { 1, "hf st25ta list" }, { 1, "hf st25ta ndefread" },