diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index bb63c1d04..bd1dbe0c6 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -377,6 +377,7 @@ start: c.arg[0] = false; goto start; } else { + // nonce2key found a candidate key. Lets verify it. uint8_t keyblock[] = {0,0,0,0,0,0}; num_to_bytes(r_key, 6, keyblock); @@ -1053,7 +1054,7 @@ int CmdHF14AMfNested(const char *Cmd) { key64 = bytes_to_num(data+10, 6); if (key64) { PrintAndLog("Data:%s", sprint_hex(data+10, 6)); - e_sector[i].foundKey[1] = TRUE; + e_sector[i].foundKey[1] = true; e_sector[i].Key[1] = key64; } } @@ -1333,11 +1334,12 @@ int CmdHF14AMfChk(const char *Cmd) { } memset(keyBlock + 6 * keycnt, 0, 6); num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt); - PrintAndLog("check key[%2d] %012" PRIx64, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6)); + //PrintAndLog("check key[%2d] %012" PRIx64, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6)); keycnt++; memset(buf, 0, sizeof(buf)); } fclose(f); + PrintAndLog("Loaded %2d keys from %s", keycnt, filename); } else { PrintAndLog("File: %s: not found or locked.", filename); free(keyBlock); @@ -1366,8 +1368,8 @@ int CmdHF14AMfChk(const char *Cmd) { for(int i = 0; i < SectorsCnt; ++i){ e_sector[i].Key[0] = 0xffffffffffff; e_sector[i].Key[1] = 0xffffffffffff; - e_sector[i].foundKey[0] = FALSE; - e_sector[i].foundKey[1] = FALSE; + e_sector[i].foundKey[0] = false; + e_sector[i].foundKey[1] = false; } @@ -1502,8 +1504,8 @@ static void emptySectorTable(){ for(int i = 0; i < k_sectorsCount; ++i){ k_sector[i].Key[0] = 0xffffffffffff; k_sector[i].Key[1] = 0xffffffffffff; - k_sector[i].foundKey[0] = FALSE; - k_sector[i].foundKey[1] = FALSE; + k_sector[i].foundKey[0] = false; + k_sector[i].foundKey[1] = false; } } void showSectorTable(){ @@ -1516,7 +1518,7 @@ void showSectorTable(){ void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose) { uint64_t key = 0; - bool success = FALSE; + bool success = false; if (k_sector == NULL) emptySectorTable(); @@ -1533,7 +1535,7 @@ void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose) { ); k_sector[sector].Key[keytype] = key; - k_sector[sector].foundKey[keytype] = TRUE; + k_sector[sector].foundKey[keytype] = true; //set emulator memory for keys if (setEmulatorMem) { @@ -1557,16 +1559,16 @@ int CmdHF14AMf1kSim(const char *Cmd) { uint8_t flags = (FLAG_UID_IN_EMUL | FLAG_4B_UID_IN_DATA); int uidlen = 0; uint8_t cmdp = 0; - bool errors = FALSE; - bool verbose = FALSE; - bool setEmulatorMem = FALSE; + bool errors = false; + bool verbose = false; + bool setEmulatorMem = false; nonces_t data[1]; while(param_getchar(Cmd, cmdp) != 0x00) { switch(param_getchar(Cmd, cmdp)) { case 'e': case 'E': - setEmulatorMem = TRUE; + setEmulatorMem = true; cmdp++; break; case 'h': @@ -1595,7 +1597,7 @@ int CmdHF14AMf1kSim(const char *Cmd) { break; case 'v': case 'V': - verbose = TRUE; + verbose = true; cmdp++; break; case 'x': @@ -1605,7 +1607,7 @@ int CmdHF14AMf1kSim(const char *Cmd) { break; default: PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = TRUE; + errors = true; break; } if(errors) break; @@ -1642,10 +1644,10 @@ int CmdHF14AMf1kSim(const char *Cmd) { } int CmdHF14AMfSniff(const char *Cmd){ - bool wantLogToFile = FALSE; - bool wantDecrypt = FALSE; - //bool wantSaveToEml = FALSE; TODO - bool wantSaveToEmlFile = FALSE; + bool wantLogToFile = false; + bool wantDecrypt = false; + //bool wantSaveToEml = false; TODO + bool wantSaveToEmlFile = false; //var int tmpchar; @@ -1658,7 +1660,7 @@ int CmdHF14AMfSniff(const char *Cmd){ uint8_t uid_len = 0; uint8_t atqa[2] = {0x00, 0x00}; uint8_t sak = 0; - bool isTag = FALSE; + bool isTag = false; uint8_t *buf = NULL; uint16_t bufsize = 0; uint8_t *bufPtr = NULL; diff --git a/client/cmdlf.c b/client/cmdlf.c index 414e4a2be..6e3422a4f 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -9,7 +9,7 @@ //----------------------------------------------------------------------------- #include "cmdlf.h" -bool g_lf_threshold_set = FALSE; +bool g_lf_threshold_set = false; static int CmdHelp(const char *Cmd); @@ -125,8 +125,8 @@ int usage_lf_find(void){ /* send a LF command before reading */ int CmdLFCommandRead(const char *Cmd) { - bool errors = FALSE; - bool useHighFreq = FALSE; + bool errors = false; + bool useHighFreq = false; uint16_t one = 0, zero = 0; uint8_t cmdp = 0; UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, {0,0,0}}; @@ -136,7 +136,7 @@ int CmdLFCommandRead(const char *Cmd) { case 'h': return usage_lf_cmdread(); case 'H': - useHighFreq = TRUE; + useHighFreq = true; cmdp++; break; case 'L': @@ -166,7 +166,7 @@ int CmdLFCommandRead(const char *Cmd) { if(errors) break; } // No args - if (cmdp == 0) errors = TRUE; + if (cmdp == 0) errors = true; //Validations if (errors) return usage_lf_cmdread(); @@ -481,7 +481,7 @@ int CmdLFSetConfig(const char *Cmd) { uint8_t bps = 0; // Bits per sample uint8_t decimation = 0; //How many to keep bool averaging = 1; // Defaults to true - bool errors = FALSE; + bool errors = false; int trigger_threshold = -1;//Means no change uint8_t unsigned_trigg = 0; @@ -654,7 +654,7 @@ int CmdLFfskSim(const char *Cmd) // otherwise will need FChigh, FClow, Clock, and bitstream uint8_t fcHigh = 0, fcLow = 0, clk = 0; uint8_t invert = 0; - bool errors = FALSE; + bool errors = false; char hexData[32] = {0x00}; // store entered hex data uint8_t data[255] = {0x00}; int dataLen = 0; @@ -687,17 +687,17 @@ int CmdLFfskSim(const char *Cmd) case 'd': dataLen = param_getstr(Cmd, cmdp+1, hexData); if (dataLen == 0) - errors = TRUE; + errors = true; else dataLen = hextobinarray((char *)data, hexData); - if (dataLen == 0) errors = TRUE; + if (dataLen == 0) errors = true; if (errors) PrintAndLog ("Error getting hex data"); cmdp+=2; break; default: PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = TRUE; + errors = true; break; } if(errors) break; @@ -705,7 +705,7 @@ int CmdLFfskSim(const char *Cmd) // No args if(cmdp == 0 && DemodBufferLen == 0) - errors = TRUE; + errors = true; //Validations if(errors) return usage_lf_simfsk(); @@ -751,7 +751,7 @@ int CmdLFaskSim(const char *Cmd) // autodetect clock from Graphbuffer if using demod buffer // needs clock, invert, manchester/raw as m or r, separator as s, and bitstream uint8_t encoding = 1, separator = 0, clk = 0, invert = 0; - bool errors = FALSE; + bool errors = false; char hexData[32] = {0x00}; uint8_t data[255]= {0x00}; // store entered hex data int dataLen = 0; @@ -788,17 +788,17 @@ int CmdLFaskSim(const char *Cmd) case 'd': dataLen = param_getstr(Cmd, cmdp+1, hexData); if (dataLen == 0) - errors = TRUE; + errors = true; else dataLen = hextobinarray((char *)data, hexData); - if (dataLen == 0) errors = TRUE; + if (dataLen == 0) errors = true; if (errors) PrintAndLog ("Error getting hex data, datalen: %d", dataLen); cmdp += 2; break; default: PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = TRUE; + errors = true; break; } if(errors) break; @@ -806,7 +806,7 @@ int CmdLFaskSim(const char *Cmd) // No args if(cmdp == 0 && DemodBufferLen == 0) - errors = TRUE; + errors = true; //Validations if(errors) return usage_lf_simask(); @@ -818,7 +818,7 @@ int CmdLFaskSim(const char *Cmd) setDemodBuf(data, dataLen, 0); } if (clk == 0) clk = 64; - if (encoding == 0) clk >>= 2; //askraw needs to double the clock speed + if (encoding == 0) clk /= 2; //askraw needs to double the clock speed size_t size = DemodBufferLen; @@ -847,7 +847,7 @@ int CmdLFpskSim(const char *Cmd) { //will need carrier, Clock, and bitstream uint8_t carrier=0, clk=0; uint8_t invert=0; - bool errors = FALSE; + bool errors = false; char hexData[32] = {0x00}; // store entered hex data uint8_t data[255] = {0x00}; int dataLen = 0; @@ -885,24 +885,24 @@ int CmdLFpskSim(const char *Cmd) { case 'd': dataLen = param_getstr(Cmd, cmdp+1, hexData); if (dataLen == 0) - errors = TRUE; + errors = true; else dataLen = hextobinarray((char *)data, hexData); - if (dataLen == 0) errors = TRUE; + if (dataLen == 0) errors = true; if (errors) PrintAndLog ("Error getting hex data"); cmdp+=2; break; default: PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = TRUE; + errors = true; break; } if (errors) break; } // No args if (cmdp == 0 && DemodBufferLen == 0) - errors = TRUE; + errors = true; //Validations if (errors) return usage_lf_simpsk(); @@ -910,10 +910,10 @@ int CmdLFpskSim(const char *Cmd) { if (dataLen == 0){ //using DemodBuffer PrintAndLog("Getting Clocks"); - if (clk==0) clk = GetPskClock("", FALSE, FALSE); + if (clk==0) clk = GetPskClock("", false, false); PrintAndLog("clk: %d",clk); - if (!carrier) carrier = GetPskCarrier("", FALSE, FALSE); + if (!carrier) carrier = GetPskCarrier("", false, false); PrintAndLog("carrier: %d", carrier); } else { @@ -1232,9 +1232,9 @@ int CmdLFfind(const char *Cmd) { } } - ans=GetFskClock("",FALSE,FALSE); + ans=GetFskClock("",false,false); if (ans != 0){ //fsk - ans=FSKrawDemod("",TRUE); + ans=FSKrawDemod("",true); if (ans>0) { PrintAndLog("\nUnknown FSK Modulated Tag Found!"); return 1; diff --git a/client/cmdlf.h b/client/cmdlf.h index 8764c7fc2..0bd2f6dbd 100644 --- a/client/cmdlf.h +++ b/client/cmdlf.h @@ -12,6 +12,9 @@ #define CMDLF_H__ #include #include +#include +#include + #include #include #include "proxmark3.h" @@ -46,28 +49,29 @@ int CmdLF(const char *Cmd); -int CmdLFSetConfig(const char *Cmd); +extern int CmdLFSetConfig(const char *Cmd); + +extern int CmdLFCommandRead(const char *Cmd); +extern int CmdFlexdemod(const char *Cmd); +extern int CmdIndalaDemod(const char *Cmd); +extern int CmdIndalaClone(const char *Cmd); +extern int CmdLFRead(const char *Cmd); +extern int CmdLFSim(const char *Cmd); +extern int CmdLFaskSim(const char *Cmd); +extern int CmdLFfskSim(const char *Cmd); +extern int CmdLFpskSim(const char *Cmd); +extern int CmdLFSimBidir(const char *Cmd); +extern int CmdLFSnoop(const char *Cmd); +extern int CmdVchDemod(const char *Cmd); +extern int CmdLFfind(const char *Cmd); -int CmdLFCommandRead(const char *Cmd); -int CmdFlexdemod(const char *Cmd); -int CmdIndalaDemod(const char *Cmd); -int CmdIndalaClone(const char *Cmd); -int CmdLFRead(const char *Cmd); -int CmdLFSim(const char *Cmd); -int CmdLFaskSim(const char *Cmd); -int CmdLFfskSim(const char *Cmd); -int CmdLFpskSim(const char *Cmd); -int CmdLFSimBidir(const char *Cmd); -int CmdLFSnoop(const char *Cmd); -int CmdVchDemod(const char *Cmd); -int CmdLFfind(const char *Cmd); // usages helptext -int usage_lf_cmdread(void); -int usage_lf_read(void); -int usage_lf_snoop(void); -int usage_lf_config(void); -int usage_lf_simfsk(void); -int usage_lf_simask(void); -int usage_lf_simpsk(void); +extern int usage_lf_cmdread(void); +extern int usage_lf_read(void); +extern int usage_lf_snoop(void); +extern int usage_lf_config(void); +extern int usage_lf_simfsk(void); +extern int usage_lf_simask(void); +extern int usage_lf_simpsk(void); #endif diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 5b650b30d..8dcf6bee6 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -9,7 +9,7 @@ #include "cmdlft55xx.h" // Default configuration -t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE }; +t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = false, .offset = 0x00, .block0 = 0x00, .Q5 = false }; t55xx_conf_block_t Get_t55xx_Config(){ return config; @@ -188,7 +188,7 @@ int CmdT55xxSetConfig(const char *Cmd) { uint8_t bitRate = 0; uint8_t rates[9] = {8,16,32,40,50,64,100,128,0}; uint8_t cmdp = 0; - bool errors = FALSE; + bool errors = false; while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { tmp = param_getchar(Cmd, cmdp); @@ -207,7 +207,7 @@ int CmdT55xxSetConfig(const char *Cmd) { break; } } - if (i==9) errors = TRUE; + if (i==9) errors = true; } cmdp+=2; break; @@ -247,7 +247,7 @@ int CmdT55xxSetConfig(const char *Cmd) { config.inverted=0; } else { PrintAndLog("Unknown modulation '%s'", modulation); - errors = TRUE; + errors = true; } break; case 'i': @@ -262,17 +262,17 @@ int CmdT55xxSetConfig(const char *Cmd) { break; case 'Q': case 'q': - config.Q5 = TRUE; + config.Q5 = true; cmdp++; break; case 'S': case 's': - config.ST = TRUE; + config.ST = true; cmdp++; break; default: PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = TRUE; + errors = true; break; } } @@ -337,7 +337,7 @@ int CmdT55xxReadBlock(const char *Cmd) { break; case 'o': case 'O': - override = TRUE; + override = true; cmdp++; break; case 'p': @@ -379,28 +379,28 @@ bool DecodeT55xxBlock(){ switch( config.modulation ){ case DEMOD_FSK: snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted ); - ans = FSKrawDemod(cmdStr, FALSE); + ans = FSKrawDemod(cmdStr, false); break; case DEMOD_FSK1: case DEMOD_FSK1a: snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted ); - ans = FSKrawDemod(cmdStr, FALSE); + ans = FSKrawDemod(cmdStr, false); break; case DEMOD_FSK2: case DEMOD_FSK2a: snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted ); - ans = FSKrawDemod(cmdStr, FALSE); + ans = FSKrawDemod(cmdStr, false); break; case DEMOD_ASK: snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted ); - ans = ASKDemod_ext(cmdStr, FALSE, FALSE, 1, &ST); + ans = ASKDemod_ext(cmdStr, false, false, 1, &ST); break; case DEMOD_PSK1: // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) save_restoreGB(1); CmdLtrim("160"); snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted ); - ans = PSKDemod(cmdStr, FALSE); + ans = PSKDemod(cmdStr, false); //undo trim samples save_restoreGB(0); break; @@ -410,22 +410,22 @@ bool DecodeT55xxBlock(){ save_restoreGB(1); CmdLtrim("160"); snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] ); - ans = PSKDemod(cmdStr, FALSE); + ans = PSKDemod(cmdStr, false); psk1TOpsk2(DemodBuffer, DemodBufferLen); //undo trim samples save_restoreGB(0); break; case DEMOD_NRZ: snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted ); - ans = NRZrawDemod(cmdStr, FALSE); + ans = NRZrawDemod(cmdStr, false); break; case DEMOD_BI: case DEMOD_BIa: snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted ); - ans = ASKbiphaseDemod(cmdStr, FALSE); + ans = ASKbiphaseDemod(cmdStr, false); break; default: - return FALSE; + return false; } return (bool) ans; } @@ -434,7 +434,7 @@ bool DecodeT5555TraceBlock() { DemodBufferLen = 0x00; // According to datasheet. Always: RF/64, not inverted, Manchester - return (bool) ASKDemod("64 0 1", FALSE, FALSE, 1); + return (bool) ASKDemod("64 0 1", false, false, 1); } // sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf @@ -447,9 +447,9 @@ static int SanityOfflineCheck( bool useGraphBuffer ){ } int CmdT55xxDetect(const char *Cmd){ - bool errors = FALSE; - bool useGB = FALSE; - bool usepwd = FALSE; + bool errors = false; + bool useGB = false; + bool usepwd = false; uint32_t password = 0; uint8_t cmdp = 0; @@ -461,12 +461,12 @@ int CmdT55xxDetect(const char *Cmd){ case 'p': case 'P': password = param_get32ex(Cmd, cmdp+1, 0, 16); - usepwd = TRUE; + usepwd = true; cmdp += 2; break; case '1': // use Graphbuffer data - useGB = TRUE; + useGB = true; cmdp++; break; default: @@ -507,66 +507,66 @@ bool tryDetectModulation(){ else if (fc1==10 && fc2 == 8) tests[hits].modulation = DEMOD_FSK2; tests[hits].bitrate = bitRate; - tests[hits].inverted = FALSE; + tests[hits].inverted = false; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } - if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { + if ( FSKrawDemod("0 1", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_FSK; if (fc1 == 8 && fc2 == 5) tests[hits].modulation = DEMOD_FSK1; else if (fc1 == 10 && fc2 == 8) tests[hits].modulation = DEMOD_FSK2a; tests[hits].bitrate = bitRate; - tests[hits].inverted = TRUE; + tests[hits].inverted = true; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } } else { - clk = GetAskClock("", FALSE, FALSE); + clk = GetAskClock("", false, false); if (clk>0) { - tests[hits].ST = TRUE; + tests[hits].ST = true; // "0 0 1 " == clock auto, invert false, maxError 1. // false = no verbose // false = no emSearch // 1 = Ask/Man // st = true - if ( ASKDemod_ext("0 0 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { + if ( ASKDemod_ext("0 0 1", false, false, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_ASK; tests[hits].bitrate = bitRate; - tests[hits].inverted = FALSE; + tests[hits].inverted = false; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); ++hits; } - tests[hits].ST = TRUE; + tests[hits].ST = true; // "0 0 1 " == clock auto, invert true, maxError 1. // false = no verbose // false = no emSearch // 1 = Ask/Man // st = true - if ( ASKDemod_ext("0 1 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { + if ( ASKDemod_ext("0 1 1", false, false, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_ASK; tests[hits].bitrate = bitRate; - tests[hits].inverted = TRUE; + tests[hits].inverted = true; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); ++hits; } - if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) { + if ( ASKbiphaseDemod("0 0 0 2", false) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) { tests[hits].modulation = DEMOD_BI; tests[hits].bitrate = bitRate; - tests[hits].inverted = FALSE; + tests[hits].inverted = false; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } - if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) { + if ( ASKbiphaseDemod("0 0 1 2", false) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) { tests[hits].modulation = DEMOD_BIa; tests[hits].bitrate = bitRate; - tests[hits].inverted = TRUE; + tests[hits].inverted = true; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } } @@ -602,41 +602,41 @@ bool tryDetectModulation(){ if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_PSK1; tests[hits].bitrate = bitRate; - tests[hits].inverted = FALSE; + tests[hits].inverted = false; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } - if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { + if ( PSKDemod("0 1 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) { tests[hits].modulation = DEMOD_PSK1; tests[hits].bitrate = bitRate; - tests[hits].inverted = TRUE; + tests[hits].inverted = true; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } //ICEMAN: are these PSKDemod calls needed? // PSK2 - needs a call to psk1TOpsk2. - if ( PSKDemod("0 0 6", FALSE)) { + if ( PSKDemod("0 0 6", false)) { psk1TOpsk2(DemodBuffer, DemodBufferLen); if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){ tests[hits].modulation = DEMOD_PSK2; tests[hits].bitrate = bitRate; - tests[hits].inverted = FALSE; + tests[hits].inverted = false; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } } // inverse waves does not affect this demod // PSK3 - needs a call to psk1TOpsk2. - if ( PSKDemod("0 0 6", FALSE)) { + if ( PSKDemod("0 0 6", false)) { psk1TOpsk2(DemodBuffer, DemodBufferLen); if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){ tests[hits].modulation = DEMOD_PSK3; tests[hits].bitrate = bitRate; - tests[hits].inverted = FALSE; + tests[hits].inverted = false; tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer); - tests[hits].ST = FALSE; + tests[hits].ST = false; ++hits; } } // inverse waves does not affect this demod @@ -653,10 +653,10 @@ bool tryDetectModulation(){ config.Q5 = tests[0].Q5; config.ST = tests[0].ST; printConfiguration( config ); - return TRUE; + return true; } - bool retval = FALSE; + bool retval = false; if ( hits > 1) { PrintAndLog("Found [%d] possible matches for modulation.",hits); for(int i=0; i= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE; + if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return true; break; case DEMOD_ASK: - if (modread == DEMOD_ASK) return TRUE; + if (modread == DEMOD_ASK) return true; break; case DEMOD_PSK1: - if (modread == DEMOD_PSK1) return TRUE; + if (modread == DEMOD_PSK1) return true; break; case DEMOD_PSK2: - if (modread == DEMOD_PSK2) return TRUE; + if (modread == DEMOD_PSK2) return true; break; case DEMOD_PSK3: - if (modread == DEMOD_PSK3) return TRUE; + if (modread == DEMOD_PSK3) return true; break; case DEMOD_NRZ: - if (modread == DEMOD_NRZ) return TRUE; + if (modread == DEMOD_NRZ) return true; break; case DEMOD_BI: - if (modread == DEMOD_BI) return TRUE; + if (modread == DEMOD_BI) return true; break; case DEMOD_BIa: - if (modread == DEMOD_BIa) return TRUE; + if (modread == DEMOD_BIa) return true; break; default: - return FALSE; + return false; } - return FALSE; + return false; } bool testQ5Modulation(uint8_t mode, uint8_t modread){ switch( mode ){ case DEMOD_FSK: - if (modread >= 4 && modread <= 5) return TRUE; + if (modread >= 4 && modread <= 5) return true; break; case DEMOD_ASK: - if (modread == 0) return TRUE; + if (modread == 0) return true; break; case DEMOD_PSK1: - if (modread == 1) return TRUE; + if (modread == 1) return true; break; case DEMOD_PSK2: - if (modread == 2) return TRUE; + if (modread == 2) return true; break; case DEMOD_PSK3: - if (modread == 3) return TRUE; + if (modread == 3) return true; break; case DEMOD_NRZ: - if (modread == 7) return TRUE; + if (modread == 7) return true; break; case DEMOD_BI: - if (modread == 6) return TRUE; + if (modread == 6) return true; break; default: - return FALSE; + return false; } - return FALSE; + return false; } int convertQ5bitRate(uint8_t bitRateRead) { @@ -771,7 +771,7 @@ int convertQ5bitRate(uint8_t bitRateRead) { bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){ - if ( DemodBufferLen < 64 ) return FALSE; + if ( DemodBufferLen < 64 ) return false; uint8_t si = 0; for (uint8_t idx = 28; idx < 64; idx++){ si = idx; @@ -804,9 +804,9 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){ if (*fndBitRate < 0) continue; *offset = idx; - return TRUE; + return true; } - return FALSE; + return false; } bool testBitRate(uint8_t readRate, uint8_t clk){ @@ -819,7 +819,7 @@ bool testBitRate(uint8_t readRate, uint8_t clk){ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){ - if ( DemodBufferLen < 64 ) return FALSE; + if ( DemodBufferLen < 64 ) return false; uint8_t si = 0; for (uint8_t idx = 28; idx < 64; idx++){ si = idx; @@ -841,7 +841,7 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5) //uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2; //if extended mode - bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE; + bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? true : false; if (!extMode){ if (xtRate) continue; //nml01 || nml02 || caused issues on noralys tags @@ -851,14 +851,14 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5) if (!testBitRate(bitRate, clk)) continue; *fndBitRate = bitRate; *offset = idx; - *Q5 = FALSE; - return TRUE; + *Q5 = false; + return true; } if (testQ5(mode, offset, fndBitRate, clk)) { - *Q5 = TRUE; - return TRUE; + *Q5 = true; + return true; } - return FALSE; + return false; } void printT55xxBlock(const char *blockNum){ @@ -953,6 +953,7 @@ int CmdT55xxWriteBlock(const char *Cmd) { bool usepwd = false; bool page1 = false; bool gotdata = false; + bool testMode = false; bool errors = false; uint8_t cmdp = 0; while(param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -1025,7 +1026,7 @@ int CmdT55xxReadTrace(const char *Cmd) { if (strlen(Cmd)==0) { // sanity check. - if (!SanityOfflineCheck(FALSE)) return 1; + if (!SanityOfflineCheck(false)) return 1; if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) ) return 1; @@ -1192,7 +1193,7 @@ int CmdT55xxInfo(const char *Cmd){ if (strlen(Cmd)==0){ // sanity check. - if (!SanityOfflineCheck(FALSE)) return 1; + if (!SanityOfflineCheck(false)) return 1; if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) ) return 1; @@ -1424,7 +1425,7 @@ int CmdResetRead(const char *Cmd) { setGraphBuf(got, sizeof(got)); return 1; } -// ADD T5555 (Q5) Default config block + int CmdT55xxWipe(const char *Cmd) { char writeData[20] = {0}; char *ptrData = writeData; @@ -1460,9 +1461,9 @@ bool IsCancelled(void) { int ch = getchar(); (void)ch; printf("\naborted via keyboard!\n"); - return TRUE; + return true; } - return FALSE; + return false; } int CmdT55xxBruteForce(const char *Cmd) { @@ -1564,8 +1565,8 @@ int CmdT55xxBruteForce(const char *Cmd) { PrintAndLog("Testing %08X", testpwd); - if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) { - PrintAndLog("Acquire data from device failed. Quitting"); + if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, testpwd)) { + PrintAndLog("Aquireing data from device failed. Quitting"); free(keyBlock); return 0; } @@ -1607,8 +1608,8 @@ int CmdT55xxBruteForce(const char *Cmd) { return 0; } - if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) { - PrintAndLog("Acquire data from device failed. Quitting"); + if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, i)) { + PrintAndLog("Aquireing data from device failed. Quitting"); free(keyBlock); return 0; } @@ -1631,7 +1632,7 @@ int CmdT55xxBruteForce(const char *Cmd) { int tryOnePassword(uint32_t password) { PrintAndLog("Trying password %08x", password); - if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, password)) { + if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, password)) { PrintAndLog("Acquire data from device failed. Quitting"); return -1; } diff --git a/client/cmdlft55xx.h b/client/cmdlft55xx.h index 131cc8822..301a814ef 100644 --- a/client/cmdlft55xx.h +++ b/client/cmdlft55xx.h @@ -126,16 +126,16 @@ typedef struct { t55xx_conf_block_t Get_t55xx_Config(); void Set_t55xx_Config(t55xx_conf_block_t conf); -int CmdLFT55XX(const char *Cmd); -int CmdT55xxSetConfig(const char *Cmd); -int CmdT55xxReadBlock(const char *Cmd); -int CmdT55xxWriteBlock(const char *Cmd); -int CmdT55xxReadTrace(const char *Cmd); -int CmdT55xxInfo(const char *Cmd); -int CmdT55xxDetect(const char *Cmd); -int CmdResetRead(const char *Cmd); -int CmdT55xxWipe(const char *Cmd); -int CmdT55xxBruteForce(const char *Cmd); +extern int CmdLFT55XX(const char *Cmd); +extern int CmdT55xxSetConfig(const char *Cmd); +extern int CmdT55xxReadBlock(const char *Cmd); +extern int CmdT55xxWriteBlock(const char *Cmd); +extern int CmdT55xxReadTrace(const char *Cmd); +extern int CmdT55xxInfo(const char *Cmd); +extern int CmdT55xxDetect(const char *Cmd); +extern int CmdResetRead(const char *Cmd); +extern int CmdT55xxWipe(const char *Cmd); +extern int CmdT55xxBruteForce(const char *Cmd); char * GetBitRateStr(uint32_t id); char * GetSaferStr(uint32_t id); @@ -147,8 +147,8 @@ void printT5xxHeader(uint8_t page); void printT55xxBlock(const char *demodStr); int printConfiguration( t55xx_conf_block_t b); -bool DecodeT55xxBlock(); -bool tryDetectModulation(); +bool DecodeT55xxBlock(void); +bool tryDetectModulation(void); bool testKnownConfigBlock(uint32_t block0); bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5); int special(const char *Cmd); diff --git a/client/cmdmain.c b/client/cmdmain.c index 374f8166b..058fc3ee7 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -208,8 +208,11 @@ void UsbCommandReceived(UsbCommand *UC) // arg0 = offset in transfer. Startindex of this chunk // arg1 = length bytes to transfer // arg2 = bigbuff tracelength (?) - memcpy( sample_buf + (UC->arg[0]), UC->d.asBytes, UC->arg[1]); - //printf("DBG:: Download from device. chunk %" PRIu64 " | size %" PRIu64 " | tracelen:%" PRIu64 " \n", UC->arg[0], UC->arg[1], UC->arg[2]); + uint32_t offset = UC->arg[0]; + uint32_t len = UC->arg[1]; + //uint32_t tracelen = UC->arg[2]; + memcpy( sample_buf + offset, UC->d.asBytes, len); + //printf("ICE:: Download from device. chunk %" PRIu32 " | size %" PRIu32 " | tracelen:%" PRIu32 " \n", offset, len, UC->arg[2]); break; } default: { diff --git a/client/cmdmain.h b/client/cmdmain.h index 9cb3e95d3..6c11f6429 100644 --- a/client/cmdmain.h +++ b/client/cmdmain.h @@ -11,14 +11,16 @@ #ifndef CMDMAIN_H__ #define CMDMAIN_H__ +#include +#include #include "usb_cmd.h" #include "cmdparser.h" -void UsbCommandReceived(UsbCommand *UC); -int CommandReceived(char *Cmd); -bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout); -bool WaitForResponse(uint32_t cmd, UsbCommand* response); -void clearCommandBuffer(); -command_t* getTopLevelCommandTable(); +extern void UsbCommandReceived(UsbCommand *UC); +extern int CommandReceived(char *Cmd); +extern bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout); +extern bool WaitForResponse(uint32_t cmd, UsbCommand* response); +extern void clearCommandBuffer(); +extern command_t* getTopLevelCommandTable(); //For storing command that are received from the device #define CMD_BUFFER_SIZE 50 diff --git a/client/mifarehost.c b/client/mifarehost.c index f0537a442..c26fb0d27 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -192,10 +192,8 @@ out: } int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){ -#define STD_SEARCH 1 -#define EXT_SEARCH 2 *key = 0; - UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType << 8)), ((EXT_SEARCH << 8) | clear_trace), keycnt}}; + UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType << 8)), clear_trace, keycnt}}; memcpy(c.d.asBytes, keyBlock, 6 * keycnt); clearCommandBuffer(); SendCommand(&c); @@ -336,7 +334,7 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) { clearCommandBuffer(); SendCommand(&c); UsbCommand resp; - if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { + if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { isOK = resp.arg[0] & 0xff; memcpy(data, resp.d.asBytes, 16); if (!isOK) return 2; diff --git a/client/proxmark3.h b/client/proxmark3.h index 6874f9d8e..389d234f7 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -28,9 +28,16 @@ #include "usb_cmd.h" #define PROXPROMPT "pm3 --> " +#ifdef __cplusplus +extern "C" { +#endif void SendCommand(UsbCommand *c); const char *get_my_executable_path(void); const char *get_my_executable_directory(void); -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif diff --git a/client/scripting.c b/client/scripting.c index 013eba716..2f707ddd5 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -82,11 +82,9 @@ static int l_WaitForResponseTimeout(lua_State *L){ } UsbCommand response; - if(WaitForResponseTimeout(cmd, &response, ms_timeout)) - { + if(WaitForResponseTimeout(cmd, &response, ms_timeout)) { //Push it as a string lua_pushlstring(L,(const char *)&response, sizeof(UsbCommand)); - return 1;// return 1 to signal one return value }else{ //Push a Nil instead @@ -177,7 +175,6 @@ static int l_foobar(lua_State *L) num_to_bytes(x,sizeof(x),destination); lua_pushlstring(L,(const char *)&x,sizeof(x)); lua_pushlstring(L,(const char *)destination,sizeof(destination)); - return 2; } @@ -484,7 +481,7 @@ static int l_hardnested(lua_State *L){ const char *p_trgkey = luaL_checklstring(L, 6, &size); if(size != 12) - haveTarget = FALSE; + haveTarget = false; const char *p_nonce_file_read = luaL_checklstring(L, 7, &size); if(size != 1) return returnToLuaWithError(L,"Wrong size of nonce_file_read, got %d bytes, expected 1", (int) size); @@ -544,8 +541,7 @@ static int l_hardnested(lua_State *L){ * @param path * @return */ -int setLuaPath( lua_State* L, const char* path ) -{ +int setLuaPath( lua_State* L, const char* path ) { lua_getglobal( L, "package" ); lua_getfield( L, -1, "path" ); // get field "path" from table at top of stack (-1) const char* cur_path = lua_tostring( L, -1 ); // grab path string from top of stack @@ -560,8 +556,7 @@ int setLuaPath( lua_State* L, const char* path ) return 0; // all done! } -int set_pm3_libraries(lua_State *L) -{ +int set_pm3_libraries(lua_State *L) { static const luaL_Reg libs[] = { {"SendCommand", l_SendCommand}, {"WaitForResponseTimeout", l_WaitForResponseTimeout}, diff --git a/client/util.c b/client/util.c index 5485488c9..93e368de4 100644 --- a/client/util.c +++ b/client/util.c @@ -19,18 +19,18 @@ int ukbhit(void) { int error; static struct termios Otty, Ntty; - if ( tcgetattr( 0, &Otty) == -1) return -1; + if ( tcgetattr(STDIN_FILENO, &Otty) == -1) return -1; + Ntty = Otty; + Ntty.c_iflag = 0x000; // input mode + Ntty.c_oflag = 0x000; // output mode + Ntty.c_lflag &= ~ICANON; // control mode = raw + Ntty.c_cc[VMIN] = 1; // return if at least 1 character is in the queue + Ntty.c_cc[VTIME] = 0; // no timeout. Wait forever - Ntty.c_iflag = 0; /* input mode */ - Ntty.c_oflag = 0; /* output mode */ - Ntty.c_lflag &= ~ICANON; /* raw mode */ - Ntty.c_cc[VMIN] = CMIN; /* minimum time to wait */ - Ntty.c_cc[VTIME] = CTIME; /* minimum characters to wait for */ - - if (0 == (error = tcsetattr(0, TCSANOW, &Ntty))) { - error += ioctl(0, FIONREAD, &cnt); - error += tcsetattr(0, TCSANOW, &Otty); + if (0 == (error = tcsetattr(STDIN_FILENO, TCSANOW, &Ntty))) { // set new attributes + error += ioctl(STDIN_FILENO, FIONREAD, &cnt); // get number of characters available + error += tcsetattr(STDIN_FILENO, TCSANOW, &Otty); // reset attributes } return ( error == 0 ? cnt : -1 ); diff --git a/client/util.h b/client/util.h index 84d1a3163..580bd85a6 100644 --- a/client/util.h +++ b/client/util.h @@ -26,6 +26,7 @@ #include #include #include + #include #else #include #include diff --git a/client/whereami.c b/client/whereami.c index a85318895..7cb045a6c 100644 --- a/client/whereami.c +++ b/client/whereami.c @@ -140,8 +140,9 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length); } -/* -WAI_NOINLINE +// GetModuleHandleEx() is not available on old mingw environments. We don't need getModulePath() yet. +// Sacrifice it for the time being to improve backwards compatibility +/* WAI_NOINLINE WAI_FUNCSPEC int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) { @@ -165,6 +166,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) */ #elif defined(__linux__) + #include #include #include @@ -257,7 +259,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) if (!fgets(buffer, sizeof(buffer), maps)) break; - if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) + if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) { uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS(); if (low <= addr && addr <= high)