]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: The input handling for "hf 14b write" is now correct. Thanks Asper for spotting...
authoriceman1001 <iceman@iuse.se>
Wed, 7 Jan 2015 21:51:34 +0000 (22:51 +0100)
committericeman1001 <iceman@iuse.se>
Wed, 7 Jan 2015 21:51:34 +0000 (22:51 +0100)
Minor code clean up.
Added from Pm3-master which will make this fork one step closer to Pm3-master.

armsrc/hitag2.c
armsrc/iclass.c
client/cmdhf14b.c
client/cmdhfmf.c
client/cmdhw.c
client/loclass/fileutils.c
client/proxmark3.c

index dc4c4232c98c2c3cf5086829048a9512a4513771..d25fe4c8293cf7c4b71d4a2536ffe82c855c8757 100644 (file)
@@ -1158,7 +1158,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
       
                case RHT2F_CRYPTO: {
                        DbpString("Authenticating using key:");
       
                case RHT2F_CRYPTO: {
                        DbpString("Authenticating using key:");
-                       memcpy(key,htd->crypto.key,6);  // 4 or 6 ??
+                       memcpy(key,htd->crypto.key,4);    //HACK; 4 or 6??  I read both in the code.
                        Dbhexdump(6,key,false);
       blocknr = 0;
                        bQuiet = false;
                        Dbhexdump(6,key,false);
       blocknr = 0;
                        bQuiet = false;
index 474a336c224c116914fff514430d8a1a0b26cfb9..aca2c91833363f7357bda1506c657e59fe31446a 100644 (file)
@@ -1587,7 +1587,7 @@ void ReaderIClass(uint8_t arg0) {
 
 void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) {
 
 
 void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) {
 
-       uint8_t card_data[24]={0};
+       uint8_t card_data[USB_CMD_DATA_SIZE]={0};
        uint16_t block_crc_LUT[255] = {0};
 
        {//Generate a lookup table for block crc
        uint16_t block_crc_LUT[255] = {0};
 
        {//Generate a lookup table for block crc
@@ -1660,7 +1660,10 @@ void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) {
 
                cardsize = memory.k16 ? 255 : 32;
                WDT_HIT();
 
                cardsize = memory.k16 ? 255 : 32;
                WDT_HIT();
-
+               //Set card_data to all zeroes, we'll fill it with data
+               memset(card_data,0x0,USB_CMD_DATA_SIZE);
+               uint8_t failedRead =0;
+               uint8_t stored_data_length =0;
                                //then loop around remaining blocks
                for(int block=0; block < cardsize; block++){
 
                                //then loop around remaining blocks
                for(int block=0; block < cardsize; block++){
 
@@ -1676,14 +1679,47 @@ void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) {
                                          resp[3], resp[4], resp[5],
                                          resp[6], resp[7]);
 
                                          resp[3], resp[4], resp[5],
                                          resp[6], resp[7]);
 
+                               //Fill up the buffer
+                               memcpy(card_data+stored_data_length,resp,8);
+                               stored_data_length += 8;
+
+                               if(stored_data_length +8 > USB_CMD_DATA_SIZE)
+                               {//Time to send this off and start afresh
+                                       cmd_send(CMD_ACK,
+                                                        stored_data_length,//data length
+                                                        failedRead,//Failed blocks?
+                                                        0,//Not used ATM
+                                                        card_data, stored_data_length);
+                                       //reset
+                                       stored_data_length = 0;
+                                       failedRead = 0;
+                               }
+
                        }else{
                        }else{
+                               failedRead = 1;
+                               stored_data_length +=8;//Otherwise, data becomes misaligned
                                Dbprintf("Failed to dump block %d", block);
                                Dbprintf("Failed to dump block %d", block);
-
                        }
                }
                        }
                }
+               //Send off any remaining data
+               if(stored_data_length > 0)
+               {
+                       cmd_send(CMD_ACK,
+                                        stored_data_length,//data length
+                                        failedRead,//Failed blocks?
+                                        0,//Not used ATM
+                                        card_data, stored_data_length);
+               }
                //If we got here, let's break
                break;
        }
                //If we got here, let's break
                break;
        }
+       //Signal end of transmission
+       cmd_send(CMD_ACK,
+                        0,//data length
+                        0,//Failed blocks?
+                        0,//Not used ATM
+                        card_data, 0);
+
        LED_A_OFF();
 }
 
        LED_A_OFF();
 }
 
