]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhflegic.c
CHG: unused variables and remove of compiler warnings.
[proxmark3-svn] / client / cmdhflegic.c
index 155d2759f3ce43916554a001c55c07ae88c6fa3a..62c43f0443eb9c296a20e5168a1a24c1e5ed55a6 100644 (file)
@@ -149,7 +149,16 @@ int usage_legic_esave(void){
        PrintAndLog("      hf legic esave 2 myfile");
        return 0;
 }
        PrintAndLog("      hf legic esave 2 myfile");
        return 0;
 }
-
+int usage_legic_wipe(void){
+       PrintAndLog("Fills a legic tag memory with zeros. From byte7 and to the end.");
+       PrintAndLog(" Usage:  hf legic wipe [h]");
+       PrintAndLog("Options:");
+       PrintAndLog("      h             : this help");
+       PrintAndLog("");
+       PrintAndLog("Samples:");        
+       PrintAndLog("      hf legic wipe");
+       return 0;
+}
 /*
  *  Output BigBuf and deobfuscate LEGIC RF tag data.
  *  This is based on information given in the talk held
 /*
  *  Output BigBuf and deobfuscate LEGIC RF tag data.
  *  This is based on information given in the talk held
@@ -627,14 +636,13 @@ int CmdLegicRfWrite(const char *Cmd) {
                PrintAndLog("############# DANGER ################");
                PrintAndLog("# changing the DCF is irreversible  #");
                PrintAndLog("#####################################");
                PrintAndLog("############# DANGER ################");
                PrintAndLog("# changing the DCF is irreversible  #");
                PrintAndLog("#####################################");
-               PrintAndLog("do you really want to continue? y(es) n(o)");              
-               char answer;
-               sscanf("%c", &answer);
-               bool exit = !(answer == 'n' || answer == 'N');
-               if (exit)
+               char *answer = NULL;
+               answer = readline("do you really want to continue? y(es) n(o) : ");
+               bool overwrite = (answer[0] == 'y' || answer[0] == 'Y');
+               if (!overwrite){
+                       PrintAndLog("command cancelled");
                        return 0;
                        return 0;
-               printf("ICE DCF:  %c answer, %d\n", answer, exit);
-               return 0;
+               }
        }
        
        legic_chk_iv(&IV);
        }
        
        legic_chk_iv(&IV);
@@ -916,7 +924,8 @@ int CmdLegicDump(const char *Cmd){
        else
                sprintf(fnameptr + fileNlen,".bin");
 
        else
                sprintf(fnameptr + fileNlen,".bin");
 
-       if ((f = fopen(filename,"wb")) == NULL) { 
+       f = fopen(filename,"wb");
+       if (!f) { 
                PrintAndLog("Could not create file name %s", filename);
                if (data)
                        free(data);
                PrintAndLog("Could not create file name %s", filename);
                if (data)
                        free(data);
@@ -992,7 +1001,8 @@ int CmdLegicRestore(const char *Cmd){
        fnameptr += fileNlen;
        sprintf(fnameptr, ".bin");
 
        fnameptr += fileNlen;
        sprintf(fnameptr, ".bin");
 
-       if ((f = fopen(filename,"rb")) == NULL) {
+       f = fopen(filename,"rb");
+       if (!f) {
                PrintAndLog("File %s not found or locked", filename);
                return 3;
        }       
                PrintAndLog("File %s not found or locked", filename);
                return 3;
        }       
@@ -1011,14 +1021,14 @@ int CmdLegicRestore(const char *Cmd){
 
        // load file
        size_t bytes_read = fread(data, 1, numofbytes, f);
 
        // load file
        size_t bytes_read = fread(data, 1, numofbytes, f);
+       fclose(f);
+       
        if ( bytes_read == 0){
                PrintAndLog("File reading error");
                free(data);
        if ( bytes_read == 0){
                PrintAndLog("File reading error");
                free(data);
-               fclose(f);
                return 2;
        }
                return 2;
        }
-       fclose(f);
-
+       
        PrintAndLog("Restoring to card");
 
        // transfer to device
        PrintAndLog("Restoring to card");
 
        // transfer to device
@@ -1088,7 +1098,8 @@ int CmdLegicELoad(const char *Cmd) {
        sprintf(fnameptr, ".bin");
        
        // open file
        sprintf(fnameptr, ".bin");
        
        // open file
-       if ((f = fopen(filename,"rb")) == NULL) { 
+       f = fopen(filename,"rb");
+       if (!f) { 
                PrintAndLog("File %s not found or locked", filename);
                free(data);
                return 1;
                PrintAndLog("File %s not found or locked", filename);
                free(data);
                return 1;
@@ -1100,9 +1111,11 @@ int CmdLegicELoad(const char *Cmd) {
                PrintAndLog("File reading error");
                free(data);
                fclose(f);
                PrintAndLog("File reading error");
                free(data);
                fclose(f);
+               f = NULL;               
                return 2;
        }
        fclose(f);
                return 2;
        }
        fclose(f);
+       f = NULL;
        
        // transfer to device
        legic_seteml(data, 0, numofbytes);
        
        // transfer to device
        legic_seteml(data, 0, numofbytes);
@@ -1162,7 +1175,8 @@ int CmdLegicESave(const char *Cmd) {
                sprintf(fnameptr + fileNlen,".bin");
        
        // open file
                sprintf(fnameptr + fileNlen,".bin");
        
        // open file
-       if ((f = fopen(filename,"wb")) == NULL) { 
+       f = fopen(filename,"wb");
+       if (!f) { 
                PrintAndLog("Could not create file name %s", filename);
                free(data);
                return 1;
                PrintAndLog("Could not create file name %s", filename);
                free(data);
                return 1;
@@ -1174,6 +1188,61 @@ int CmdLegicESave(const char *Cmd) {
        return 0;
 }
 
        return 0;
 }
 
+int CmdLegicWipe(const char *Cmd){
+
+       char cmdp = param_getchar(Cmd, 0);
+       
+       if ( cmdp == 'h' || cmdp == 'H') return usage_legic_wipe();
+       
+       // tagtype
+       legic_card_select_t card;
+       if (legic_get_type(&card)) {
+               PrintAndLog("Failed to identify tagtype");
+               return 1;
+       }
+       
+       // set up buffer
+       uint8_t *data = malloc(card.cardsize);
+       if (!data) {
+               PrintAndLog("Fail, cannot allocate memory");
+               return 2;               
+       }
+       memset(data, 0, card.cardsize);
+       
+       legic_print_type(card.cardsize, 0);
+
+       printf("Erasing");
+       
+       // transfer to device
+       size_t len = 0;
+       UsbCommand c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}};
+       UsbCommand resp;
+       for(size_t i = 7; i < card.cardsize; i += USB_CMD_DATA_SIZE) {
+               
+               printf(".");
+               len = MIN((card.cardsize - i), USB_CMD_DATA_SIZE);              
+               c.arg[0] = i; // offset
+               c.arg[1] = len; // number of bytes
+               memcpy(c.d.asBytes, data+i, len); 
+               clearCommandBuffer();
+               SendCommand(&c);
+       
+               if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
+                       PrintAndLog("command execution time out");
+                       free(data);     
+                       return 3;
+               }
+               uint8_t isOK = resp.arg[0] & 0xFF;
+               if ( !isOK ) {
+                       PrintAndLog("failed writing tag [msg = %u]", resp.arg[1] & 0xFF);
+                       free(data);     
+                       return 4;
+               }
+       }
+       printf("ok\n");
+       return 0;
+}
+
 int CmdLegicList(const char *Cmd) {
        CmdHFList("legic");
        return 0;
 int CmdLegicList(const char *Cmd) {
        CmdHFList("legic");
        return 0;
@@ -1192,6 +1261,7 @@ static command_t CommandTable[] =  {
        {"eload",       CmdLegicELoad,          1, "Load binary dump to emulator memory"},
        {"esave",       CmdLegicESave,          1, "Save emulator memory to binary file"},
        {"list",        CmdLegicList,           1, "[Deprecated] List LEGIC history"},
        {"eload",       CmdLegicELoad,          1, "Load binary dump to emulator memory"},
        {"esave",       CmdLegicESave,          1, "Save emulator memory to binary file"},
        {"list",        CmdLegicList,           1, "[Deprecated] List LEGIC history"},
+       {"wipe",        CmdLegicWipe,           1, "Wipe a LEGIC Prime tag"},
        {NULL, NULL, 0, NULL}
 };
 
        {NULL, NULL, 0, NULL}
 };
 
Impressum, Datenschutz