]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmddata.c
CHG: 'lf search' changed output to be visible when debugging for IO prox
[proxmark3-svn] / client / cmddata.c
index eb12fc8496a8354bc9b20e600bed67a92d98acd8..f59b7342b3d9b90b9422b40c92858753ef08f7f5 100644 (file)
@@ -458,23 +458,36 @@ void printEM410x(uint32_t hi, uint64_t id)
 int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo )
 {
        size_t idx = 0;
-       size_t BitLen = DemodBufferLen;
+       size_t size = DemodBufferLen;
        uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
-       memcpy(BitStream, DemodBuffer, BitLen); 
-       if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)){
-               //set GraphBuffer for clone or sim command
-               setDemodBuf(BitStream, BitLen, idx);
+       memcpy(BitStream, DemodBuffer, size); 
+       int ans = Em410xDecode(BitStream, &size, &idx, hi, lo);
+       if ( ans < 0){
                if (g_debugMode){
-                       PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
-                       printDemodBuff();
-               }
-               if (verbose){
-                       PrintAndLog("EM410x pattern found: ");
-                       printEM410x(*hi, *lo);
+
+                       if (ans == -1)
+                               PrintAndLog("DEBUG: Error - Em410x not only 0|1 in decoded bitstream");
+                       else if (ans == -3)
+                               PrintAndLog("DEBUG: Error - Em410x Size not correct: %d", size);
+                       else if (ans == -4)
+                               PrintAndLog("DEBUG: Error - Em410x preamble not found");
+                       else if (ans == -5)
+                               PrintAndLog("DEBUG: Error - Em410x parity failed");
                }
-               return 1;
+               return 0;
        }
-       return 0;
+       
+       //set GraphBuffer for clone or sim command
+       setDemodBuf(BitStream, size, idx);
+       if (g_debugMode){
+               PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, size);
+               printDemodBuff();
+       }
+       if (verbose){
+               PrintAndLog("EM410x pattern found: ");
+               printEM410x(*hi, *lo);
+       }
+       return 1;
 }
 
 int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose)
@@ -969,17 +982,17 @@ int CmdUndec(const char *Cmd)
 //shift graph zero up or down based on input + or -
 int CmdGraphShiftZero(const char *Cmd)
 {
-       int shift=0;
+       int shift = 0, shiftedVal = 0;
        //set options from parameters entered with the command
        sscanf(Cmd, "%i", &shift);
-       int shiftedVal=0;
+
        for(int i = 0; i<GraphTraceLen; i++){
                shiftedVal=GraphBuffer[i]+shift;
-               if (shiftedVal>127) 
-                       shiftedVal=127;
-               else if (shiftedVal<-127) 
-                       shiftedVal=-127;
-               GraphBuffer[i]= shiftedVal;
+               if (shiftedVal > 127) 
+                       shiftedVal = 127;
+               else if (shiftedVal < -127) 
+                       shiftedVal = -127;
+               GraphBuffer[i] = shiftedVal;
        }
        CmdNorm("");
        return 0;
@@ -1325,14 +1338,16 @@ int CmdFSKdemodIO(const char *Cmd)
                if (g_debugMode) PrintAndLog("not enough bits found - bitlen: %d",BitLen);
                return 0;
        }
