\r
int CmdHF14AMfCSetBlk(const char *Cmd)\r
{\r
+ uint8_t uid[8];\r
+ uint8_t memBlock[16];\r
+ uint8_t blockNo = 0;\r
+ int res;\r
+ memset(memBlock, 0x00, sizeof(memBlock));\r
+\r
+ if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
+ PrintAndLog("Usage: hf mf csetblk <block number> <block data (32 hex symbols)>");\r
+ PrintAndLog("sample: hf mf csetblk 1 01020304050607080910111213141516");\r
+ PrintAndLog("Set block data for magic Chinese card (only works with!!!)");\r
+ PrintAndLog("If you want wipe card then add 'w' into command line. \n");\r
+ return 0;\r
+ } \r
+\r
+ blockNo = param_get8(Cmd, 0);\r
+ if (blockNo >= 32 * 4 + 8 * 16) {\r
+ PrintAndLog("Block number must be in [0..255] as in MIFARE classic.");\r
+ return 1;\r
+ }\r
+\r
+ if (param_gethex(Cmd, 1, memBlock, 32)) {\r
+ PrintAndLog("block data must include 32 HEX symbols");\r
+ return 1;\r
+ }\r
+\r
+ PrintAndLog("--block number:%02x data:%s", blockNo, sprint_hex(memBlock, 16));\r
+\r
+ res = mfCSetBlock(blockNo, memBlock, uid, 0);\r
+ if (res) {\r
+ PrintAndLog("Can't write block. error=%d", res);\r
+ return 1;\r
+ }\r
+ \r
+ PrintAndLog("UID:%s", sprint_hex(uid, 4));\r
return 0;\r
}\r
\r
{"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},\r
{"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},\r
{"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},\r
- {"csetblk", CmdHF14AMfCSetBlk, 0, "(n/a)Write block into magic Chinese card"},\r
+ {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block into magic Chinese card"},\r
{"cload", CmdHF14AMfCLoad, 0, "(n/a)Load dump into magic Chinese card"},\r
{NULL, NULL, 0, NULL}\r
};\r
}\r
\r
int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe) {\r
- uint8_t isOK = 0;\r
uint8_t block0[16];\r
memset(block0, 0, 16);\r
memcpy(block0, uid, 4); \r
block0[4] = block0[0]^block0[1]^block0[2]^block0[3]; // Mifare UID BCC\r
+ \r
+ return mfCSetBlock(0, block0, oldUID, wantWipe);\r
+}\r
+\r
+int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe) {\r
+ uint8_t isOK = 0;\r
\r
- UsbCommand c = {CMD_MIFARE_EML_CSETBLOCK, {wantWipe, 1, 0}};\r
- memcpy(c.d.asBytes, block0, 16); \r
+ UsbCommand c = {CMD_MIFARE_EML_CSETBLOCK, {wantWipe, 1, blockNo}};\r
+ memcpy(c.d.asBytes, data, 16); \r
SendCommand(&c);\r
\r
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);\r
if (resp != NULL) {\r
isOK = resp->arg[0] & 0xff;\r
PrintAndLog("isOk:%02x", isOK);\r
- memcpy(oldUID, resp->d.asBytes, 4); \r
+ memcpy(uid, resp->d.asBytes, 4); \r
if (!isOK) return 2;\r
} else {\r
PrintAndLog("Command execute timeout");\r
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);\r
int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);\r
int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe);\r
+int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe);\r
\r