]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/graph.c
fix: array index out of range in mfkeys.log (thanks to @TomHarkness)
[proxmark3-svn] / client / graph.c
index 547e9b30d8e26672ef54dc48332dfd1cc6053a13..3ea47d2d4267ca30b7cdb5a7645ee350a994808c 100644 (file)
@@ -53,16 +53,19 @@ int ClearGraph(int redraw)
 void save_restoreGB(uint8_t saveOpt)
 {
        static int SavedGB[MAX_GRAPH_TRACE_LEN];
-       static int SavedGBlen;
+       static int SavedGBlen=0;
        static bool GB_Saved = false;
+       static int SavedGridOffsetAdj=0;
 
-       if (saveOpt==1) { //save
+       if (saveOpt == GRAPH_SAVE) { //save
                memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer));
                SavedGBlen = GraphTraceLen;
                GB_Saved=true;
-       } else if (GB_Saved){ //restore
+               SavedGridOffsetAdj = GridOffset;
+       } else if (GB_Saved) { //restore
                memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
                GraphTraceLen = SavedGBlen;
+               GridOffset = SavedGridOffsetAdj;
                RepaintGraphWindow();
        }
        return;
@@ -293,57 +296,3 @@ bool graphJustNoise(int *BitStream, int size)
        }
        return justNoise1;
 }
-int autoCorr(const int* in, int *out, size_t len, int window)
-{
-       static int CorrelBuffer[MAX_GRAPH_TRACE_LEN];
-
-       if (window == 0) {
-               PrintAndLog("needs a window");
-               return 0;
-       }
-       if (window >= len) {
-               PrintAndLog("window must be smaller than trace (%d samples)",
-               len);
-               return 0;
-       }
-
-       PrintAndLog("performing %d correlations", len - window);
-
-       for (int i = 0; i < len - window; ++i) {
-               int sum = 0;
-               for (int j = 0; j < window; ++j) {
-                       sum += (in[j]*in[i + j]) / 256;
-               }
-               CorrelBuffer[i] = sum;
-       }
-       //GraphTraceLen = GraphTraceLen - window;
-       memcpy(out, CorrelBuffer, len * sizeof (int));
-       return 0;
-}
-int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down)
-{
-       int lastValue = in[0];
-       out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in.
-
-       for (int i = 1; i < len; ++i) {
-               // Apply first threshold to samples heading up
-               if (in[i] >= up && in[i] > lastValue)
-               {
-                       lastValue = out[i]; // Buffer last value as we overwrite it.
-                       out[i] = 1;
-               }
-               // Apply second threshold to samples heading down
-               else if (in[i] <= down && in[i] < lastValue)
-               {
-                       lastValue = out[i]; // Buffer last value as we overwrite it.
-                       out[i] = -1;
-               }
-               else
-               {
-                       lastValue = out[i]; // Buffer last value as we overwrite it.
-                       out[i] = out[i-1];
-               }
-       }
-       out[0] = out[1]; // Align with first edited sample.
-       return 0;
-}
Impressum, Datenschutz