added colors and show all sectors in range for hf mf chk

This commit is contained in:
iceman1001 2023-06-12 19:54:05 +02:00
commit 383c52c1bd

View file

@ -1097,10 +1097,6 @@ static void Fill2bPattern(uint8_t keyList[MAX_KEYS_LIST_LEN][AES_KEY_LEN], uint3
} }
static int CmdHFMFPChk(const char *Cmd) { static int CmdHFMFPChk(const char *Cmd) {
int res;
uint8_t keyList[MAX_KEYS_LIST_LEN][AES_KEY_LEN] = {{0}};
uint32_t keyListLen = 0;
uint8_t foundKeys[2][64][AES_KEY_LEN + 1] = {{{0}}};
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfp chk", CLIParserInit(&ctx, "hf mfp chk",
@ -1133,6 +1129,10 @@ static int CmdHFMFPChk(const char *Cmd) {
uint8_t startSector = arg_get_int_def(ctx, 3, 0); uint8_t startSector = arg_get_int_def(ctx, 3, 0);
uint8_t endSector = arg_get_int_def(ctx, 4, 0); uint8_t endSector = arg_get_int_def(ctx, 4, 0);
uint8_t keyList[MAX_KEYS_LIST_LEN][AES_KEY_LEN] = {{0}};
uint32_t keyListLen = 0;
uint8_t foundKeys[2][64][AES_KEY_LEN + 1] = {{{0}}};
uint8_t vkey[16] = {0}; uint8_t vkey[16] = {0};
int vkeylen = 0; int vkeylen = 0;
CLIGetHexWithReturn(ctx, 5, vkey, &vkeylen); CLIGetHexWithReturn(ctx, 5, vkey, &vkeylen);
@ -1222,6 +1222,8 @@ static int CmdHFMFPChk(const char *Cmd) {
if (pattern2b) if (pattern2b)
Fill2bPattern(keyList, &keyListLen, &startPattern); Fill2bPattern(keyList, &keyListLen, &startPattern);
int res = PM3_SUCCESS;
// dictionary mode // dictionary mode
size_t endFilePosition = 0; size_t endFilePosition = 0;
if (dict_filenamelen) { if (dict_filenamelen) {
@ -1265,6 +1267,7 @@ static int CmdHFMFPChk(const char *Cmd) {
Fill2bPattern(keyList, &keyListLen, &startPattern); Fill2bPattern(keyList, &keyListLen, &startPattern);
continue; continue;
} }
if (dict_filenamelen && endFilePosition) { if (dict_filenamelen && endFilePosition) {
if (verbose == false) if (verbose == false)
PrintAndLogEx(NORMAL, "d" NOLF); PrintAndLogEx(NORMAL, "d" NOLF);
@ -1274,6 +1277,7 @@ static int CmdHFMFPChk(const char *Cmd) {
if (res == PM3_SUCCESS && endFilePosition) { if (res == PM3_SUCCESS && endFilePosition) {
keyListLen = keycnt; keyListLen = keycnt;
} }
continue; continue;
} }
break; break;
@ -1282,26 +1286,38 @@ static int CmdHFMFPChk(const char *Cmd) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
// print result // print result
char strA[46 + 1] = {0};
char strB[46 + 1] = {0};
bool printedHeader = false; bool printedHeader = false;
for (uint8_t sector = startSector; sector <= endSector; sector++) { for (uint8_t s = startSector; s <= endSector; s++) {
if (foundKeys[0][sector][0] || foundKeys[1][sector][0]) { if (printedHeader == false) {
if (!printedHeader) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "-------+--------------------------------+---------------------------------"); PrintAndLogEx(INFO, "-----+----------------------------------+----------------------------------");
PrintAndLogEx(INFO, "|sector| key A | key B |"); PrintAndLogEx(INFO, " Sec | key A | key B");
PrintAndLogEx(INFO, "|------+--------------------------------+--------------------------------|"); PrintAndLogEx(INFO, "-----+----------------------------------+----------------------------------");
printedHeader = true; printedHeader = true;
} }
PrintAndLogEx(INFO, "| %02d |%32s|%32s|",
sector, if (foundKeys[0][s][0]) {
(foundKeys[0][sector][0] == 0) ? "------ " : sprint_hex_inrow(&foundKeys[0][sector][1], AES_KEY_LEN), snprintf(strA, sizeof(strA), _GREEN_("%s"), sprint_hex_inrow(&foundKeys[0][s][1], AES_KEY_LEN));
(foundKeys[1][sector][0] == 0) ? "------ " : sprint_hex_inrow(&foundKeys[1][sector][1], AES_KEY_LEN)); } else {
snprintf(strA, sizeof(strA), _RED_("%s"), "--------------------------------");
} }
if (foundKeys[1][s][0]) {
snprintf(strB, sizeof(strB), _GREEN_("%s"), sprint_hex_inrow(&foundKeys[1][s][1], AES_KEY_LEN));
} else {
snprintf(strB, sizeof(strB), _RED_("%s"), "--------------------------------");
} }
if (!printedHeader)
PrintAndLogEx(INFO, " " _YELLOW_("%03d") " | %s | %s", s, strA, strB);
}
if (printedHeader == false)
PrintAndLogEx(INFO, "No keys found("); PrintAndLogEx(INFO, "No keys found(");
else else
PrintAndLogEx(INFO, "'------+--------------------------------+--------------------------------'\n"); PrintAndLogEx(INFO, "-----+----------------------------------+----------------------------------\n");
// save keys to json // save keys to json
if ((jsonnamelen > 0) && printedHeader) { if ((jsonnamelen > 0) && printedHeader) {