]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmfu.c
ADD: marshmellows new lf command and DetectClock. (works great!)
[proxmark3-svn] / client / cmdhfmfu.c
index 3b9f2e6d9d4919963c9a980e43a2d894e95f49d1..52b7ad14c46b46f9e06f3f618cc1cf014380a912 100644 (file)
@@ -24,9 +24,9 @@ static int CmdHelp(const char *Cmd);
 //  Mifare Ultralight Write Single Block
 //
 int CmdHF14AMfUWrBl(const char *Cmd){
-    uint8_t blockNo = 0;
-    bool chinese_card=0;
-    uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+    uint8_t blockNo    = 0;
+    bool chinese_card  = 0;
+    uint8_t bldata[16] = {0x00};
     UsbCommand resp;
         
     if (strlen(Cmd)<3) {
@@ -158,10 +158,11 @@ int CmdHF14AMfURdBl(const char *Cmd){
         if (isOK)
             PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 4));
         else
-           PrintAndLog("isOk:%02x", isOK);
-        } else {
-                PrintAndLog("Command execute timeout");
+                       PrintAndLog("isOk:%02x", isOK);
         }
+       else {
+        PrintAndLog("Command execute timeout");
+    }
     return 0;
 }
 
@@ -171,12 +172,12 @@ int CmdHF14AMfURdBl(const char *Cmd){
 int CmdHF14AMfURdCard(const char *Cmd){
     int i;
     uint8_t BlockNo = 0;
-    int Pages=16;
+    int pages=16;
     uint8_t *lockbytes_t=NULL;
-    uint8_t lockbytes[2]={0,0};
-    bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+    uint8_t lockbytes[2]={0x00};
+    bool bit[16]={0x00};
     bool dump=false;
-    uint8_t datatemp[5]={0,0,0,0,0};
+    uint8_t datatemp[7]= {0x00};
         
     uint8_t isOK  = 0;
     uint8_t * data  = NULL;
@@ -191,7 +192,7 @@ int CmdHF14AMfURdCard(const char *Cmd){
         PrintAndLog("Dumping Ultralight Card Data...");
     }
     PrintAndLog("Attempting to Read Ultralight... ");
-    UsbCommand c = {CMD_MIFAREU_READCARD, {BlockNo, Pages}};
+    UsbCommand c = {CMD_MIFAREU_READCARD, {BlockNo, pages}};
     SendCommand(&c);
     UsbCommand resp;
 
@@ -231,7 +232,7 @@ int CmdHF14AMfURdCard(const char *Cmd){
                        PrintAndLog(" OneTimePad :%s ", sprint_hex(data + 3*4, 4));
                        PrintAndLog("");
                        
-            for (i = 0; i < Pages; i++) {
+            for (i = 0; i < pages; i++) {
                 switch(i){
                     case 2:
                         //process lock bytes
@@ -327,19 +328,17 @@ int CmdHF14AMfURdCard(const char *Cmd){
 
 int CmdHF14AMfUDump(const char *Cmd){
     int i;
-    uint8_t BlockNo = 0;
-    int Pages=16;
-    uint8_t *lockbytes_t=NULL;
-    uint8_t lockbytes[2]={0,0};
-    bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-    bool dump=false;
-    uint8_t datatemp[5]={0,0,0,0,0};
-        
-    uint8_t isOK  = 0;
-    uint8_t * data  = NULL;
+    uint8_t BlockNo      = 0;
+    int Pages            = 16;
+    uint8_t *lockbytes_t = NULL;
+    uint8_t lockbytes[2] = {0x00};
+    bool bit[16]         = {0x00};
+    uint8_t datatemp[5]  = {0x00};
+       bool dump            = true;
+    uint8_t isOK         = 0;
+    uint8_t * data       = NULL;
     FILE *fout;
 
-    dump=true;
     if ((fout = fopen("dump_ultralight_data.bin","wb")) == NULL) { 
         PrintAndLog("Could not create file name dumpdata.bin");
         return 1;      
@@ -468,15 +467,18 @@ void rol (uint8_t *data, const size_t len){
 int CmdHF14AMfucAuth(const char *Cmd){
         
     uint8_t blockNo = 0, keyNo=0;
-    uint8_t e_RndB[8];
+    uint8_t e_RndB[8] = {0x00};
     uint32_t cuid=0;
-    unsigned char RndARndB[16];
-    uint8_t key[16];
+    unsigned char RndARndB[16] = {0x00};
+    uint8_t key[16] = {0x00};
     DES_cblock RndA, RndB;
-    DES_cblock iv={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+    DES_cblock iv;
     DES_key_schedule ks1,ks2;
     DES_cblock key1,key2;
 
+       // 
+       memset(iv, 0, 8);
+       
     if (strlen(Cmd)<1) {
         PrintAndLog("Usage:  hf mfu auth k <key number>");
         PrintAndLog("        sample: hf mfu auth k 0");
@@ -566,7 +568,6 @@ int CmdHF14AMfucAuth(const char *Cmd){
 //
 int CmdHF14AMfUCRdBl(const char *Cmd)
 {
-
     uint8_t blockNo = 0;
         
     if (strlen(Cmd)<1) {
@@ -607,14 +608,13 @@ int CmdHF14AMfUCRdCard(const char *Cmd){
     uint8_t BlockNo = 0;
     int Pages=44;
     uint8_t *lockbytes_t=NULL;
-    uint8_t lockbytes[2]={0,0};
+    uint8_t lockbytes[2]={0x00};
     uint8_t *lockbytes_t2=NULL;
-    uint8_t lockbytes2[2]={0,0};
-    bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-    bool bit2[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+    uint8_t lockbytes2[2]={0x00};
+    bool bit[16]={0x00};
+    bool bit2[16]={0x00};
     bool dump=false;
-    uint8_t datatemp[5]={0,0,0,0,0};
-        
+    uint8_t datatemp[5]={0x00};
     uint8_t isOK  = 0;
     uint8_t * data  = NULL;
     FILE *fout = NULL;
@@ -635,7 +635,7 @@ int CmdHF14AMfUCRdCard(const char *Cmd){
     if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
         isOK  = resp.arg[0] & 0xff;
         data  = resp.d.asBytes;
-       //Pages=sizeof(data)/sizeof(data[0]);
+
         PrintAndLog("isOk:%02x", isOK);
         if (isOK) 
             for (i = 0; i < Pages; i++) {
@@ -817,25 +817,24 @@ int CmdHF14AMfUCDump(const char *Cmd){
     uint8_t BlockNo = 0;
     int Pages=44;
     uint8_t *lockbytes_t=NULL;
-    uint8_t lockbytes[2]={0,0};
+    uint8_t lockbytes[2]={0x00};
     uint8_t *lockbytes_t2=NULL;
-    uint8_t lockbytes2[2]={0,0};
-    bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-    bool bit2[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-    bool dump=false;
-    uint8_t datatemp[5]={0,0,0,0,0};
+    uint8_t lockbytes2[2]={0x00};
+    bool bit[16]={0x00};
+    bool bit2[16]={0x00};
+    bool dump=true;
+    uint8_t datatemp[5]={0x00};
         
     uint8_t isOK  = 0;
     uint8_t * data  = NULL;
     FILE *fout;
 
-       dump=true;
        if ((fout = fopen("dump_ultralightc_data.bin","wb")) == NULL) { 
                PrintAndLog("Could not create file name dumpdata.bin");
                return 1;       
        }
        PrintAndLog("Dumping Ultralight C Card Data...");
-   PrintAndLog("Attempting to Read Ultralight C... ");
+    PrintAndLog("Attempting to Read Ultralight C... ");
     UsbCommand c = {CMD_MIFAREU_READCARD, {BlockNo,Pages}};
     SendCommand(&c);
     UsbCommand resp;
@@ -1024,8 +1023,8 @@ int CmdHF14AMfUCDump(const char *Cmd){
 int CmdHF14AMfUCWrBl(const char *Cmd){
     
     uint8_t blockNo = 0;
-    bool chinese_card=0;
-    uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+    bool chinese_card = 0;
+    uint8_t bldata[16] = {0x00};
     UsbCommand resp;
         
     if (strlen(Cmd)<3) {
@@ -1132,14 +1131,14 @@ int CmdHF14AMfUCWrBl(const char *Cmd){
 //------------------------------------
 static command_t CommandTable[] =
 {
-    {"help",    CmdHelp,               1,"This help"},
+    {"help",    CmdHelp,                   1,"This help"},
     {"dbg",     CmdHF14AMfDbg,         0,"Set default debug mode"},
-    {"urdbl",   CmdHF14AMfURdBl,        0,"Read MIFARE Ultralight block"},
-    {"urdcard", CmdHF14AMfURdCard,      0,"Read MIFARE Ultralight Card"},
+    {"urdbl",   CmdHF14AMfURdBl,    0,"Read MIFARE Ultralight block"},
+    {"urdcard", CmdHF14AMfURdCard,  0,"Read MIFARE Ultralight Card"},
     {"udump",   CmdHF14AMfUDump,       0,"Dump MIFARE Ultralight tag to binary file"},
     {"uwrbl",   CmdHF14AMfUWrBl,       0,"Write MIFARE Ultralight block"},
-    {"ucrdbl",  CmdHF14AMfUCRdBl,       0,"Read MIFARE Ultralight C block"},
-    {"ucrdcard",CmdHF14AMfUCRdCard,     0,"Read MIFARE Ultralight C Card"},
+    {"ucrdbl",  CmdHF14AMfUCRdBl,   0,"Read MIFARE Ultralight C block"},
+    {"ucrdcard",CmdHF14AMfUCRdCard, 0,"Read MIFARE Ultralight C Card"},
     {"ucdump",  CmdHF14AMfUCDump,      0,"Dump MIFARE Ultralight C tag to binary file"},
     {"ucwrbl",  CmdHF14AMfUCWrBl,      0,"Write MIFARE Ultralight C block"},
     {"auth",    CmdHF14AMfucAuth,      0,"Ultralight C Authentication"},
@@ -1147,7 +1146,6 @@ static command_t CommandTable[] =
 };
 
 int CmdHFMFUltra(const char *Cmd){
-    // flush
     WaitForResponseTimeout(CMD_ACK,NULL,100);
     CmdsParse(CommandTable, Cmd);
     return 0;
Impressum, Datenschutz