]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
added simple test suite for tools/findbits.py
[proxmark3-svn] / client / cmdhfmf.c
index ac4f1087d131bcba3cd8d21dceadbe54dbbe1876..081d197c1ffe7027ab6798f61c1ed4080d3caa8b 100644 (file)
@@ -712,6 +712,7 @@ int CmdHF14AMfChk(const char *Cmd)
 {\r
        FILE * f;\r
        char filename[256]={0};\r
+       char buf[13];\r
        uint8_t *keyBlock = NULL, *p;\r
        uint8_t stKeyBlock = 20;\r
        \r
@@ -810,20 +811,24 @@ int CmdHF14AMfChk(const char *Cmd)
                                return 2;\r
                        }\r
                        \r
-            char * line = NULL;\r
-            size_t len = 0;\r
-            ssize_t read;\r
                        if ( (f = fopen( filename , "r")) ) {\r
-                               while((read = getline(&line, &len, f)) != -1){\r
+                               while( !feof(f) ){\r
+                                       memset(buf, 0, sizeof(buf));\r
+                                       fgets(buf, sizeof(buf), f);\r
+                                       \r
+                                       if (strlen(buf) < 12 || buf[11] == '\n')\r
+                                               continue;\r
                                \r
-                                       if( line[0]=='#' || line[0]=='\n' ) continue;   //The line start with # is remcommnet,skip\r
+                                       while (fgetc(f) != '\n' && !feof(f)) ;  //goto next line\r
+                                       \r
+                                       if( buf[0]=='#' ) continue;     //The line start with # is remcommnet,skip\r
 \r
-                                       if (read < 12 || !isxdigit(line[0])){\r
-                                               PrintAndLog("File content error. '%s' must include 12 HEX symbols",line);\r
+                                       if (!isxdigit(buf[0])){\r
+                                               PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);\r
                                                continue;\r
                                        }\r
                                        \r
-                                       line[12] = 0;\r
+                                       buf[12] = 0;\r
 \r
                                        if ( stKeyBlock - keycnt < 2) {\r
                                                p = realloc(keyBlock, 6*(stKeyBlock+=10));\r
@@ -835,11 +840,10 @@ int CmdHF14AMfChk(const char *Cmd)
                                                keyBlock = p;\r
                                        }\r
                                        memset(keyBlock + 6 * keycnt, 0, 6);\r
-                                       num_to_bytes(strtoll(line, NULL, 16), 6, keyBlock + 6*keycnt);\r
+                                       num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);\r
                                        PrintAndLog("chk custom key[%d] %012llx", keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));\r
                                        keycnt++;\r
                                }\r
-                               free(line);\r
                        } else {\r
                                PrintAndLog("File: %s: not found or locked.", filename);\r
                                free(keyBlock);\r
Impressum, Datenschutz