]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
Merge branch 'master' of https://github.com/Proxmark/proxmark3
[proxmark3-svn] / client / cmdhfmf.c
index f225359d7d8801cfb4e053f0d47bce73e1f831e1..db563cadf7de224bf012bfc3c60e836d79ea511d 100644 (file)
@@ -1023,6 +1023,7 @@ int CmdHF14AMf1kSim(const char *Cmd)
                PrintAndLog("           x    (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");\r
                PrintAndLog("");\r
                PrintAndLog("           sample: hf mf sim u 0a0a0a0a ");\r
+               PrintAndLog("                 : hf mf sim u 0a0a0a0a i x");\r
                return 0;\r
        }\r
        uint8_t pnr = 0;\r
@@ -1433,27 +1434,60 @@ int CmdHF14AMfCSetUID(const char *Cmd)
        uint8_t wipeCard = 0;\r
        uint8_t uid[8] = {0x00};\r
        uint8_t oldUid[8] = {0x00};\r
+       uint8_t atqa[2] = {0x00};\r
+       uint8_t sak[1] = {0x00};\r
+       uint8_t atqaPresent = 1;\r
        int res;\r
-\r
-       if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
-               PrintAndLog("Usage:  hf mf csetuid <UID 8 hex symbols> <w>");\r
-               PrintAndLog("sample:  hf mf csetuid 01020304 w");\r
-               PrintAndLog("Set UID for magic Chinese card (only works with!!!)");\r
-               PrintAndLog("If you want wipe card then add 'w' into command line. \n");\r
+       char ctmp;\r
+       int argi=0;\r
+\r
+       if (strlen(Cmd) < 1 || param_getchar(Cmd, argi) == 'h') {\r
+               PrintAndLog("Usage:  hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols] [w]");\r
+               PrintAndLog("sample:  hf mf csetuid 01020304");\r
+               PrintAndLog("sample:  hf mf csetuid 01020304 0004 08 w");\r
+               PrintAndLog("Set UID, ATQA, and SAK for magic Chinese card (only works with such cards)");\r
+               PrintAndLog("If you also want to wipe the card then add 'w' at the end of the command line.");\r
                return 0;\r
-       }       \r
+       }\r
 \r
