From 4fb096966e3470315830d21551f37bf923214191 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 20 Nov 2022 16:34:45 +0100 Subject: [PATCH] extra checks for argument parsing of ints. And some text updates. There are other int parsing but they are checked with mandatory param int1 --- client/src/cmdhf14a.c | 11 ++++++++--- client/src/cmdhficlass.c | 2 +- client/src/cmdhfmfp.c | 16 ++++++++-------- client/src/cmdhfmfu.c | 4 ++-- client/src/cmdhw.c | 2 +- client/src/cmdlfem4x70.c | 8 ++++---- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index f8a96fedd..4c2498a85 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -670,7 +670,7 @@ int CmdHF14ASim(const char *Cmd) { "hf 14a sim -t 4 -> ISO/IEC 14443-4\n" "hf 14a sim -t 5 -> MIFARE Tnp3xxx\n" "hf 14a sim -t 6 -> MIFARE Mini\n" - "hf 14a sim -t 7 -> MFUEV1 / NTAG 215 Amiibo\n" + "hf 14a sim -t 7 -> MFU EV1 / NTAG 215 Amiibo\n" "hf 14a sim -t 8 -> MIFARE Classic 4k\n" "hf 14a sim -t 9 -> FM11RF005SH Shanghai Metro\n" "hf 14a sim -t 10 -> ST25TA IKEA Rothult\n"); @@ -687,7 +687,7 @@ int CmdHF14ASim(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, false); - int tagtype = arg_get_int(ctx, 1); + int tagtype = arg_get_int_def(ctx, 1, 1); int uid_len = 0; uint8_t uid[10] = {0}; @@ -727,6 +727,11 @@ int CmdHF14ASim(const char *Cmd) { CLIParserFree(ctx); + if (tagtype > 10) { + PrintAndLogEx(ERR, "Undefined tag %d", tagtype); + return PM3_EINVARG; + } + sector_t *k_sector = NULL; uint8_t k_sectorsCount = 40; @@ -752,7 +757,7 @@ int CmdHF14ASim(const char *Cmd) { PrintAndLogEx(INFO, "Press pm3-button to abort simulation"); bool keypress = kbd_enter_pressed(); - while (!keypress) { + while (keypress == false) { if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == 0) continue; if (resp.status != PM3_SUCCESS) break; diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 755d71aeb..95e5a7bef 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -706,7 +706,7 @@ static int CmdHFiClassSim(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, false); - int sim_type = arg_get_int(ctx, 1); + int sim_type = arg_get_int_def(ctx, 1, 3); int csn_len = 0; uint8_t csn[8] = {0}; diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index 9de9d40c1..fe11836e1 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -713,18 +713,18 @@ static int CmdHFMFPRdbl(const char *Cmd) { } if (blockn > 255) { - PrintAndLogEx(ERR, " must be in range [0..255] instead of: %d", blockn); + PrintAndLogEx(ERR, " must be in range [0..255] got: %d", blockn); return PM3_EINVARG; } if (keylen != 16) { - PrintAndLogEx(ERR, " must be 16 bytes long instead of: %d", keylen); + PrintAndLogEx(ERR, " must be 16 bytes long. got: %d", keylen); return PM3_EINVARG; } // 3 blocks - wo iso14443-4 chaining if (blocksCount > 3) { - PrintAndLogEx(ERR, "blocks count must be less than 3 instead of: %d", blocksCount); + PrintAndLogEx(ERR, "blocks count must be less than 3. got: %d", blocksCount); return PM3_EINVARG; } @@ -823,12 +823,12 @@ static int CmdHFMFPRdsc(const char *Cmd) { } if (sectorNum > 39) { - PrintAndLogEx(ERR, " must be in range [0..39] instead of: %d", sectorNum); + PrintAndLogEx(ERR, " must be in range [0..39] got: %d", sectorNum); return PM3_EINVARG; } if (keylen != 16) { - PrintAndLogEx(ERR, " must be 16 bytes long instead of: %d", keylen); + PrintAndLogEx(ERR, " must be 16 bytes long. got: %d", keylen); return PM3_EINVARG; } @@ -925,17 +925,17 @@ static int CmdHFMFPWrbl(const char *Cmd) { } if (blockNum > 255) { - PrintAndLogEx(ERR, " must be in range [0..255] instead of: %d", blockNum); + PrintAndLogEx(ERR, " must be in range [0..255] got: %d", blockNum); return PM3_EINVARG; } if (keylen != 16) { - PrintAndLogEx(ERR, " must be 16 bytes long instead of: %d", keylen); + PrintAndLogEx(ERR, " must be 16 bytes long. got: %d", keylen); return PM3_EINVARG; } if (datainlen != 16) { - PrintAndLogEx(ERR, " must be 16 bytes long instead of: %d", datainlen); + PrintAndLogEx(ERR, " must be 16 bytes long. got: %d", datainlen); return PM3_EINVARG; } diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index aa93047e2..5b0004c09 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -2730,8 +2730,8 @@ static int CmdHF14AMfUSim(const char *Cmd) { "The UID from emulator memory will be used if not specified.\n" "See `hf 14a sim -h` to see available types. You want 2 or 7 usually.", "hf mfu sim -t 2 --uid 11223344556677 -> MIFARE Ultralight\n" - "hf mfu sim -t 7 --uid 11223344556677 -n 5 -> MFUEV1 / NTAG 215 Amiibo\n" - "hf mfu sim -t 7 -> MFUEV1 / NTAG 215 Amiibo" + "hf mfu sim -t 7 --uid 11223344556677 -n 5 -> MFU EV1 / NTAG 215 Amiibo\n" + "hf mfu sim -t 7 -> MFU EV1 / NTAG 215 Amiibo" ); void *argtable[] = { diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 9831135f5..4962edfe2 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -597,7 +597,7 @@ static int CmdLCD(const char *Cmd) { int r_len = 0; uint8_t raw[1] = {0}; CLIGetHexWithReturn(ctx, 1, raw, &r_len); - int j = arg_get_int(ctx, 2); + int j = arg_get_int_def(ctx, 2, 1); if (j < 1) { PrintAndLogEx(WARNING, "Count must be larger than zero"); return PM3_EINVARG; diff --git a/client/src/cmdlfem4x70.c b/client/src/cmdlfem4x70.c index e0087e230..7021b2b95 100644 --- a/client/src/cmdlfem4x70.c +++ b/client/src/cmdlfem4x70.c @@ -165,7 +165,7 @@ int CmdEM4x70Write(const char *Cmd) { CLIParserInit(&ctx, "lf em 4x70 write", "Write EM4x70\n", - "lf em 4x70 write -b 15 -d c0de -> write 'c0de' to block 15\n" + "lf em 4x70 write -b 15 -d c0de -> write 'c0de' to block 15\n" "lf em 4x70 write -b 15 -d c0de --par -> adds parity bit to commands\n" ); @@ -181,7 +181,7 @@ int CmdEM4x70Write(const char *Cmd) { etd.parity = arg_get_lit(ctx, 1); - int addr = arg_get_int(ctx, 2); + int addr = arg_get_int_def(ctx, 2, 1); int word_len = 0; uint8_t word[2] = {0x0}; @@ -190,12 +190,12 @@ int CmdEM4x70Write(const char *Cmd) { CLIParserFree(ctx); if (addr < 0 || addr >= EM4X70_NUM_BLOCKS) { - PrintAndLogEx(FAILED, "block has to be within range [0, 15]"); + PrintAndLogEx(FAILED, "block has to be within range [0, 15] got: %d", addr); return PM3_EINVARG; } if (word_len != 2) { - PrintAndLogEx(FAILED, "word/data length must be 2 bytes instead of %d", word_len); + PrintAndLogEx(FAILED, "word/data length must be 2 bytes. got: %d", word_len); return PM3_EINVARG; }