]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmddata.c
add: added a test function for nonce distance
[proxmark3-svn] / client / cmddata.c
index ad86f45f43fa3bd25de86b1b81dff1b0b368c42e..e3226a777c0a9117709ce29d88fd782c93cbd61d 100644 (file)
@@ -827,19 +827,20 @@ int CmdUndec(const char *Cmd)
                return 0;
        }
 
                return 0;
        }
 
-       uint8_t factor = param_get8ex(Cmd, 0,2, 10);
+       uint8_t factor = param_get8ex(Cmd, 0, 2, 10);
        //We have memory, don't we?
        int swap[MAX_GRAPH_TRACE_LEN] = { 0 };
        uint32_t g_index = 0 ,s_index = 0;
        //We have memory, don't we?
        int swap[MAX_GRAPH_TRACE_LEN] = { 0 };
        uint32_t g_index = 0 ,s_index = 0;
-       while(g_index < GraphTraceLen && s_index < MAX_GRAPH_TRACE_LEN)
+       while(g_index < GraphTraceLen && s_index + factor < MAX_GRAPH_TRACE_LEN)
        {
                int count = 0;
        {
                int count = 0;
-               for(count = 0; count < factor && s_index+count < MAX_GRAPH_TRACE_LEN; count ++)
+               for (count = 0; count < factor && s_index + count < MAX_GRAPH_TRACE_LEN; count++)
                        swap[s_index+count] = GraphBuffer[g_index];
                        swap[s_index+count] = GraphBuffer[g_index];
-               s_index+=count;
+               s_index += count;
+               g_index++;
        }
 
        }
 
-       memcpy(GraphBuffer,swap, s_index * sizeof(int));
+       memcpy(GraphBuffer, swap, s_index * sizeof(int));
        GraphTraceLen = s_index;
        RepaintGraphWindow();
        return 0;
        GraphTraceLen = s_index;
        RepaintGraphWindow();
        return 0;
@@ -919,19 +920,21 @@ int CmdDetectClockRate(const char *Cmd)
 
 char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
 {
 
 char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
 {
-       char *fskType;
+       static char fType[8];
+       memset(fType, 0x00, 8); 
+       char *fskType = fType;
        if (fchigh==10 && fclow==8){
                if (invert) //fsk2a
        if (fchigh==10 && fclow==8){
                if (invert) //fsk2a
-                       fskType = "FSK2a";
+                       memcpy(fskType, "FSK2a", 5);
                else //fsk2
                else //fsk2
-                       fskType = "FSK2";
+                       memcpy(fskType, "FSK2", 4);
        } else if (fchigh == 8 && fclow == 5) {
                if (invert)
        } else if (fchigh == 8 && fclow == 5) {
                if (invert)
-                       fskType = "FSK1";
+                       memcpy(fskType, "FSK1", 4);
                else
                else
-                       fskType = "FSK1a";
+                       memcpy(fskType, "FSK1a", 5);
        } else {
        } else {
-               fskType = "FSK??";
+               memcpy(fskType, "FSK??", 5);
        }
        return fskType;
 }
        }
        return fskType;
 }
@@ -952,39 +955,40 @@ int FSKrawDemod(const char *Cmd, bool verbose)
        fchigh = param_get8(Cmd, 2);
        fclow = param_get8(Cmd, 3);
        if (strlen(Cmd)>0 && strlen(Cmd)<=2) {
        fchigh = param_get8(Cmd, 2);
        fclow = param_get8(Cmd, 3);
        if (strlen(Cmd)>0 && strlen(Cmd)<=2) {
-                if (rfLen==1){
+               if (rfLen==1) {
                        invert = 1;   //if invert option only is used
                        rfLen = 0;
                        invert = 1;   //if invert option only is used
                        rfLen = 0;
-                }
+               }
        }
 
        uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
        size_t BitLen = getFromGraphBuf(BitStream);
        if (BitLen==0) return 0;
        }
 
        uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
        size_t BitLen = getFromGraphBuf(BitStream);
        if (BitLen==0) return 0;
+       if (g_debugMode==2) PrintAndLog("DEBUG: Got samples");  
        //get field clock lengths
        //get field clock lengths
