]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
magic Chinese card fully supported. Added commands:csetuid-set card uid and wipe...
[proxmark3-svn] / client / cmdhfmf.c
index 8c91e84cb9f3015510841735467a514a27bffae4..eafb29197592bc7801e6d0433b8eeb3e0ef17964 100644 (file)
@@ -1282,7 +1282,7 @@ int CmdHF14AMfCSetBlk(const char *Cmd)
 \r
        PrintAndLog("--block number:%02x data:%s", blockNo, sprint_hex(memBlock, 16));\r
 \r
-       res = mfCSetBlock(blockNo, memBlock, uid, 0);\r
+       res = mfCSetBlock(blockNo, memBlock, uid, 0, CSETBLOCK_SINGLE_OPER);\r
        if (res) {\r
                        PrintAndLog("Can't write block. error=%d", res);\r
                        return 1;\r
@@ -1294,7 +1294,97 @@ int CmdHF14AMfCSetBlk(const char *Cmd)
 \r
 int CmdHF14AMfCLoad(const char *Cmd)\r
 {\r
-       return 0;\r
+       FILE * f;\r
+       char filename[20];\r
+       char * fnameptr = filename;\r
+       char buf[64];\r
+       uint8_t buf8[64];\r
+       uint8_t fillFromEmulator = 0;\r
+       int i, len, blockNum, flags;\r
+       \r
+       memset(filename, 0, sizeof(filename));\r
+       memset(buf, 0, sizeof(buf));\r
+\r
+       if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {\r
+               PrintAndLog("It loads magic Chinese card (only works with!!!) from the file `filename.eml`");\r
+               PrintAndLog("or from emulator memory (option `e`)");\r
+               PrintAndLog("Usage:  hf mf cload <file name w/o `.eml`>");\r
+               PrintAndLog("   or:  hf mf cload e ");\r
+               PrintAndLog(" sample: hf mf cload filename");\r
+               return 0;\r
+       }       \r
+\r
+       char ctmp = param_getchar(Cmd, 0);\r
+       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
+\r
+                       if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) {\r
+                               PrintAndLog("Cant set magic card block: %d", blockNum);\r
+                               return 3;\r
+                       }\r
+               }\r
+               return 0;\r
+       } else {\r
+               len = strlen(Cmd);\r
+               if (len > 14) len = 14;\r
+\r
+               memcpy(filename, Cmd, len);\r
+               fnameptr += len;\r
+\r
+               sprintf(fnameptr, ".eml"); \r
+       \r
+               // open file\r
+               f = fopen(filename, "r");\r
+               if (f == NULL) {\r
+                       PrintAndLog("File not found or locked.");\r
+                       return 1;\r
+               }\r
+       \r
+               blockNum = 0;\r
+               flags = CSETBLOCK_INIT_FIELD + CSETBLOCK_WUPC;\r
+               while(!feof(f)){\r
+                       memset(buf, 0, sizeof(buf));\r
+                       fgets(buf, sizeof(buf), f);\r
+\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
+                               return 2;\r
+                       }\r
+                       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
+\r
+                       if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) {\r
+                               PrintAndLog("Cant set magic card block: %d", blockNum);\r
+                               return 3;\r
+                       }\r
+                       blockNum++;\r
+               \r
+                       if (blockNum >= 16 * 4) break;  // magic card type - mifare 1K\r
+               }\r
+               fclose(f);\r
+       \r
+               if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16){\r
+                       PrintAndLog("File content error. There must be 64 blocks");\r
+                       return 4;\r
+               }\r
+               PrintAndLog("Loaded from file: %s", filename);\r
+               return 0;\r
+       }\r
 }\r
 \r
 static command_t CommandTable[] =\r
@@ -1319,7 +1409,7 @@ static command_t CommandTable[] =
   {"ekeyprn",  CmdHF14AMfEKeyPrn,      0, "Print keys from simulator memory"},\r
   {"csetuid",  CmdHF14AMfCSetUID,      0, "Set UID for 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
+  {"cload",            CmdHF14AMfCLoad,                0, "Load dump into magic Chinese card"},\r
   {NULL, NULL, 0, NULL}\r
 };\r
 \r
Impressum, Datenschutz