From f79c0075c44d30b1ba4dd35e2f940428e38daebd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 19 Mar 2019 00:12:46 +0100 Subject: [PATCH 1/5] style --- client/reveng/model.c | 4 ++-- client/reveng/poly.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/reveng/model.c b/client/reveng/model.c index ba5e84f07..16a791312 100644 --- a/client/reveng/model.c +++ b/client/reveng/model.c @@ -113,8 +113,8 @@ char *mtostr(const model_t *model) { + strlen(strbuf) + (polystr && *polystr ? strlen(polystr) : 6) + (initstr && *initstr ? strlen(initstr) : 6) - + (model->flags & P_REFIN ? 4 : 5) - + (model->flags & P_REFOUT ? 4 : 5) + + ((model->flags & P_REFIN) ? 4 : 5) + + ((model->flags & P_REFOUT) ? 4 : 5) + (xorotstr && *xorotstr ? strlen(xorotstr) : 6) + (checkstr && *checkstr ? strlen(checkstr) : 6) + (magicstr && *magicstr ? strlen(magicstr) : 6) diff --git a/client/reveng/poly.c b/client/reveng/poly.c index 1a2ca958f..7e35be18c 100644 --- a/client/reveng/poly.c +++ b/client/reveng/poly.c @@ -1207,7 +1207,7 @@ prhex(char **spp, bmp_t bits, int flags, int bperhx) { * Set P_UPPER in flags to write A-F in uppercase. */ static const char hex[] = "0123456789abcdef0123456789ABCDEF"; - const int upper = (flags & P_UPPER ? 0x10 : 0); + const int upper = ((flags & P_UPPER) ? 0x10 : 0); while (bperhx > 0) { bperhx -= ((bperhx + 3) & 3) + 1; *(*spp)++ = hex[(bits >> bperhx & BMP_C(0xf)) | upper]; From ab226c28648bcca6a6270de9b1538774c22196a5 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 19 Mar 2019 10:20:10 +0100 Subject: [PATCH 2/5] detectST has better clock detection. Since 'data raw am' fails but 'data detect a' succeed in finding a clock. Lets see if anything else breaks because of this? --- client/cmddata.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 072e8a73e..b50d44649 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -458,7 +458,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0}; sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &); - + if (!maxLen) maxLen = BIGBUF_SIZE; if (invert != 0 && invert != 1) { @@ -485,14 +485,13 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, if (amp == 'a') askAmp(bits, BitLen); - bool st = false; size_t ststart = 0, stend = 0; - if (*stCheck) - st = DetectST(bits, &BitLen, &foundclk, &ststart, &stend); - +// if (*stCheck) + bool st = DetectST(bits, &BitLen, &foundclk, &ststart, &stend); + clk = (clk == 0) ? foundclk : clk; + if (st) { *stCheck = st; - clk = (clk == 0) ? foundclk : clk; CursorCPos = ststart; CursorDPos = stend; if (verbose) @@ -1607,8 +1606,7 @@ int CmdLoad(const char *Cmd) { break; } - if (f) - fclose(f); + fclose(f); PrintAndLogEx(SUCCESS, "loaded %d samples", GraphTraceLen); From 42bbf6a761f24f4cc4d26a5dcf57bdcd4416fdb4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 19 Mar 2019 10:26:36 +0100 Subject: [PATCH 3/5] style --- armsrc/apps.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/apps.h b/armsrc/apps.h index 62fce3931..b1a0969f3 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -231,7 +231,7 @@ void HfSniff(int, int); //felica.c extern void felica_sendraw(UsbCommand *c); -extern void felica_sniff(uint32_t samples, uint32_t triggers); +extern void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip); extern void felica_sim_lite(uint64_t uid); extern void felica_dump_lite_s(); From a41d6fbfb2c7a46f3ade052d964331c9c4874807 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 19 Mar 2019 10:26:52 +0100 Subject: [PATCH 4/5] style --- armsrc/felica.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/armsrc/felica.c b/armsrc/felica.c index 190960bd4..f220a8a24 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -611,13 +611,13 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) { #define R_READBLK_LEN 0x21 //simulate NFC Tag3 card - for now only poll response works // second half (4 bytes) of NDEF2 goes into nfcid2_0, first into nfcid2_1 -void felica_sim_lite(uint64_t nfcid) { +void felica_sim_lite(uint64_t uid) { int i, curlen = 0; uint8_t *curresp = 0; uint8_t ndef[8]; - num_to_bytes(nfcid, 8, ndef); + num_to_bytes(uid, 8, ndef); //prepare our 3 responses... uint8_t resp_poll0[R_POLL0_LEN] = { 0xb2, 0x4d, 0x12, FELICA_POLL_ACK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f}; From 54a1d576eed93c5f07c9484e1aa01b281a14a121 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 19 Mar 2019 14:41:57 +0100 Subject: [PATCH 5/5] fix: better ASK strong /clipped clock detection. --- common/lfdemod.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/common/lfdemod.c b/common/lfdemod.c index eb7c629f5..3b4a3a30c 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -480,12 +480,25 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo size_t startwave; size_t i = 100; size_t minClk = 512; - int shortestWaveIdx = 0; + uint16_t shortestWaveIdx = 0; // get to first full low to prime loop and skip incomplete first pulse getNextHigh(dest, size, high, &i); getNextLow(dest, size, low, &i); + // clock, numoftimes, first idx + uint16_t tmpclk[9][3] = { + {8, 0, 0}, + {16, 0, 0}, + {32, 0, 0}, + {40, 0, 0}, + {50, 0, 0}, + {64, 0, 0}, + {128, 0, 0}, + {256, 0, 0}, + {384, 0, 0}, + }; + // loop through all samples (well, we don't want to go out-of-bounds) while (i < size - 512) { // measure from low to low @@ -499,11 +512,38 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo minClk = i - startwave; shortestWaveIdx = startwave; } + + int foo = getClosestClock(minClk); + if (foo > 0 ) { + for (uint8_t i = 0; i < 9; i++) { + if ( tmpclk[i][0] == foo ) { + tmpclk[i][1]++; + + if ( tmpclk[i][2] == 0) { + tmpclk[i][2] = shortestWaveIdx; + } + break; + } + } + } } - // set clock - if (g_debugMode == 2) prnt("DEBUG ASK: DetectStrongAskClock smallest wave: %d", minClk); - *clock = getClosestClock(minClk); + // find the clock with most hits and it the first index it was encountered. + int max = 0; + for (uint8_t i = 0; i < 9; i++) { + if (g_debugMode == 2) { + prnt("DEBUG, ASK, clocks %u | hits %u | idx %u" + , tmpclk[i][0] + , tmpclk[i][1] + , tmpclk[i][2] + ); + } + if ( max < tmpclk[i][1] ) { + *clock = tmpclk[i][0]; + shortestWaveIdx = tmpclk[i][2]; + max = tmpclk[i][1]; + } + } if (*clock == 0) return -1;