From 1df51f38753fe9c61a8ecc12daf7e4ceb5003e55 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 30 Jul 2022 15:42:07 +0200 Subject: [PATCH] add hf lto reader command with continious mode --- client/src/cmdhf.c | 2 +- client/src/cmdhflto.c | 71 ++++++++++++++++++++++++++++++++++++++++--- client/src/cmdhflto.h | 1 + 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 44b9b078f..d1628a054 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -92,7 +92,7 @@ int CmdHFSearch(const char *Cmd) { PROMPT_CLEARLINE; PrintAndLogEx(INPLACE, " Searching for LTO-CM tag..."); if (IfPm3Iso14443a()) { - if (infoLTO(false) == PM3_SUCCESS) { + if (reader_lto(false, false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LTO-CM tag") " found\n"); res = PM3_SUCCESS; } diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index a0e6d00f8..1bdc7ac1a 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -385,6 +385,65 @@ static void lto_print_mmi(uint8_t *d) { // - Application Specific Data (1056b) // - Suspended Append Writes (128b) +static int CmdHFLTOReader(const char *Cmd) { + + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto reader", + "Act as a LTO-CM reader. Look for LTO-CM tags until Enter or the pm3 button is pressed", + "hf lto reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + if (cm) { + PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + } + + return reader_lto(cm, true); +} + +int reader_lto(bool loop, bool verbose) { + + int ret = PM3_SUCCESS; + + do { + uint8_t serial[5]; + uint8_t serial_len = sizeof(serial); + uint8_t type_info[2]; + + lto_switch_off_field(); + lto_switch_on_field(); + clearCommandBuffer(); + + ret = lto_select(serial, serial_len, type_info, verbose); + if (loop) { + if (ret != PM3_SUCCESS) { + continue; + } + } + + if (ret == PM3_SUCCESS) { + + if (loop == false) { + PrintAndLogEx(NORMAL, ""); + } + + PrintAndLogEx(INFO, "UID......... " _GREEN_("%s"), sprint_hex_inrow(serial, sizeof(serial))); + } + + } while (loop && kbd_enter_pressed() == false); + + lto_switch_off_field(); + return ret; +} + int infoLTO(bool verbose) { clearCommandBuffer(); @@ -397,6 +456,7 @@ int infoLTO(bool verbose) { int ret_val = lto_select(serial_number, serial_len, type_info, verbose); if (verbose == false) { if (ret_val == PM3_SUCCESS) { + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "UID......... " _YELLOW_("%s"), sprint_hex_inrow(serial_number, sizeof(serial_number))); } lto_switch_off_field(); @@ -801,12 +861,13 @@ static int CmdHfLTRestore(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"dump", CmdHfLTODump, IfPm3Iso14443a, "Dump LTO-CM tag to file"}, - {"restore", CmdHfLTRestore, IfPm3Iso14443a, "Restore dump file to LTO-CM tag"}, - {"info", CmdHfLTOInfo, IfPm3Iso14443a, "Tag information"}, - {"rdbl", CmdHfLTOReadBlock, IfPm3Iso14443a, "Read block"}, - {"wrbl", CmdHfLTOWriteBlock, IfPm3Iso14443a, "Write block"}, + {"dump", CmdHfLTODump, IfPm3Iso14443a, "Dump LTO-CM tag to file"}, + {"info", CmdHfLTOInfo, IfPm3Iso14443a, "Tag information"}, {"list", CmdHfLTOList, AlwaysAvailable, "List LTO-CM history"}, + {"rdbl", CmdHfLTOReadBlock, IfPm3Iso14443a, "Read block"}, + {"reader", CmdHFLTOReader, IfPm3Iso14443a, "Act like a LTO-CM reader"}, + {"restore", CmdHfLTRestore, IfPm3Iso14443a, "Restore dump file to LTO-CM tag"}, + {"wrbl", CmdHfLTOWriteBlock, IfPm3Iso14443a, "Write block"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdhflto.h b/client/src/cmdhflto.h index beade8fa9..3c9b310a4 100644 --- a/client/src/cmdhflto.h +++ b/client/src/cmdhflto.h @@ -21,6 +21,7 @@ #include "common.h" +int reader_lto(bool loop, bool verbose); int infoLTO(bool verbose); int dumpLTO(uint8_t *dump, bool verbose); int restoreLTO(uint8_t *dump, bool verbose);