]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
FIXED: Merged all Holimans code-review issues which should fix a lot of memoryleaks.
authoriceman1001 <iceman@iuse.se>
Wed, 29 Oct 2014 23:09:01 +0000 (00:09 +0100)
committericeman1001 <iceman@iuse.se>
Wed, 29 Oct 2014 23:09:01 +0000 (00:09 +0100)
18 files changed:
armsrc/appmain.c
armsrc/epa.c
armsrc/iso14443a.c
armsrc/lfops.c
armsrc/util.c
client/cmddata.c
client/cmdhf15.c
client/cmdhficlass.c
client/cmdhfmf.c
client/cmdlf.c
client/cmdlfem4x.c
client/cmdlft55xx.c
client/cmdmain.c
client/graph.c
client/loclass/ikeys.c
client/mifarehost.c
client/nonce2key/crapto1.c
client/ui.c

index 6d18561a532fe0b4342472d57e8da8c148add905..581335de60439a53c3f8d1b744ed3cae6e867e6d 100644 (file)
@@ -674,7 +674,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        break;
                case CMD_SIMULATE_TAG_125K:
                        LED_A_ON();
                        break;
                case CMD_SIMULATE_TAG_125K:
                        LED_A_ON();
-                       SimulateTagLowFrequency(c->arg[0], c->arg[1], 1);
+                       SimulateTagLowFrequency(c->arg[0], c->arg[1], 0);
                        LED_A_OFF();
                        break;
                case CMD_LF_SIMULATE_BIDIR:
                        LED_A_OFF();
                        break;
                case CMD_LF_SIMULATE_BIDIR:
index 565019ce22ec621285b77d5f2334fae24ec7e1a1..69599dc9fd8460bcbdb5fba67b3f24f3e85b46b7 100644 (file)
@@ -419,7 +419,7 @@ int EPA_Setup()
        // return code
        int return_code = 0;
        // card UID
        // return code
        int return_code = 0;
        // card UID
-       uint8_t uid[8];
+       uint8_t uid[10];
        // card select information
        iso14a_card_select_t card_select_info;
        // power up the field
        // card select information
        iso14a_card_select_t card_select_info;
        // power up the field
index 3b17bd4b393b59f5579a3b674c543cbb937a702e..6fe83c6e672cede74bad42d286f1e8fccf0f1b4a 100644 (file)
@@ -1717,7 +1717,13 @@ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, u
     if ((sak & 0x04) /* && uid_resp[0] == 0x88 */) {
       // Remove first byte, 0x88 is not an UID byte, it CT, see page 3 of:
       // http://www.nxp.com/documents/application_note/AN10927.pdf
     if ((sak & 0x04) /* && uid_resp[0] == 0x88 */) {
       // Remove first byte, 0x88 is not an UID byte, it CT, see page 3 of:
       // http://www.nxp.com/documents/application_note/AN10927.pdf
-      memcpy(uid_resp, uid_resp + 1, 3);
+      // This was earlier:
+         //memcpy(uid_resp, uid_resp + 1, 3);
+         // But memcpy should not be used for overlapping arrays,
+         // and memmove appears to not be available in the arm build.
+         // So this has been replaced with a for-loop:
+         for(int xx = 0; xx < 3; xx++) 
+            uid_resp[xx] = uid_resp[xx+1];
       uid_resp_len = 3;
     }
 
       uid_resp_len = 3;
     }
 
@@ -1928,7 +1934,8 @@ void ReaderMifare(bool first_try)
        uint8_t uid[10];
        uint32_t cuid;
 
        uint8_t uid[10];
        uint32_t cuid;
 
-       uint32_t nt, previous_nt;
+       uint32_t nt = 0;
+       uint32_t previous_nt = 0;
        static uint32_t nt_attacked = 0;
        byte_t par_list[8] = {0,0,0,0,0,0,0,0};
        byte_t ks_list[8] = {0,0,0,0,0,0,0,0};
        static uint32_t nt_attacked = 0;
        byte_t par_list[8] = {0,0,0,0,0,0,0,0};
        byte_t ks_list[8] = {0,0,0,0,0,0,0,0};
index 025314a04ad49745a57d0aa799c65a106c64b0ee..c80caf776b323d600453b62c557c5f4e4d90778f 100644 (file)
@@ -17,6 +17,9 @@
 #include "crapto1.h"
 #include "mifareutil.h"
 
 #include "crapto1.h"
 #include "mifareutil.h"
 
