]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
fix hf mf sim (#812)
[proxmark3-svn] / client / cmdhfmf.c
index 1c006fbf6924d15c46009c5d048b447474a067f7..903e8575c4f6797d15553ce55bf560661e2846c7 100644 (file)
@@ -254,14 +254,14 @@ uint8_t NumBlocksPerSector(uint8_t sectorNo)
 }\r
 \r
 static int ParamCardSizeSectors(const char c) {\r
 }\r
 \r
 static int ParamCardSizeSectors(const char c) {\r
-       int numBlocks = 16;\r
+       int numSectors = 16;\r
        switch (c) {\r
        switch (c) {\r
-               case '0' : numBlocks = 5; break;\r
-               case '2' : numBlocks = 32; break;\r
-               case '4' : numBlocks = 40; break;\r
-               default:   numBlocks = 16;\r
+               case '0' : numSectors = 5; break;\r
+               case '2' : numSectors = 32; break;\r
+               case '4' : numSectors = 40; break;\r
+               default:   numSectors = 16;\r
        }\r
        }\r
-       return numBlocks;\r
+       return numSectors;\r
 }\r
 \r
 static int ParamCardSizeBlocks(const char c) {\r
 }\r
 \r
 static int ParamCardSizeBlocks(const char c) {\r
@@ -1421,11 +1421,12 @@ void readerAttack(nonces_t ar_resp[], bool setEmulatorMem, bool doStandardAttack
        }*/\r
 }\r
 \r
        }*/\r
 }\r
 \r
