]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
ADD @pwpiwi 's fixes for "HF 14B" commands.
[proxmark3-svn] / client / cmdhfmf.c
index eb2479ff26308f61f5f5842b3c109b447a4747fa..809c623acff06c3d05fad362c48aa19503e25fdb 100644 (file)
@@ -1012,8 +1012,10 @@ int CmdHF14AMf1kSim(const char *Cmd)
        uint8_t uid[7] = {0, 0, 0, 0, 0, 0, 0};\r
        uint8_t exitAfterNReads = 0;\r
        uint8_t flags = 0;\r
-\r
+       \r
        uint8_t cmdp = param_getchar(Cmd, 0);\r
+\r
+       clearCommandBuffer();\r
        \r
        if (cmdp == 'h' || cmdp == 'H') {\r
                PrintAndLog("Usage:  hf mf sim  u <uid (8 hex symbols)> n <numreads> i x");\r
@@ -1065,25 +1067,38 @@ int CmdHF14AMf1kSim(const char *Cmd)
 \r
        if(flags & FLAG_INTERACTIVE)\r
        {               \r
-               uint64_t corr_uid =  bytes_to_num(uid,  ( flags & FLAG_4B_UID_IN_DATA ) ? 4 : 7 );\r
-\r
                PrintAndLog("Press pm3-button to abort simulation");\r
                \r
                uint8_t data[40];\r
                uint8_t key[6];\r
 \r
-               while(!ukbhit()){\r
-                       UsbCommand resp;                \r
-                       WaitForResponseTimeout(CMD_ACK,&resp,1500);\r
-                       PrintAndLog("CMD_SIMULATE_MIFARE_CARD [%04X] -- %04X", CMD_SIMULATE_MIFARE_CARD, resp.arg[0]);                  \r
-                       if ( (resp.arg[0] & 0xffff) == CMD_SIMULATE_MIFARE_CARD ){\r
-                               memset(data, 0x00, sizeof(data));\r
-                               memset(key, 0x00, sizeof(key));\r
-                               int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];\r
-                               memcpy(data, resp.d.asBytes, len);\r
-                               tryMfk32(corr_uid, data, key);\r
-                               //tryMfk64(corr_uid, data, key);\r
-                               PrintAndLog("--");\r
+               UsbCommand resp;                \r
+               while(!ukbhit() ){\r
+                       if ( WaitForResponseTimeout(CMD_ACK,&resp,1500) ) {\r
+                               if ( (resp.arg[0] & 0xffff) == CMD_SIMULATE_MIFARE_CARD ){\r
+                                       memset(data, 0x00, sizeof(data));\r
+                                       memset(key, 0x00, sizeof(key));\r
+                                       int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];\r
+                                       \r
+                                       memcpy(data, resp.d.asBytes, len);\r
+                                       \r
+                                       uint64_t corr_uid = 0;\r
+                                       if ( memcmp(data, "\x00\x00\x00\x00", 4) == 0 ) {\r
+                                               corr_uid = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];\r
+                                       }\r
+                                       else {\r
+                                               corr_uid |= (uint64_t)data[2] << 48; \r
+                                               corr_uid |= (uint64_t)data[1] << 40; \r
+                                               corr_uid |= (uint64_t)data[0] << 32;\r
+                                               corr_uid |= data[7] << 24;\r
+                                               corr_uid |= data[6] << 16;\r
+                                               corr_uid |= data[5] << 8;\r
+                                               corr_uid |= data[4];\r
+                                       }\r
+                                       tryMfk32(corr_uid, data, key);\r
+                                       //tryMfk64(corr_uid, data, key);\r
+                                       PrintAndLog("--");\r
+                               }\r
                        }\r
                }\r
        }\r
@@ -1328,7 +1343,6 @@ int CmdHF14AMfESave(const char *Cmd)
                        for (j = 0; j < 7; j++, fnameptr += 2)\r
                                sprintf(fnameptr, "%02X", buf[j]);\r
                }\r
-               }\r
        } else {\r
                fnameptr += len;\r
        }\r
@@ -1613,7 +1627,6 @@ int CmdHF14AMfCLoad(const char *Cmd)
                        if (fgets(buf, sizeof(buf), f) == NULL) {\r
                                fclose(f);\r
                                PrintAndLog("File reading error.");\r
-                               fclose(f);\r
                                return 2;\r
                        }\r
 \r
Impressum, Datenschutz