+#define SHORT_COIL()   LOW(GPIO_SSC_DOUT)
+#define OPEN_COIL()            HIGH(GPIO_SSC_DOUT)
+
 void LFSetupFPGAForADC(int divisor, bool lf_field)
 {
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 void LFSetupFPGAForADC(int divisor, bool lf_field)
 {
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
@@ -56,10 +59,9 @@ void DoAcquisition125k_internal(int trigger_threshold, bool silent)
 {
        uint8_t *dest =  mifare_get_bigbufptr();
        int n = 24000;
 {
        uint8_t *dest =  mifare_get_bigbufptr();
        int n = 24000;
-       int i;
-
+       int i = 0;
        memset(dest, 0x00, n);
        memset(dest, 0x00, n);
-       i = 0;
+
        for(;;) {
                if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
                        AT91C_BASE_SSC->SSC_THR = 0x43;
        for(;;) {
                if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
                        AT91C_BASE_SSC->SSC_THR = 0x43;
@@ -289,17 +291,17 @@ void WriteTIbyte(uint8_t b)
        {
                if (b&(1<<i)) {
                        // stop modulating antenna
        {
                if (b&(1<<i)) {
                        // stop modulating antenna
-                       LOW(GPIO_SSC_DOUT);
+                       SHORT_COIL();
                        SpinDelayUs(1000);
                        // modulate antenna
                        SpinDelayUs(1000);
                        // modulate antenna
-                       HIGH(GPIO_SSC_DOUT);
+                       OPEN_COIL();
                        SpinDelayUs(1000);
                } else {
                        // stop modulating antenna
                        SpinDelayUs(1000);
                } else {
                        // stop modulating antenna
-                       LOW(GPIO_SSC_DOUT);
+                       SHORT_COIL();
                        SpinDelayUs(300);
                        // modulate antenna
                        SpinDelayUs(300);
                        // modulate antenna
-                       HIGH(GPIO_SSC_DOUT);
+                       OPEN_COIL();
                        SpinDelayUs(1700);
                }
        }
                        SpinDelayUs(1700);
                }
        }
@@ -449,60 +451,57 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
 
 void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
 {
 
 void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
 {
-       int i;
+       int i = 0;
        uint8_t *buff = (uint8_t *)BigBuf;
        uint8_t *buff = (uint8_t *)BigBuf;
-    
+
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
        SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
        SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
-       
-       // Give it a bit of time for the resonant antenna to settle.
-       SpinDelay(150);
-       
+
+       // Configure output and enable pin that is connected to the FPGA (for modulating)
        AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;    
        AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
        AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;    
        AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
+       
        AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
        AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
-    
-#define SHORT_COIL()   LOW(GPIO_SSC_DOUT)
-#define OPEN_COIL()            HIGH(GPIO_SSC_DOUT)
-    
-       i = 0;
-       for(;;) {
+
+       // Give it a bit of time for the resonant antenna to settle.
+       SpinDelay(30);
+
+       for(;;) { 
+               
                while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
                while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
-                       if(BUTTON_PRESS()) {
-                               DbpString("Stopped");
-                               return;
-                       }
-                       WDT_HIT();
+                        if(BUTTON_PRESS()) {
+                                DbpString("Stopped at 0");
+                                FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off
+                                return;
+                        }
+                        WDT_HIT();
                }
         
                }
         
-               if (ledcontrol)
-                       LED_D_ON();
-        
-               if(buff[i])
+               if ( buff[i] )
                        OPEN_COIL();
                else
                        SHORT_COIL();
                        OPEN_COIL();
                else
                        SHORT_COIL();
-        
-               if (ledcontrol)
-                       LED_D_OFF();
-        
-               while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
-                       if(BUTTON_PRESS()) {
-                               DbpString("Stopped");
+       
+                while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
+                        if(BUTTON_PRESS()) {
+                               DbpString("Stopped at 1");
+                               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off
                                return;
                        }
                        WDT_HIT();
                                return;
                        }
                        WDT_HIT();
-               }
+                }
         
         
-               i++;
+               ++i;
                if(i == period) {
                        i = 0;
                        if (gap) {
                if(i == period) {
                        i = 0;
                        if (gap) {
+                               // turn of modulation
                                SHORT_COIL();
                                SHORT_COIL();
-                               SpinDelayUs(gap);
-                       }
+                               // wait
+                               SpinDelay(gap);
+                       } 
                }
        }
 }
                }
        }
 }
@@ -609,6 +608,7 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
 
        if (ledcontrol)
                LED_A_ON();
 
        if (ledcontrol)
                LED_A_ON();
+       
        SimulateTagLowFrequency(n, 0, ledcontrol);
 
        if (ledcontrol)
        SimulateTagLowFrequency(n, 0, ledcontrol);
 
        if (ledcontrol)
@@ -793,8 +793,6 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
        LFSetupFPGAForADC(0, true);
 
        while(!BUTTON_PRESS()) {
        LFSetupFPGAForADC(0, true);
 
        while(!BUTTON_PRESS()) {
-
-
                WDT_HIT();
                if (ledcontrol) LED_A_ON();
 
                WDT_HIT();
                if (ledcontrol) LED_A_ON();
 
index 8ff5b68d560669b4070e316d733c2957293a3d00..0558fb947024e2095d3ad57ad566fb88ba4a506b 100644 (file)
@@ -265,7 +265,7 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
 {
        struct version_information *v = (struct version_information*)version_information;
        dst[0] = 0;
 {
        struct version_information *v = (struct version_information*)version_information;
        dst[0] = 0;
-       strncat(dst, prefix, len);
+       strncat(dst, prefix, len-1);
        if(v->magic != VERSION_INFORMATION_MAGIC) {
                strncat(dst, "Missing/Invalid version information", len - strlen(dst) - 1);
                return;
        if(v->magic != VERSION_INFORMATION_MAGIC) {
                strncat(dst, "Missing/Invalid version information", len - strlen(dst) - 1);
                return;
index c58f6f62007f669619df8bc5a1d7ff84ade1aee5..b01b45ba02c582f9bc209f0a8feff1d3a7c936c8 100644 (file)
@@ -552,7 +552,7 @@ int CmdManchesterDemod(const char *Cmd)
 
   /* But it does not work if compiling on WIndows: therefore we just allocate a */
   /* large array */
 
   /* But it does not work if compiling on WIndows: therefore we just allocate a */
   /* large array */
-  uint8_t BitStream[MAX_GRAPH_TRACE_LEN];
+  uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0x00};
 
   /* Detect high and lows */
   for (i = 0; i < GraphTraceLen; i++)
 
   /* Detect high and lows */
   for (i = 0; i < GraphTraceLen; i++)
@@ -564,8 +564,7 @@ int CmdManchesterDemod(const char *Cmd)
   }
 
   /* Get our clock */
   }
 
   /* Get our clock */
-  clock = GetClock(Cmd, high, 1);
-
+  clock = GetClock(Cmd, high, 1); 
   int tolerance = clock/4;
 
   /* Detect first transition */
   int tolerance = clock/4;
 
   /* Detect first transition */
@@ -583,8 +582,6 @@ int CmdManchesterDemod(const char *Cmd)
       break;
     }
   }
       break;
     }
   }
-
-  PrintAndLog("Clock:  %d", clock); 
   
   /* If we're not working with 1/0s, demod based off clock */
   if (high != 1)
   
   /* If we're not working with 1/0s, demod based off clock */
   if (high != 1)
@@ -723,21 +720,22 @@ int CmdManchesterDemod(const char *Cmd)
 int CmdManchesterMod(const char *Cmd)
 {
   int i, j;
 int CmdManchesterMod(const char *Cmd)
 {
   int i, j;
-  int clock;
   int bit, lastbit, wave;
   int bit, lastbit, wave;
-
-  /* Get our clock */
-  clock = GetClock(Cmd, 0, 1);
-
+  int clock = GetClock(Cmd, 0, 1);
+  int clock1 = GetT55x7Clock( GraphBuffer, GraphTraceLen, 0 );
+  PrintAndLog("MAN MOD CLOCKS:  %d  ice %d", clock,clock1);
+  
+  int half = (int)(clock/2);
+  
   wave = 0;
   lastbit = 1;
   for (i = 0; i < (int)(GraphTraceLen / clock); i++)
   {
     bit = GraphBuffer[i * clock] ^ 1;
 
   wave = 0;
   lastbit = 1;
   for (i = 0; i < (int)(GraphTraceLen / clock); i++)
   {
     bit = GraphBuffer[i * clock] ^ 1;
 
-    for (j = 0; j < (int)(clock/2); j++)
+    for (j = 0; j < half; ++j)
       GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave;
       GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave;
-    for (j = (int)(clock/2); j < clock; j++)
+    for (j = half; j < clock; ++j)
       GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave ^ 1;
 
     /* Keep track of how we start our wave and if we changed or not this time */
       GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave ^ 1;
 
     /* Keep track of how we start our wave and if we changed or not this time */
index bdc08521144bc5d12480790e84b135d6ea726686..556d3f569a2067f8286c6c57196e6c081a277843 100644 (file)
@@ -561,8 +561,9 @@ int CmdHF15CmdRaw (const char *cmd) {
  */
 int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) {
        int temp;
  */
 int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) {
        int temp;
-       uint8_t *req=c->d.asBytes, uid[8];
-       uint32_t reqlen=0;
+       uint8_t *req = c->d.asBytes;
+       uint8_t uid[8] = {0x00};
+       uint32_t reqlen = 0;
 
        // strip
        while (**cmd==' ' || **cmd=='\t') (*cmd)++;
 
        // strip
        while (**cmd==' ' || **cmd=='\t') (*cmd)++;
index bd215a611ccf370eccc5c6d7e3e8d85afab2c638..47ff2db0f226494888246eef619273e805cda741 100644 (file)
@@ -501,7 +501,9 @@ int CmdHFiClassReader_Dump(const char *Cmd)
   SendCommand(&c);
   
   UsbCommand resp;
   SendCommand(&c);
   
   UsbCommand resp;
-
+  uint8_t key_sel[8] = {0x00};
+  uint8_t key_sel_p[8] = {0x00};
+                               
   if (WaitForResponseTimeout(CMD_ACK,&resp,4500)) {
         uint8_t isOK    = resp.arg[0] & 0xff;
         uint8_t * data  = resp.d.asBytes;
   if (WaitForResponseTimeout(CMD_ACK,&resp,4500)) {
         uint8_t isOK    = resp.arg[0] & 0xff;
         uint8_t * data  = resp.d.asBytes;
@@ -519,8 +521,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
         {
             if(elite)
             {
         {
             if(elite)
             {
-                uint8_t key_sel[8] = {0};
-                uint8_t key_sel_p[8] = { 0 };
+
                 //Get the key index (hash1)
                 uint8_t key_index[8] = {0};
 
                 //Get the key index (hash1)
                 uint8_t key_index[8] = {0};
 
index 0e212b2d13c211b30c47fd9080dc1eee4bd61d32..1d2de683fed5cd572f071b3791f7787f5459f489 100644 (file)
@@ -521,8 +521,6 @@ int CmdHF14AMfDump(const char *Cmd)
 \r
        int size = GetCardSize();               \r
        char cmdp = param_getchar(Cmd, 0);\r
 \r
        int size = GetCardSize();               \r
        char cmdp = param_getchar(Cmd, 0);\r
-       \r
-       \r
 \r
        if  ( size > -1) \r
                cmdp = (char)(48+size);\r
 \r
        if  ( size > -1) \r
                cmdp = (char)(48+size);\r
@@ -548,7 +546,7 @@ int CmdHF14AMfDump(const char *Cmd)
        }\r
        \r
        if ((fin = fopen("dumpkeys.bin","rb")) == NULL) {\r
        }\r
        \r
        if ((fin = fopen("dumpkeys.bin","rb")) == NULL) {\r
-               PrintAndLog("Could not find file dumpkeys.bin");\r
+               PrintAndLog("Could not find file dumpkeys.bin");                \r
                return 1;\r
        }\r
        \r
                return 1;\r
        }\r
        \r
@@ -556,6 +554,7 @@ int CmdHF14AMfDump(const char *Cmd)
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
+                       fclose(fin);\r
                        return 2;\r
                }\r
        }\r
                        return 2;\r
                }\r
        }\r
@@ -564,10 +563,13 @@ int CmdHF14AMfDump(const char *Cmd)
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
+                       fclose(fin);\r
                        return 2;\r
                }\r
        }\r
        \r
                        return 2;\r
                }\r
        }\r
        \r
+       fclose(fin);\r
+       \r
        PrintAndLog("|-----------------------------------------|");\r
        PrintAndLog("|------ Reading sector access bits...-----|");\r
        PrintAndLog("|-----------------------------------------|");\r
        PrintAndLog("|-----------------------------------------|");\r
        PrintAndLog("|------ Reading sector access bits...-----|");\r
        PrintAndLog("|-----------------------------------------|");\r
@@ -673,7 +675,6 @@ int CmdHF14AMfDump(const char *Cmd)
                PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
        }\r
        \r
                PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
        }\r
        \r
