+ FILE * f;\r
+ char filename[20];\r
+ char * fnameptr = filename;\r
+ char buf[64];\r
+ uint8_t buf8[64];\r
+ int i, len, blockNum;\r
+ \r
+ memset(filename, 0, sizeof(filename));\r
+ memset(buf, 0, sizeof(buf));\r
+\r
+ if (param_getchar(Cmd, 0) == 'h') {\r
+ PrintAndLog("It loads emul dump from the file `filename.eml`");\r
+ PrintAndLog("Usage: hf mf eload <file name w/o `.eml`>");\r
+ PrintAndLog(" sample: hf mf eload filename");\r
+ return 0;\r
+ } \r
+\r
+ len = strlen(Cmd);\r
+ if (len > 14) len = 14;\r
+ \r
+ if (len < 1) {\r
+ }\r
+\r
+ memcpy(filename, Cmd, len);\r
+ fnameptr += len;\r
+\r
+ sprintf(fnameptr, ".eml"); \r
+ \r
+ // open file\r
+ f = fopen(filename, "r");\r
+ if (f == NULL) {\r
+ PrintAndLog("File not found or locked.");\r
+ return 1;\r
+ }\r
+ \r
+ blockNum = 0;\r
+ while(!feof(f)){\r
+ memset(buf, 0, sizeof(buf));\r
+ fgets(buf, sizeof(buf), f);\r
+ if (strlen(buf) < 32){\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
+// PrintAndLog("data[%02d]:%s", blockNum, sprint_hex(buf8, 16));\r
+\r
+ if (mfEmlSetMem(buf8, blockNum, 1)) {\r
+ PrintAndLog("Cant set emul block: %d", blockNum);\r
+ return 3;\r
+ }\r
+ blockNum++;\r
+ \r
+ if (blockNum >= 16 * 4) break;\r
+ }\r
+ fclose(f);\r
+ \r
+ if (blockNum != 16 * 4){\r
+ PrintAndLog("File content error. There must be 64 blocks");\r
+ return 4;\r
+ }\r
+ PrintAndLog("Loaded from file: %s", filename);\r