+ FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
+\r
+ f = fopen(traceFileName, "r");\r
+ if (!f) return 1;\r
+ \r
+ blockNum = 0;\r
+ while(!feof(f)){\r
+ memset(buf, 0, sizeof(buf));\r
+ if (fgets(buf, sizeof(buf), f) == NULL) {\r
+ PrintAndLog("File reading error.");\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
+ return 2;\r
+ }\r
+ for (i = 0; i < 32; i += 2)\r
+ sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r
+\r
+ memcpy(traceCard + blockNum * 16, buf8, 16);\r
+\r
+ blockNum++;\r
+ }\r
+ fclose(f);\r
+\r
+ return 0;\r
+}\r
+\r
+int saveTraceCard(void) {\r
+ FILE * f;\r
+ \r
+ if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
+ \r
+ f = fopen(traceFileName, "w+");\r
+ for (int i = 0; i < 64; i++) { // blocks\r
+ for (int j = 0; j < 16; j++) // bytes\r
+ fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
+ fprintf(f,"\n");\r
+ }\r
+ fclose(f);\r
+\r
+ return 0;\r
+}\r
+\r
+int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile) {\r
+\r
+ if (traceCrypto1) crypto1_destroy(traceCrypto1);\r
+ traceCrypto1 = NULL;\r
+\r
+ if (wantSaveToEmlFile) loadTraceCard(tuid);\r