-       fclose(fin);\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
@@ -1169,11 +1170,12 @@ int CmdHF14AMfChk(const char *Cmd)
                                        keycnt++;\r
                                        memset(buf, 0, sizeof(buf));\r
                                }\r
                                        keycnt++;\r
                                        memset(buf, 0, sizeof(buf));\r
                                }\r
+                               fclose(f);\r
                        } else {\r
                                PrintAndLog("File: %s: not found or locked.", filename);\r
                                free(keyBlock);\r
                                return 1;\r
                        } else {\r
                                PrintAndLog("File: %s: not found or locked.", filename);\r
                                free(keyBlock);\r
                                return 1;\r
-                       fclose(f);\r
+                       \r
                        }\r
                }\r
        }\r
                        }\r
                }\r
        }\r
@@ -1454,6 +1456,7 @@ int CmdHF14AMfELoad(const char *Cmd)
                                break;\r
                        }\r
                        PrintAndLog("File reading error.");\r
                                break;\r
                        }\r
                        PrintAndLog("File reading error.");\r
+                       fclose(f);\r
                        return 2;\r
                }\r
                if (strlen(buf) < 32){\r
                        return 2;\r
                }\r
                if (strlen(buf) < 32){\r
@@ -1478,6 +1481,7 @@ int CmdHF14AMfELoad(const char *Cmd)
        \r
        if ((blockNum != 16*4) && (blockNum != 32*4 + 8*16)) {\r
                PrintAndLog("File content error. There must be 64 or 256 blocks.");\r
        \r
        if ((blockNum != 16*4) && (blockNum != 32*4 + 8*16)) {\r
                PrintAndLog("File content error. There must be 64 or 256 blocks.");\r
+               fclose(f);\r
                return 4;\r
        }\r
        PrintAndLog("Loaded %d blocks from file: %s", blockNum, filename);\r
                return 4;\r
        }\r
        PrintAndLog("Loaded %d blocks from file: %s", blockNum, filename);\r
@@ -1610,8 +1614,8 @@ int CmdHF14AMfEKeyPrn(const char *Cmd)
 int CmdHF14AMfCSetUID(const char *Cmd)\r
 {\r
        uint8_t wipeCard = 0;\r
 int CmdHF14AMfCSetUID(const char *Cmd)\r
 {\r
        uint8_t wipeCard = 0;\r
-       uint8_t uid[8];\r
-       uint8_t oldUid[8];\r
+       uint8_t uid[8] = {0x00};\r
+       uint8_t oldUid[8] = {0x00};\r
        int res;\r
 \r
        if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
        int res;\r
 \r
        if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
index 1ce0ac81544e4562fd00fbe89c0d806c7d78e086..da74f97f62d0900d2d0ea0fad55cb2985d8731e3 100644 (file)
@@ -410,7 +410,7 @@ int CmdLFSim(const char *Cmd)
        printf(".");
   }
   printf("\n");
        printf(".");
   }
   printf("\n");
-  PrintAndLog("Starting simulator...");
+  PrintAndLog("Starting to simulate");
   UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
   SendCommand(&c);
   return 0;
   UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
   SendCommand(&c);
   return 0;
index 45a95f02c26b34848d15b7834f2060f972bb5ea5..d371bf279067bc3fe2cd829d60860588de60ee3a 100644 (file)
@@ -57,7 +57,8 @@ int CmdEM410xRead(const char *Cmd)
 
   /* get clock */
   clock = GetClock(Cmd, high, 0);
 
   /* get clock */
   clock = GetClock(Cmd, high, 0);
-
+  
   /* parity for our 4 columns */
   parity[0] = parity[1] = parity[2] = parity[3] = 0;
   header = rows = 0;
   /* parity for our 4 columns */
   parity[0] = parity[1] = parity[2] = parity[3] = 0;
   header = rows = 0;
@@ -220,8 +221,7 @@ int CmdEM410xSim(const char *Cmd)
   int clock = 64;
 
   /* clear our graph */
   int clock = 64;
 
   /* clear our graph */
-  ClearGraph(0);
-  GraphTraceLen = 0;
+  ClearGraph(1);
   
   /* write it out a few times */
   for (h = 0; h < 4; h++)
   
   /* write it out a few times */
   for (h = 0; h < 4; h++)
@@ -266,12 +266,12 @@ int CmdEM410xSim(const char *Cmd)
   }
 
   /* modulate that biatch */
   }
 
   /* modulate that biatch */
