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
\r
// "MAGIC" CARD\r
\r
-int mfCSetUID(uint8_t *uid, uint8_t *oldUID, bool wantWipe) {\r
- \r
+int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe) {\r
uint8_t oldblock0[16] = {0x00};\r
uint8_t block0[16] = {0x00};\r
- memcpy(block0, uid, 4); \r
- block0[4] = block0[0]^block0[1]^block0[2]^block0[3]; // Mifare UID BCC\r
- // mifare classic SAK(byte 5) and ATQA(byte 6 and 7)\r
- //block0[5] = 0x08;\r
- //block0[6] = 0x04;\r
- //block0[7] = 0x00;\r
- \r
- block0[5] = 0x01; //sak\r
- block0[6] = 0x01;\r
- block0[7] = 0x0f;\r
- \r
+\r
int old = mfCGetBlock(0, oldblock0, CSETBLOCK_SINGLE_OPER);\r
- if ( old == 0) {\r
- memcpy(block0+8, oldblock0+8, 8);\r
- PrintAndLog("block 0: %s", sprint_hex(block0,16));\r
+ if (old == 0) {\r
+ memcpy(block0, oldblock0, 16);\r
+ PrintAndLog("old block 0: %s", sprint_hex(block0,16));\r
} else {\r
- PrintAndLog("Couldn't get olddata. Will write over the last bytes of Block 0.");\r
+ PrintAndLog("Couldn't get old data. Will write over the last bytes of Block 0.");\r
+ }\r
+\r
+ // fill in the new values\r
+ // UID\r
+ memcpy(block0, uid, 4); \r
+ // Mifare UID BCC\r
+ block0[4] = block0[0]^block0[1]^block0[2]^block0[3];\r
+ // mifare classic SAK(byte 5) and ATQA(byte 6 and 7, reversed)\r
+ if (sak!=NULL)\r
+ block0[5]=sak[0];\r
+ if (atqa!=NULL) {\r
+ block0[6]=atqa[1];\r
+ block0[7]=atqa[0];\r
}\r
+ PrintAndLog("new block 0: %s", sprint_hex(block0,16));\r
return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
}\r
\r
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);\r
int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);\r
\r
-int mfCSetUID(uint8_t *uid, uint8_t *oldUID, bool wantWipe);\r
+int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe);\r
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params);\r
int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);\r
\r