Adds colors, etc

This commit is contained in:
iceman1001 2019-03-09 11:29:34 +01:00
parent dc36bd5e5a
commit e093d1ab29

View file

@ -252,7 +252,7 @@ void printEM410x(uint32_t hi, uint64_t id) {
if (!id && !hi) return; if (!id && !hi) return;
PrintAndLogEx(NORMAL, "EM410x %s pattern found", (hi) ? "XL" : "" ); PrintAndLogEx(SUCCESS, "EM410x %s pattern found", (hi) ? "XL" : "" );
uint64_t iii=1; uint64_t iii=1;
uint64_t id2lo=0; uint64_t id2lo=0;
@ -549,7 +549,7 @@ int CmdEM410xBrute(const char *Cmd) {
if (ukbhit()) { if (ukbhit()) {
int gc = getchar(); (void)gc; int gc = getchar(); (void)gc;
PrintAndLogEx(NORMAL, "\nAborted via keyboard!\n"); PrintAndLogEx(WARNING, "\nAborted via keyboard!\n");
free(uidBlock); free(uidBlock);
return 0; return 0;
} }
@ -583,7 +583,7 @@ int CmdEM410xWatch(const char *Cmd) {
do { do {
if (ukbhit()) { if (ukbhit()) {
int gc = getchar(); (void)gc; int gc = getchar(); (void)gc;
PrintAndLogEx(NORMAL, "\naborted via keyboard!\n"); PrintAndLogEx(WARNING, "\naborted via keyboard!\n");
break; break;
} }
lf_read(true, 8201); lf_read(true, 8201);
@ -606,8 +606,8 @@ int CmdEM410xWatchnSpoof(const char *Cmd) {
} }
int CmdEM410xWrite(const char *Cmd) { int CmdEM410xWrite(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0); char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h' || cmdp == 'H') return usage_lf_em410x_write(); if (cmdp == 'h') return usage_lf_em410x_write();
uint64_t id = 0xFFFFFFFFFFFFFFFF; // invalid id value uint64_t id = 0xFFFFFFFFFFFFFFFF; // invalid id value
int card = 0xFF; // invalid card value int card = 0xFF; // invalid card value
@ -666,26 +666,27 @@ int CmdEM410xWrite(const char *Cmd) {
} }
//**************** Start of EM4x50 Code ************************ //**************** Start of EM4x50 Code ************************
bool EM_EndParityTest(uint8_t *BitStream, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) { bool EM_EndParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) {
if (rows*cols>size) return false; if (rows * cols > size) return false;
uint8_t colP=0; uint8_t colP = 0;
//assume last col is a parity and do not test //assume last col is a parity and do not test
for (uint8_t colNum = 0; colNum < cols-1; colNum++) { for (uint8_t colNum = 0; colNum < cols-1; colNum++) {
for (uint8_t rowNum = 0; rowNum < rows; rowNum++) { for (uint8_t rowNum = 0; rowNum < rows; rowNum++) {
colP ^= BitStream[(rowNum*cols)+colNum]; colP ^= bs[(rowNum * cols) + colNum];
} }
if (colP != pType) return false; if (colP != pType) return false;
} }
return true; return true;
} }
bool EM_ByteParityTest(uint8_t *BitStream, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) { bool EM_ByteParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) {
if (rows*cols>size) return false; if (rows * cols > size) return false;
uint8_t rowP=0;
uint8_t rowP = 0;
//assume last row is a parity row and do not test //assume last row is a parity row and do not test
for (uint8_t rowNum = 0; rowNum < rows-1; rowNum++) { for (uint8_t rowNum = 0; rowNum < rows-1; rowNum++) {
for (uint8_t colNum = 0; colNum < cols; colNum++) { for (uint8_t colNum = 0; colNum < cols; colNum++) {
rowP ^= BitStream[(rowNum*cols)+colNum]; rowP ^= bs[(rowNum * cols) + colNum];
} }
if (rowP != pType) return false; if (rowP != pType) return false;
} }
@ -755,10 +756,8 @@ uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool
bytebits_to_byte(BitStream+i*9,8) bytebits_to_byte(BitStream+i*9,8)
); );
} }
if (pTest)
PrintAndLogEx(NORMAL, "Parity Passed"); PrintAndLogEx(SUCCESS, "Parity checks | %s", (pTest)? _GREEN_(Passed) : _RED_(Failed));
else
PrintAndLogEx(NORMAL, "Parity Failed");
} }
return code; return code;
} }
@ -949,7 +948,7 @@ int EM4x50Read(const char *Cmd, bool verbose) {
//print full code: //print full code:
if (verbose || g_debugMode || AllPTest){ if (verbose || g_debugMode || AllPTest){
if (!complete) { if (!complete) {
PrintAndLogEx(NORMAL, "*** Warning!"); PrintAndLogEx(NORMAL, _RED_(*** Warning!) );
PrintAndLogEx(NORMAL, "Partial data - no end found!"); PrintAndLogEx(NORMAL, "Partial data - no end found!");
PrintAndLogEx(NORMAL, "Try again with more samples."); PrintAndLogEx(NORMAL, "Try again with more samples.");
} }
@ -958,11 +957,11 @@ int EM4x50Read(const char *Cmd, bool verbose) {
for (block=0; block < end; block++){ for (block=0; block < end; block++){
PrintAndLogEx(NORMAL, "Block %d: %08x", block, Code[block]); PrintAndLogEx(NORMAL, "Block %d: %08x", block, Code[block]);
} }
if (AllPTest) {
PrintAndLogEx(NORMAL, "Parities Passed"); PrintAndLogEx(NORMAL, "Parities checks | %s", (AllPTest) ? _GREEN_(Passed) : _RED_(Failed) );
} else {
PrintAndLogEx(NORMAL, "Parities Failed"); if (AllPTest == 0) {
PrintAndLogEx(NORMAL, "Try cleaning the read samples with 'data askedge'"); PrintAndLogEx(NORMAL, "Try cleaning the read samples with " _YELLOW_('data askedge') );
} }
} }
@ -1005,7 +1004,7 @@ bool downloadSamplesEM(){
computeSignalProperties(got, sizeof(got)); computeSignalProperties(got, sizeof(got));
RepaintGraphWindow(); RepaintGraphWindow();
if (getSignalProperties()->isnoise) { if (getSignalProperties()->isnoise) {
PrintAndLogEx(DEBUG, "No tag found"); PrintAndLogEx(DEBUG, "No tag found - signal looks like noise");
return false; return false;
} }
return true; return true;
@ -1148,7 +1147,7 @@ int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t *word)
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)){ if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)){
PrintAndLogEx(DEBUG, "Command timed out"); PrintAndLogEx(DEBUG, "timeout while waiting for reply.");
return -1; return -1;
} }
if ( !downloadSamplesEM() ) { if ( !downloadSamplesEM() ) {
@ -1162,8 +1161,8 @@ int CmdEM4x05Dump(const char *Cmd) {
uint8_t addr = 0; uint8_t addr = 0;
uint32_t pwd = 0; uint32_t pwd = 0;
bool usePwd = false; bool usePwd = false;
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if ( ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x05_dump(); if ( ctmp == 'h' ) return usage_lf_em4x05_dump();
// for now use default input of 1 as invalid (unlikely 1 will be a valid password...) // for now use default input of 1 as invalid (unlikely 1 will be a valid password...)
pwd = param_get32ex(Cmd, 0, 1, 16); pwd = param_get32ex(Cmd, 0, 1, 16);
@ -1181,7 +1180,7 @@ int CmdEM4x05Dump(const char *Cmd) {
if (usePwd) { if (usePwd) {
PrintAndLogEx(NORMAL, " %02u | %08X", addr, pwd, word ); PrintAndLogEx(NORMAL, " %02u | %08X", addr, pwd, word );
} else { } else {
PrintAndLogEx(NORMAL, " 02 | cannot read"); PrintAndLogEx(NORMAL, " 02 | " _RED_(cannot read) );
} }
} else { } else {
success &= EM4x05ReadWord_ext(addr, pwd, usePwd, &word); success &= EM4x05ReadWord_ext(addr, pwd, usePwd, &word);
@ -1195,8 +1194,8 @@ int CmdEM4x05Read(const char *Cmd) {
uint8_t addr; uint8_t addr;
uint32_t pwd; uint32_t pwd;
bool usePwd = false; bool usePwd = false;
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if ( strlen(Cmd) == 0 || ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x05_read(); if ( strlen(Cmd) == 0 || ctmp == 'h' ) return usage_lf_em4x05_read();
addr = param_get8ex(Cmd, 0, 50, 10); addr = param_get8ex(Cmd, 0, 50, 10);
pwd = param_get32ex(Cmd, 1, 1, 16); pwd = param_get32ex(Cmd, 1, 1, 16);
@ -1217,13 +1216,13 @@ int CmdEM4x05Read(const char *Cmd) {
if (isOk) if (isOk)
PrintAndLogEx(NORMAL, "Address %02d | %08X - %s", addr, word, (addr > 13) ? "Lock" : ""); PrintAndLogEx(NORMAL, "Address %02d | %08X - %s", addr, word, (addr > 13) ? "Lock" : "");
else else
PrintAndLogEx(NORMAL, "Read Address %02d | failed",addr); PrintAndLogEx(NORMAL, "Read Address %02d | " _RED_(failed), addr);
return isOk; return isOk;
} }
int CmdEM4x05Write(const char *Cmd) { int CmdEM4x05Write(const char *Cmd) {
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if ( strlen(Cmd) == 0 || ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x05_write(); if ( strlen(Cmd) == 0 || ctmp == 'h' ) return usage_lf_em4x05_write();
bool usePwd = false; bool usePwd = false;
uint8_t addr = 50; // default to invalid address uint8_t addr = 50; // default to invalid address
@ -1263,9 +1262,9 @@ int CmdEM4x05Write(const char *Cmd) {
uint32_t dummy = 0; uint32_t dummy = 0;
int isOk = demodEM4x05resp(&dummy); int isOk = demodEM4x05resp(&dummy);
if (isOk) if (isOk)
PrintAndLogEx(NORMAL, "Write Verified"); PrintAndLogEx(NORMAL, "Write " _GREEN_(Verified) );
else else
PrintAndLogEx(NORMAL, "Write could not be verified"); PrintAndLogEx(NORMAL, "Write could " _RED_(not) "be verified");
return isOk; return isOk;
} }
@ -1385,8 +1384,8 @@ int CmdEM4x05Info(const char *Cmd) {
uint32_t pwd; uint32_t pwd;
uint32_t word = 0, block0 = 0, serial = 0; uint32_t word = 0, block0 = 0, serial = 0;
bool usePwd = false; bool usePwd = false;
uint8_t ctmp = param_getchar(Cmd, 0); uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if ( ctmp == 'H' || ctmp == 'h' ) return usage_lf_em4x05_info(); if ( ctmp == 'h' ) return usage_lf_em4x05_info();
// for now use default input of 1 as invalid (unlikely 1 will be a valid password...) // for now use default input of 1 as invalid (unlikely 1 will be a valid password...)
pwd = param_get32ex(Cmd, 0, 1, 16); pwd = param_get32ex(Cmd, 0, 1, 16);