-  CmdManchesterMod("");
+  CmdManchesterMod("64");
 
   /* booyah! */
   RepaintGraphWindow();
   
 
   /* booyah! */
   RepaintGraphWindow();
   
-  CmdLFSim("64");
+  CmdLFSim("");
   return 0;
 }
 
   return 0;
 }
 
@@ -296,10 +296,10 @@ int CmdEM410xWatch(const char *Cmd)
                }
                
                CmdLFRead(read_h ? "h" : "");
                }
                
                CmdLFRead(read_h ? "h" : "");
-               CmdSamples("12000");
+               CmdSamples("16000");
                
        } while (
                
        } while (
-               !CmdEM410xRead("64") 
+               !CmdEM410xRead("") 
        );
        return 0;
 }
        );
        return 0;
 }
@@ -363,7 +363,7 @@ int CmdEM4x50Read(const char *Cmd)
       ++i;
     while ((GraphBuffer[i] > low) && (i<GraphTraceLen))
       ++i;
       ++i;
     while ((GraphBuffer[i] > low) && (i<GraphTraceLen))
       ++i;
-    if (j>(MAX_GRAPH_TRACE_LEN/64)) {
+    if (j>=(MAX_GRAPH_TRACE_LEN/64)) {
       break;
     }
     tmpbuff[j++]= i - start;
       break;
     }
     tmpbuff[j++]= i - start;
