extra checks for argument parsing of ints. And some text updates. There are other int parsing but they are checked with mandatory param int1

This commit is contained in:
iceman1001 2022-11-20 16:34:45 +01:00
commit 4fb096966e
6 changed files with 24 additions and 19 deletions

View file

@ -687,7 +687,7 @@ int CmdHF14ASim(const char *Cmd) {
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); 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; int uid_len = 0;
uint8_t uid[10] = {0}; uint8_t uid[10] = {0};
@ -727,6 +727,11 @@ int CmdHF14ASim(const char *Cmd) {
CLIParserFree(ctx); CLIParserFree(ctx);
if (tagtype > 10) {
PrintAndLogEx(ERR, "Undefined tag %d", tagtype);
return PM3_EINVARG;
}
sector_t *k_sector = NULL; sector_t *k_sector = NULL;
uint8_t k_sectorsCount = 40; uint8_t k_sectorsCount = 40;
@ -752,7 +757,7 @@ int CmdHF14ASim(const char *Cmd) {
PrintAndLogEx(INFO, "Press pm3-button to abort simulation"); PrintAndLogEx(INFO, "Press pm3-button to abort simulation");
bool keypress = kbd_enter_pressed(); bool keypress = kbd_enter_pressed();
while (!keypress) { while (keypress == false) {
if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == 0) continue; if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == 0) continue;
if (resp.status != PM3_SUCCESS) break; if (resp.status != PM3_SUCCESS) break;

View file

@ -706,7 +706,7 @@ static int CmdHFiClassSim(const char *Cmd) {
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); 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; int csn_len = 0;
uint8_t csn[8] = {0}; uint8_t csn[8] = {0};

View file

@ -713,18 +713,18 @@ static int CmdHFMFPRdbl(const char *Cmd) {
} }
if (blockn > 255) { if (blockn > 255) {
PrintAndLogEx(ERR, "<block number> must be in range [0..255] instead of: %d", blockn); PrintAndLogEx(ERR, "<block number> must be in range [0..255] got: %d", blockn);
return PM3_EINVARG; return PM3_EINVARG;
} }
if (keylen != 16) { if (keylen != 16) {
PrintAndLogEx(ERR, "<key> must be 16 bytes long instead of: %d", keylen); PrintAndLogEx(ERR, "<key> must be 16 bytes long. got: %d", keylen);
return PM3_EINVARG; return PM3_EINVARG;
} }
// 3 blocks - wo iso14443-4 chaining // 3 blocks - wo iso14443-4 chaining
if (blocksCount > 3) { 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; return PM3_EINVARG;
} }
@ -823,12 +823,12 @@ static int CmdHFMFPRdsc(const char *Cmd) {
} }
if (sectorNum > 39) { if (sectorNum > 39) {
PrintAndLogEx(ERR, "<sector number> must be in range [0..39] instead of: %d", sectorNum); PrintAndLogEx(ERR, "<sector number> must be in range [0..39] got: %d", sectorNum);
return PM3_EINVARG; return PM3_EINVARG;
} }
if (keylen != 16) { if (keylen != 16) {
PrintAndLogEx(ERR, "<key> must be 16 bytes long instead of: %d", keylen); PrintAndLogEx(ERR, "<key> must be 16 bytes long. got: %d", keylen);
return PM3_EINVARG; return PM3_EINVARG;
} }
@ -925,17 +925,17 @@ static int CmdHFMFPWrbl(const char *Cmd) {
} }
if (blockNum > 255) { if (blockNum > 255) {
PrintAndLogEx(ERR, "<block number> must be in range [0..255] instead of: %d", blockNum); PrintAndLogEx(ERR, "<block number> must be in range [0..255] got: %d", blockNum);
return PM3_EINVARG; return PM3_EINVARG;
} }
if (keylen != 16) { if (keylen != 16) {
PrintAndLogEx(ERR, "<key> must be 16 bytes long instead of: %d", keylen); PrintAndLogEx(ERR, "<key> must be 16 bytes long. got: %d", keylen);
return PM3_EINVARG; return PM3_EINVARG;
} }
if (datainlen != 16) { if (datainlen != 16) {
PrintAndLogEx(ERR, "<data> must be 16 bytes long instead of: %d", datainlen); PrintAndLogEx(ERR, "<data> must be 16 bytes long. got: %d", datainlen);
return PM3_EINVARG; return PM3_EINVARG;
} }

View file

@ -597,7 +597,7 @@ static int CmdLCD(const char *Cmd) {
int r_len = 0; int r_len = 0;
uint8_t raw[1] = {0}; uint8_t raw[1] = {0};
CLIGetHexWithReturn(ctx, 1, raw, &r_len); 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) { if (j < 1) {
PrintAndLogEx(WARNING, "Count must be larger than zero"); PrintAndLogEx(WARNING, "Count must be larger than zero");
return PM3_EINVARG; return PM3_EINVARG;

View file

@ -181,7 +181,7 @@ int CmdEM4x70Write(const char *Cmd) {
etd.parity = arg_get_lit(ctx, 1); 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; int word_len = 0;
uint8_t word[2] = {0x0}; uint8_t word[2] = {0x0};
@ -190,12 +190,12 @@ int CmdEM4x70Write(const char *Cmd) {
CLIParserFree(ctx); CLIParserFree(ctx);
if (addr < 0 || addr >= EM4X70_NUM_BLOCKS) { 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; return PM3_EINVARG;
} }
if (word_len != 2) { 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; return PM3_EINVARG;
} }