From 9fe4507c03c26715b532b4ceb1f46e8198ecd4c9 Mon Sep 17 00:00:00 2001 From: marshmellow42 Date: Wed, 12 Apr 2017 17:55:31 -0400 Subject: [PATCH] update more demods for graphing still todo fsk based tag demods (like HID, AWID, IO, Pyramid...) --- client/cmddata.c | 16 ++++++++++------ client/cmdlfawid.c | 1 + client/cmdlfem4x.c | 5 ++++- client/cmdlffdx.c | 2 ++ client/cmdlfgproxii.c | 4 +++- client/cmdlfhid.c | 1 + client/cmdlfindala.c | 1 + client/cmdlfio.c | 2 ++ client/cmdlfjablotron.c | 4 ++-- client/cmdlfnexwatch.c | 3 ++- client/cmdlfnoralsy.c | 1 + client/cmdlfparadox.c | 1 + client/cmdlfpresco.c | 5 +++-- client/cmdlfpyramid.c | 1 + client/cmdlfsecurakey.c | 2 +- client/cmdlfviking.c | 3 ++- client/cmdlfvisa2000.c | 2 +- client/proxguiqt.cpp | 6 ++++-- common/lfdemod.c | 19 +++++-------------- common/lfdemod.h | 2 +- 20 files changed, 48 insertions(+), 33 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 7a411324..a59236e6 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -394,7 +394,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd) uint8_t BitStream[MAX_DEMOD_BUF_LEN]={0}; size = sizeof(BitStream); if ( !getDemodBuf(BitStream, &size) ) return 0; - errCnt=BiphaseRawDecode(BitStream, &size, offset, invert); + errCnt=BiphaseRawDecode(BitStream, &size, &offset, invert); if (errCnt<0){ PrintAndLog("Error during decode:%d", errCnt); return 0; @@ -407,10 +407,12 @@ int CmdBiphaseDecodeRaw(const char *Cmd) if (errCnt>0){ PrintAndLog("# Errors found during Demod (shown as 7 in bit stream): %d",errCnt); } + PrintAndLog("Biphase Decoded using offset: %d - # invert:%d - data:",offset,invert); PrintAndLog("%s", sprint_bin_break(BitStream, size, 16)); if (offset) setDemodBuf(DemodBuffer,DemodBufferLen-offset, offset); //remove first bit from raw demod + setClockGrid(g_DemodClock, g_DemodStartIdx + g_DemodClock*offset/2); return 1; } @@ -423,26 +425,28 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose) sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr); uint8_t BitStream[MAX_GRAPH_TRACE_LEN]; - size_t size = getFromGraphBuf(BitStream); + size_t size = getFromGraphBuf(BitStream); + int startIdx = 0; //invert here inverts the ask raw demoded bits which has no effect on the demod, but we need the pointer - int errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0); + int errCnt = askdemod_ext(BitStream, &size, &clk, &invert, maxErr, 0, 0, &startIdx); if ( errCnt < 0 || errCnt > maxErr ) { if (g_debugMode) PrintAndLog("DEBUG: no data or error found %d, clock: %d", errCnt, clk); return 0; - } + } //attempt to Biphase decode BitStream - errCnt = BiphaseRawDecode(BitStream, &size, offset, invert); + errCnt = BiphaseRawDecode(BitStream, &size, &offset, invert); if (errCnt < 0){ if (g_debugMode || verbose) PrintAndLog("Error BiphaseRawDecode: %d", errCnt); return 0; - } + } if (errCnt > maxErr) { if (g_debugMode || verbose) PrintAndLog("Error BiphaseRawDecode too many errors: %d", errCnt); return 0; } //success set DemodBuffer and return setDemodBuf(BitStream, size, 0); + setClockGrid(clk, startIdx + clk*offset/2); if (g_debugMode || verbose){ PrintAndLog("Biphase Decoded using offset: %d - clock: %d - # errors:%d - data:",offset,clk,errCnt); printDemodBuff(); diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 225816df..7f0b9910 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -126,6 +126,7 @@ int CmdFSKdemodAWID(const char *Cmd) uint32_t rawHi = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi2 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,96,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); size = removeParity(BitStream, idx+8, 4, 1, 88); if (size != 66){ diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 83a7da4e..6587afe8 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -153,7 +153,8 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)) { //set GraphBuffer for clone or sim command setDemodBuf(DemodBuffer, (BitLen==40) ? 64 : 128, idx+1); - g_DemodStartIdx += (idx+1)*g_DemodClock; + setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock)); + if (g_debugMode) { PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); @@ -704,6 +705,8 @@ bool EM4x05testDemodReadData(uint32_t *word, bool readCmd) { } setDemodBuf(DemodBuffer, 32, 0); + setClockGrid(0,0); + *word = bytebits_to_byteLSBF(DemodBuffer, 32); } return true; diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index e90d024e..234db59f 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -159,6 +159,8 @@ int CmdFdxDemod(const char *Cmd){ // set and leave DemodBuffer intact setDemodBuf(DemodBuffer, 128, preambleIndex); + setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex*g_DemodClock)); + uint8_t bits_no_spacer[117]; memcpy(bits_no_spacer, DemodBuffer + 11, 117); diff --git a/client/cmdlfgproxii.c b/client/cmdlfgproxii.c index 1657f761..71c5f391 100644 --- a/client/cmdlfgproxii.c +++ b/client/cmdlfgproxii.c @@ -83,7 +83,9 @@ int CmdG_Prox_II_Demod(const char *Cmd) PrintAndLog("Decoded Raw: %s", sprint_hex(ByteStream, 8)); } PrintAndLog("Raw: %08x%08x%08x", raw1,raw2,raw3); - setDemodBuf(DemodBuffer+ans, 96, 0); + setDemodBuf(DemodBuffer, 96, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); + return 1; } //by marshmellow diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index e580a10d..a9693fb2 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -99,6 +99,7 @@ int CmdFSKdemodHID(const char *Cmd) (unsigned int) fmtLen, (unsigned int) fc, (unsigned int) cardnum); } setDemodBuf(BitStream,BitLen,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index fc396ac6..de1757e9 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -46,6 +46,7 @@ int CmdIndalaDecode(const char *Cmd) { return -1; } setDemodBuf(DemodBuffer, size, (size_t)startIdx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (startIdx*g_DemodClock)); if (invert) if (g_debugMode) PrintAndLog("Had to invert bits"); diff --git a/client/cmdlfio.c b/client/cmdlfio.c index cfcc7d62..be8cf25e 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -119,6 +119,8 @@ int CmdFSKdemodIO(const char *Cmd) PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [%02x %s]",version,facilitycode,number,code,code2, crc, crcStr); setDemodBuf(BitStream,64,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing demod buffer:",idx,64); printDemodBuff(); diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index a2984ac8..9c69099e 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -117,8 +117,8 @@ int CmdJablotronDemod(const char *Cmd) { return 0; } - setDemodBuf(DemodBuffer+ans, 64, 0); - //setGrid_Clock(64); + setDemodBuf(DemodBuffer, 64, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); diff --git a/client/cmdlfnexwatch.c b/client/cmdlfnexwatch.c index 64ea54e5..caabe835 100644 --- a/client/cmdlfnexwatch.c +++ b/client/cmdlfnexwatch.c @@ -38,7 +38,8 @@ int CmdPSKNexWatch(const char *Cmd) } if (size != 128) return 0; setDemodBuf(DemodBuffer, size, startIdx+4); - startIdx = 8+32; //4 = extra i added, 8 = preamble, 32 = reserved bits (always 0) + setClockGrid(g_DemodClock, g_DemodStartIdx + ((startIdx+4)*g_DemodClock)); + startIdx = 8+32; // 8 = preamble, 32 = reserved bits (always 0) //get ID uint32_t ID = 0; for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){ diff --git a/client/cmdlfnoralsy.c b/client/cmdlfnoralsy.c index 282a79ae..2c90fa14 100644 --- a/client/cmdlfnoralsy.c +++ b/client/cmdlfnoralsy.c @@ -135,6 +135,7 @@ int CmdNoralsyDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //setGrid_Clock(32); //got a good demod diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 87e49b3a..6582eb35 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -63,6 +63,7 @@ int CmdFSKdemodParadox(const char *Cmd) PrintAndLog("Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x", hi>>10, (hi & 0x3)<<26 | (lo>>10), fc, cardnum, (lo>>2) & 0xFF, rawHi2, rawHi, rawLo); setDemodBuf(BitStream,BitLen,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index f18c3ec6..8ac3a71e 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -144,8 +144,9 @@ int CmdPrescoDemod(const char *Cmd) { uint32_t cardid = raw4; PrintAndLog("Presco Tag Found: Card ID %08X", cardid); PrintAndLog("Raw: %08X%08X%08X%08X", raw1,raw2,raw3,raw4); - setDemodBuf(DemodBuffer+ans, 128, 0); - + setDemodBuf(DemodBuffer, 128, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); + uint32_t sitecode = 0, usercode = 0, fullcode = 0; bool Q5=false; char cmd[12] = {0}; diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index 9cd4b207..c7a6cb93 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -152,6 +152,7 @@ int CmdFSKdemodPyramid(const char *Cmd) uint32_t rawHi2 = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi3 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,128,idx); + setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); size = removeParity(BitStream, idx+8, 8, 1, 120); if (size != 105){ diff --git a/client/cmdlfsecurakey.c b/client/cmdlfsecurakey.c index 87ebb25e..8085eedc 100644 --- a/client/cmdlfsecurakey.c +++ b/client/cmdlfsecurakey.c @@ -64,7 +64,7 @@ int CmdSecurakeyDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); - //setGrid_Clock(40); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer , 32); diff --git a/client/cmdlfviking.c b/client/cmdlfviking.c index 3d525c1c..779156c8 100644 --- a/client/cmdlfviking.c +++ b/client/cmdlfviking.c @@ -73,7 +73,8 @@ int CmdVikingDemod(const char *Cmd) { uint8_t checksum = bytebits_to_byte(DemodBuffer+ans+32+24, 8); PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, (unsigned int) checksum); PrintAndLog("Raw: %08X%08X", raw1,raw2); - setDemodBuf(DemodBuffer+ans, 64, 0); + setDemodBuf(DemodBuffer, 64, ans); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); return 1; } diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index b461d94d..562b9bcd 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -119,7 +119,7 @@ int CmdVisa2kDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); - //setGrid_Clock(64); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index c0aff8b6..05a048d8 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include "proxguiqt.h" @@ -431,11 +432,11 @@ void Plot::paintEvent(QPaintEvent *event) plotGridLines(&painter, plotRect); //Start painting graph - PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); - PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); if (showDemod && DemodBufferLen > 8) { PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx); } + PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); + PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); // End graph drawing //Draw the cursors @@ -472,6 +473,7 @@ void Plot::paintEvent(QPaintEvent *event) Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) { + //Need to set this, otherwise we don't receive keypress events setFocusPolicy( Qt::StrongFocus); resize(600, 300); diff --git a/common/lfdemod.c b/common/lfdemod.c index d6ef88a4..072bd120 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1130,10 +1130,10 @@ int millerRawDecode(uint8_t *BitStream, size_t *size, int invert) { //take 01 or 10 = 1 and 11 or 00 = 0 //check for phase errors - should never have 111 or 000 should be 01001011 or 10110100 for 1010 //decodes biphase or if inverted it is AKA conditional dephase encoding AKA differential manchester encoding -int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int offset, int invert) { +int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int *offset, int invert) { uint16_t bitnum = 0; uint16_t errCnt = 0; - size_t i = offset; + size_t i = *offset; uint16_t MaxBits=512; //if not enough samples - error if (*size < 51) return -1; @@ -1143,8 +1143,8 @@ int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int offset, int invert) { if (BitStream[i+1]==BitStream[i+2]) offsetA=0; if (BitStream[i+2]==BitStream[i+3]) offsetB=0; } - if (!offsetA && offsetB) offset++; - for (i=offset; i<*size-3; i+=2){ + if (!offsetA && offsetB) *offset+=1; + for (i=*offset; i<*size-3; i+=2){ //check for phase error if (BitStream[i+1]==BitStream[i+2]) { BitStream[bitnum++]=7; @@ -1490,6 +1490,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, //by marshmellow (from holiman's base) // full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod) int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { + if (justNoise(dest, *size)) return 0; // FSK demodulator size = fsk_wave_demod(dest, size, fchigh, fclow, startIdx); size = aggregate_bits(dest, size, rfLen, invert, fchigh, fclow, startIdx); @@ -1631,8 +1632,6 @@ int AWIDdemodFSK(uint8_t *dest, size_t *size) { //make sure buffer has enough data if (*size < 96*50) return -1; - if (justNoise(dest, *size)) return -2; - // FSK demodulator *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 if (*size < 96) return -3; //did we get a good demod? @@ -1717,8 +1716,6 @@ int gProxII_Demod(uint8_t BitStream[], size_t *size) { // loop to get raw HID waveform then FSK demodulate the TAG ID from it int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { - if (justNoise(dest, *size)) return -1; - size_t numStart=0, size2=*size, startIdx=0; // FSK demodulator *size = fskdemod(dest, size2,50,1,10,8); //fsk2a @@ -1747,7 +1744,6 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32 } int IOdemodFSK(uint8_t *dest, size_t size) { - if (justNoise(dest, size)) return -1; //make sure buffer has data if (size < 66*64) return -2; // FSK demodulator @@ -1797,8 +1793,6 @@ int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert) { // loop to get raw paradox waveform then FSK demodulate the TAG ID from it int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { - if (justNoise(dest, *size)) return -1; - size_t numStart=0, size2=*size, startIdx=0; // FSK demodulator *size = fskdemod(dest, size2,50,1,10,8); //fsk2a @@ -1845,9 +1839,6 @@ int PyramiddemodFSK(uint8_t *dest, size_t *size) { //make sure buffer has data if (*size < 128*50) return -5; - //test samples are not just noise - if (justNoise(dest, *size)) return -1; - // FSK demodulator *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 if (*size < 128) return -2; //did we get a good demod? diff --git a/common/lfdemod.h b/common/lfdemod.h index 9f37a969..56e07e56 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -21,7 +21,7 @@ extern size_t addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, extern int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType); extern int askdemod_ext(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx); extern void askAmp(uint8_t *BitStream, size_t size); -extern int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int offset, int invert); +extern int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int *offset, int invert); extern uint32_t bytebits_to_byte(uint8_t* src, size_t numbits); extern uint32_t bytebits_to_byteLSBF(uint8_t* src, size_t numbits); extern uint16_t countFC(uint8_t *BitStream, size_t size, uint8_t fskAdj); -- 2.39.5