-       uint8_t fc1=0, fc2=0, rf1=0;
+       uint16_t fcs=0;
        if (!fchigh || !fclow) {
        if (!fchigh || !fclow) {
-               uint8_t ans = fskClocks(&fc1, &fc2, &rf1, false);
-               if (ans == 0) {
-                       if (g_debugMode) PrintAndLog("\nError: cannot detect valid fsk field clocks");                  
-                       return 0; // can't detect field clock
+               fcs = countFC(BitStream, BitLen, 1);
+               if (!fcs) {
+                       fchigh = 10;
+                       fclow = 8;
+               } else {
+                       fchigh = (fcs >> 8) & 0x00FF;
+                       fclow = fcs & 0x00FF;
                }
                }
-               fchigh = fc1;
-               fclow = fc2;
-               if (rfLen == 0) rfLen = rf1;
        }
        //get bit clock length
        }
        //get bit clock length
-       if (!rfLen){
+       if (!rfLen) {
                rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow);
                if (!rfLen) rfLen = 50;
        }
        int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow);
                rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow);
                if (!rfLen) rfLen = 50;
        }
        int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow);
-       if (size > 0){
+       if (size > 0) {
                setDemodBuf(BitStream, size, 0);
 
                // Now output the bitstream to the scrollback by line of 16 bits
                if (verbose || g_debugMode) {
                setDemodBuf(BitStream, size, 0);
 
                // Now output the bitstream to the scrollback by line of 16 bits
                if (verbose || g_debugMode) {
-                       PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", rfLen, invert, fchigh, fclow);
+                       PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen,  (unsigned int)invert,  (unsigned int)fchigh,  (unsigned int)fclow);
                        PrintAndLog("%s decoded bitstream:", GetFSKType(fchigh, fclow, invert));
                        printDemodBuff();
                }
                        PrintAndLog("%s decoded bitstream:", GetFSKType(fchigh, fclow, invert));
                        printDemodBuff();
                }
@@ -2046,7 +2050,7 @@ int CmdTuneSamples(const char *Cmd)
        clearCommandBuffer();
        SendCommand(&c);
        UsbCommand resp;
        clearCommandBuffer();
        SendCommand(&c);
        UsbCommand resp;
-       while(!WaitForResponseTimeout(CMD_MEASURED_ANTENNA_TUNING,&resp,1000)) {
+       while(!WaitForResponseTimeout(CMD_MEASURED_ANTENNA_TUNING, &resp, 2000)) {
                timeout++;
                printf(".");
                if (timeout > 7) {
                timeout++;
                printf(".");
                if (timeout > 7) {
@@ -2325,21 +2329,15 @@ int Cmdbin2hex(const char *Cmd)
 }
 
 int usage_data_hex2bin(){
 }
 
 int usage_data_hex2bin(){
-
-       PrintAndLog("Usage: data bin2hex <binary_digits>");
+       PrintAndLog("Usage: data hex2bin <hex_digits>");
        PrintAndLog("       This function will ignore all non-hexadecimal characters (but stop reading on whitespace)");
        return 0;
        PrintAndLog("       This function will ignore all non-hexadecimal characters (but stop reading on whitespace)");
        return 0;
-
 }
 
 int Cmdhex2bin(const char *Cmd)
 {
        int bg =0, en =0;
 }
 
 int Cmdhex2bin(const char *Cmd)
 {
        int bg =0, en =0;
-       if(param_getptr(Cmd, &bg, &en, 0))
-       {
-               return usage_data_hex2bin();
-       }
-
+       if(param_getptr(Cmd, &bg, &en, 0))  return usage_data_hex2bin();
 
        while(bg <= en )
        {
 
        while(bg <= en )
        {
@@ -2416,8 +2414,8 @@ static command_t CommandTable[] =
        {NULL, NULL, 0, NULL}
 };
 
        {NULL, NULL, 0, NULL}
 };
 
-int CmdData(const char *Cmd)
-{
+int CmdData(const char *Cmd){
+       clearCommandBuffer();
        CmdsParse(CommandTable, Cmd);
        return 0;
 }
        CmdsParse(CommandTable, Cmd);
        return 0;
 }
Impressum, Datenschutz