@@ -616,7 +616,7 @@ int CmdWriteWord(const char *Cmd)
     return 1;
   }
   
     return 1;
   }
   
-  PrintAndLog("Writting word %d with data %08X", Word, Data);
+  PrintAndLog("Writing word %d with data %08X", Word, Data);
   
   c.cmd = CMD_EM4X_WRITE_WORD;
   c.d.asBytes[0] = 0x0; //Normal mode
   
   c.cmd = CMD_EM4X_WRITE_WORD;
   c.d.asBytes[0] = 0x0; //Normal mode
@@ -629,7 +629,7 @@ int CmdWriteWord(const char *Cmd)
 
 int CmdWriteWordPWD(const char *Cmd)
 {
 
 int CmdWriteWordPWD(const char *Cmd)
 {
-  int Word = 8; //default to invalid word
+  int Word = 16; //default to invalid word
   int Data = 0xFFFFFFFF; //default to blank data
   int Password = 0xFFFFFFFF; //default to blank password
   UsbCommand c;
   int Data = 0xFFFFFFFF; //default to blank data
   int Password = 0xFFFFFFFF; //default to blank password
   UsbCommand c;
@@ -641,7 +641,7 @@ int CmdWriteWordPWD(const char *Cmd)
     return 1;
   }
   
     return 1;
   }
   
