mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
improved the autocorreleate detection. lf search -1uc got some more textual improvements
This commit is contained in:
parent
586acf0933
commit
7fa09a556a
2 changed files with 72 additions and 53 deletions
|
@ -814,9 +814,13 @@ static int Cmdaskrawdemod(const char *Cmd) {
|
||||||
|
|
||||||
int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveGrph, bool verbose) {
|
int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveGrph, bool verbose) {
|
||||||
// sanity check
|
// sanity check
|
||||||
if (window > len) window = len;
|
if (window > len) {
|
||||||
|
window = len;
|
||||||
|
}
|
||||||
|
|
||||||
if (verbose) PrintAndLogEx(INFO, "performing " _YELLOW_("%zu") " correlations", g_GraphTraceLen - window);
|
if (verbose) {
|
||||||
|
PrintAndLogEx(INFO, "performing " _YELLOW_("%zu") " correlations", g_GraphTraceLen - window);
|
||||||
|
}
|
||||||
|
|
||||||
//test
|
//test
|
||||||
double autocv = 0.0; // Autocovariance value
|
double autocv = 0.0; // Autocovariance value
|
||||||
|
@ -830,6 +834,9 @@ int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveG
|
||||||
|
|
||||||
int *correl_buf = calloc(MAX_GRAPH_TRACE_LEN, sizeof(int));
|
int *correl_buf = calloc(MAX_GRAPH_TRACE_LEN, sizeof(int));
|
||||||
|
|
||||||
|
uint8_t peak_cnt = 0;
|
||||||
|
size_t peaks[10] = {0};
|
||||||
|
|
||||||
for (size_t i = 0; i < len - window; ++i) {
|
for (size_t i = 0; i < len - window; ++i) {
|
||||||
|
|
||||||
for (size_t j = 0; j < (len - i); j++) {
|
for (size_t j = 0; j < (len - i); j++) {
|
||||||
|
@ -844,44 +851,38 @@ int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveG
|
||||||
double ac_value = autocv / variance;
|
double ac_value = autocv / variance;
|
||||||
|
|
||||||
// keep track of which distance is repeating.
|
// keep track of which distance is repeating.
|
||||||
if (ac_value > 1) {
|
// A value near 1.0 or more indicates a correlation in the signal
|
||||||
|
if (ac_value > 0.95) {
|
||||||
correlation = i - lastmax;
|
correlation = i - lastmax;
|
||||||
lastmax = i;
|
lastmax = i;
|
||||||
|
|
||||||
|
if ((correlation > 1) && peak_cnt < ARRAYLEN(peaks)) {
|
||||||
|
peaks[peak_cnt++] = correlation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// Find shorts distance between peaks
|
||||||
int hi = 0, idx = 0;
|
int distance = -1;
|
||||||
int distance = 0, hi_1 = 0, idx_1 = 0;
|
for (size_t i = 0; i < ARRAYLEN(peaks); ++i) {
|
||||||
for (size_t i = 0; i <= len; ++i) {
|
|
||||||
if (correl_buf[i] > hi) {
|
if (peaks[i] < 2) {
|
||||||
hi = correl_buf[i];
|
continue;
|
||||||
idx = i;
|
}
|
||||||
|
|
||||||
|
if (distance == -1) {
|
||||||
|
distance = peaks[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (peaks[i] < distance) {
|
||||||
|
distance = peaks[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = idx + 1; i <= window; ++i) {
|
if (distance > -1) {
|
||||||
if (correl_buf[i] > hi_1) {
|
|
||||||
hi_1 = correl_buf[i];
|
|
||||||
idx_1 = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int foo = ABS(hi - hi_1);
|
|
||||||
int bar = (int)((int)((hi + hi_1) / 2) * 0.04);
|
|
||||||
|
|
||||||
int retval = correlation;
|
|
||||||
|
|
||||||
if (foo < bar) {
|
|
||||||
distance = (idx_1 - idx);
|
|
||||||
retval = distance;
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
PrintAndLogEx(SUCCESS, "possible visible correlation "_YELLOW_("%4d") " samples", distance);
|
PrintAndLogEx(SUCCESS, "possible correlation at "_YELLOW_("%4d") " samples", distance);
|
||||||
}
|
|
||||||
|
|
||||||
} else if (correlation > 1) {
|
|
||||||
if (verbose) {
|
|
||||||
PrintAndLogEx(SUCCESS, "possible correlation " _YELLOW_("%4zu") " samples", correlation);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(HINT, "no repeating pattern found, try increasing window size");
|
PrintAndLogEx(HINT, "no repeating pattern found, try increasing window size");
|
||||||
|
@ -892,20 +893,12 @@ int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveG
|
||||||
if (SaveGrph) {
|
if (SaveGrph) {
|
||||||
//g_GraphTraceLen = g_GraphTraceLen - window;
|
//g_GraphTraceLen = g_GraphTraceLen - window;
|
||||||
memcpy(out, correl_buf, len * sizeof(int));
|
memcpy(out, correl_buf, len * sizeof(int));
|
||||||
if (distance > 0) {
|
setClockGrid(distance, 0);
|
||||||
setClockGrid(distance, idx);
|
|
||||||
retval = distance;
|
|
||||||
} else {
|
|
||||||
setClockGrid(correlation, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_CursorCPos = idx_1;
|
|
||||||
g_CursorDPos = idx_1 + retval;
|
|
||||||
g_DemodBufferLen = 0;
|
g_DemodBufferLen = 0;
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
}
|
}
|
||||||
free(correl_buf);
|
free(correl_buf);
|
||||||
return retval;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdAutoCorr(const char *Cmd) {
|
static int CmdAutoCorr(const char *Cmd) {
|
||||||
|
@ -1413,7 +1406,8 @@ int NRZrawDemod(int clk, int invert, int maxErr, bool verbose) {
|
||||||
|
|
||||||
if (errCnt > 0 && (verbose || g_debugMode)) PrintAndLogEx(DEBUG, "DEBUG: (NRZrawDemod) Errors during Demoding (shown as 7 in bit stream): %d", errCnt);
|
if (errCnt > 0 && (verbose || g_debugMode)) PrintAndLogEx(DEBUG, "DEBUG: (NRZrawDemod) Errors during Demoding (shown as 7 in bit stream): %d", errCnt);
|
||||||
if (verbose || g_debugMode) {
|
if (verbose || g_debugMode) {
|
||||||
PrintAndLogEx(SUCCESS, "NRZ demoded bitstream:");
|
PrintAndLogEx(SUCCESS, "NRZ demoded bitstream");
|
||||||
|
PrintAndLogEx(INFO, "---------------------");
|
||||||
// Now output the bitstream to the scrollback by line of 16 bits
|
// Now output the bitstream to the scrollback by line of 16 bits
|
||||||
printDemodBuff(0, false, invert, false);
|
printDemodBuff(0, false, invert, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1555,11 +1555,11 @@ out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_autocorrelate(int clock) {
|
static int check_autocorrelate(const char *prefix, int clock) {
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(INFO, _CYAN_("Performing auto correlations..."));
|
PrintAndLogEx(INFO, _CYAN_("%s - auto correlations"), prefix);
|
||||||
for (int win = 4000; win < 30000; win += 2000) {
|
for (int win = 2000; win < 30000; win += 2000) {
|
||||||
int ans = AutoCorrelate(g_GraphBuffer, g_GraphBuffer, g_GraphTraceLen, win, false, false);
|
int ans = AutoCorrelate(g_GraphBuffer, g_GraphBuffer, g_GraphTraceLen, win, false, false);
|
||||||
if (ans == -1) {
|
if (ans == -1) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1912,68 +1912,93 @@ int CmdLFfind(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, _CYAN_("Checking for unknown tags...") "\n");
|
PrintAndLogEx(INFO, _CYAN_("Checking for unknown tags...") "\n");
|
||||||
|
|
||||||
// FSK
|
// FSK
|
||||||
|
PrintAndLogEx(INFO, "FSK clock.......... " NOLF);
|
||||||
int clock = GetFskClock("", false);
|
int clock = GetFskClock("", false);
|
||||||
if (clock) {
|
if (clock) {
|
||||||
|
PrintAndLogEx(NORMAL, _GREEN_("detected"));
|
||||||
if (FSKrawDemod(0, 0, 0, 0, true) == PM3_SUCCESS) {
|
if (FSKrawDemod(0, 0, 0, 0, true) == PM3_SUCCESS) {
|
||||||
PrintAndLogEx(INFO, _GREEN_("FSK") " modulation detected!");
|
PrintAndLogEx(INFO, _GREEN_("FSK") " modulation detected!");
|
||||||
check_autocorrelate(clock);
|
check_autocorrelate("FSK", clock);
|
||||||
|
|
||||||
if (search_cont) {
|
if (search_cont) {
|
||||||
found++;
|
found++;
|
||||||
} else {
|
} else {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO, "FSK demodulation... " _RED_("failed"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(NORMAL, _RED_("no"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ASK
|
// ASK
|
||||||
|
PrintAndLogEx(INFO, "ASK clock.......... " NOLF);
|
||||||
clock = GetAskClock("", false);
|
clock = GetAskClock("", false);
|
||||||
if (clock) {
|
if (clock) {
|
||||||
|
PrintAndLogEx(NORMAL, _GREEN_("detected"));
|
||||||
bool st = true;
|
bool st = true;
|
||||||
if (ASKDemod_ext(0, 0, 0, 0, false, true, false, 1, &st) == PM3_SUCCESS) {
|
if (ASKDemod_ext(0, 0, 0, 0, false, true, false, 1, &st) == PM3_SUCCESS) {
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(INFO, _GREEN_("ASK") " modulation / Manchester encoding detected!");
|
PrintAndLogEx(INFO, _GREEN_("ASK") " modulation / Manchester encoding detected!");
|
||||||
PrintAndLogEx(INFO, "if it does not look right it could instead be ASK/Biphase - try " _YELLOW_("'data rawdemod --ab'"));
|
PrintAndLogEx(INFO, "if it does not look right it could instead be ASK/Biphase - try " _YELLOW_("'data rawdemod --ab'"));
|
||||||
check_autocorrelate(clock);
|
check_autocorrelate("ASK", clock);
|
||||||
|
|
||||||
if (search_cont) {
|
if (search_cont) {
|
||||||
found++;
|
found++;
|
||||||
} else {
|
} else {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO, "ASK demodulation... " _RED_("failed"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(NORMAL, _RED_("no"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NZR
|
// NZR
|
||||||
|
PrintAndLogEx(INFO, "NRZ clock.......... " NOLF);
|
||||||
clock = GetNrzClock("", false);
|
clock = GetNrzClock("", false);
|
||||||
if (clock) {
|
if (clock) {
|
||||||
if (NRZrawDemod(0, 0, 0,false) == PM3_SUCCESS) {
|
PrintAndLogEx(NORMAL, _GREEN_("detected"));
|
||||||
|
if (NRZrawDemod(0, 0, 0, true) == PM3_SUCCESS) {
|
||||||
PrintAndLogEx(INFO, _GREEN_("NRZ") " modulation detected!");
|
PrintAndLogEx(INFO, _GREEN_("NRZ") " modulation detected!");
|
||||||
check_autocorrelate(clock);
|
check_autocorrelate("NRZ", clock);
|
||||||
|
|
||||||
if (search_cont) {
|
if (search_cont) {
|
||||||
found++;
|
found++;
|
||||||
} else {
|
} else {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO, "NRZ demodulation... " _RED_("failed"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(NORMAL, _RED_("no"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// PSK
|
// PSK
|
||||||
|
PrintAndLogEx(INFO, "PSK clock.......... " NOLF);
|
||||||
clock = GetPskClock("", false);
|
clock = GetPskClock("", false);
|
||||||
if (clock) {
|
if (clock) {
|
||||||
|
PrintAndLogEx(NORMAL, _GREEN_("detected"));
|
||||||
if (CmdPSK1rawDemod("") == PM3_SUCCESS) {
|
if (CmdPSK1rawDemod("") == PM3_SUCCESS) {
|
||||||
PrintAndLogEx(INFO, "Possible " _GREEN_("PSK1") " modulation detected!");
|
PrintAndLogEx(INFO, "Possible " _GREEN_("PSK1") " modulation detected!");
|
||||||
PrintAndLogEx(INFO, " Could also be PSK2 - try " _YELLOW_("'data rawdemod --p2'"));
|
PrintAndLogEx(INFO, " Could also be PSK2 - try " _YELLOW_("'data rawdemod --p2'"));
|
||||||
PrintAndLogEx(INFO, " Could also be PSK3 - [currently not supported]");
|
PrintAndLogEx(INFO, " Could also be PSK3 - [currently not supported]");
|
||||||
PrintAndLogEx(INFO, " Could also be NRZ - try " _YELLOW_("'data rawdemod --nr"));
|
PrintAndLogEx(INFO, " Could also be NRZ - try " _YELLOW_("'data rawdemod --nr"));
|
||||||
check_autocorrelate(clock);
|
check_autocorrelate("PSK", clock);
|
||||||
|
|
||||||
if (search_cont) {
|
if (search_cont) {
|
||||||
found++;
|
found++;
|
||||||
} else {
|
} else {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO, "PSK demodulation... " _RED_("failed"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(NORMAL, _RED_("no"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found == 0) {
|
if (found == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue