X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/1fbf89561686188fa869a10e1251406740238234..ba765c9edcdbc624c9e77673acf5fa60daec9deb:/common/lfdemod.c diff --git a/common/lfdemod.c b/common/lfdemod.c index c7acb404..3305c8b0 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -97,6 +97,7 @@ uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_ for (uint8_t extraBitChk=0; extraBitChk<5; extraBitChk++){ errChk = preambleSearch(BitStream+extraBitChk+*startIdx, preamble, sizeof(preamble), size, startIdx); if (errChk == 0) return 0; + if (*size<64) return 0; if (*size>64) FmtLen = 22; if (*size<64) return 0; idx = *startIdx + 9; @@ -1751,22 +1752,22 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert) //find first phase shift for (i=0; i= dest[i+2]){ - waveEnd = i+1; - //PrintAndLog("DEBUG: waveEnd: %d",waveEnd); - waveLenCnt = waveEnd-waveStart; + waveEnd = i+1; + //PrintAndLog("DEBUG: waveEnd: %d",waveEnd); + waveLenCnt = waveEnd-waveStart; if (waveLenCnt > fc && waveStart > fc){ //not first peak and is a large wave lastAvgWaveVal = avgWaveVal/(waveLenCnt); - firstFullWave = waveStart; - fullWaveLen=waveLenCnt; - //if average wave value is > graph 0 then it is an up wave or a 1 + firstFullWave = waveStart; + fullWaveLen=waveLenCnt; + //if average wave value is > graph 0 then it is an up wave or a 1 if (lastAvgWaveVal > 123) curPhase^=1; //fudge graph 0 a little 123 vs 128 - break; - } + break; + } waveStart = i+1; avgWaveVal = 0; - } + } avgWaveVal+=dest[i+2]; - } + } //PrintAndLog("DEBUG: firstFullWave: %d, waveLen: %d",firstFullWave,fullWaveLen); lastClkBit = firstFullWave; //set start of wave as clock align //PrintAndLog("DEBUG: clk: %d, lastClkBit: %d", *clock, lastClkBit); @@ -1788,7 +1789,7 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert) waveEnd = i+1; waveLenCnt = waveEnd-waveStart; lastAvgWaveVal = avgWaveVal/waveLenCnt; - if (waveLenCnt > fc){ + if (waveLenCnt > fc){ //PrintAndLog("DEBUG: avgWaveVal: %d, waveSum: %d",lastAvgWaveVal,avgWaveVal); //if this wave is a phase shift //PrintAndLog("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d",waveStart,waveLenCnt,lastClkBit+*clock-tol,i+1,fc);