diff --git a/CHANGELOG.md b/CHANGELOG.md index 643ce9e79..074cd9b2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added `hf thinfilm sniff` - passively records the frames a Thinfilm / NFC Barcode tag beams at a reader (@iceman1001) - Fixed `hf thinfilm sim` - it now holds the genuine tag's measured 65536 carrier period frame rate instead of a fixed delay (@iceman1001) - Changed `mem spiffs upload`/`mem spiffs dump` - both now print inline progress, and a refused write is reported with the byte it stopped at instead of claiming success (@iceman1001) +- Changed real-time LF sample reads `lf read`, `lf sniff`, `lf cotag reader`(@iceman1001) +- Changed the `INPLACE` spinner prefix (@iceman1001) - Fixed `mem spiffs dump` - a file of 64K or more wrapped the uint16_t `BigBuf_calloc()` takes, the download now streams one frame at a time (@iceman1001) - Fixed SPIFFS flash layer - a failed erase was reported to SPIFFS as success, letting it write into an un-erased sector where NOR AND-semantics silently mangled file data (@iceman1001) - Fixed `hf thinfilm sim` - a 32 sample field read between every frame cost 3.8ms and nearly doubled the frame repeat period (@iceman1001) diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 245853457..b2bb0ad7e 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -93,7 +93,7 @@ int CmdHFSearch(const char *Cmd) { uint8_t success[COUNT_OF_PROTOCOLS] = {0}; PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for ThinFilm tag..."); + PrintAndLogEx(INPLACE, "Searching for ThinFilm tag..."); if (IfPm3NfcBarcode()) { if (infoThinFilm(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n"); @@ -103,7 +103,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for Topaz tag..."); + PrintAndLogEx(INPLACE, "Searching for Topaz tag..."); if (IfPm3Iso14443a()) { if (readTopazUid(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n"); @@ -113,7 +113,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for LTO-CM tag..."); + PrintAndLogEx(INPLACE, "Searching for LTO-CM tag..."); if (IfPm3Iso14443a()) { if (reader_lto(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LTO-CM tag") " found\n"); @@ -123,7 +123,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for ISO14443-A tag..."); + PrintAndLogEx(INPLACE, "Searching for ISO14443-A tag..."); if (IfPm3Iso14443a()) { int sel_state = infoHF14A(false, false, false); if (sel_state > 0) { @@ -152,7 +152,7 @@ int CmdHFSearch(const char *Cmd) { */ PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for LEGIC tag..."); + PrintAndLogEx(INPLACE, "Searching for LEGIC tag..."); if (IfPm3Legicrf()) { if (readLegicUid(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LEGIC Prime tag") " found\n"); @@ -163,7 +163,7 @@ int CmdHFSearch(const char *Cmd) { // texkom PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for TEXKOM tag..."); + PrintAndLogEx(INPLACE, "Searching for TEXKOM tag..."); if (read_texkom_uid(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("TEXKOM tag") " found\n"); success[PROTO_TEXKOM] = true; @@ -172,7 +172,7 @@ int CmdHFSearch(const char *Cmd) { // xerox PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for Fuji/Xerox tag..."); + PrintAndLogEx(INPLACE, "Searching for Fuji/Xerox tag..."); if (IfPm3Iso14443b()) { if (read_xerox_uid(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Fuji/Xerox tag") " found\n"); @@ -183,7 +183,7 @@ int CmdHFSearch(const char *Cmd) { // 14b is the longest test PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for ISO14443-B tag..."); + PrintAndLogEx(INPLACE, "Searching for ISO14443-B tag..."); if (IfPm3Iso14443b()) { if (readHF14B(false, false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 14443-B tag") " found\n"); @@ -195,7 +195,7 @@ int CmdHFSearch(const char *Cmd) { // OBS! This triggers a swap to FPGA_BITSTREAM_HF_15 == 1.5sec delay PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for ISO15693 tag..."); + PrintAndLogEx(INPLACE, "Searching for ISO15693 tag..."); if (IfPm3Iso15693()) { if (readHF15Uid(false, true)) { PrintAndLogEx(SUCCESS, "Valid " _GREEN_("ISO 15693 tag") " found\n"); @@ -205,7 +205,7 @@ int CmdHFSearch(const char *Cmd) { } PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for iCLASS / PicoPass tag..."); + PrintAndLogEx(INPLACE, "Searching for iCLASS / PicoPass tag..."); if (IfPm3Iclass()) { if (read_iclass_csn(false, false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("iCLASS tag / PicoPass tag") " found\n"); @@ -217,7 +217,7 @@ int CmdHFSearch(const char *Cmd) { // OBS! This triggers a swap to FPGA_BITSTREAM_HF_FELICA == 1.5sec delay PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for FeliCa tag..."); + PrintAndLogEx(INPLACE, "Searching for FeliCa tag..."); if (IfPm3Felica()) { if (read_felica_uid(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 18092 / FeliCa tag") " found\n"); @@ -232,7 +232,7 @@ int CmdHFSearch(const char *Cmd) { /* PROMPT_CLEARLINE; - PrintAndLogEx(INPLACE, " Searching for CryptoRF tag..."); + PrintAndLogEx(INPLACE, "Searching for CryptoRF tag..."); if (IfPm3Iso14443b()) { if (readHFCryptoRF(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("CryptoRF tag") " found\n"); diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 2166159f4..a5fb913e5 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -4315,9 +4315,9 @@ static int CmdHFiClass_TearBlock(const char *Cmd) { } if (tearoff_loop > 1) { - PrintAndLogEx(INPLACE, " Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us - "_YELLOW_("%3u")" iter", params.delay_us, (tearoff_end & 0xFFFF), loop_count + 1); + PrintAndLogEx(INPLACE, "Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us - "_YELLOW_("%3u")" iter", params.delay_us, (tearoff_end & 0xFFFF), loop_count + 1); } else { - PrintAndLogEx(INPLACE, " Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us", params.delay_us, (tearoff_end & 0xFFFF)); + PrintAndLogEx(INPLACE, "Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us", params.delay_us, (tearoff_end & 0xFFFF)); } // write block - don't check the return value. As a tear-off occurred, the write failed. @@ -4814,9 +4814,9 @@ static int CmdHFiClass_BlackTears(const char *Cmd) { } if (tearoff_loop > 1) { - PrintAndLogEx(INPLACE, " Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us - "_YELLOW_("%3u")" iter", params.delay_us, (tearoff_end & 0xFFFF), loop_count + 1); + PrintAndLogEx(INPLACE, "Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us - "_YELLOW_("%3u")" iter", params.delay_us, (tearoff_end & 0xFFFF), loop_count + 1); } else { - PrintAndLogEx(INPLACE, " Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us", params.delay_us, (tearoff_end & 0xFFFF)); + PrintAndLogEx(INPLACE, "Tear off delay "_YELLOW_("%u")" / "_YELLOW_("%d")" us", params.delay_us, (tearoff_end & 0xFFFF)); } // write block - don't check the return value. As a tear-off occurred, the write failed. diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index fc918c4d5..5ad11c440 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -6873,7 +6873,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) { post_tear_check = (post_tear == 0xBD); a = (pre[0] | pre[1] << 8 | pre[2] << 16); b = (post[0] | post[1] << 8 | post[2] << 16); - PrintAndLogEx(INPLACE, " Delay: " _YELLOW_("%d") " Tear: %s Counter: " _YELLOW_("%s") "" + PrintAndLogEx(INPLACE, "Delay: " _YELLOW_("%d") " Tear: %s Counter: " _YELLOW_("%s") "" , delay_bd , sprint_hex_inrow(tear, sizeof(tear)) , poststr @@ -6984,7 +6984,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) { post_tear_check = (post_tear == 0xBD); - PrintAndLogEx(INPLACE, " Delay: " _YELLOW_("%d") " Tear: %s Counter: " _YELLOW_("%s") "" + PrintAndLogEx(INPLACE, "Delay: " _YELLOW_("%d") " Tear: %s Counter: " _YELLOW_("%s") "" , delay_00 , sprint_hex_inrow(tear, sizeof(tear)) , poststr diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 26fb3d83f..ed262118e 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -831,7 +831,11 @@ static int lf_read_internal(bool realtime, bool verbose, uint64_t samples, bool sample_bytes = WaitForRawDataTimeout(realtimeBuf, sample_bytes, 1000, true, false); } samples = sample_bytes * 8 / bits_per_sample; - PrintAndLogEx(INFO, "Done: %" PRIu64 " samples (%zu bytes)", samples, sample_bytes); + // the inline "Received x / y bytes" counter already says the transfer is + // done, so only repeat it in samples when asked + if (verbose) { + PrintAndLogEx(INFO, "Done: %" PRIu64 " samples (%zu bytes)", samples, sample_bytes); + } if (samples != 0) { getSamplesFromBufEx(realtimeBuf, samples, bits_per_sample, verbose); } @@ -966,7 +970,11 @@ int lf_sniff(bool realtime, bool verbose, uint64_t samples) { sample_bytes = WaitForRawDataTimeout(realtimeBuf, sample_bytes, 1000, true, false); } samples = sample_bytes * 8 / bits_per_sample; - PrintAndLogEx(INFO, "Done: %" PRIu64 " samples (%zu bytes)", samples, sample_bytes); + // the inline "Received x / y bytes" counter already says the transfer is + // done, so only repeat it in samples when asked + if (verbose) { + PrintAndLogEx(INFO, "Done: %" PRIu64 " samples (%zu bytes)", samples, sample_bytes); + } if (samples != 0) { getSamplesFromBufEx(realtimeBuf, samples, bits_per_sample, verbose); } diff --git a/client/src/cmdlfcotag.c b/client/src/cmdlfcotag.c index 5ef8b9b28..e6d81fa8d 100644 --- a/client/src/cmdlfcotag.c +++ b/client/src/cmdlfcotag.c @@ -512,6 +512,9 @@ static int CmdCOTAGReader(const char *Cmd) { } if (cm || realtime) { + // close any inline line the caller left open, ie: `lf search` printing + // "Searching for COTAG tag..." right before this + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); } diff --git a/client/src/cmdlfhitaghts.c b/client/src/cmdlfhitaghts.c index d2a697dfc..2f52823f8 100644 --- a/client/src/cmdlfhitaghts.c +++ b/client/src/cmdlfhitaghts.c @@ -765,7 +765,7 @@ static int CmdLFHitagSRestore(const char *Cmd) { packet.page = page; memcpy(packet.data, &dump_bytes[offset], HITAGS_PAGE_SIZE); - PrintAndLogEx(INPLACE, " Writing page "_YELLOW_("%d")", data: " _GREEN_("%02X %02X %02X %02X"), page, + PrintAndLogEx(INPLACE, "Writing page "_YELLOW_("%d")", data: " _GREEN_("%02X %02X %02X %02X"), page, dump_bytes[offset], dump_bytes[offset + 1], dump_bytes[offset + 2], diff --git a/client/src/comms.c b/client/src/comms.c index 59755cff0..7c54e17bf 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -78,7 +78,7 @@ static uint64_t timeout_start_time; static uint64_t last_packet_time; -static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd, uint32_t req_cmd); +static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, size_t ms_timeout, bool show_warning, bool show_progress, uint32_t rec_cmd, uint32_t req_cmd); // Wait until the comm thread has actually put a queued command on the wire. // Callers used to sleep a fixed guess instead, which was reasonable when a @@ -1047,8 +1047,9 @@ static size_t communication_delay(void) { * @return the number of received bytes */ size_t WaitForRawDataTimeout(uint8_t *buffer, size_t len, size_t ms_timeout, bool show_process, bool keep_raw_mode) { - uint8_t print_counter = 0; size_t last_pos = 0; + uint64_t last_update = 0; + bool printed_progress = false; // Add delay depending on the communication channel & speed if (ms_timeout != (size_t) - 1) { @@ -1084,16 +1085,26 @@ size_t WaitForRawDataTimeout(uint8_t *buffer, size_t len, size_t ms_timeout, boo break; } } else { - // Print process when (print_counter % 64) == 0 - if (show_process && (print_counter & 0x3F) == 0) { - PrintAndLogEx(INFO, "[%zu/%zu]", pos, len); + // one line that updates in place, not a line per update + if (show_process && ((msclock() - last_update > 100) || (pos == len))) { + PrintAndLogEx(INPLACE, "Received " _YELLOW_("%zu") " / " _YELLOW_("%zu") " bytes (" _YELLOW_("%zu") "%%)" + , pos + , len + , (pos * 100) / len + ); + last_update = msclock(); + printed_progress = true; } } - print_counter++; last_pos = pos; msleep(10); } + + if (printed_progress) { + PrintAndLogEx(NORMAL, ""); + } + if (pos == len && (ms_timeout != (size_t) - 1) && (keep_raw_mode == false)) { // If ms_timeout != -1, when the desired data is received, tell the arm side // to stop the current process, and wait for some time to make sure the process @@ -1228,12 +1239,12 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3 case BIG_BUF: { download_req_t req = { .start_index = start_index, .bytes = bytes }; SendCommandNG(CMD_DOWNLOAD_BIGBUF, (uint8_t *)&req, sizeof(req)); - return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_BIGBUF, CMD_DOWNLOAD_BIGBUF); + return dl_it(dest, bytes, response, ms_timeout, show_warning, false, CMD_DOWNLOADED_BIGBUF, CMD_DOWNLOAD_BIGBUF); } case BIG_BUF_EML: { download_req_t req = { .start_index = start_index, .bytes = bytes }; SendCommandNG(CMD_DOWNLOAD_EML_BIGBUF, (uint8_t *)&req, sizeof(req)); - return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF, CMD_DOWNLOAD_EML_BIGBUF); + return dl_it(dest, bytes, response, ms_timeout, show_warning, false, CMD_DOWNLOADED_EML_BIGBUF, CMD_DOWNLOAD_EML_BIGBUF); } case SPIFFS: { uint8_t sbuf[PM3_CMD_DATA_SIZE] = {0}; @@ -1244,40 +1255,42 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3 memcpy(sreq->data, data, datalen); } SendCommandNG(CMD_SPIFFS_DOWNLOAD, sbuf, sizeof(download_req_t) + datalen); - return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_SPIFFS_DOWNLOADED, CMD_SPIFFS_DOWNLOAD); + return dl_it(dest, bytes, response, ms_timeout, show_warning, true, CMD_SPIFFS_DOWNLOADED, CMD_SPIFFS_DOWNLOAD); } case FLASH_MEM: { download_req_t req = { .start_index = start_index, .bytes = bytes }; SendCommandNG(CMD_FLASHMEM_DOWNLOAD, (uint8_t *)&req, sizeof(req)); - return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED, CMD_FLASHMEM_DOWNLOAD); + return dl_it(dest, bytes, response, ms_timeout, show_warning, true, CMD_FLASHMEM_DOWNLOADED, CMD_FLASHMEM_DOWNLOAD); } case SIM_MEM: { //SendCommandNG(CMD_DOWNLOAD_SIM_MEM, (uint8_t *)&req, sizeof(req)); - //return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM); + //return dl_it(dest, bytes, response, ms_timeout, show_warning, false, CMD_DOWNLOADED_SIMMEM); return false; } case FPGA_MEM: { SendCommandNG(CMD_FPGAMEM_DOWNLOAD, NULL, 0); - return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_FPGAMEM_DOWNLOADED, CMD_FPGAMEM_DOWNLOAD); + return dl_it(dest, bytes, response, ms_timeout, show_warning, false, CMD_FPGAMEM_DOWNLOADED, CMD_FPGAMEM_DOWNLOAD); } case MCU_FLASH: case MCU_MEM: { uint32_t flags = (memtype == MCU_MEM) ? READ_MEM_DOWNLOAD_FLAG_RAW : 0; SendCommandBL(CMD_READ_MEM_DOWNLOAD, start_index, bytes, flags, NULL, 0); - return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_READ_MEM_DOWNLOADED, CMD_READ_MEM_DOWNLOAD); + return dl_it(dest, bytes, response, ms_timeout, show_warning, true, CMD_READ_MEM_DOWNLOADED, CMD_READ_MEM_DOWNLOAD); } } return false; } -static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd, uint32_t req_cmd) { +static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, size_t ms_timeout, bool show_warning, bool show_progress, uint32_t rec_cmd, uint32_t req_cmd) { uint32_t bytes_completed = 0; __atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST); - // inline feedback. Small transfers finish before a line could be read, so - // only the ones that actually take time say anything - const bool show_progress = (bytes > 4096); + // Inline feedback, only for the flash backed transfers the caller asked it + // for. BigBuf reads are a memcpy over USB and every command does them, so + // a progress line there is just noise. Small transfers finish before a + // line could be read. + show_progress = (show_progress && (bytes > 4096)); uint64_t last_update = 0; // Add delay depending on the communication channel & speed diff --git a/client/src/ui.c b/client/src/ui.c index 1a5f81a7b..265fbd598 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -288,7 +288,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) { char *token = NULL; char *tmp_ptr = NULL; FILE *stream = stdout; - const char *spinner[] = {_YELLOW_("[\\]"), _YELLOW_("[|]"), _YELLOW_("[/]"), _YELLOW_("[-]")}; + const char *spinner[] = {_YELLOW_("[\\]") " ", _YELLOW_("[|]") " ", _YELLOW_("[/]") " ", _YELLOW_("[-]") " "}; const char *spinner_emoji[] = {" :clock1: ", " :clock2: ", " :clock3: ", " :clock4: ", " :clock5: ", " :clock6: ", " :clock7: ", " :clock8: ", " :clock9: ", " :clock10: ", " :clock11: ", " :clock12: " };