+struct Crypto1State *revstate = NULL;\r
+uint64_t key = 0;\r
+uint32_t ks2 = 0;\r
+uint32_t ks3 = 0;\r
+\r
+uint32_t cuid = 0; // serial number\r
+uint32_t nt =0; // tag challenge\r
+uint32_t nr_enc =0; // encrypted reader challenge\r
+uint32_t ar_enc =0; // encrypted reader response\r
+uint32_t at_enc =0; // encrypted tag response\r
+\r
+int isTraceCardEmpty(void) {\r
+ return ((traceCard[0] == 0) && (traceCard[1] == 0) && (traceCard[2] == 0) && (traceCard[3] == 0));\r
+}\r
+\r
+int isBlockEmpty(int blockN) {\r
+ for (int i = 0; i < 16; i++) \r
+ if (traceCard[blockN * 16 + i] != 0) return 0;\r
+\r
+ return 1;\r
+}\r
+\r
+int isBlockTrailer(int blockN) {\r
+ return ((blockN & 0x03) == 0x03);\r
+}\r
+\r
+int loadTraceCard(uint8_t *tuid, uint8_t uidlen) {\r
+ FILE * f;\r
+ char buf[64] = {0x00};\r
+ uint8_t buf8[64] = {0x00};\r
+ int i, blockNum;\r
+ \r
+ if (!isTraceCardEmpty()) \r
+ saveTraceCard();\r
+ \r
+ memset(traceCard, 0x00, 4096);\r
+ memcpy(traceCard, tuid, uidlen);\r
+\r
+ FillFileNameByUID(traceFileName, tuid, ".eml", uidlen);\r
+\r
+ f = fopen(traceFileName, "r");\r
+ if (!f) return 1;\r
+ \r
+ blockNum = 0;\r
+ \r
+ while(!feof(f)){\r
+ \r
+ memset(buf, 0, sizeof(buf));\r
+ if (fgets(buf, sizeof(buf), f) == NULL) {\r
+ PrintAndLog("No trace file found or reading error.");\r
+ if (f) {\r
+ fclose(f);\r
+ f = NULL;\r
+ }\r
+ return 2;\r
+ }\r
+\r
+ if (strlen(buf) < 32){\r
+ if (feof(f)) break;\r
+ PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
+ if (f) {\r
+ fclose(f);\r
+ f = NULL;\r
+ }\r
+ return 2;\r
+ }\r
+ for (i = 0; i < 32; i += 2)\r
+ sscanf(&buf[i], "%02X", (unsigned int *)&buf8[i / 2]);\r