-int usage_hf14_mf1ksim(void) {\r
-       PrintAndLog("Usage:  hf mf sim h u <uid (8, 14, or 20 hex symbols)> n <numreads> i x");\r
+int usage_hf14_mfsim(void) {\r
+       PrintAndLog("Usage:  hf mf sim [h] [*<card memory>] [u <uid (8, 14, or 20 hex symbols)>] [n <numreads>] [i] [x]");\r
        PrintAndLog("options:");\r
        PrintAndLog("options:");\r
-       PrintAndLog("      h    this help");\r
-       PrintAndLog("      u    (Optional) UID 4,7 or 10 bytes. If not specified, the UID 4B from emulator memory will be used");\r
+       PrintAndLog("      h    (Optional) this help");\r
+       PrintAndLog("      card memory: 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other, default> - 1K");\r
+       PrintAndLog("      u    (Optional) UID 4 or 7 bytes. If not specified, the UID 4B from emulator memory will be used");\r
        PrintAndLog("      n    (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");\r
        PrintAndLog("      i    (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");\r
        PrintAndLog("      x    (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");\r
        PrintAndLog("      n    (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");\r
        PrintAndLog("      i    (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");\r
        PrintAndLog("      x    (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");\r
@@ -1434,21 +1435,20 @@ int usage_hf14_mf1ksim(void) {
        PrintAndLog("      r    (Optional) Generate random nonces instead of sequential nonces. Standard reader attack won't work with this option, only moebius attack works.");\r
        PrintAndLog("samples:");\r
        PrintAndLog("           hf mf sim u 0a0a0a0a");\r
        PrintAndLog("      r    (Optional) Generate random nonces instead of sequential nonces. Standard reader attack won't work with this option, only moebius attack works.");\r
        PrintAndLog("samples:");\r
        PrintAndLog("           hf mf sim u 0a0a0a0a");\r
+       PrintAndLog("           hf mf sim *4");\r
        PrintAndLog("           hf mf sim u 11223344556677");\r
        PrintAndLog("           hf mf sim u 11223344556677");\r
-       PrintAndLog("           hf mf sim u 112233445566778899AA");\r
        PrintAndLog("           hf mf sim f uids.txt");\r
        PrintAndLog("           hf mf sim u 0a0a0a0a e");\r
 \r
        return 0;\r
 }\r
 \r
        PrintAndLog("           hf mf sim f uids.txt");\r
        PrintAndLog("           hf mf sim u 0a0a0a0a e");\r
 \r
        return 0;\r
 }\r
 \r
-int CmdHF14AMf1kSim(const char *Cmd) {\r
+int CmdHF14AMfSim(const char *Cmd) {\r
        UsbCommand resp;\r
        UsbCommand resp;\r
-       uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r
+       uint8_t uid[7] = {0};\r
        uint8_t exitAfterNReads = 0;\r
        uint8_t flags = 0;\r
        int uidlen = 0;\r
        uint8_t exitAfterNReads = 0;\r
        uint8_t flags = 0;\r
        int uidlen = 0;\r
-       uint8_t pnr = 0;\r
        bool setEmulatorMem = false;\r
        bool attackFromFile = false;\r
        FILE *f;\r
        bool setEmulatorMem = false;\r
        bool attackFromFile = false;\r
        FILE *f;\r
@@ -1459,9 +1459,21 @@ int CmdHF14AMf1kSim(const char *Cmd) {
 \r
        uint8_t cmdp = 0;\r
        bool errors = false;\r
 \r
        uint8_t cmdp = 0;\r
        bool errors = false;\r
+       uint8_t cardsize = '1';\r
 \r
        while(param_getchar(Cmd, cmdp) != 0x00) {\r
                switch(param_getchar(Cmd, cmdp)) {\r
 \r
        while(param_getchar(Cmd, cmdp) != 0x00) {\r
                switch(param_getchar(Cmd, cmdp)) {\r
+               case '*': \r
+                       cardsize = param_getchar(Cmd + 1, cmdp);\r
+                       switch(cardsize) {\r
+                               case '0':\r
+                               case '1':\r
+                               case '2':\r
+                               case '4': break;\r
+                               default: cardsize = '1';\r
+                       }\r
+                       cmdp++;\r
+                       break;\r
                case 'e':\r
                case 'E':\r
                        setEmulatorMem = true;\r
                case 'e':\r
                case 'E':\r
                        setEmulatorMem = true;\r
@@ -1485,7 +1497,7 @@ int CmdHF14AMf1kSim(const char *Cmd) {
                        break;\r
                case 'h':\r
                case 'H':\r
                        break;\r
                case 'h':\r
                case 'H':\r
-                       return usage_hf14_mf1ksim();\r
+                       return usage_hf14_mfsim();\r
                case 'i':\r
                case 'I':\r
                        flags |= FLAG_INTERACTIVE;\r
                case 'i':\r
                case 'I':\r
                        flags |= FLAG_INTERACTIVE;\r
@@ -1493,7 +1505,7 @@ int CmdHF14AMf1kSim(const char *Cmd) {
                        break;\r
                case 'n':\r
                case 'N':\r
                        break;\r
                case 'n':\r
                case 'N':\r
-                       exitAfterNReads = param_get8(Cmd, pnr+1);\r
+                       exitAfterNReads = param_get8(Cmd, cmdp+1);\r
                        cmdp += 2;\r
                        break;\r
                case 'r':\r
                        cmdp += 2;\r
                        break;\r
                case 'r':\r
@@ -1505,10 +1517,9 @@ int CmdHF14AMf1kSim(const char *Cmd) {
                case 'U':\r
                        param_gethex_ex(Cmd, cmdp+1, uid, &uidlen);\r
                        switch(uidlen) {\r
                case 'U':\r
                        param_gethex_ex(Cmd, cmdp+1, uid, &uidlen);\r
                        switch(uidlen) {\r
-                               case 20: flags = FLAG_10B_UID_IN_DATA;  break; //not complete\r
                                case 14: flags = FLAG_7B_UID_IN_DATA; break;\r
                                case  8: flags = FLAG_4B_UID_IN_DATA; break;\r
                                case 14: flags = FLAG_7B_UID_IN_DATA; break;\r
                                case  8: flags = FLAG_4B_UID_IN_DATA; break;\r
-                               default: return usage_hf14_mf1ksim();\r
+                               default: return usage_hf14_mfsim();\r
                        }\r
                        cmdp += 2;\r
                        break;\r
                        }\r
                        cmdp += 2;\r
                        break;\r
@@ -1525,7 +1536,7 @@ int CmdHF14AMf1kSim(const char *Cmd) {
                if(errors) break;\r
        }\r
        //Validations\r
                if(errors) break;\r
        }\r
        //Validations\r
-       if(errors) return usage_hf14_mf1ksim();\r
+       if(errors) return usage_hf14_mfsim();\r
 \r
        //get uid from file\r
        if (attackFromFile) {\r
 \r
        //get uid from file\r
        if (attackFromFile) {\r
@@ -1552,7 +1563,6 @@ int CmdHF14AMf1kSim(const char *Cmd) {
 \r
                        uidlen = strlen(buf)-1;\r
                        switch(uidlen) {\r
 \r
                        uidlen = strlen(buf)-1;\r
                        switch(uidlen) {\r
-                               case 20: flags |= FLAG_10B_UID_IN_DATA; break; //not complete\r
                                case 14: flags |= FLAG_7B_UID_IN_DATA; break;\r
                                case  8: flags |= FLAG_4B_UID_IN_DATA; break;\r
                                default:\r
                                case 14: flags |= FLAG_7B_UID_IN_DATA; break;\r
                                case  8: flags |= FLAG_4B_UID_IN_DATA; break;\r
                                default:\r
@@ -1565,18 +1575,22 @@ int CmdHF14AMf1kSim(const char *Cmd) {
                                sscanf(&buf[i], "%02x", (unsigned int *)&uid[i / 2]);\r
                        }\r
 \r
                                sscanf(&buf[i], "%02x", (unsigned int *)&uid[i / 2]);\r
                        }\r
 \r
-                       PrintAndLog("mf 1k sim uid: %s, numreads:%d, flags:%d (0x%02x) - press button to abort",\r
-                                       flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):\r
-                                               flags & FLAG_7B_UID_IN_DATA     ? sprint_hex(uid,7):\r
-                                                       flags & FLAG_10B_UID_IN_DATA ? sprint_hex(uid,10): "N/A"\r
-                                       , exitAfterNReads, flags, flags);\r
+                       PrintAndLog("mf sim cardsize: %s, uid: %s, numreads:%d, flags:%d (0x%02x) - press button to abort",\r
+                               cardsize == '0' ? "Mini" :\r
+                                       cardsize == '2' ? "2K" :\r
+                                               cardsize == '4' ? "4K" : "1K",\r
+                               flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):\r
+                                       flags & FLAG_7B_UID_IN_DATA     ? sprint_hex(uid,7): "N/A",\r
+                               exitAfterNReads,\r
+                               flags,\r
+                               flags);\r
 \r
 \r
-                       UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};\r
+                       UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads, cardsize}};\r
                        memcpy(c.d.asBytes, uid, sizeof(uid));\r
                        clearCommandBuffer();\r
                        SendCommand(&c);\r
 \r
                        memcpy(c.d.asBytes, uid, sizeof(uid));\r
                        clearCommandBuffer();\r
                        SendCommand(&c);\r
 \r
-                       while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                       while (! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
                                //We're waiting only 1.5 s at a time, otherwise we get the\r
                                // annoying message about "Waiting for a response... "\r
                        }\r
                                //We're waiting only 1.5 s at a time, otherwise we get the\r
                                // annoying message about "Waiting for a response... "\r
                        }\r
@@ -1593,22 +1607,27 @@ int CmdHF14AMf1kSim(const char *Cmd) {
                        count++;\r
                }\r
                fclose(f);\r
                        count++;\r
                }\r
                fclose(f);\r
-       } else { //not from file\r
 \r
 \r
-               PrintAndLog("mf 1k sim uid: %s, numreads:%d, flags:%d (0x%02x) ",\r
-                               flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):\r
-                                       flags & FLAG_7B_UID_IN_DATA     ? sprint_hex(uid,7):\r
-                                               flags & FLAG_10B_UID_IN_DATA ? sprint_hex(uid,10): "N/A"\r
-                               , exitAfterNReads, flags, flags);\r
+       } else { //not from file\r
 \r
 \r
-               UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};\r
+               PrintAndLog("mf sim cardsize: %s, uid: %s, numreads:%d, flags:%d (0x%02x) ",\r
+                       cardsize == '0' ? "Mini" :\r
+                               cardsize == '2' ? "2K" :\r
+                                       cardsize == '4' ? "4K" : "1K",\r
+                       flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):\r
+                               flags & FLAG_7B_UID_IN_DATA     ? sprint_hex(uid,7): "N/A",\r
+                       exitAfterNReads,\r
+                       flags,\r
+                       flags);\r
+\r
+               UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads, cardsize}};\r
                memcpy(c.d.asBytes, uid, sizeof(uid));\r
                clearCommandBuffer();\r
                SendCommand(&c);\r
 \r
                if(flags & FLAG_INTERACTIVE) {\r
                        PrintAndLog("Press pm3-button to abort simulation");\r
                memcpy(c.d.asBytes, uid, sizeof(uid));\r
                clearCommandBuffer();\r
                SendCommand(&c);\r
 \r
                if(flags & FLAG_INTERACTIVE) {\r
                        PrintAndLog("Press pm3-button to abort simulation");\r
-                       while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                       while(! WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {\r
                                //We're waiting only 1.5 s at a time, otherwise we get the\r
                                // annoying message about "Waiting for a response... "\r
                        }\r
                                //We're waiting only 1.5 s at a time, otherwise we get the\r
                                // annoying message about "Waiting for a response... "\r
                        }\r
@@ -1745,7 +1764,7 @@ int CmdHF14AMfELoad(const char *Cmd)
                }\r
        }\r
 \r
                }\r
        }\r
 \r
