hf mf ndefformat now uses the binary key loading

This commit is contained in:
iceman1001 2023-05-30 16:19:33 +02:00
commit 1107c214c5

View file

@ -1266,6 +1266,7 @@ static int CmdHF14AMfRestore(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(INFO, "Using `" _YELLOW_("%s") "`", keyfilename);
// try reading card uid and create filename // try reading card uid and create filename
if (datafnlen == 0) { if (datafnlen == 0) {
@ -6116,39 +6117,27 @@ int CmdHFMFNDEFFormat(const char *Cmd) {
DropField(); DropField();
} }
// load key file if exist // load key file if exist
if (strlen(keyFilename)) { if (strlen(keyFilename)) {
//
FILE *f; size_t alen = 0, blen = 0;
if ((f = fopen(keyFilename, "rb")) == NULL) { uint8_t *tmpA, *tmpB;
// PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), keyFilename); if (loadFileBinaryKey(keyFilename, "", (void**)&tmpA, (void**)&tmpB, &alen, &blen) != PM3_SUCCESS) {
if (tmpA) {
free(tmpA);
}
goto skipfile; goto skipfile;
} }
PrintAndLogEx(INFO, "Using `" _YELLOW_("%s") "`", keyFilename); PrintAndLogEx(INFO, "Using `" _YELLOW_("%s") "`", keyFilename);
// Read keys A from file for (int i=0; i < numSectors; i++) {
size_t bytes_read; memcpy(keyA[i], tmpA + (i *MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
for (uint8_t i = 0; i < numSectors; i++) { memcpy(keyB[i], tmpB + (i *MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
bytes_read = fread(keyA[i], 1, MFKEY_SIZE, f);
if (bytes_read != MFKEY_SIZE) {
PrintAndLogEx(ERR, "File reading error.");
fclose(f);
return PM3_EFILE;
}
} }
free(tmpA);
// Read keys B from file free(tmpB);
for (uint8_t i = 0; i < numSectors; i++) {
bytes_read = fread(keyB[i], 1, MFKEY_SIZE, f);
if (bytes_read != MFKEY_SIZE) {
PrintAndLogEx(ERR, "File reading error.");
fclose(f);
return PM3_EFILE;
}
}
fclose(f);
} }
skipfile: skipfile:
@ -6191,7 +6180,6 @@ skipfile:
} }
break; break;
} }
} }
// write to card, try B key first // write to card, try B key first
@ -6206,7 +6194,6 @@ skipfile:
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS; return PM3_SUCCESS;
} }