-  PrintAndLog("Writting word %d with data %08X and password %08X", Word, Data, Password);
+  PrintAndLog("Writing word %d with data %08X and password %08X", Word, Data, Password);
   
   c.cmd = CMD_EM4X_WRITE_WORD;
   c.d.asBytes[0] = 0x1; //Password mode
   
   c.cmd = CMD_EM4X_WRITE_WORD;
   c.d.asBytes[0] = 0x1; //Password mode
index 9eaa646301f873f33db0edf54208a9d90e6deb78..513eb0ef668683334191f388243951ba5567cfc3 100644 (file)
@@ -482,8 +482,8 @@ static command_t CommandTable[] =
   {"rdpwd",  CmdReadBlkPWD,  0, "<block> <password> -- Read T55xx block data with password mode"},\r
   {"wr",     CmdWriteBlk,    0, "<data> <block> -- Write T55xx block data (page 0)"},\r
   {"wrpwd",  CmdWriteBlkPWD, 0, "<data> <block> <password> -- Write T55xx block data with password"},\r
   {"rdpwd",  CmdReadBlkPWD,  0, "<block> <password> -- Read T55xx block data with password mode"},\r
   {"wr",     CmdWriteBlk,    0, "<data> <block> -- Write T55xx block data (page 0)"},\r
   {"wrpwd",  CmdWriteBlkPWD, 0, "<data> <block> <password> -- Write T55xx block data with password"},\r
-  {"trace",  CmdReadTrace,   0, "[1] Read T55xx traceability data (page 1 / blk 0-1) "},\r
-  {"info",   CmdInfo,        0, "[1] Read T55xx configuration data (page0 /blk 0)"},\r
+  {"trace",  CmdReadTrace,   0, "[1] Read T55xx traceability data (page 1/ blk 0-1)"},\r
+  {"info",   CmdInfo,        0, "[1] Read T55xx configuration data (page 0/ blk 0)"},\r
   {"dump",   CmdDump,        0, "[password] Dump T55xx card block 0-7. optional with password"},\r
   {"fsk",    CmdIceFsk,      0, "FSK demod"},\r
   {"man",    CmdIceManchester,      0, "Manchester demod (with SST)"},\r
   {"dump",   CmdDump,        0, "[password] Dump T55xx card block 0-7. optional with password"},\r
   {"fsk",    CmdIceFsk,      0, "FSK demod"},\r
   {"man",    CmdIceManchester,      0, "Manchester demod (with SST)"},\r