-       len = param_getstr(Cmd,nameParamNo,filename,sizeof(filename));\r
+       len = param_getstr(Cmd, nameParamNo, filename, sizeof(filename));\r
 \r
        if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
 \r
 \r
        if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
 \r
@@ -2925,8 +2944,8 @@ static command_t CommandTable[] =
   {"hardnested",       CmdHF14AMfNestedHard,    0, "Nested attack for hardened Mifare cards"},\r
   {"nested",           CmdHF14AMfNested,        0, "Test nested authentication"},\r
   {"sniff",            CmdHF14AMfSniff,         0, "Sniff card-reader communication"},\r
   {"hardnested",       CmdHF14AMfNestedHard,    0, "Nested attack for hardened Mifare cards"},\r
   {"nested",           CmdHF14AMfNested,        0, "Test nested authentication"},\r
   {"sniff",            CmdHF14AMfSniff,         0, "Sniff card-reader communication"},\r
-  {"sim",              CmdHF14AMf1kSim,         0, "Simulate MIFARE card"},\r
-  {"eclr",             CmdHF14AMfEClear,        0, "Clear simulator memory block"},\r
+  {"sim",              CmdHF14AMfSim,           0, "Simulate MIFARE card"},\r
+  {"eclr",             CmdHF14AMfEClear,        0, "Clear simulator memory"},\r
   {"eget",             CmdHF14AMfEGet,          0, "Get simulator memory block"},\r
   {"eset",             CmdHF14AMfESet,          0, "Set simulator memory block"},\r
   {"eload",            CmdHF14AMfELoad,         0, "Load from file emul dump"},\r
   {"eget",             CmdHF14AMfEGet,          0, "Get simulator memory block"},\r
   {"eset",             CmdHF14AMfESet,          0, "Set simulator memory block"},\r
   {"eload",            CmdHF14AMfELoad,         0, "Load from file emul dump"},\r
Impressum, Datenschutz