@@ -1702,7 +1738,7 @@ void IClass_iso14443A_write(uint8_t arg0, uint8_t blockNo, uint8_t *data, uint8_
        
     uint16_t crc = 0;
        
        
     uint16_t crc = 0;
        
-       uint8_t* resp = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
+       uint8_t* resp = (((uint8_t *)BigBuf) + 3560);
 
        // Reset trace buffer
        memset(trace, 0x44, RECV_CMD_OFFSET);
 
        // Reset trace buffer
        memset(trace, 0x44, RECV_CMD_OFFSET);
index 03152cddb7bc0516f475b5dd2d20557d2ab53de6..15a6ab9042dc626cbe1ff09a476b38c046247313 100644 (file)
@@ -407,18 +407,23 @@ int CmdHF14BWrite( const char *Cmd){
                PrintAndLog("Usage:  hf 14b write <1|2> <BLOCK> <DATA>");
                PrintAndLog("    [1 = SRIX4K]");
                PrintAndLog("    [2 = SRI512]");
                PrintAndLog("Usage:  hf 14b write <1|2> <BLOCK> <DATA>");
                PrintAndLog("    [1 = SRIX4K]");
                PrintAndLog("    [2 = SRI512]");
-               PrintAndLog("    [BLOCK number depends on which tag, special block == 255]");
-               PrintAndLog("     sample: hf 14b write 1 127 11223344");
-               PrintAndLog("           : hf 14b write 1 255 11223344");
+               PrintAndLog("    [BLOCK number depends on tag, special block == FF]");
+               PrintAndLog("     sample: hf 14b write 1 7F 11223344");
+               PrintAndLog("           : hf 14b write 1 FF 11223344");
                PrintAndLog("           : hf 14b write 2 15 11223344");
                PrintAndLog("           : hf 14b write 2 15 11223344");
-               PrintAndLog("           : hf 14b write 2 255 11223344");
+               PrintAndLog("           : hf 14b write 2 FF 11223344");
                return 0;
        }
 
                return 0;
        }
 
-       if ( param_getchar(Cmd, 0) == '2' )
+       if ( cmdp == '2' )
                isSrix4k = false;
        
                isSrix4k = false;
        
