]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Merge pull request #7 from PenturaLabs/master
authorW8M2Hg9lLmWqXSGC <kb@barkweb.com.au>
Mon, 24 Mar 2014 20:07:48 +0000 (07:07 +1100)
committerW8M2Hg9lLmWqXSGC <kb@barkweb.com.au>
Mon, 24 Mar 2014 20:07:48 +0000 (07:07 +1100)
Re-submitting Midnitesnake's Mifare Ultralight Patch

client/cmdhfmf.c

index cc9b4c76df53d30f442a67bad0d97256b67181c6..adf456f8ee21eec6646c57c442677982940c678b 100644 (file)
@@ -142,76 +142,112 @@ int CmdHF14AMfWrBl(const char *Cmd)
 \r
 int CmdHF14AMfUWrBl(const char *Cmd)\r
 {\r
-        uint8_t blockNo = 0;\r
-        uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r
+       uint8_t blockNo = 0;\r
+       bool chinese_card=0;\r
+       uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r
        UsbCommand resp;\r
-        \r
-        if (strlen(Cmd)<3) {\r
-                PrintAndLog("Usage:  hf mf uwrbl    <block number> <block data (8 hex symbols)>");\r
-                PrintAndLog("        sample: hf mf uwrbl 0 01020304");\r
-                return 0;\r
-        }       \r
+       \r
+       if (strlen(Cmd)<3) {\r
+               PrintAndLog("Usage:  hf mf uwrbl    <block number> <block data (8 hex symbols)> <w>");\r
+               PrintAndLog("        sample: hf mf uwrbl 0 01020304");\r
+               return 0;\r
+       }      \r
 \r
-        blockNo = param_get8(Cmd, 0);\r
-        if (param_gethex(Cmd, 1, bldata, 8)) {\r
-                PrintAndLog("Block data must include 8 HEX symbols");\r
-                return 1;\r
-        }\r
+       blockNo = param_get8(Cmd, 0);\r
+       if (param_gethex(Cmd, 1, bldata, 8)) {\r
+               PrintAndLog("Block data must include 8 HEX symbols");\r
+               return 1;\r
+       }\r
+       \r
+       if (strchr(Cmd,'w') != 0) {\r
+         chinese_card=1;\r
+       }\r
+       \r
+       switch(blockNo){\r
+               case 0:\r
+                       if (!chinese_card){\r
+                               PrintAndLog("Access Denied");\r
+                       }else{\r
+                               PrintAndLog("--specialblock no:%02x", blockNo);\r
+                               PrintAndLog("--data: %s", sprint_hex(bldata, 4));\r
+                               UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
+                               memcpy(d.d.asBytes,bldata, 4);\r
+                               SendCommand(&d);\r
+\r
+                               if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                                       uint8_t isOK  = resp.arg[0] & 0xff;\r
+                                       PrintAndLog("isOk:%02x", isOK);\r
+                               } else {\r
+                                       PrintAndLog("Command execute timeout");\r
+                             }\r
+                       }\r
+                       break;\r
+               case 1:\r
+                         if (!chinese_card){\r
+                               PrintAndLog("Access Denied");\r
+                         }else{\r
+                               PrintAndLog("--specialblock no:%02x", blockNo);\r
+                               PrintAndLog("--data: %s", sprint_hex(bldata, 4));\r
+                               UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
+                               memcpy(d.d.asBytes,bldata, 4);\r
+                               SendCommand(&d);\r
+\r
+                               if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                               uint8_t isOK  = resp.arg[0] & 0xff;\r
+                               PrintAndLog("isOk:%02x", isOK);\r
+                               } else {\r
+                                       PrintAndLog("Command execute timeout");\r
+                               }\r
+                       }\r
+                       break;\r
+               case 2:\r
+                       if (!chinese_card){\r
+                               PrintAndLog("Access Denied");\r
+                       }else{\r
+                               PrintAndLog("--specialblock no:%02x", blockNo);\r
+                               PrintAndLog("--data: %s", sprint_hex(bldata, 4));\r
+                               UsbCommand c = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
+                               memcpy(c.d.asBytes, bldata, 4);\r
+                               SendCommand(&c);\r
 \r
-       switch(blockNo)\r
-       {\r
-       case 0:\r
-               PrintAndLog("Access Denied");\r
-               break;\r
-       case 1:\r
-               PrintAndLog("Access Denied");\r
-               break;\r
-       case 2:\r
-               PrintAndLog("--specialblock no:%02x", blockNo);\r
-                PrintAndLog("--data: %s", sprint_hex(bldata, 4));\r
-                UsbCommand c = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
-                memcpy(c.d.asBytes, bldata, 4);\r
-                SendCommand(&c);\r
-\r
-                if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
-                        uint8_t isOK  = resp.arg[0] & 0xff;\r
-                        PrintAndLog("isOk:%02x", isOK);\r
-                } else {\r
-                        PrintAndLog("Command execute timeout");\r
-                }\r
-               break;\r
-       case 3:\r
-               PrintAndLog("--specialblock no:%02x", blockNo);\r
-                PrintAndLog("--data: %s", sprint_hex(bldata, 4));\r
-                UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
-                memcpy(d.d.asBytes,bldata, 4);\r
-                SendCommand(&d);\r
-\r
-                if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
-                        uint8_t isOK  = resp.arg[0] & 0xff;\r
-                        PrintAndLog("isOk:%02x", isOK);\r
-                } else {\r
-                        PrintAndLog("Command execute timeout");\r
-                }\r
-               break;\r
-       default: \r
-               PrintAndLog("--block no:%02x", blockNo);\r
-               PrintAndLog("--data: %s", sprint_hex(bldata, 4));               \r
-               //UsbCommand e = {CMD_MIFAREU_WRITEBL_COMPAT, {blockNo}};\r
-               //memcpy(e.d.asBytes,bldata, 16);\r
-               UsbCommand e = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
-                memcpy(e.d.asBytes,bldata, 4);\r
-               SendCommand(&e);\r
-\r
-               if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
-                       uint8_t isOK  = resp.arg[0] & 0xff;\r
-                       PrintAndLog("isOk:%02x", isOK);\r
-               } else {\r
-                       PrintAndLog("Command execute timeout");\r
-               }\r
-               break;\r
+                               if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                                       uint8_t isOK  = resp.arg[0] & 0xff;\r
+                                       PrintAndLog("isOk:%02x", isOK);\r
+                               } else {\r
+                                       PrintAndLog("Command execute timeout");\r
+                               }\r
+                       }\r
+                       break;\r
+               case 3:\r
+                       PrintAndLog("--specialblock no:%02x", blockNo);\r
+                       PrintAndLog("--data: %s", sprint_hex(bldata, 4));\r
+                       UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
+                       memcpy(d.d.asBytes,bldata, 4);\r
+                       SendCommand(&d);\r
+\r
+                       if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                               uint8_t isOK  = resp.arg[0] & 0xff;\r
+                               PrintAndLog("isOk:%02x", isOK);\r
+                       } else {\r
+                               PrintAndLog("Command execute timeout");\r
+                       }\r
+                       break;\r
+               default: \r
+                       PrintAndLog("--block no:%02x", blockNo);\r
+                       PrintAndLog("--data: %s", sprint_hex(bldata, 4));               \r
+                       UsbCommand e = {CMD_MIFAREU_WRITEBL, {blockNo}};\r
+                       memcpy(e.d.asBytes,bldata, 4);\r
+                       SendCommand(&e);\r
+\r
+                       if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+                               uint8_t isOK  = resp.arg[0] & 0xff;\r
+                               PrintAndLog("isOk:%02x", isOK);\r
+                       } else {\r
+                               PrintAndLog("Command execute timeout");\r
+                     }\r
+                     break;\r
        }\r
-        return 0;\r
+       return 0;\r
 }\r
 \r
 int CmdHF14AMfRdBl(const char *Cmd)\r
Impressum, Datenschutz