From a8fd088d8b142520fbb686b315df7216a81d481f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 28 Feb 2017 14:47:25 +0100 Subject: [PATCH] FIX: `lf search` - em410x demod was a bit greedy. --- client/cmddata.c | 6 +++--- common/lfdemod.c | 11 +++++------ common/lfdemod.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 74973b34..398d31fb 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -364,7 +364,7 @@ int CmdGetBitStream(const char *Cmd) //print 64 bit EM410x ID in multiple formats void printEM410x(uint32_t hi, uint64_t id) { - //if (!id && !hi) return; + if (!id && !hi) return; PrintAndLog("EM410x %s pattern found", (hi) ? "XL" : "" ); @@ -471,11 +471,11 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) if (g_debugMode){ if (ans == -1) PrintAndLog("DEBUG: Error - Em410x not only 0|1 in decoded bitstream"); + else if (ans == -2) + PrintAndLog("DEBUG: Error - Em410x preamble not found"); 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 0; diff --git a/common/lfdemod.c b/common/lfdemod.c index ca126df3..439699c6 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -203,10 +203,10 @@ size_t findModStart(uint8_t dest[], size_t size, uint8_t threshold_value, uint8_ //by marshmellow //takes 1s and 0s and searches for EM410x format - output EM ID // actually, no arguments needed - built this way in case we want this to be a direct call from "data " cmds in the future -uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo) +int Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo) { // sanity check - if (BitStream[1] > 1) return 0; + if (BitStream[1] > 1) return -1; uint8_t fmtlen; *startIdx = 0; @@ -215,8 +215,8 @@ uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_ // include 0 in front to help get start pos uint8_t preamble[] = {0,1,1,1,1,1,1,1,1,1}; if (!preambleSearch(BitStream, preamble, sizeof(preamble), size, startIdx)) - return 0; - if (*size < 64) return 0; + return -2; + if (*size < 64) return -3; fmtlen = (*size == 110) ? 22 : 10; @@ -236,8 +236,7 @@ uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_ *lo = ((uint64_t)(bytebits_to_byte(BitStream + 24, 32)) << 32) | (bytebits_to_byte(BitStream + 24 + 32, 32)); break; } - default: return 0; - + default: return -4; } return 1; } diff --git a/common/lfdemod.h b/common/lfdemod.h index 4c2cb9fb..ce71fad2 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -50,7 +50,7 @@ size_t removeParity(uint8_t *BitStream, size_t startIdx, uint8_t pLen, uint8_t //tag specific int AWIDdemodFSK(uint8_t *dest, size_t *size); -uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo); +int Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo); int FDXBdemodBI(uint8_t *dest, size_t *size); int gProxII_Demod(uint8_t BitStream[], size_t *size); int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); -- 2.39.2