]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
Added binlib, to handle binary data from lua, based on lpack http://www.tecgraf.puc...
[proxmark3-svn] / client / cmdhfmf.c
index 11288085ecd436c80b3fa4763dc2b48959eca9fc..597841e17fa08b41ff80b3932f87411794163713 100644 (file)
@@ -287,10 +287,16 @@ int CmdHF14AMfDump(const char *Cmd)
        // Read key file\r
        \r
        for (i=0 ; i<16 ; i++) {\r
        // 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
        }\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
        // Read access rights to sectors\r
@@ -416,10 +422,16 @@ int CmdHF14AMfRestore(const char *Cmd)
        }\r
        \r
        for (i=0 ; i<16 ; i++) {\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
        }\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
        }\r
        \r
        PrintAndLog("Restoring dumpdata.bin to card");\r
@@ -429,7 +441,10 @@ int CmdHF14AMfRestore(const char *Cmd)
                        UsbCommand c = {CMD_MIFARE_WRITEBL, {i*4 + j, keyType, 0}};\r
                        memcpy(c.d.asBytes, key, 6);\r
                        \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
                                        \r
                        if (j == 3) {\r
                                bldata[0]  = (keyA[i][0]);\r
@@ -816,8 +831,11 @@ int CmdHF14AMfChk(const char *Cmd)
                        if ( (f = fopen( filename , "r")) ) {\r
                                while( !feof(f) ){\r
                                        memset(buf, 0, sizeof(buf));\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
                                        if (strlen(buf) < 12 || buf[11] == '\n')\r
                                                continue;\r
                                \r
@@ -1077,7 +1095,10 @@ int CmdHF14AMfELoad(const char *Cmd)
        blockNum = 0;\r
        while(!feof(f)){\r
                memset(buf, 0, sizeof(buf));\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
 \r
                if (strlen(buf) < 32){\r
                        if(strlen(buf) && feof(f))\r
@@ -1344,7 +1365,10 @@ int CmdHF14AMfCLoad(const char *Cmd)
                flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r
                while(!feof(f)){\r
                        memset(buf, 0, sizeof(buf));\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
 \r
                        if (strlen(buf) < 32){\r
                                if(strlen(buf) && feof(f))\r
Impressum, Datenschutz