]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmfu.c
Split data askgproxiidemod to own file
[proxmark3-svn] / client / cmdhfmfu.c
index 3dfee3a6afe33f09add7d9db2d347c1345adaf73..ed8c588d3e4750a9c3edf0aee508799a665324d5 100644 (file)
@@ -7,8 +7,16 @@
 //-----------------------------------------------------------------------------
 // High frequency MIFARE ULTRALIGHT (C) commands
 //-----------------------------------------------------------------------------
-#include "loclass/des.h"
+
 #include "cmdhfmfu.h"
+
+#include <stdint.h>
+#include <stdio.h>
+#include "proxmark3.h"
+#include "usb_cmd.h"
+#include "cmdmain.h"
+#include "ui.h"
+#include "loclass/des.h"
 #include "cmdhfmf.h"
 #include "cmdhf14a.h"
 #include "mifare.h"
@@ -908,10 +916,6 @@ int CmdHF14AMfUWrBl(const char *Cmd){
        uint8_t authenticationkey[16] = {0x00};
        uint8_t *authKeyPtr = authenticationkey;
 
-       // starting with getting tagtype
-       TagTypeUL_t tagtype = GetHF14AMfU_Type();
-       if (tagtype == UL_ERROR) return -1;
-
        while(param_getchar(Cmd, cmdp) != 0x00)
        {
                switch(param_getchar(Cmd, cmdp))
@@ -943,21 +947,10 @@ int CmdHF14AMfUWrBl(const char *Cmd){
                        case 'b':
                        case 'B':
                                blockNo = param_get8(Cmd, cmdp+1);
-                               
-                               uint8_t maxblockno = 0;
-                               for (uint8_t idx = 0; idx < MAX_UL_TYPES; idx++){
-                                       if (tagtype & UL_TYPES_ARRAY[idx])
-                                               maxblockno = UL_MEMORY_ARRAY[idx];
-                               }
-               
                                if (blockNo < 0) {
                                        PrintAndLog("Wrong block number");
                                        errors = true;
                                }
-                               if (blockNo > maxblockno){
-                                       PrintAndLog("block number too large. Max block is %u/0x%02X \n", maxblockno,maxblockno);
-                                       errors = true;
-                               }
                                cmdp += 2;
                                break;
                        case 'l':
@@ -984,6 +977,19 @@ int CmdHF14AMfUWrBl(const char *Cmd){
        }
 
        if ( blockNo == -1 ) return usage_hf_mfu_wrbl();
+       // starting with getting tagtype
+       TagTypeUL_t tagtype = GetHF14AMfU_Type();
+       if (tagtype == UL_ERROR) return -1;
+
+       uint8_t maxblockno = 0;
+       for (uint8_t idx = 0; idx < MAX_UL_TYPES; idx++){
+               if (tagtype & UL_TYPES_ARRAY[idx])
+                       maxblockno = UL_MEMORY_ARRAY[idx];
+       }
+       if (blockNo > maxblockno){
+               PrintAndLog("block number too large. Max block is %u/0x%02X \n", maxblockno,maxblockno);
+               return usage_hf_mfu_wrbl();
+       }
 
        // Swap endianness 
        if (swapEndian && hasAuthKey) authKeyPtr = SwapEndian64(authenticationkey, 16, 8);
@@ -1035,10 +1041,6 @@ int CmdHF14AMfURdBl(const char *Cmd){
        uint8_t authenticationkey[16] = {0x00};
        uint8_t *authKeyPtr = authenticationkey;
 
-       // starting with getting tagtype
-       TagTypeUL_t tagtype = GetHF14AMfU_Type();
-       if (tagtype == UL_ERROR) return -1;
-
        while(param_getchar(Cmd, cmdp) != 0x00)
        {
                switch(param_getchar(Cmd, cmdp))
@@ -1070,21 +1072,10 @@ int CmdHF14AMfURdBl(const char *Cmd){
                        case 'b':
                        case 'B':
                                blockNo = param_get8(Cmd, cmdp+1);
-
-                               uint8_t maxblockno = 0;
-                               for (uint8_t idx = 0; idx < MAX_UL_TYPES; idx++){
-                                       if (tagtype & UL_TYPES_ARRAY[idx])
-                                               maxblockno = UL_MEMORY_ARRAY[idx];
-                               }
-
                                if (blockNo < 0) {
                                        PrintAndLog("Wrong block number");
                                        errors = true;
                                }
-                               if (blockNo > maxblockno){
-                                       PrintAndLog("block number to large. Max block is %u/0x%02X \n", maxblockno,maxblockno);
-                                       errors = true;
-                               }
                                cmdp += 2;
                                break;
                        case 'l':
@@ -1102,6 +1093,19 @@ int CmdHF14AMfURdBl(const char *Cmd){
        }
 
        if ( blockNo == -1 ) return usage_hf_mfu_rdbl();
+       // start with getting tagtype
+       TagTypeUL_t tagtype = GetHF14AMfU_Type();
+       if (tagtype == UL_ERROR) return -1;
+
+       uint8_t maxblockno = 0;
+       for (uint8_t idx = 0; idx < MAX_UL_TYPES; idx++){
+               if (tagtype & UL_TYPES_ARRAY[idx])
+                       maxblockno = UL_MEMORY_ARRAY[idx];
+       }
+       if (blockNo > maxblockno){
+               PrintAndLog("block number to large. Max block is %u/0x%02X \n", maxblockno,maxblockno);
+               return usage_hf_mfu_rdbl();
+       }
 
        // Swap endianness 
        if (swapEndian && hasAuthKey) authKeyPtr = SwapEndian64(authenticationkey, 16, 8);
@@ -1234,6 +1238,7 @@ int CmdHF14AMfUDump(const char *Cmd){
        bool manualPages = false;
        uint8_t startPage = 0;
        char tempStr[50];
+       unsigned char cleanASCII[4];
 
        while(param_getchar(Cmd, cmdp) != 0x00)
        {
@@ -1376,7 +1381,7 @@ int CmdHF14AMfUDump(const char *Cmd){
        PrintAndLog("---------------------------------");
        for (i = 0; i < Pages; ++i) {
                if ( i < 3 ) {
-                       PrintAndLog("%02d/0x%02X | %s|   | ", i+startPage, i+startPage, sprint_hex(data + i * 4, 4));
+                       PrintAndLog("%3d/0x%02X | %s|   | ", i+startPage, i+startPage, sprint_hex(data + i * 4, 4));
                        continue;
                }
                switch(i){
@@ -1423,7 +1428,12 @@ int CmdHF14AMfUDump(const char *Cmd){
                        case 43: tmplockbit = bit2[9]; break;  //auth1
                        default: break;
                }
-               PrintAndLog("%02d/0x%02X | %s| %d | %.4s", i+startPage, i+startPage, sprint_hex(data + i * 4, 4), tmplockbit, data+i*4);
+
+               // convert unprintable characters and line breaks to dots
+               memcpy(cleanASCII, data+i*4, 4);
+               clean_ascii(cleanASCII, 4);
+
+               PrintAndLog("%3d/0x%02X | %s| %d | %.4s", i+startPage, i+startPage, sprint_hex(data + i * 4, 4), tmplockbit, cleanASCII);
        }
        PrintAndLog("---------------------------------");
 
Impressum, Datenschutz