X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/4c36581b96dfb81c85f34a4229d82e51edeaf499..ce9a7cbf33ff29722d7e7f6adec4fe149f55ce87:/client/cmddata.c diff --git a/client/cmddata.c b/client/cmddata.c index 23863131..9b893328 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -277,7 +277,8 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) { - if (!ASKDemod(Cmd, FALSE, FALSE, 1)) return 0; + bool st = TRUE; + if (!ASKDemod_ext(Cmd, FALSE, FALSE, 1, &st)) return 0; return AskEm410xDecode(verbose, hi, lo); } @@ -312,8 +313,7 @@ int CmdAskEM410xDemod(const char *Cmd) //verbose will print results and demoding messages //emSearch will auto search for EM410x format in bitstream //askType switches decode: ask/raw = 0, ask/manchester = 1 -int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) -{ +int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck) { int invert=0; int clk=0; int maxErr=100; @@ -336,7 +336,14 @@ int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) if (g_debugMode) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen); if (BitLen<255) return 0; if (maxLen 25 || cmdp == 'h' || cmdp == 'H') { - PrintAndLog("Usage: data rawdemod am [clock] [maxError] [maxLen] [amplify]"); + PrintAndLog("Usage: data rawdemod am [clock] [maxError] [maxLen] [amplify]"); + PrintAndLog(" ['s'] optional, check for Sequence Terminator"); PrintAndLog(" [set clock as integer] optional, if not set, autodetect"); PrintAndLog(" , 1 to invert output"); PrintAndLog(" [set maximum allowed errors], default = 100"); @@ -388,6 +400,12 @@ int Cmdaskmandemod(const char *Cmd) PrintAndLog(" : data rawdemod am 64 1 0 = demod an ask/manchester tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); return 0; } + bool st = TRUE; + if (Cmd[0]=='s') + return ASKDemod_ext(Cmd++, TRUE, TRUE, 1, &st); + else if (Cmd[1] == 's') + return ASKDemod_ext(Cmd+=2, TRUE, TRUE, 1, &st); + else return ASKDemod(Cmd, TRUE, TRUE, 1); } @@ -595,7 +613,7 @@ int CmdG_Prox_II_Demod(const char *Cmd) if ((idx+1) % 5 == 0){ //spacer bit - should be 0 if (DemodBuffer[startIdx+idx] != 0) { - if (g_debugMode) PrintAndLog("Error spacer not 0: %d, pos: %d",DemodBuffer[startIdx+idx],startIdx+idx); + if (g_debugMode) PrintAndLog("Error spacer not 0: %u, pos: %u", (unsigned int)DemodBuffer[startIdx+idx],(unsigned int)(startIdx+idx)); return 0; } continue; @@ -610,14 +628,14 @@ int CmdG_Prox_II_Demod(const char *Cmd) ByteStream[ByteCnt] = ByteStream[ByteCnt] | (DemodBuffer[startIdx+idx]<0 && strlen(Cmd)<=2) { - if (rfLen==1){ + if (rfLen==1) { invert = 1; //if invert option only is used rfLen = 0; - } + } } uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; //get field clock lengths - uint8_t fc1=0, fc2=0, rf1=0; + uint16_t fcs=0; if (!fchigh || !fclow) { - uint8_t ans = fskClocks(&fc1, &fc2, &rf1, false); - if (ans == 0) { - if (g_debugMode) PrintAndLog("\nError: cannot detect valid fsk field clocks"); - return 0; // can't detect field clock + fcs = countFC(BitStream, BitLen, 1); + if (!fcs) { + fchigh = 10; + fclow = 8; + } else { + fchigh = (fcs >> 8) & 0x00FF; + fclow = fcs & 0x00FF; } - fchigh = fc1; - fclow = fc2; - if (rfLen == 0) rfLen = rf1; } //get bit clock length - if (!rfLen){ + if (!rfLen) { rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow); if (!rfLen) rfLen = 50; } int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow); - if (size > 0){ + if (size > 0) { setDemodBuf(BitStream, size, 0); // 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", rfLen, invert, fchigh, fclow); + PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen, (unsigned int)invert, (unsigned int)fchigh, (unsigned int)fclow); PrintAndLog("%s decoded bitstream:", GetFSKType(fchigh, fclow, invert)); printDemodBuff(); } @@ -1390,7 +1410,7 @@ int CmdFSKdemodPyramid(const char *Cmd) // s = format start bit, o = odd parity of last 7 bits // f = facility code, c = card number // w = wiegand parity, x = extra space for other formats - // p = unknown checksum + // p = CRC8maxim checksum // (26 bit format shown) //get bytes for checksum calc @@ -1437,38 +1457,36 @@ int CmdFSKdemodPyramid(const char *Cmd) // s = format start bit, o = odd parity of last 7 bits // f = facility code, c = card number // w = wiegand parity, x = extra space for other formats - // p = unknown checksum + // p = CRC8-Maxim checksum // (26 bit format shown) //find start bit to get fmtLen int j; - for (j=0; j32){ - //code1 = bytebits_to_byte(BitStream+(size-fmtLen),fmtLen-32); - //code2 = bytebits_to_byte(BitStream+(size-32),32); + if (fmtLen > 32) PrintAndLog("Pyramid ID Found - BitLength: %d -unknown BitLength- (%d), Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo); - } else{ - //code1 = bytebits_to_byte(BitStream+(size-fmtLen),fmtLen); + else PrintAndLog("Pyramid ID Found - BitLength: %d -unknown BitLength- (%d), Raw: %08x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo); - } } if (checksum == checkCS) PrintAndLog("Checksum %02x passed", checksum);