// Read key file\r
\r
for (i=0 ; i<16 ; i++) {\r
- fread ( keyA[i], 1, 6, fin );\r
+ if (fread( keyA[i], 1, 6, fin ) == 0) {\r
+ PrintAndLog("File reading error.");\r
+ return 2;\r
+ }\r
}\r
for (i=0 ; i<16 ; i++) {\r
- fread ( keyB[i], 1, 6, fin );\r
+ if (fread( keyB[i], 1, 6, fin ) == 0) {\r
+ PrintAndLog("File reading error.");\r
+ return 2;\r
+ }\r
}\r
\r
// Read access rights to sectors\r
}\r
\r
for (i=0 ; i<16 ; i++) {\r
- fread(keyA[i], 1, 6, fkeys);\r
+ if (fread(keyA[i], 1, 6, fkeys) == 0) {\r
+ PrintAndLog("File reading error.");\r
+ return 2;\r
+ }\r
}\r
for (i=0 ; i<16 ; i++) {\r
- fread(keyB[i], 1, 6, fkeys);\r
+ if (fread(keyB[i], 1, 6, fkeys) == 0) {\r
+ PrintAndLog("File reading error.");\r
+ return 2;\r
+ }\r
}\r
\r
PrintAndLog("Restoring dumpdata.bin to card");\r
UsbCommand c = {CMD_MIFARE_WRITEBL, {i*4 + j, keyType, 0}};\r
memcpy(c.d.asBytes, key, 6);\r
\r
- fread(bldata, 1, 16, fdump);\r
+ if (fread(bldata, 1, 16, fdump) == 0) {\r
+ PrintAndLog("File reading error.");\r
+ return 2;\r
+ }\r
\r
if (j == 3) {\r
bldata[0] = (keyA[i][0]);\r
if ( (f = fopen( filename , "r")) ) {\r
while( !feof(f) ){\r
memset(buf, 0, sizeof(buf));\r
- fgets(buf, sizeof(buf), f);\r
- \r
+ if (fgets(buf, sizeof(buf), f) == NULL) {\r
+ PrintAndLog("File reading error.");\r
+ return 2;\r
+ }\r
+ \r
if (strlen(buf) < 12 || buf[11] == '\n')\r
continue;\r
\r
blockNum = 0;\r
while(!feof(f)){\r
memset(buf, 0, sizeof(buf));\r
- fgets(buf, sizeof(buf), f);\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(strlen(buf) && feof(f))\r
flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r
while(!feof(f)){\r
memset(buf, 0, sizeof(buf));\r
- fgets(buf, sizeof(buf), f);\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(strlen(buf) && feof(f))\r