-
- uint8_t blockNo = 0;
- bool chinese_card = 0;
- uint8_t bldata[16] = {0x00};
- UsbCommand resp;
-
- if (strlen(Cmd)<3) {
- PrintAndLog("Usage: hf mfu cwrbl <block number> <block data (8 hex symbols)> [w]");
- PrintAndLog(" sample: hf mfu wrbl 0 01020304");
- return 0;
- }
- blockNo = param_get8(Cmd, 0);
- if (blockNo>(MAX_ULTRAC_BLOCKS+4)){
- PrintAndLog("Error: Maximum number of blocks is 47 for Ultralight Cards!");
- return 1;
- }
- if (param_gethex(Cmd, 1, bldata, 8)) {
- PrintAndLog("Block data must include 8 HEX symbols");
- return 1;
- }
- if (strchr(Cmd,'w') != 0) {
- chinese_card=1;
- }
- switch(blockNo){
- case 0:
- if (!chinese_card){
- PrintAndLog("Access Denied");
- }else{
- PrintAndLog("--specialblock no:%02x", blockNo);
- PrintAndLog("--data: %s", sprint_hex(bldata, 4));
- UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
- memcpy(d.d.asBytes,bldata, 4);
- SendCommand(&d);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
- uint8_t isOK = resp.arg[0] & 0xff;
- PrintAndLog("isOk:%02x", isOK);
- } else {
- PrintAndLog("Command execute timeout");
- }
- }
- break;
- case 1:
- if (!chinese_card){
- PrintAndLog("Access Denied");
- }else{
- PrintAndLog("--specialblock no:%02x", blockNo);
- PrintAndLog("--data: %s", sprint_hex(bldata, 4));
- UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
- memcpy(d.d.asBytes,bldata, 4);
- SendCommand(&d);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
- uint8_t isOK = resp.arg[0] & 0xff;
- PrintAndLog("isOk:%02x", isOK);
- } else {
- PrintAndLog("Command execute timeout");
- }
- }
- break;
- case 2:
- if (!chinese_card){
- PrintAndLog("Access Denied");
- }else{
- PrintAndLog("--specialblock no:%02x", blockNo);
- PrintAndLog("--data: %s", sprint_hex(bldata, 4));
- UsbCommand c = {CMD_MIFAREU_WRITEBL, {blockNo}};
- memcpy(c.d.asBytes, bldata, 4);
- SendCommand(&c);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
- uint8_t isOK = resp.arg[0] & 0xff;
- PrintAndLog("isOk:%02x", isOK);
- } else {
- PrintAndLog("Command execute timeout");
- }
- }
- break;
- case 3:
- PrintAndLog("--specialblock no:%02x", blockNo);
- PrintAndLog("--data: %s", sprint_hex(bldata, 4));
- UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
- memcpy(d.d.asBytes,bldata, 4);
- SendCommand(&d);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
- uint8_t isOK = resp.arg[0] & 0xff;
- PrintAndLog("isOk:%02x", isOK);
- } else {
- PrintAndLog("Command execute timeout");
- }
- break;
- default:
- PrintAndLog("--block no:%02x", blockNo);
- PrintAndLog("--data: %s", sprint_hex(bldata, 4));
- UsbCommand e = {CMD_MIFAREU_WRITEBL, {blockNo}};
- memcpy(e.d.asBytes,bldata, 4);
- SendCommand(&e);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
- uint8_t isOK = resp.arg[0] & 0xff;
- PrintAndLog("isOk:%02x", isOK);
- } else {
- PrintAndLog("Command execute timeout");
- }
- break;
- }
- return 0;
+
+ uint8_t blockNo = -1;
+ bool chinese_card = FALSE;
+ uint8_t bldata[16] = {0x00};
+ UsbCommand resp;
+
+ char cmdp = param_getchar(Cmd, 0);
+
+ if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') {
+ PrintAndLog("Usage: hf mfu cwrbl <block number> <block data (8 hex symbols)> [w]");
+ PrintAndLog(" [block number]");
+ PrintAndLog(" [block data] - (8 hex symbols)");
+ PrintAndLog(" [w] - Chinese magic ultralight tag");
+ PrintAndLog("");
+ PrintAndLog(" sample: hf mfu cwrbl 0 01020304");
+ PrintAndLog("");
+ return 0;
+ }
+
+ blockNo = param_get8(Cmd, 0);
+ if (blockNo > MAX_ULTRAC_BLOCKS ){
+ PrintAndLog("Error: Maximum number of blocks is 47 for Ultralight-C Cards!");
+ return 1;
+ }
+
+ if (param_gethex(Cmd, 1, bldata, 8)) {
+ PrintAndLog("Block data must include 8 HEX symbols");
+ return 1;
+ }
+
+ if (strchr(Cmd,'w') != 0 || strchr(Cmd,'W') != 0 ) {
+ chinese_card = TRUE;
+ }
+
+ if ( blockNo <= 3 ) {
+ if (!chinese_card){
+ PrintAndLog("Access Denied");
+ } else {
+ PrintAndLog("--Special block no: 0x%02x", blockNo);
+ PrintAndLog("--Data: %s", sprint_hex(bldata, 4));
+ UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
+ memcpy(d.d.asBytes,bldata, 4);
+ SendCommand(&d);
+ if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
+ uint8_t isOK = resp.arg[0] & 0xff;
+ PrintAndLog("isOk:%02x", isOK);
+ } else {
+ PrintAndLog("Command execute timeout");
+ }
+ }
+ } else {
+ PrintAndLog("--Block no : 0x%02x", blockNo);
+ PrintAndLog("--Data: %s", sprint_hex(bldata, 4));
+ UsbCommand e = {CMD_MIFAREU_WRITEBL, {blockNo}};
+ memcpy(e.d.asBytes,bldata, 4);
+ SendCommand(&e);
+ if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
+ uint8_t isOK = resp.arg[0] & 0xff;
+ PrintAndLog("isOk : %02x", isOK);
+ } else {
+ PrintAndLog("Command execute timeout");
+ }
+ }
+ return 0;