Simplify color & banner logic

This commit is contained in:
Philippe Teuwen 2019-04-30 13:02:27 +02:00
commit 0a4b90ac20
12 changed files with 77 additions and 72 deletions

View file

@ -96,10 +96,10 @@ void BigBuf_free_keep_EM(void) {
}
void BigBuf_print_status(void) {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Memory"));
DbpString(_BLUE_("Memory"));
Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE);
Dbprintf(" Available memory........%d", BigBuf_hi);
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Tracing"));
DbpString(_BLUE_("Tracing"));
Dbprintf(" tracing ................%d", tracing);
Dbprintf(" traceLen ...............%d", traceLen);
}

View file

@ -124,7 +124,7 @@ void ReadLastTagFromFlash() {
end_time = GetTickCount();
DbprintfEx(FLAG_NEWLINE, "[OK] Last tag recovered from FLASHMEM set to emulator");
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s[IN]%s %s%dms%s for TAG_FLASH_READ", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s[IN]%s %s%dms%s for TAG_FLASH_READ", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
cjSetCursLeft();
FlashStop();
SpinOff(0);
@ -188,7 +188,7 @@ void WriteTagToFlash(uint8_t index, size_t size) {
DbprintfEx(FLAG_NEWLINE, "[OK] TAG WRITTEN TO FLASH ! [0-to offset %u]", bytes_sent);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s[IN]%s %s%dms%s for TAG_FLASH_WRITE", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s[IN]%s %s%dms%s for TAG_FLASH_WRITE", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
cjSetCursLeft();
FlashStop();
SpinOff(0);
@ -329,8 +329,8 @@ void RunMod() {
// banner:
vtsend_reset(NULL);
DbprintfEx(FLAG_NEWLINE, "\r\n%s", clearTerm);
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s%s%s", _CYAN_, sub_banner, _WHITE_);
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>%s C.J.B's MifareFastPwn Started\r\n", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s%s%s", _CYAN_, sub_banner, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>%s C.J.B's MifareFastPwn Started\r\n", _RED_, _WHITE_);
currline = 20;
curlline = 20;
@ -370,16 +370,16 @@ failtag:
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
vtsend_cursor_position_restore(NULL);
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "\t\t\t%s[ GOT a Tag ! ]%s", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "\t\t\t%s[ GOT a Tag ! ]%s", _GREEN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE, "\t\t\t `---> Breaking keys ---->");
cjSetCursRight();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "\t%sGOT TAG :%s %08x%s", _RED_, _CYAN_, cjcuid, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "\t%sGOT TAG :%s %08x%s", _RED_, _CYAN_, cjcuid, _WHITE_);
if (cjcuid == 0) {
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>%s BUG: 0000_CJCUID! Retrying...", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>%s BUG: 0000_CJCUID! Retrying...", _RED_, _WHITE_);
SpinErr(0, 100, 8);
goto failtag;
}
@ -452,19 +452,19 @@ failtag:
// COMMON SCHEME 1 : INFINITRON/HEXACT
case 0x484558414354:
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%sDetected: %s INFI_HEXACT_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%sDetected: %s INFI_HEXACT_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_);
DbprintfEx(FLAG_NEWLINE, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_);
;
// Type 0 / A first
uint16_t t = 0;
@ -597,19 +597,19 @@ failtag:
case 0x8829da9daf76:
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%sDetected :%sURMET_CAPTIVE_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%sDetected :%sURMET_CAPTIVE_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_);
DbprintfEx(FLAG_NEWLINE, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_);
cjSetCursLeft();
// emlClearMem();
@ -639,19 +639,19 @@ failtag:
case 0x424c41524f4e:
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s Detected :%sNORALSY_VIGIK_TAG %s", _ORANGE_, _CYAN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s Detected :%sNORALSY_VIGIK_TAG %s", _ORANGE_, _CYAN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_);
DbprintfEx(FLAG_NEWLINE, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_);
t = 0;
for (uint16_t s = 0; s < sectorsCnt; s++) {
@ -692,7 +692,7 @@ failtag:
if (!allKeysFound) {
cjSetCursLeft();
cjTabulize();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s[ FAIL ]%s\r\n->did not found all the keys :'(", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s[ FAIL ]%s\r\n->did not found all the keys :'(", _RED_, _WHITE_);
cjSetCursLeft();
SpinErr(1, 100, 8);
SpinOff(100);
@ -711,25 +711,25 @@ failtag:
}
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>%s Setting Keys->Emulator MEM...[%sOK%s]", _YELLOW_, _WHITE_, _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>%s Setting Keys->Emulator MEM...[%sOK%s]", _YELLOW_, _WHITE_, _GREEN_, _WHITE_);
/* filling TAG to emulator */
uint8_t filled = 0;
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>%s Filling Emulator <- from A keys...", _YELLOW_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>%s Filling Emulator <- from A keys...", _YELLOW_, _WHITE_);
e_MifareECardLoad(sectorsCnt, 0, 0, &filled);
if (filled != 1) {
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>%s W_FAILURE ! %sTrying fallback B keys....", _RED_, _ORANGE_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>%s W_FAILURE ! %sTrying fallback B keys....", _RED_, _ORANGE_, _WHITE_);
/* no trace, no dbg */
e_MifareECardLoad(sectorsCnt, 1, 0, &filled);
if (filled != 1) {
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "FATAL:EML_FALLBACKFILL_B");
DbprintfEx(FLAG_NEWLINE, "FATAL:EML_FALLBACKFILL_B");
SpinErr(2, 100, 8);
SpinOff(100);
return;
@ -739,7 +739,7 @@ failtag:
end_time = GetTickCount();
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>%s Time for VIGIK break :%s%dms%s", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>%s Time for VIGIK break :%s%dms%s", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
vtsend_cursor_position_save(NULL);
vtsend_set_attribute(NULL, 1);
@ -758,10 +758,10 @@ readysim:
DbprintfEx(FLAG_NEWLINE, "-> We launch Emulation ->");
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s!> HOLD ON : %s When you'll click, simm will stop", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s!> HOLD ON : %s When you'll click, simm will stop", _RED_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "Then %s immediately %s we'll try to %s dump our emulator state%s \r\nin a %s chinese tag%s", _RED_, _WHITE_, _YELLOW_, _WHITE_,
DbprintfEx(FLAG_NEWLINE, "Then %s immediately %s we'll try to %s dump our emulator state%s \r\nin a %s chinese tag%s", _RED_, _WHITE_, _YELLOW_, _WHITE_,
_CYAN_, _WHITE_);
cjSetCursLeft();
cjSetCursLeft();
@ -777,7 +777,7 @@ readysim:
LED_C_OFF();
SpinOff(50);
vtsend_cursor_position_restore(NULL);
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "[ SIMUL ENDED ]%s", _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "[ SIMUL ENDED ]%s", _GREEN_, _WHITE_);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE, "<- We're out of Emulation");
@ -789,7 +789,7 @@ readysim:
saMifareMakeTag();
cjSetCursLeft();
vtsend_cursor_position_restore(NULL);
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s[ CLONED? ]", _CYAN_);
DbprintfEx(FLAG_NEWLINE, "%s[ CLONED? ]", _CYAN_);
DbprintfEx(FLAG_NEWLINE, "-> End Cloning.");
WDT_HIT();
@ -799,7 +799,7 @@ readysim:
cjTabulize();
vtsend_set_attribute(NULL, 0);
vtsend_set_attribute(NULL, 7);
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "- [ LA FIN ] -\r\n%s`-> You can take shell back :) ...", _WHITE_);
DbprintfEx(FLAG_NEWLINE, "- [ LA FIN ] -\r\n%s`-> You can take shell back :) ...", _WHITE_);
cjSetCursLeft();
vtsend_set_attribute(NULL, 0);
SpinErr(3, 100, 16);
@ -909,7 +909,7 @@ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
// if (!iso14443a_fast_select_card(cjuid, 0)) {
if (!iso14443a_select_card(cjuid, NULL, &cjcuid, true, 0, true)) {
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%sFATAL%s : E_MF_LOSTTAG", _RED_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%sFATAL%s : E_MF_LOSTTAG", _RED_, _WHITE_);
return -1;
}
@ -968,7 +968,7 @@ void saMifareMakeTag(void) {
if (currfline > 53) {
currfline = 54;
}
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "Block :%02x %sOK%s", blockNum, _GREEN_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "Block :%02x %sOK%s", blockNum, _GREEN_, _WHITE_);
// DbprintfEx(FLAG_RAWPRINT,"FATAL:E_MF_CHINESECOOK_NORICE");
// cfail=1;
// return;
@ -977,15 +977,15 @@ void saMifareMakeTag(void) {
cjSetCursLeft();
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "`--> %sFAIL%s : CHN_FAIL_BLK_%02x_NOK", _RED_, _WHITE_, blockNum);
DbprintfEx(FLAG_NEWLINE, "`--> %sFAIL%s : CHN_FAIL_BLK_%02x_NOK", _RED_, _WHITE_, blockNum);
cjSetCursFRight();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>%s STOP AT %02x", _RED_, _WHITE_, blockNum);
DbprintfEx(FLAG_NEWLINE, "%s>>>>%s STOP AT %02x", _RED_, _WHITE_, blockNum);
cfail++;
break;
}
cjSetCursFRight();
DbprintfEx(FLAG_NEWLINE | FLAG_ANSI, "%s>>>>>>>> END <<<<<<<<%s", _YELLOW_, _WHITE_);
DbprintfEx(FLAG_NEWLINE, "%s>>>>>>>> END <<<<<<<<%s", _YELLOW_, _WHITE_);
// break;
/*if (cfail == 1) {
DbprintfEx(FLAG_RAWPRINT,"FATAL: E_MF_HARA_KIRI_\r\n");

View file

@ -319,7 +319,7 @@ void MeasureAntennaTuningHf(void) {
DbprintfEx(FLAG_INPLACE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000));
}
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
DbprintfEx(FLAG_LOG, "\n[+] cancelled", 1);
Dbprintf("\n[+] cancelled", 1);
}
void ReadMem(int addr) {
@ -371,7 +371,7 @@ void SendVersion(void) {
// measure the USB Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the PacketCommandNG structure included.
void printUSBSpeed(void) {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Transfer Speed"));
DbpString(_BLUE_("Transfer Speed"));
Dbprintf(" Sending packets to client...");
#define USB_SPEED_TEST_MIN_TIME 1500 // in milliseconds
@ -392,7 +392,7 @@ void printUSBSpeed(void) {
Dbprintf(" Time elapsed............%dms", end_time - start_time);
Dbprintf(" Bytes transferred.......%d", bytes_transferred);
DbprintfEx(FLAG_LOG | FLAG_ANSI, " Transfer Speed PM3 -> Client = " _YELLOW_("%d") " bytes/s", 1000 * bytes_transferred / (end_time - start_time));
Dbprintf(" Transfer Speed PM3 -> Client = " _YELLOW_("%d") " bytes/s", 1000 * bytes_transferred / (end_time - start_time));
}
/**
@ -412,12 +412,12 @@ void SendStatus(void) {
printT55xxConfig(); // LF T55XX Config
#endif
printUSBSpeed();
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Various"));
DbpString(_BLUE_("Various"));
Dbprintf(" MF_DBGLEVEL.............%d", MF_DBGLEVEL);
Dbprintf(" ToSendMax...............%d", ToSendMax);
Dbprintf(" ToSendBit...............%d", ToSendBit);
Dbprintf(" ToSend BUFFERSIZE.......%d", TOSEND_BUFFER_SIZE);
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Installed StandAlone Mode"));
DbpString(_BLUE_("Installed StandAlone Mode"));
ModInfo();
//DbpString("Running ");

View file

@ -517,7 +517,7 @@ void Flash_EraseChip(void) {
*/
void Flashmem_print_status(void) {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Flash memory"));
DbpString(_BLUE_("Flash memory"));
Dbprintf(" Baudrate................%dMHz", FLASHMEM_SPIBAUDRATE / 1000000);
if (!FlashInit()) {

View file

@ -483,7 +483,7 @@ void SetAdcMuxFor(uint32_t whichGpio) {
}
void Fpga_print_status(void) {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Currently loaded FPGA image"));
DbpString(_BLUE_("Currently loaded FPGA image"));
Dbprintf(" mode....................%s", fpga_version_information[downloaded_bitstream - 1]);
}

View file

@ -55,7 +55,7 @@ Default LF T55xx config is set to:
t55xx_config t_config = { 29 * 8, 17 * 8, 15 * 8, 47 * 8, 15 * 8 } ;
void printT55xxConfig(void) {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("LF T55XX config"));
DbpString(_BLUE_("LF T55XX config"));
Dbprintf(" [a] startgap............%d*8 (%d)", t_config.start_gap / 8, t_config.start_gap);
Dbprintf(" [b] writegap............%d*8 (%d)", t_config.write_gap / 8, t_config.write_gap);
Dbprintf(" [c] write_0.............%d*8 (%d)", t_config.write_0 / 8, t_config.write_0);

View file

@ -19,7 +19,7 @@ Default LF config is set to:
sample_config config = { 1, 8, 1, 95, 0 } ;
void printConfig() {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("LF Sampling config"));
DbpString(_BLUE_("LF Sampling config"));
Dbprintf(" [q] divisor.............%d (%d KHz)", config.divisor, 12000 / (config.divisor + 1));
Dbprintf(" [b] bps.................%d", config.bits_per_sample);
Dbprintf(" [d] decimation..........%d", config.decimation);

View file

@ -265,13 +265,6 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
// we got a packet, reset WaitForResponseTimeout timeout
timeout_start_time = msclock();
bool filter_ansi = true;
#if defined(__linux__) || (__APPLE__)
struct stat tmp_stat;
if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
filter_ansi = false;
#endif
switch (packet->cmd) {
// First check if we are handling a debug message
case CMD_DEBUG_PRINT_STRING: {
@ -289,11 +282,11 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
struct d *data = (struct d *)&packet->data.asBytes;
len = packet->length - sizeof(data->flag);
flag = data->flag;
memcpy_filter_ansi(s, data->buf, len, (flag & FLAG_ANSI) && filter_ansi);
memcpy(s, data->buf, len);
} else {
len = MIN(packet->oldarg[0], USB_CMD_DATA_SIZE);
flag = packet->oldarg[1];
memcpy_filter_ansi(s, packet->data.asBytes, len, (flag & FLAG_ANSI) && filter_ansi);
memcpy(s, packet->data.asBytes, len);
}
if (flag & FLAG_LOG) {

View file

@ -438,9 +438,21 @@ int main(int argc, char *argv[]) {
return 1;
}
// ascii art
bool stdinOnPipe = !isatty(STDIN_FILENO);
if (!script_cmds_file && !stdinOnPipe)
session.supports_colors = false;
session.stdinOnTTY = isatty(STDIN_FILENO);
session.stdoutOnTTY = isatty(STDOUT_FILENO);
#if defined(__linux__) || (__APPLE__)
// it's okay to use color if:
// * Linux or OSX
// * Not redirected to a file but printed to term
// For info, grep --color=auto is doing sth like this, plus test getenv("TERM") != "dumb":
// struct stat tmp_stat;
// if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
if (session.stdinOnTTY && session.stdoutOnTTY)
session.supports_colors = true;
#endif
// ascii art only in interactive client
if (!script_cmds_file && !script_cmd && session.stdinOnTTY && session.stdoutOnTTY)
showBanner();
// Let's take a baudrate ok for real UART, USB-CDC & BT don't use that info anyway

View file

@ -16,10 +16,7 @@
#endif
#include "ui.h"
#if defined(__linux__) || (__APPLE__)
#include <unistd.h>
#include <sys/stat.h>
#endif
session_arg_t session;
double CursorScaleFactor = 1;
int PlotGridX = 0, PlotGridY = 0, PlotGridXdefault = 64, PlotGridYdefault = 64;
@ -179,12 +176,7 @@ void PrintAndLog(const char *fmt, ...) {
vsnprintf(buffer, sizeof(buffer), fmt, argptr);
va_end(argptr);
bool filter_ansi = true;
#if defined(__linux__) || (__APPLE__)
struct stat tmp_stat;
if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
filter_ansi = false;
#endif
bool filter_ansi = !session.supports_colors;
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
printf("%s", buffer2);
printf(" "); // cleaning prompt

View file

@ -24,6 +24,14 @@
#include <complex.h>
#include "util.h"
typedef struct {
bool stdinOnTTY;
bool stdoutOnTTY;
bool supports_colors;
} session_arg_t;
extern session_arg_t session;
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif

View file

@ -593,7 +593,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
}
void I2C_print_status(void) {
DbpStringEx(FLAG_LOG | FLAG_ANSI, _BLUE_("Smart card module (ISO 7816)"));
DbpString(_BLUE_("Smart card module (ISO 7816)"));
uint8_t resp[] = {0, 0, 0, 0};
I2C_Reset_EnterMainProgram();
uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);