+#define ATTACK_KEY_COUNT 8\r
+sector *k_sector = NULL;\r
+uint8_t k_sectorsCount = 16;\r
+void readerAttack(nonces_t data[], bool setEmulatorMem, bool verbose) {\r
+\r
+ // initialize storage for found keys\r
+ if (k_sector == NULL)\r
+ k_sector = calloc(k_sectorsCount, sizeof(sector));\r
+ if (k_sector == NULL) \r
+ return;\r
+\r
+ uint64_t key = 0;\r
+ \r
+ // empty e_sector\r
+ for(int i = 0; i < k_sectorsCount; ++i){\r
+ k_sector[i].Key[0] = 0xffffffffffff;\r
+ k_sector[i].Key[1] = 0xffffffffffff;\r
+ k_sector[i].foundKey[0] = FALSE;\r
+ k_sector[i].foundKey[1] = FALSE;\r
+ }\r
+\r
+ printf("enter reader attack\n");\r
+ for (uint8_t i = 0; i < ATTACK_KEY_COUNT; ++i) {\r
+ if (data[i].ar2 > 0) {\r
+\r
+ // We can probably skip this, mfkey32v2 is more reliable.\r
+#ifdef HFMF_TRYMFK32\r
+ if (tryMfk32(data[i], &key, verbose)) {\r
+ PrintAndLog("Found Key%s for sector %02d: [%012"llx"]"\r
+ , (data[i].keytype) ? "B" : "A"\r
+ , data[i].sector\r
+ , key\r
+ );\r
+\r
+ k_sector[i].Key[data[i].keytype] = key;\r
+ k_sector[i].foundKey[data[i].keytype] = TRUE;\r
+ \r
+ //set emulator memory for keys\r
+ if (setEmulatorMem) {\r
+ uint8_t memBlock[16] = {0,0,0,0,0,0, 0xff, 0x0F, 0x80, 0x69, 0,0,0,0,0,0};\r
+ num_to_bytes( k_sector[i].Key[0], 6, memBlock);\r
+ num_to_bytes( k_sector[i].Key[1], 6, memBlock+10);\r
+ PrintAndLog("Setting Emulator Memory Block %02d: [%s]"\r
+ , ((data[i].sector)*4) + 3\r
+ , sprint_hex( memBlock, sizeof(memBlock))\r
+ );\r
+ mfEmlSetMem( memBlock, ((data[i].sector)*4) + 3, 1);\r
+ }\r
+ continue;\r
+ }\r
+#endif\r
+ //moebius attack \r
+ if (tryMfk32_moebius(data[i+ATTACK_KEY_COUNT], &key, verbose)) {\r
+ uint8_t sectorNum = data[i+ATTACK_KEY_COUNT].sector;\r
+ uint8_t keyType = data[i+ATTACK_KEY_COUNT].keytype;\r
+\r
+ PrintAndLog("M-Found Key%s for sector %02d: [%012"llx"]"\r
+ , keyType ? "B" : "A"\r
+ , sectorNum\r
+ , key\r
+ );\r
+\r
+ k_sector[sectorNum].Key[keyType] = key;\r
+ k_sector[sectorNum].foundKey[keyType] = TRUE;\r
+\r
+ //set emulator memory for keys\r
+ if (setEmulatorMem) {\r
+ uint8_t memBlock[16] = {0,0,0,0,0,0, 0xff, 0x0F, 0x80, 0x69, 0,0,0,0,0,0};\r
+ num_to_bytes( k_sector[sectorNum].Key[0], 6, memBlock);\r
+ num_to_bytes( k_sector[sectorNum].Key[1], 6, memBlock+10);\r
+ PrintAndLog("Setting Emulator Memory Block %02d: [%s]"\r
+ , (sectorNum*4) + 3\r
+ , sprint_hex( memBlock, sizeof(memBlock))\r
+ );\r
+ mfEmlSetMem( memBlock, (sectorNum*4) + 3, 1);\r
+ }\r
+ continue;\r
+ }\r
+\r
+ }\r
+ }\r
+}\r