+sector_t *k_sector = NULL;\r
+uint8_t k_sectorsCount = 16;\r
+static void emptySectorTable(){\r
+\r
+ // initialize storage for found keys\r
+ if (k_sector == NULL)\r
+ k_sector = calloc(k_sectorsCount, sizeof(sector_t));\r
+ if (k_sector == NULL) \r
+ return;\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
+void showSectorTable(){\r
+ if (k_sector != NULL) {\r
+ printKeyTable(k_sectorsCount, k_sector);\r
+ free(k_sector);\r
+ k_sector = NULL;\r
+ }\r
+}\r
+void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose) {\r
+\r
+ uint64_t key = 0; \r
+ bool success = FALSE;\r
+ \r
+ if (k_sector == NULL)\r
+ emptySectorTable();\r
+\r
+ success = tryMfk32_moebius(data, &key, verbose);\r
+ if (success) {\r
+ uint8_t sector = data.sector;\r
+ uint8_t keytype = data.keytype;\r
+\r
+ PrintAndLog("Reader is trying authenticate with: Key %s, sector %02d: [%012" PRIx64 "]"\r
+ , keytype ? "B" : "A"\r
+ , sector\r
+ , key\r
+ );\r
+\r
+ k_sector[sector].Key[keytype] = key;\r
+ k_sector[sector].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[sector].Key[0], 6, memBlock);\r
+ num_to_bytes( k_sector[sector].Key[1], 6, memBlock+10);\r
+ //iceman, guessing this will not work so well for 4K tags.\r
+ PrintAndLog("Setting Emulator Memory Block %02d: [%s]"\r
+ , (sector*4) + 3\r
+ , sprint_hex( memBlock, sizeof(memBlock))\r
+ );\r
+ mfEmlSetMem( memBlock, (sector*4) + 3, 1);\r
+ }\r
+ }\r
+}\r
+\r