\r
int CmdHF14AMfCSetUID(const char *Cmd)\r
{\r
- 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
+ uint8_t atqaPresent = 0;\r
int res;\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
+ uint8_t needHelp = 0;\r
+ char cmdp = 1;\r
+ \r
+ if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 8)) {\r
+ PrintAndLog("UID must include 8 HEX symbols");\r
+ return 1;\r
+ }\r
+\r
+ if (param_getlength(Cmd, 1) > 1 && param_getlength(Cmd, 2) > 1) {\r
+ atqaPresent = 1;\r
+ cmdp = 3;\r
+ \r
+ if (param_gethex(Cmd, 1, atqa, 4)) {\r
+ PrintAndLog("ATQA must include 4 HEX symbols");\r
+ return 1;\r
+ }\r
+ \r
+ if (param_gethex(Cmd, 2, sak, 2)) {\r
+ PrintAndLog("SAK must include 2 HEX symbols");\r
+ return 1;\r
+ }\r
+ }\r
+\r
+ while(param_getchar(Cmd, cmdp) != 0x00)\r
+ {\r
+ switch(param_getchar(Cmd, cmdp))\r
+ {\r
+ case 'h':\r
+ case 'H':\r
+ needHelp = 1;\r
+ break;\r
+ default:\r
+ PrintAndLog("ERROR: Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
+ needHelp = 1;\r
+ break;\r
+ }\r
+ cmdp++;\r
+ }\r
+\r
+ if (strlen(Cmd) < 1 || needHelp) {\r
+ PrintAndLog("");\r
+ PrintAndLog("Usage: hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols]");\r
PrintAndLog("sample: hf mf csetuid 01020304");\r
- PrintAndLog("sample: hf mf csetuid 01020304 0004 08 w");\r
+ PrintAndLog("sample: hf mf csetuid 01020304 0004 08");\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
- if (param_getchar(Cmd, argi) && param_gethex(Cmd, argi, uid, 8)) {\r
- PrintAndLog("UID must include 8 HEX symbols");\r
- return 1;\r
+ PrintAndLog("uid:%s", sprint_hex(uid, 4));\r
+ if (atqaPresent) {\r
+ PrintAndLog("--atqa:%s sak:%02x", sprint_hex(atqa, 2), sak[0]);\r
}\r
- argi++;\r
\r
- ctmp = param_getchar(Cmd, argi);\r
- if (ctmp == 'w' || ctmp == 'W') {\r
- wipeCard = 1;\r
- atqaPresent = 0;\r
+ res = mfCSetUID(uid, (atqaPresent)?atqa:NULL, (atqaPresent)?sak:NULL, oldUid);\r
+ if (res) {\r
+ PrintAndLog("Can't set UID. Error=%d", res);\r
+ return 1;\r
+ }\r
+\r
+ PrintAndLog("old UID:%s", sprint_hex(oldUid, 4));\r
+ PrintAndLog("new UID:%s", sprint_hex(uid, 4));\r
+ return 0;\r
+}\r
+\r
+static int ParamGetCardSize(const char c) {\r
+ int numBlocks = 16 * 4;\r
+ switch (c) {\r
+ case '0' : numBlocks = 5 * 4; break;\r
+ case '2' : numBlocks = 32 * 4; break;\r
+ case '4' : numBlocks = 32 * 4 + 8 * 16; break;\r
+ default: numBlocks = 16 * 4;\r
}\r
+ return numBlocks;\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
+int CmdHF14AMfCWipe(const char *Cmd)\r
+{\r
+ int res, gen = 0;\r
+ int numBlocks = 16 * 4;\r
+ bool wipeCard = false;\r
+ bool fillCard = false;\r
+ \r
+ if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
+ PrintAndLog("Usage: hf mf cwipe [card size] [w] [p]");\r
+ PrintAndLog("sample: hf mf cwipe 1 w s");\r
+ PrintAndLog("[card size]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");\r
+ PrintAndLog("w - Wipe magic Chinese card (only works with gen:1a cards)");\r
+ PrintAndLog("f - Fill the card with default data and keys (works with gen:1a and gen:1b cards only)");\r
+ return 0;\r
}\r
\r
- if(!wipeCard) {\r
- ctmp = param_getchar(Cmd, argi);\r
- if (ctmp == 'w' || ctmp == 'W') {\r
+ gen = mfCIdentify();\r
+ if ((gen != 1) && (gen != 2)) \r
+ return 1;\r
+ \r
+ numBlocks = ParamGetCardSize(param_getchar(Cmd, 0));\r
+\r
+ char cmdp = 0;\r
+ while(param_getchar(Cmd, cmdp) != 0x00){\r
+ switch(param_getchar(Cmd, cmdp)) {\r
+ case 'w':\r
+ case 'W':\r
wipeCard = 1;\r
+ break;\r
+ case 'f':\r
+ case 'F':\r
+ fillCard = 1;\r
+ break;\r
+ default:\r
+ break;\r
}\r
+ cmdp++;\r
}\r
\r
- PrintAndLog("--wipe card:%s uid:%s", (wipeCard)?"YES":"NO", sprint_hex(uid, 4));\r
+ if (!wipeCard && !fillCard) \r
+ wipeCard = true;\r
\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
+ PrintAndLog("--blocks count:%2d wipe:%c fill:%c", numBlocks, (wipeCard)?'y':'n', (fillCard)?'y':'n');\r
+\r
+ if (gen == 2) {\r
+ /* generation 1b magic card */\r
+ if (wipeCard) {\r
+ PrintAndLog("WARNING: can't wipe magic card 1b generation");\r
}\r
+ res = mfCWipe(numBlocks, true, false, fillCard); \r
+ } else {\r
+ /* generation 1a magic card by default */\r
+ res = mfCWipe(numBlocks, false, wipeCard, fillCard); \r
+ }\r
\r
- PrintAndLog("old UID:%s", sprint_hex(oldUid, 4));\r
- PrintAndLog("new UID:%s", sprint_hex(uid, 4));\r
+ if (res) {\r
+ PrintAndLog("Can't wipe. error=%d", res);\r
+ return 1;\r
+ }\r
+ PrintAndLog("OK");\r
return 0;\r
}\r
\r
}\r
\r
gen = mfCIdentify();\r
+ if ((gen != 1) && (gen != 2)) \r
+ return 1;\r
\r
blockNo = param_get8(Cmd, 0);\r
\r
{"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},\r
{"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},\r
{"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},\r
+ {"cwipe", CmdHF14AMfCWipe, 0, "Wipe magic Chinese card"},\r
{"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},\r
{"csetblk", CmdHF14AMfCSetBlk, 0, "Write block - Magic Chinese card"},\r
{"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block - Magic Chinese card"},\r