]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
changed -elf to -eabi in install-gnuarm4.sh ARMLIB suggestion
[proxmark3-svn] / client / cmdhfmf.c
index ac4f1087d131bcba3cd8d21dceadbe54dbbe1876..8c91e84cb9f3015510841735467a514a27bffae4 100644 (file)
@@ -712,6 +712,7 @@ int CmdHF14AMfChk(const char *Cmd)
 {\r
        FILE * f;\r
        char filename[256]={0};\r
+       char buf[13];\r
        uint8_t *keyBlock = NULL, *p;\r
        uint8_t stKeyBlock = 20;\r
        \r
@@ -810,20 +811,24 @@ int CmdHF14AMfChk(const char *Cmd)
                                return 2;\r
                        }\r
                        \r
-            char * line = NULL;\r
-            size_t len = 0;\r
-            ssize_t read;\r
                        if ( (f = fopen( filename , "r")) ) {\r
-                               while((read = getline(&line, &len, f)) != -1){\r
+                               while( !feof(f) ){\r
+                                       memset(buf, 0, sizeof(buf));\r
+                                       fgets(buf, sizeof(buf), f);\r
+                                       \r
+                                       if (strlen(buf) < 12 || buf[11] == '\n')\r
+                                               continue;\r
                                \r
-                                       if( line[0]=='#' || line[0]=='\n' ) continue;   //The line start with # is remcommnet,skip\r
+                                       while (fgetc(f) != '\n' && !feof(f)) ;  //goto next line\r
+                                       \r
+                                       if( buf[0]=='#' ) continue;     //The line start with # is remcommnet,skip\r
 \r
-                                       if (read < 12 || !isxdigit(line[0])){\r
-                                               PrintAndLog("File content error. '%s' must include 12 HEX symbols",line);\r
+                                       if (!isxdigit(buf[0])){\r
+                                               PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);\r
                                                continue;\r
                                        }\r
                                        \r
-                                       line[12] = 0;\r
+                                       buf[12] = 0;\r
 \r
                                        if ( stKeyBlock - keycnt < 2) {\r
                                                p = realloc(keyBlock, 6*(stKeyBlock+=10));\r
@@ -835,11 +840,10 @@ int CmdHF14AMfChk(const char *Cmd)
                                                keyBlock = p;\r
                                        }\r
                                        memset(keyBlock + 6 * keycnt, 0, 6);\r
-                                       num_to_bytes(strtoll(line, NULL, 16), 6, keyBlock + 6*keycnt);\r
+                                       num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);\r
                                        PrintAndLog("chk custom key[%d] %012llx", keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));\r
                                        keycnt++;\r
                                }\r
-                               free(line);\r
                        } else {\r
                                PrintAndLog("File: %s: not found or locked.", filename);\r
                                free(keyBlock);\r
@@ -1214,6 +1218,85 @@ int CmdHF14AMfEKeyPrn(const char *Cmd)
        return 0;\r
 }\r
 \r
+int CmdHF14AMfCSetUID(const char *Cmd)\r
+{\r
+       uint8_t wipeCard = 0;\r
+       uint8_t uid[8];\r
+       uint8_t oldUid[8];\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
+               return 0;\r
+       }       \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
+       char ctmp = param_getchar(Cmd, 1);\r
+       if (ctmp == 'w' || ctmp == 'W') wipeCard = 1;\r
+       \r
+       PrintAndLog("--wipe card:%02x uid:%s", wipeCard, sprint_hex(uid, 4));\r
+\r
+       res = mfCSetUID(uid, oldUid, wipeCard);\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
+       return 0;\r
+}\r
+\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
+int CmdHF14AMfCLoad(const char *Cmd)\r
+{\r
+       return 0;\r
+}\r
+\r
 static command_t CommandTable[] =\r
 {\r
   {"help",             CmdHelp,                                1, "This help"},\r
@@ -1234,6 +1317,9 @@ static command_t CommandTable[] =
   {"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
+  {"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
   {NULL, NULL, 0, NULL}\r
 };\r
 \r
Impressum, Datenschutz