-       PrintAndLog("%d%d%d%d%d%d%d%d %d",BitStream[idx],    BitStream[idx+1],  BitStream[idx+2], BitStream[idx+3], BitStream[idx+4], BitStream[idx+5], BitStream[idx+6], BitStream[idx+7], BitStream[idx+8]);
-       PrintAndLog("%d%d%d%d%d%d%d%d %d",BitStream[idx+9],  BitStream[idx+10], BitStream[idx+11],BitStream[idx+12],BitStream[idx+13],BitStream[idx+14],BitStream[idx+15],BitStream[idx+16],BitStream[idx+17]);
-       PrintAndLog("%d%d%d%d%d%d%d%d %d facility",BitStream[idx+18], BitStream[idx+19], BitStream[idx+20],BitStream[idx+21],BitStream[idx+22],BitStream[idx+23],BitStream[idx+24],BitStream[idx+25],BitStream[idx+26]);
-       PrintAndLog("%d%d%d%d%d%d%d%d %d version",BitStream[idx+27], BitStream[idx+28], BitStream[idx+29],BitStream[idx+30],BitStream[idx+31],BitStream[idx+32],BitStream[idx+33],BitStream[idx+34],BitStream[idx+35]);
-       PrintAndLog("%d%d%d%d%d%d%d%d %d code1",BitStream[idx+36], BitStream[idx+37], BitStream[idx+38],BitStream[idx+39],BitStream[idx+40],BitStream[idx+41],BitStream[idx+42],BitStream[idx+43],BitStream[idx+44]);
-       PrintAndLog("%d%d%d%d%d%d%d%d %d code2",BitStream[idx+45], BitStream[idx+46], BitStream[idx+47],BitStream[idx+48],BitStream[idx+49],BitStream[idx+50],BitStream[idx+51],BitStream[idx+52],BitStream[idx+53]);
-       PrintAndLog("%d%d%d%d%d%d%d%d %d%d checksum",BitStream[idx+54],BitStream[idx+55],BitStream[idx+56],BitStream[idx+57],BitStream[idx+58],BitStream[idx+59],BitStream[idx+60],BitStream[idx+61],BitStream[idx+62],BitStream[idx+63]);
-
+       if (g_debugMode) {
+               PrintAndLog("%d%d%d%d%d%d%d%d %d", BitStream[idx], BitStream[idx+1], BitStream[idx+2], BitStream[idx+3], BitStream[idx+4], BitStream[idx+5], BitStream[idx+6], BitStream[idx+7], BitStream[idx+8]);
+               PrintAndLog("%d%d%d%d%d%d%d%d %d", BitStream[idx+9], BitStream[idx+10], BitStream[idx+11],BitStream[idx+12],BitStream[idx+13],BitStream[idx+14],BitStream[idx+15],BitStream[idx+16],BitStream[idx+17]);
+               PrintAndLog("%d%d%d%d%d%d%d%d %d facility", BitStream[idx+18], BitStream[idx+19], BitStream[idx+20],BitStream[idx+21],BitStream[idx+22],BitStream[idx+23],BitStream[idx+24],BitStream[idx+25],BitStream[idx+26]);
+               PrintAndLog("%d%d%d%d%d%d%d%d %d version", BitStream[idx+27], BitStream[idx+28], BitStream[idx+29],BitStream[idx+30],BitStream[idx+31],BitStream[idx+32],BitStream[idx+33],BitStream[idx+34],BitStream[idx+35]);
+               PrintAndLog("%d%d%d%d%d%d%d%d %d code1", BitStream[idx+36], BitStream[idx+37], BitStream[idx+38],BitStream[idx+39],BitStream[idx+40],BitStream[idx+41],BitStream[idx+42],BitStream[idx+43],BitStream[idx+44]);
+               PrintAndLog("%d%d%d%d%d%d%d%d %d code2", BitStream[idx+45], BitStream[idx+46], BitStream[idx+47],BitStream[idx+48],BitStream[idx+49],BitStream[idx+50],BitStream[idx+51],BitStream[idx+52],BitStream[idx+53]);
+               PrintAndLog("%d%d%d%d%d%d%d%d %d%d checksum", BitStream[idx+54],BitStream[idx+55],BitStream[idx+56],BitStream[idx+57],BitStream[idx+58],BitStream[idx+59],BitStream[idx+60],BitStream[idx+61],BitStream[idx+62],BitStream[idx+63]);
+       }
+       
        uint32_t code = bytebits_to_byte(BitStream+idx,32);
        uint32_t code2 = bytebits_to_byte(BitStream+idx+32,32);
        uint8_t version = bytebits_to_byte(BitStream+idx+27,8); //14,4
@@ -2203,7 +2218,10 @@ int CmdLoad(const char *Cmd)
                GraphBuffer[GraphTraceLen] = atoi(line);
                GraphTraceLen++;
        }
-       fclose(f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
        PrintAndLog("loaded %d samples", GraphTraceLen);
        RepaintGraphWindow();
        return 0;
@@ -2277,7 +2295,10 @@ int CmdSave(const char *Cmd)
        for (i = 0; i < GraphTraceLen; i++) {
                fprintf(f, "%d\n", GraphBuffer[i]);
        }
-       fclose(f);
+       if (f) {
+               fclose(f);
+               f = NULL;
+       }
        PrintAndLog("saved to '%s'", Cmd);
        return 0;
 }
Impressum, Datenschutz