chg: printandlogex now deals with string which has inital newline char.

This commit is contained in:
iceman1001 2018-04-27 11:22:30 +02:00
commit c41013d394
12 changed files with 53 additions and 46 deletions

View file

@ -435,14 +435,14 @@ int CmdrevengSearch(const char *Cmd){
if (ans) {
// test for match
if (memcmp(result, inCRC, crcChars) == 0){
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "found possible match\nmodel: %s | value: %s\n", Models[i], result);
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel: %s | value: %s\n", Models[i], result);
//optional - stop searching if found...
found = true;
} else {
if (crcChars > 2){
char *swapEndian = SwapEndianStr(result, crcChars, crcChars);
if (memcmp(swapEndian, inCRC, crcChars) == 0){
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "found possible match\nmodel: %s | value endian swapped: %s\n", Models[i], swapEndian);
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel: %s | value endian swapped: %s\n", Models[i], swapEndian);
// optional - stop searching if found...
found = true;
}
@ -454,14 +454,14 @@ int CmdrevengSearch(const char *Cmd){
if (ans) {
// test for match
if (memcmp(revResult, inCRC, crcChars) == 0){
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "found possible match\nmodel reversed: %s | value: %s\n", Models[i], revResult);
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel reversed: %s | value: %s\n", Models[i], revResult);
// optional - stop searching if found...
found = true;
} else {
if (crcChars > 2){
char *swapEndian = SwapEndianStr(revResult, crcChars, crcChars);
if (memcmp(swapEndian, inCRC, crcChars) == 0){
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "found possible match\nmodel reversed: %s | value endian swapped: %s\n", Models[i], swapEndian);
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel reversed: %s | value endian swapped: %s\n", Models[i], swapEndian);
// optional - stop searching if found...
found = true;
}

View file

@ -1416,7 +1416,7 @@ int getSamples(int n, bool silent) {
UsbCommand response;
if ( !WaitForResponseTimeout(CMD_ACK, &response, 10000) ) {
PrintAndLogEx(NORMAL, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return 1;
}
@ -1472,7 +1472,7 @@ int CmdTuneSamples(const char *Cmd) {
#define HF_MARGINAL_V 5000
#define ANTENNA_ERROR 1.03 // current algo has 3% error margin.
int timeout = 0;
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "measuring antenna characteristics, please wait...");
PrintAndLogEx(INFO, "\nmeasuring antenna characteristics, please wait...");
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING, {0,0,0}};
clearCommandBuffer();
@ -1482,7 +1482,7 @@ int CmdTuneSamples(const char *Cmd) {
timeout++;
printf("."); fflush(stdout);
if (timeout > 7) {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "no response from Proxmark. Aborting...");
PrintAndLogEx(WARNING, "\nno response from Proxmark. Aborting...");
return 1;
}
}

View file

@ -1002,7 +1002,7 @@ static int waitCmd(uint8_t iSelect) {
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.d.asBytes, len) );
} else {
PrintAndLogEx(NORMAL, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return 3;
}
return 0;

View file

@ -553,7 +553,7 @@ bool HF14B_Other_Reader(){
// WaitForResponse(CMD_ACK,&resp);
// if (datalen > 2 ) {
// PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "14443-3b tag found:");
// PrintAndLogEx(NORMAL, "\n14443-3b tag found:");
// PrintAndLogEx(NORMAL, "unknown tag type answered to a 0x000b3f80 command ans:");
// //PrintAndLogEx(NORMAL, "%s", sprint_hex(data, datalen));
// rawclose();
@ -568,7 +568,7 @@ bool HF14B_Other_Reader(){
// WaitForResponse(CMD_ACK, &resp);
// if (datalen > 0) {
// PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "14443-3b tag found:");
// PrintAndLogEx(NORMAL, "\n14443-3b tag found:");
// PrintAndLogEx(NORMAL, "Unknown tag type answered to a 0x0A command ans:");
// // PrintAndLogEx(NORMAL, "%s", sprint_hex(data, datalen));
// rawClose();
@ -583,7 +583,7 @@ bool HF14B_Other_Reader(){
// WaitForResponse(CMD_ACK, &resp);
// if (datalen > 0) {
// PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "14443-3b tag found:");
// PrintAndLogEx(NORMAL, "\n14443-3b tag found:");
// PrintAndLogEx(NORMAL, "Unknown tag type answered to a 0x0C command ans:");
// PrintAndLogEx(NORMAL, "%s", sprint_hex(data, datalen));
// rawClose();

View file

@ -220,7 +220,7 @@ int getUID(uint8_t *buf) {
} // retry
if ( retry >= 3 )
PrintAndLogEx(FAILED, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return 0;
}
@ -956,7 +956,7 @@ int CmdHF15Raw(const char *Cmd) {
PrintAndLogEx(NORMAL, "received %i octets", len);
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.d.asBytes, len) );
} else {
PrintAndLogEx(FAILED, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
}
}
return 0;

View file

@ -377,7 +377,7 @@ int CmdHFFelicaDumpLite(const char *Cmd) {
}
}
if (resp.arg[0] == 0) {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "Button pressed. Aborted.");
PrintAndLogEx(WARNING, "\nButton pressed. Aborted.");
return 1;
}

View file

@ -386,11 +386,11 @@ int CmdHFiClassSim(const char *Cmd) {
tries++;
if (ukbhit()) {
int gc = getchar(); (void)gc;
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "aborted via keyboard.");
PrintAndLogEx(WARNING, "\naborted via keyboard.");
return 0;
}
if ( tries > 20) {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "\ntimeout while waiting for reply.");
return 0;
}
}
@ -438,11 +438,11 @@ int CmdHFiClassSim(const char *Cmd) {
tries++;
if (ukbhit()) {
int gc = getchar(); (void)gc;
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "aborted via keyboard.");
PrintAndLogEx(WARNING, "\naborted via keyboard.");
return 0;
}
if ( tries > 20) {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "\ntimeout while waiting for reply.");
return 0;
}
}
@ -924,11 +924,11 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(CreditKEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit KeyNbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Credit Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -958,11 +958,11 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(KEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit KeyNbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Credit Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1219,11 +1219,11 @@ int CmdHFiClass_WriteBlock(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(KEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit KeyNbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Credit Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1308,11 +1308,11 @@ int CmdHFiClassCloneTag(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(KEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit KeyNbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Credit Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1493,11 +1493,11 @@ int CmdHFiClass_ReadBlock(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(KEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit KeyNbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Credit Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1709,11 +1709,11 @@ int CmdHFiClassCalcNewKey(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(NEWKEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: NewKey Nbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: NewKey Nbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: NewKey is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: NewKey is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1728,11 +1728,11 @@ int CmdHFiClassCalcNewKey(const char *Cmd) {
if (keyNbr < ICLASS_KEYS_MAX) {
memcpy(OLDKEY, iClass_Key_Table[keyNbr], 8);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit KeyNbr is invalid\n");
PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n");
errors = true;
}
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Credit Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Credit Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1861,7 +1861,7 @@ int CmdHFiClassManageKeys(const char *Cmd) {
if (dataLen == 16) { //ul-c or ev1/ntag key length
errors = param_gethex(tempStr, 0, KEY, dataLen);
} else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "ERROR: Key is incorrect length\n");
PrintAndLogEx(WARNING, "\nERROR: Key is incorrect length\n");
errors = true;
}
cmdp += 2;
@ -1979,7 +1979,7 @@ int CmdHFiClassCheckKeys(const char *Cmd) {
if (select_only(CSN, CCNR, false, false)) {
got_csn = true;
} else {
PrintAndLogEx(NORMAL, "[-] one more try\n");
PrintAndLogEx(WARNING, "one more try\n");
}
}
@ -2045,7 +2045,7 @@ int CmdHFiClassCheckKeys(const char *Cmd) {
timeout++;
printf("."); fflush(stdout);
if (timeout > 120) {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(WARNING, "no response from Proxmark. Aborting...");
PrintAndLogEx(WARNING, "\nno response from Proxmark. Aborting...");
goto out;
}
}
@ -2087,7 +2087,7 @@ int CmdHFiClassCheckKeys(const char *Cmd) {
out:
t1 = msclock() - t1;
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "Time in iclass checkkeys: %.0f seconds\n", (float)t1/1000.0);
PrintAndLogEx(SUCCESS, "\nTime in iclass checkkeys: %.0f seconds\n", (float)t1/1000.0);
DropField();
free(pre);
@ -2245,7 +2245,7 @@ int CmdHFiClassLookUp(const char *Cmd) {
// using find
item = (iclass_prekey_t*) bsearch(&lookup, prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32);
if( item != NULL ) {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "[debit] found key %s", sprint_hex(item->key, 8));
PrintAndLogEx(SUCCESS, "\n[debit] found key %s", sprint_hex(item->key, 8));
}
t1 = msclock() - t1;

View file

@ -251,7 +251,7 @@ int CmdLFHitagReader(const char *Cmd) {
SendCommand(&c);
UsbCommand resp;
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 4000) ) {
PrintAndLogEx(NORMAL, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return 1;
}

View file

@ -208,7 +208,7 @@ void UsbCommandReceived(UsbCommand* _ch) {
char s[USB_CMD_DATA_SIZE+1];
memset(s, 0x00, sizeof(s));
size_t len = MIN(c->arg[0],USB_CMD_DATA_SIZE);
size_t len = MIN(c->arg[0], USB_CMD_DATA_SIZE);
memcpy(s, c->d.asBytes, len);
// print debug line on same row. escape seq \r
@ -233,11 +233,10 @@ void UsbCommandReceived(UsbCommand* _ch) {
// arg1 = length bytes to transfer
// arg2 = bigbuff tracelength (?)
uint32_t offset = c->arg[0];
uint32_t len = c->arg[1];
uint32_t len = MIN(c->arg[1], sample_buf_size);
//uint32_t tracelen = c->arg[2];
// extra bounds check.
len = MIN(sample_buf_size, len);
printf("SAMPLE_BUF_SIZE %u | adjusted len %u \n", sample_buf_size, len);
memcpy( sample_buf + offset, c->d.asBytes, len);
//PrintAndLogEx(NORMAL, "ICE:: Download from device. chunk %" PRIu32 " | size %" PRIu32 " | tracelen:%" PRIu32 " \n", offset, len, c->arg[2]);

View file

@ -162,7 +162,7 @@ int CmdScriptRun(const char *Cmd) {
//luaL_dofile(lua_state, buf);
// close the Lua state
lua_close(lua_state);
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(SUCCESS, "Finished\n");
PrintAndLogEx(SUCCESS, "\nFinished\n");
return 0;
}

View file

@ -489,7 +489,7 @@ int CmdTraceList(const char *Cmd) {
UsbCommand response;
GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0);
if ( !WaitForResponseTimeout(CMD_ACK, &response, 4000) ) {
PrintAndLogEx(FAILED, "timeout while waiting for reply.");
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return 1;
}

View file

@ -87,17 +87,25 @@ void PrintAndLogEx(logLevel_t level, char *fmt, ...) {
}
if (strchr(buffer, '\n')) {
const char delim[2] = "\n";
token = strtok(buffer, "\n");
// line starts with newline
if (buffer[0] == '\n')
PrintAndLog("");
token = strtok(buffer, delim);
while (token != NULL) {
size = strlen(buffer2);
if (strlen(token))
snprintf(buffer2+size, sizeof(buffer2)-size, "%s%s\n", prefix, token);
else
snprintf(buffer2+size, sizeof(buffer2)-size, "\n");
token = strtok(NULL, "\n");
token = strtok(NULL, delim);
}
PrintAndLog(buffer2);
} else {