index b35ba63c8cf0a7c0ed1aad2a27ed3dff8936d878..d84d96ef9f957362ae17b5d1f8f1bd6b3c49fcea 100644 (file)
@@ -137,9 +137,11 @@ int getCommand(UsbCommand* response)
  * @return true if command was returned, otherwise false
  */
 bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) {
  * @return true if command was returned, otherwise false
  */
 bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) {
-  
+
+  UsbCommand resp;
+       
   if (response == NULL) {
   if (response == NULL) {
-    UsbCommand resp;
+
     response = &resp;
   }
 
     response = &resp;
   }
 
index 98dc80436db6f5660400d7d22d7a7f9fe5bf9a4b..4e8cb89cc2f287d3577cf67acee5f23e20c07cee 100644 (file)
@@ -21,11 +21,13 @@ int GraphTraceLen;
 void AppendGraph(int redraw, int clock, int bit)
 {
   int i;
 void AppendGraph(int redraw, int clock, int bit)
 {
   int i;
-
-  for (i = 0; i < (int)(clock / 2); ++i)
-    GraphBuffer[GraphTraceLen++] = bit ^ 1;
+  int half = (int)(clock/2);
+  int firstbit = bit ^ 1;
+  for (i = 0; i < half; ++i)
+    GraphBuffer[GraphTraceLen++] = firstbit;
   
   
-  for (i = (int)(clock / 2); i < clock; ++i)
+  for (i = 0; i <= half; ++i)
     GraphBuffer[GraphTraceLen++] = bit;
 
   if (redraw)
     GraphBuffer[GraphTraceLen++] = bit;
 
   if (redraw)
@@ -72,8 +74,23 @@ int DetectClock(int peak)
       lastpeak = i;
     }
   }
       lastpeak = i;
     }
   }
-
-  return clock;
+       
+       int clockmod = clock%8;
+       if ( clockmod == 0) 
+               return clock;
+       
+       // When detected clock is 31 or 33 then return 32
+
+       printf("Found clock at %d ", clock);
+       switch( clockmod )
+       {
+               case 7: clock++; break;
+               case 6: clock += 2 ; break;
+               case 1: clock--; break;
+               case 2: clock -= 2; break;
+       }
+       printf("- adjusted it to %d \n", clock);
+       return clock;
 }
 
 /* Get or auto-detect clock rate */
 }
 
 /* Get or auto-detect clock rate */
index b0528b5c3ac1c9d105e0c56e84b00e24690f99d4..a55227efd440948152a9e4478ddb97692e7aef92 100644 (file)
@@ -737,16 +737,14 @@ int doTestsWithKnownInputs()
 
 int readKeyFile(uint8_t key[8])
 {
 
 int readKeyFile(uint8_t key[8])
 {
-
        FILE *f;
        FILE *f;
-
+       int retval = 1;
        f = fopen("iclass_key.bin", "rb");
        if (f)
        {
                if(fread(key, sizeof(key), 1, f) == 1) return 0;
        }
        f = fopen("iclass_key.bin", "rb");
        if (f)
        {
                if(fread(key, sizeof(key), 1, f) == 1) return 0;
        }
-       return 1;
-
+       return retval;
 }
 
 
 }
 
 
index fe8b8b2682a3d28b46bd469a369c1c6303c93e07..ed62bcee78f03ee1f8831aa04a14f33365793480 100644 (file)
@@ -296,7 +296,7 @@ static uint8_t trailerAccessBytes[4] = {0x08, 0x77, 0x8F, 0x00};
 // variables\r
 char logHexFileName[200] = {0x00};\r
 static uint8_t traceCard[4096] = {0x00};\r
 // variables\r
 char logHexFileName[200] = {0x00};\r
 static uint8_t traceCard[4096] = {0x00};\r
-static char traceFileName[20];\r
+static char traceFileName[200] = {0x00};\r
 static int traceState = TRACE_IDLE;\r
 static uint8_t traceCurBlock = 0;\r
 static uint8_t traceCurKey = 0;\r
 static int traceState = TRACE_IDLE;\r
 static uint8_t traceCurBlock = 0;\r
 static uint8_t traceCurKey = 0;\r
@@ -449,7 +449,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
                }\r
                \r
                // AUTHENTICATION\r
                }\r
                \r
                // AUTHENTICATION\r
