+ clearCommandBuffer();\r
+ SendCommand(&c);\r
+ UsbCommand resp;\r
+ if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) return 1;\r
+ if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
+ *key = bytes_to_num(resp.d.asBytes, 6);\r
+ return 0;\r
+}\r
+// PM3 imp of J-Run mf_key_brute (part 2)\r
+// ref: https://github.com/J-Run/mf_key_brute\r
+int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultkey){\r
+\r
+ #define KEYS_IN_BLOCK 85\r
+ #define KEYBLOCK_SIZE 510\r
+ #define CANDIDATE_SIZE 0xFFFF * 6\r
+ uint8_t found = FALSE;\r
+ uint64_t key64 = 0;\r
+ uint8_t candidates[CANDIDATE_SIZE] = {0x00};\r
+ uint8_t keyBlock[KEYBLOCK_SIZE] = {0x00};\r
+\r
+ memset(candidates, 0, sizeof(candidates));\r
+ memset(keyBlock, 0, sizeof(keyBlock));\r
+ \r
+ // Generate all possible keys for the first two unknown bytes.\r
+ for (uint16_t i = 0; i < 0xFFFF; ++i) { \r
+ uint32_t j = i * 6; \r
+ candidates[0 + j] = i >> 8; \r
+ candidates[1 + j] = i;\r
+ candidates[2 + j] = key[2];\r
+ candidates[3 + j] = key[3];\r
+ candidates[4 + j] = key[4];\r
+ candidates[5 + j] = key[5];\r
+ }\r
+ uint32_t counter, i;\r
+ for ( i = 0, counter = 1; i < CANDIDATE_SIZE; i += KEYBLOCK_SIZE, ++counter){\r