X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/0f321d631adb37c7cc6c6567f66eef8e2a795760..9fe4507c03c26715b532b4ceb1f46e8198ecd4c9:/client/cmddata.c?ds=sidebyside diff --git a/client/cmddata.c b/client/cmddata.c index 664ef850..a59236e6 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -28,6 +28,8 @@ uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; uint8_t g_debugMode=0; size_t DemodBufferLen=0; +int g_DemodStartIdx=0; +int g_DemodClock=0; static int CmdHelp(const char *Cmd); @@ -245,7 +247,6 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, return 0; } if (verbose || g_debugMode) PrintAndLog("\nUsing Clock:%d, Invert:%d, Bits Found:%d",clk,invert,BitLen); - //output setDemodBuf(BitStream,BitLen,0); setClockGrid(clk, startIdx); @@ -295,11 +296,11 @@ int Cmdaskmandemod(const char *Cmd) } bool st = true; if (Cmd[0]=='s') - return ASKDemod_ext(Cmd++, true, true, 1, &st); + return ASKDemod_ext(Cmd++, true, false, 1, &st); else if (Cmd[1] == 's') - return ASKDemod_ext(Cmd+=2, true, true, 1, &st); + return ASKDemod_ext(Cmd+=2, true, false, 1, &st); else - return ASKDemod(Cmd, true, true, 1); + return ASKDemod(Cmd, true, false, 1); } //by marshmellow @@ -393,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; @@ -406,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; } @@ -422,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(); @@ -797,7 +802,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) if (size > 0) { setDemodBuf(BitStream,size,0); setClockGrid(rfLen, startIdx); - + // Now output the bitstream to the scrollback by line of 16 bits if (verbose || g_debugMode) { PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen, (unsigned int)invert, (unsigned int)fchigh, (unsigned int)fclow); @@ -1057,6 +1062,9 @@ int CmdRawDemod(const char *Cmd) } void setClockGrid(int clk, int offset) { + g_DemodStartIdx = offset; + g_DemodClock = clk; + PrintAndLog("demodoffset %d, clk %d",offset,clk); if (offset > clk) offset %= clk; if (offset < 0) offset += clk; @@ -1213,6 +1221,7 @@ int getSamples(int n, bool silent) GraphTraceLen = n; } + setClockGrid(0,0); RepaintGraphWindow(); return 0; } @@ -1316,6 +1325,7 @@ int CmdLoad(const char *Cmd) } fclose(f); PrintAndLog("loaded %d samples", GraphTraceLen); + setClockGrid(0,0); RepaintGraphWindow(); return 0; }