-
- //flush queue
- while (ukbhit()) getchar();
-
- // message
- printf("-------------------------------------------------------------------------\n");
- printf("Executing command. It may take up to 30 min.\n");
- printf("Press the key on proxmark3 device to abort proxmark3.\n");
- printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");
- printf("-------------------------------------------------------------------------\n");
-
- // wait cycle
- while (true) {
- printf(".");
- if (ukbhit()) {
- getchar();
- printf("\naborted via keyboard!\n");
- break;
- }
-
- UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 2000);
- if (resp != NULL) {
- isOK = resp->arg[0] & 0xff;
-
- uid = (uint32_t)bytes_to_num(resp->d.asBytes + 0, 4);
- nt = (uint32_t)bytes_to_num(resp->d.asBytes + 4, 4);
- par_list = bytes_to_num(resp->d.asBytes + 8, 8);
- ks_list = bytes_to_num(resp->d.asBytes + 16, 8);
-
- printf("\n\n");
- PrintAndLog("isOk:%02x", isOK);
- if (!isOK) PrintAndLog("Proxmark can't get statistic info. Execution aborted.\n");
- break;
- }
- }
- printf("\n");
-
- // error
- if (isOK != 1) return 1;
-
- // execute original function from util nonce2key
- if (nonce2key(uid, nt, par_list, ks_list, &r_key)) return 2;
- printf("------------------------------------------------------------------\n");
- PrintAndLog("Key found:%012llx \n", r_key);
-
- num_to_bytes(r_key, 6, keyBlock);
- isOK = mfCheckKeys(0, 0, 1, keyBlock, &r_key);
- if (!isOK)
- PrintAndLog("Found valid key:%012llx", r_key);
- else
- PrintAndLog("Found invalid key. (");
-
-
- return 0;
-}
-
-int CmdHF14AMfWrBl(const char *Cmd)
-{
- uint8_t blockNo = 0;
- uint8_t keyType = 0;
- uint8_t key[6] = {0, 0, 0, 0, 0, 0};
- uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
- char cmdp = 0x00;
-
- if (strlen(Cmd)<3) {
- PrintAndLog("Usage: hf 14 mfwrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>");
- PrintAndLog(" sample: hf 14a mfwrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F");
- return 0;
- }
-
- blockNo = param_get8(Cmd, 0);
- cmdp = param_getchar(Cmd, 1);
- if (cmdp == 0x00) {
- PrintAndLog("Key type must be A or B");
- return 1;
- }
- if (cmdp != 'A' && cmdp != 'a') keyType = 1;
- if (param_gethex(Cmd, 2, key, 12)) {
- PrintAndLog("Key must include 12 HEX symbols");
- return 1;
- }
- if (param_gethex(Cmd, 3, bldata, 32)) {
- PrintAndLog("Block data must include 32 HEX symbols");
- return 1;
- }
- PrintAndLog("--block no:%02x key type:%02x key:%s", blockNo, keyType, sprint_hex(key, 6));
- PrintAndLog("--data: %s", sprint_hex(bldata, 16));
-
- UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}};
- memcpy(c.d.asBytes, key, 6);
- memcpy(c.d.asBytes + 10, bldata, 16);
- SendCommand(&c);
- UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
-
- if (resp != NULL) {
- uint8_t isOK = resp->arg[0] & 0xff;
-
- PrintAndLog("isOk:%02x", isOK);
- } else {
- PrintAndLog("Command execute timeout");
- }
-
- return 0;
-}
-
-int CmdHF14AMfRdBl(const char *Cmd)
-{
- uint8_t blockNo = 0;
- uint8_t keyType = 0;
- uint8_t key[6] = {0, 0, 0, 0, 0, 0};
-
- char cmdp = 0x00;