-               if ((len ==4) && ((data[0] == 0x60) || (data[0] == 0x61))) {\r
+               if ((len == 4) && ((data[0] == 0x60) || (data[0] == 0x61))) {\r
                        traceState = TRACE_AUTH1;\r
                        traceCurBlock = data[1];\r
                        traceCurKey = data[0] == 60 ? 1:0;\r
                        traceState = TRACE_AUTH1;\r
                        traceCurBlock = data[1];\r
                        traceCurKey = data[0] == 60 ? 1:0;\r
@@ -497,7 +497,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
        break;\r
 \r
        case TRACE_WRITE_OK: \r
        break;\r
 \r
        case TRACE_WRITE_OK: \r
-               if ((len == 1) && (data[0] = 0x0a)) {\r
+               if ((len == 1) && (data[0] == 0x0a)) {\r
                        traceState = TRACE_WRITE_DATA;\r
 \r
                        return 0;\r
                        traceState = TRACE_WRITE_DATA;\r
 \r
                        return 0;\r
@@ -555,23 +555,14 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
                        at_par = parity;\r
                        \r
                        //  decode key here)\r
                        at_par = parity;\r
                        \r
                        //  decode key here)\r
-                       if (!traceCrypto1) {\r
-                               ks2 = ar_enc ^ prng_successor(nt, 64);\r
-                               ks3 = at_enc ^ prng_successor(nt, 96);\r
-                               revstate = lfsr_recovery64(ks2, ks3);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, nr_enc, 1);\r
-                               lfsr_rollback_word(revstate, uid ^ nt, 0);\r
-                       }else{\r
-                               ks2 = ar_enc ^ prng_successor(nt, 64);\r
-                               ks3 = at_enc ^ prng_successor(nt, 96);\r
-                               revstate = lfsr_recovery64(ks2, ks3);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, nr_enc, 1);\r
-                               lfsr_rollback_word(revstate, uid ^ nt, 0);\r
-                       }\r
+                       ks2 = ar_enc ^ prng_successor(nt, 64);\r
+                       ks3 = at_enc ^ prng_successor(nt, 96);\r
+                       revstate = lfsr_recovery64(ks2, ks3);\r
+                       lfsr_rollback_word(revstate, 0, 0);\r
+                       lfsr_rollback_word(revstate, 0, 0);\r
+                       lfsr_rollback_word(revstate, nr_enc, 1);\r
+                       lfsr_rollback_word(revstate, uid ^ nt, 0);\r
+\r
                        crypto1_get_lfsr(revstate, &lfsr);\r
                        printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));\r
                        AddLogUint64(logHexFileName, "key> ", lfsr); \r
                        crypto1_get_lfsr(revstate, &lfsr);\r
                        printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));\r
                        AddLogUint64(logHexFileName, "key> ", lfsr); \r
index 90f55ab4c6cce6ad91ad594059069a7e64a0a270..c2dd7a547bfff60365f3b6a36ac87e280aeb4409 100644 (file)
@@ -544,7 +544,12 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8],
 \r
        statelist = malloc((sizeof *statelist) << 21);  //how large should be? \r
        if(!statelist || !odd || !even)\r
 \r
        statelist = malloc((sizeof *statelist) << 21);  //how large should be? \r
        if(!statelist || !odd || !even)\r
-                return 0;\r
+       {\r
+          free(statelist);\r
+          free(odd);\r
+          free(even);\r
+          return 0;\r
+       }\r
 \r
        s = statelist;\r
        for(o = odd; *o != -1; ++o)\r
 \r
        s = statelist;\r
        for(o = odd; *o != -1; ++o)\r
index 816bff44058dea8230617a1da3ad8e466b00d45d..5111e2952b993c21664e04bea6c153843878356c 100644 (file)
@@ -152,30 +152,13 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout,  size_t
                        lastpeak = i;
                }
        }
                        lastpeak = i;
                }
        }
-       //return clock;  
-       //defaults clock to precise values.
-       switch(clock){
-               case 8:
-               case 16:
-               case 32:
-               case 40:
-               case 50:
-               case 64:
-               case 100:
-               case 128:
-               return clock;
-               break;
-               default:  break;
-       }
-       
-       //PrintAndLog(" Found Clock : %d  - trying to adjust", clock);
        
        // When detected clock is 31 or 33 then then return 
        int clockmod = clock%8;
        
        // When detected clock is 31 or 33 then then return 
        int clockmod = clock%8;
-       if ( clockmod == 7 ) 
-               clock += 1;
-       else if ( clockmod == 1 )
-               clock -= 1;
+       if ( clockmod == 0) return clock;
+       
+       if ( clockmod == 7 ) clock += 1;
+       else if ( clockmod == 1 ) clock -= 1;
        
        return clock;
  }
        
        return clock;
  }
Impressum, Datenschutz