-       blockno = param_get8(Cmd, 1);
+       //blockno = param_get8(Cmd, 1);
+       
+       if ( param_gethex(Cmd,1, &blockno, 2) ) {
+               PrintAndLog("Block number must include 2 HEX symbols");
+               return 0;
+       }
        
        if ( isSrix4k ){
                if ( blockno > 0x7f && blockno != 0xff ){
        
        if ( isSrix4k ){
                if ( blockno > 0x7f && blockno != 0xff ){
@@ -438,11 +443,12 @@ int CmdHF14BWrite( const char *Cmd){
        }
  
        if ( blockno == 0xff)
        }
  
        if ( blockno == 0xff)
-               PrintAndLog("Writing to special block %02X [ %s]", blockno,  sprint_hex(data,4) );
+               PrintAndLog("[%s] Write special block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512" , blockno,  sprint_hex(data,4) );
        else
        else
-               PrintAndLog("Writing to block %02X [ %s]", blockno,  sprint_hex(data,4) );
+               PrintAndLog("[%s] Write block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512", blockno,  sprint_hex(data,4) );
  
        sprintf(str, "-c -p 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
  
        sprintf(str, "-c -p 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
+
        CmdHF14BCmdRaw(str);
        return 0;
 }
        CmdHF14BCmdRaw(str);
        return 0;
 }
index 0229c9477489137e9c722f786bac6c44ffc53f51..703e4c8becefc785ddace74167ac945d94d2613a 100644 (file)
@@ -460,7 +460,7 @@ int CmdHF14AMfRestore(const char *Cmd)
                default:   numSectors = 16;\r
        }       \r
 \r
                default:   numSectors = 16;\r
        }       \r
 \r
-       if (cmdp == 'h' || cmdp == 'H') {\r
+       if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') {\r
                PrintAndLog("Usage:   hf mf restore [card memory]");\r
                PrintAndLog("  [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");\r
                PrintAndLog("");\r
                PrintAndLog("Usage:   hf mf restore [card memory]");\r
                PrintAndLog("  [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");\r
                PrintAndLog("");\r
index 642f63c55af6639a5ffc235a0c693051f6c98337..4f65fb8c2badddf4fe45cdc6bd6f4e73ad54cdde 100644 (file)
@@ -18,6 +18,7 @@
 #include "cmddata.h"
 #include "cmdhw.h"
 #include "cmdmain.h"
 #include "cmddata.h"
 #include "cmdhw.h"
 #include "cmdmain.h"
+#include "cmddata.h"
 
 /* low-level hardware control */
 
 
 /* low-level hardware control */
 
index 6475c126b8c1fb4270321f91ae1553c291cac34a..8ec52cfeb8d4da51c86797362dc473cf1df4f128 100644 (file)
@@ -76,14 +76,14 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
        /* We should have a valid filename now, e.g. dumpdata-3.bin */
 
        /*Opening file for writing in binary mode*/
        /* We should have a valid filename now, e.g. dumpdata-3.bin */
 
        /*Opening file for writing in binary mode*/
-       FILE *fh=fopen(fileName,"wb");
-       if(!fh) {
+       FILE *fileHandle=fopen(fileName,"wb");
+       if(!fileHandle) {
                PrintAndLog("Failed to write to file '%s'", fileName);
                PrintAndLog("Failed to write to file '%s'", fileName);
-               free(fh);
+               free(fileName);
                return 1;
        }
                return 1;
        }
-       fwrite(data, 1, datalen, fh);
-       fclose(fh);
+       fwrite(data, 1, datalen, fileHandle);
+       fclose(fileHandle);
        PrintAndLog("Saved data to '%s'", fileName);
        free(fileName);
 
        PrintAndLog("Saved data to '%s'", fileName);
        free(fileName);
 
index 681ec2d84c5afc2e73a275d39bd643d46d65f0e9..1e9a635e1f9d017248df67a0a5123548d08bd971 100644 (file)
@@ -37,13 +37,8 @@ void SendCommand(UsbCommand *c) {
 #if 0
   printf("Sending %d bytes\n", sizeof(UsbCommand));
 #endif
 #if 0
   printf("Sending %d bytes\n", sizeof(UsbCommand));
 #endif
-/*
-  if (txcmd_pending) {
-    ERR("Sending command failed, previous command is still pending");
-  }
-*/
-  if(offline)
-    {
+
+       if (offline) {
       PrintAndLog("Sending bytes to proxmark failed - offline");
       return;
     }
       PrintAndLog("Sending bytes to proxmark failed - offline");
       return;
     }
@@ -82,7 +77,7 @@ static void *uart_receiver(void *targ) {
         continue;
       }
       cmd_count = (prx-rx) / sizeof(UsbCommand);
         continue;
       }
       cmd_count = (prx-rx) / sizeof(UsbCommand);
-      //      printf("received %d bytes, which represents %d commands\n",(prx-rx), cmd_count);
+
       for (size_t i=0; i<cmd_count; i++) {
         UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
       }
       for (size_t i=0; i<cmd_count; i++) {
         UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
       }
@@ -109,43 +104,37 @@ static void *main_loop(void *targ) {
   
   if (arg->usb_present == 1) {
     rarg.run=1;
   
   if (arg->usb_present == 1) {
     rarg.run=1;
-    // pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
     pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
   }
   
   FILE *script_file = NULL;
   char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
   
     pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
   }
   
   FILE *script_file = NULL;
   char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
   
-  if (arg->script_cmds_file)
-  {
+       if (arg->script_cmds_file) {
     script_file = fopen(arg->script_cmds_file, "r");
     script_file = fopen(arg->script_cmds_file, "r");
-    if (script_file)
-    {
+               if (script_file) {
       printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
     }
   }
 
        read_history(".history");
       printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
     }
   }
 
        read_history(".history");
-       while(1)
-  {
+
+       while(1)  {
+
     // If there is a script file
     if (script_file)
     {
     // If there is a script file
     if (script_file)
     {
-      if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file))
-      {
+                       if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) {
         fclose(script_file);
         script_file = NULL;
         fclose(script_file);
         script_file = NULL;
-      }
-      else
-      {
+                       } else {
         char *nl;
         nl = strrchr(script_cmd_buf, '\r');
         if (nl) *nl = '\0';
         nl = strrchr(script_cmd_buf, '\n');
         if (nl) *nl = '\0';
         
         char *nl;
         nl = strrchr(script_cmd_buf, '\r');
         if (nl) *nl = '\0';
         nl = strrchr(script_cmd_buf, '\n');
         if (nl) *nl = '\0';
         
-        if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL)
-        {
+                               if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
           memset(cmd, 0, strlen(script_cmd_buf));
           strcpy(cmd, script_cmd_buf);
           printf("%s\n", cmd);
           memset(cmd, 0, strlen(script_cmd_buf));
           strcpy(cmd, script_cmd_buf);
           printf("%s\n", cmd);
@@ -153,12 +142,12 @@ static void *main_loop(void *targ) {
       }
     }
                
       }
     }
                
-               if (!script_file)
-               {
+               if (!script_file) {
       cmd = readline(PROXPROMPT);
                }
                
                if (cmd) {
       cmd = readline(PROXPROMPT);
                }
                
                if (cmd) {
+
                        while(cmd[strlen(cmd) - 1] == ' ')
         cmd[strlen(cmd) - 1] = 0x00;
                        
                        while(cmd[strlen(cmd) - 1] == ' ')
         cmd[strlen(cmd) - 1] = 0x00;
                        
@@ -167,7 +156,6 @@ static void *main_loop(void *targ) {
                                        exit(0);
                                        break;
                                }
                                        exit(0);
                                        break;
                                }
-                               
                                CommandReceived(cmd);
                                add_history(cmd);
                        }
                                CommandReceived(cmd);
                                add_history(cmd);
                        }
@@ -185,8 +173,7 @@ static void *main_loop(void *targ) {
     pthread_join(reader_thread, NULL);
   }
   
     pthread_join(reader_thread, NULL);
   }
   
-  if (script_file)
-  {
+       if (script_file) {
     fclose(script_file);
     script_file = NULL;
   }
     fclose(script_file);
     script_file = NULL;
   }
Impressum, Datenschutz