-       if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 8)) {\r
+       if (param_getchar(Cmd, argi) && param_gethex(Cmd, argi, uid, 8)) {\r
                PrintAndLog("UID must include 8 HEX symbols");\r
                return 1;\r
        }\r
+       argi++;\r
+\r
+       ctmp = param_getchar(Cmd, argi);\r
+       if (ctmp == 'w' || ctmp == 'W') {\r
+               wipeCard = 1;\r
+               atqaPresent = 0;\r
+       }\r
+\r
+       if (atqaPresent) {\r
+               if (param_getchar(Cmd, argi)) {\r
+                       if (param_gethex(Cmd, argi, atqa, 4)) {\r
+                               PrintAndLog("ATQA must include 4 HEX symbols");\r
+                               return 1;\r
+                       }\r
+                       argi++;\r
+                       if (!param_getchar(Cmd, argi) || param_gethex(Cmd, argi, sak, 2)) {\r
+                               PrintAndLog("SAK must include 2 HEX symbols");\r
+                               return 1;\r
+                       }\r
+                       argi++;\r
+               } else\r
+                       atqaPresent = 0;\r
+       }\r
+\r
+       if(!wipeCard) {\r
+               ctmp = param_getchar(Cmd, argi);\r
+               if (ctmp == 'w' || ctmp == 'W') {\r
+                       wipeCard = 1;\r
+               }\r
+       }\r
 \r
-       char ctmp = param_getchar(Cmd, 1);\r
-       if (ctmp == 'w' || ctmp == 'W') wipeCard = 1;\r
-       \r
        PrintAndLog("--wipe card:%s  uid:%s", (wipeCard)?"YES":"NO", sprint_hex(uid, 4));\r
 \r
-       res = mfCSetUID(uid, oldUid, wipeCard);\r
+       res = mfCSetUID(uid, (atqaPresent)?atqa:NULL, (atqaPresent)?sak:NULL, oldUid, wipeCard);\r
        if (res) {\r
                        PrintAndLog("Can't set UID. error=%d", res);\r
                        return 1;\r
@@ -1466,7 +1500,7 @@ int CmdHF14AMfCSetUID(const char *Cmd)
 \r
 int CmdHF14AMfCSetBlk(const char *Cmd)\r
 {\r
-       uint8_t uid[8] = {0x00};\r
+       //uint8_t uid[8] = {0x00};\r
        uint8_t memBlock[16] = {0x00};\r
        uint8_t blockNo = 0;\r
        int res;\r
@@ -1488,7 +1522,8 @@ int CmdHF14AMfCSetBlk(const char *Cmd)
 \r
        PrintAndLog("--block number:%2d data:%s", blockNo, sprint_hex(memBlock, 16));\r
 \r
-       res = mfCSetBlock(blockNo, memBlock, uid, 0, CSETBLOCK_SINGLE_OPER);\r
+       //res = mfCSetBlock(blockNo, memBlock, uid, 0, CSETBLOCK_SINGLE_OPER);\r
+       res = mfCSetBlock(blockNo, memBlock, NULL, 0, CSETBLOCK_SINGLE_OPER);\r
        if (res) {\r
                        PrintAndLog("Can't write block. error=%d", res);\r
                        return 1;\r
@@ -1506,7 +1541,7 @@ int CmdHF14AMfCLoad(const char *Cmd)
        char buf[64] = {0x00};\r
        uint8_t buf8[64] = {0x00};\r
        uint8_t fillFromEmulator = 0;\r
-       int i, len, blockNum, flags;\r
+       int i, len, blockNum, flags=0;\r
        \r
        if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {\r
                PrintAndLog("It loads magic Chinese card from the file `filename.eml`");\r
@@ -1521,15 +1556,14 @@ int CmdHF14AMfCLoad(const char *Cmd)
        if (ctmp == 'e' || ctmp == 'E') fillFromEmulator = 1;\r
        \r
        if (fillFromEmulator) {\r
-               flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r
                for (blockNum = 0; blockNum < 16 * 4; blockNum += 1) {\r
                        if (mfEmlGetMem(buf8, blockNum, 1)) {\r
                                PrintAndLog("Cant get block: %d", blockNum);\r
                                return 2;\r
                        }\r
-                       \r
-                       if (blockNum == 2) flags = 0;\r
-                       if (blockNum == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r
+                       if (blockNum == 0) flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;                               // switch on field and send magic sequence\r
+                       if (blockNum == 1) flags = 0;                                                                                                   // just write\r
+                       if (blockNum == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;             // Done. Magic Halt and switch off field.\r
 \r
                        if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) {\r
                                PrintAndLog("Cant set magic card block: %d", blockNum);\r
@@ -1554,7 +1588,6 @@ int CmdHF14AMfCLoad(const char *Cmd)
                }\r
        \r
                blockNum = 0;\r
-               flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r
                while(!feof(f)){\r
                \r
                        memset(buf, 0, sizeof(buf));\r
@@ -1564,7 +1597,7 @@ int CmdHF14AMfCLoad(const char *Cmd)
                                return 2;\r
                        }\r
 \r
-                       if (strlen(buf) < 32){\r
+                       if (strlen(buf) < 32) {\r
                                if(strlen(buf) && feof(f))\r
                                        break;\r
                                PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
@@ -1573,8 +1606,9 @@ int CmdHF14AMfCLoad(const char *Cmd)
                        for (i = 0; i < 32; i += 2)\r
                                sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r
 \r
-                       if (blockNum == 2) flags = 0;\r
-                       if (blockNum == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;\r
+                       if (blockNum == 0) flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;                               // switch on field and send magic sequence\r
+                       if (blockNum == 1) flags = 0;                                                                                                   // just write\r
+                       if (blockNum == 16 * 4 - 1) flags = CSETBLOCK_HALT + CSETBLOCK_RESET_FIELD;             // Done. Switch off field.\r
 \r
                        if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) {\r
                                PrintAndLog("Can't set magic card block: %d", blockNum);\r
Impressum, Datenschutz