Merge branch 'better_color_handling'

* better_color_handling:
  Remove cmd_debug from flasher, we've COMMS_DEBUG_RAW if needed
  Use PrintAndLogEx in flasher
  Simplify color & banner logic
  Smart color handling:
This commit is contained in:
Philippe Teuwen 2019-04-30 21:37:19 +02:00
commit 63cd4a9fbb
20 changed files with 241 additions and 252 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

@ -15,7 +15,7 @@
#include "proxmark3.h"
#include "apps.h"
#include "parity.h"
#include "commonutil.h"
#include "util.h"
#include "string.h"
#include "iso14443a.h"
#include "crapto1/crapto1.h"

View file

@ -12,18 +12,13 @@
#define __UTIL_H
#include "common.h"
#include "commonutil.h"
#include "proxmark3.h"
#include "string.h"
#include "BigBuf.h"
#include "ticks.h"
// Basic macros
# define _BLUE_(s) "\x1b[34m" s "\x1b[0m "
# define _RED_(s) "\x1b[31m" s "\x1b[0m "
# define _GREEN_(s) "\x1b[32m" s "\x1b[0m "
# define _YELLOW_(s) "\x1b[33m" s "\x1b[0m "
# define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m "
# define _CYAN_(s) "\x1b[36m" s "\x1b[0m "
#ifndef SHORT_COIL
#define SHORT_COIL() LOW(GPIO_SSC_DOUT)

View file

@ -11,6 +11,10 @@
#include "comms.h"
#include "crc16.h"
#if defined(__linux__) || (__APPLE__)
#include <sys/stat.h>
#include <unistd.h>
#endif
//#define COMMS_DEBUG
//#define COMMS_DEBUG_RAW
@ -249,48 +253,6 @@ static int getReply(PacketResponseNG *packet) {
return 1;
}
static void memcpy_filtered(void *dest, const void *src, size_t n, bool filter) {
#if defined(__linux__) || (__APPLE__)
memcpy(dest, src, n);
#else
if (filter) {
// Filter out ANSI sequences on these OS
uint8_t *rdest = (uint8_t *)dest;
uint8_t *rsrc = (uint8_t *)src;
uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) {
if ((rsrc[i] == '\x1b')
&& (i < n - 1)
&& (rsrc[i + 1] >= 0x40)
&& (rsrc[i + 1] <= 0x5F)) { // entering ANSI sequence
i++;
if ((rsrc[i] == '[') && (i < n - 1)) { // entering CSI sequence
i++;
while ((i < n - 1) && (rsrc[i] >= 0x30) && (rsrc[i] <= 0x3F)) { // parameter bytes
i++;
}
while ((i < n - 1) && (rsrc[i] >= 0x20) && (rsrc[i] <= 0x2F)) { // intermediate bytes
i++;
}
if ((rsrc[i] >= 0x40) && (rsrc[i] <= 0x7F)) { // final byte
continue;
}
} else {
continue;
}
}
rdest[si++] = rsrc[i];
}
} else {
memcpy(dest, src, n);
}
#endif
}
//-----------------------------------------------------------------------------
// Entry point into our code: called whenever we received a packet over USB
// that we weren't necessarily expecting, for example a debug print.
@ -320,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_filtered(s, data->buf, len, flag & FLAG_ANSI);
memcpy(s, data->buf, len);
} else {
len = MIN(packet->oldarg[0], PM3_CMD_DATA_SIZE);
flag = packet->oldarg[1];
memcpy_filtered(s, packet->data.asBytes, len, flag & FLAG_ANSI);
memcpy(s, packet->data.asBytes, len);
}
if (flag & FLAG_LOG) {
@ -581,12 +543,12 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
// check result of uart opening
if (sp == INVALID_SERIAL_PORT) {
PrintAndLogEx(WARNING, _RED_("ERROR:") "invalid serial port " _YELLOW_("%s"), portname);
PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") "invalid serial port " _YELLOW_("%s"), portname);
sp = NULL;
serial_port_name = NULL;
return false;
} else if (sp == CLAIMED_SERIAL_PORT) {
PrintAndLogEx(WARNING, _RED_("ERROR:") "serial port " _YELLOW_("%s") " is claimed by another process", portname);
PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") "serial port " _YELLOW_("%s") " is claimed by another process", portname);
sp = NULL;
serial_port_name = NULL;
return false;

View file

@ -12,7 +12,6 @@
#include <jansson.h>
#include "tlv.h"
#include "commonutil.h"
typedef struct {
tlv_tag_t Tag;

View file

@ -16,7 +16,6 @@
#include <stddef.h>
#include <stdint.h>
#include <cbor.h>
#include "commonutil.h"
#include "util.h"
const char *GetCOSEAlgName(int id);

View file

@ -40,13 +40,13 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
ctx->segments = calloc(sizeof(flash_seg_t) * num_phdrs, sizeof(uint8_t));
if (!ctx->segments) {
fprintf(stderr, "Out of memory\n");
PrintAndLogEx(ERR, "Out of memory");
return -1;
}
ctx->num_segs = 0;
seg = ctx->segments;
fprintf(stdout, "Loading usable ELF segments:\n");
PrintAndLogEx(NORMAL, "Loading usable ELF segments:");
for (int i = 0; i < num_phdrs; i++) {
if (le32(phdr->p_type) != PT_LOAD) {
phdr++;
@ -62,27 +62,27 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
phdr++;
continue;
}
fprintf(stdout, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x\n",
PrintAndLogEx(NORMAL, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x",
i, vaddr, paddr, filesz, memsz,
(flags & PF_R) ? 'R' : ' ',
(flags & PF_W) ? 'W' : ' ',
(flags & PF_X) ? 'X' : ' ',
offset);
if (filesz != memsz) {
fprintf(stderr, "Error: PHDR file size does not equal memory size\n"
"(DATA+BSS PHDRs do not make sense on ROM platforms!)\n");
PrintAndLogEx(ERR, "Error: PHDR file size does not equal memory size\n"
"(DATA+BSS PHDRs do not make sense on ROM platforms!)");
return -1;
}
if (paddr < last_end) {
fprintf(stderr, "Error: PHDRs not sorted or overlap\n");
PrintAndLogEx(ERR, "Error: PHDRs not sorted or overlap");
return -1;
}
if (paddr < FLASH_START || (paddr + filesz) > FLASH_END) {
fprintf(stderr, "Error: PHDR is not contained in Flash\n");
PrintAndLogEx(ERR, "Error: PHDR is not contained in Flash");
return -1;
}
if (vaddr >= FLASH_START && vaddr < FLASH_END && (flags & PF_W)) {
fprintf(stderr, "Error: Flash VMA segment is writable\n");
PrintAndLogEx(ERR, "Error: Flash VMA segment is writable");
return -1;
}
@ -90,11 +90,11 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
// make extra space if we need to move the data forward
data = calloc(filesz + BLOCK_SIZE, sizeof(uint8_t));
if (!data) {
fprintf(stderr, "Error: Out of memory\n");
PrintAndLogEx(ERR, "Error: Out of memory");
return -1;
}
if (fseek(fd, offset, SEEK_SET) < 0 || fread(data, 1, filesz, fd) != filesz) {
fprintf(stderr, "Error while reading PHDR payload\n");
PrintAndLogEx(ERR, "Error while reading PHDR payload");
free(data);
return -1;
}
@ -113,17 +113,17 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
uint32_t hole = this_offset - prev_seg->length;
uint8_t *new_data = calloc(new_length, sizeof(uint8_t));
if (!new_data) {
fprintf(stderr, "Error: Out of memory\n");
PrintAndLogEx(ERR, "Error: Out of memory");
free(data);
return -1;
}
memset(new_data, 0xff, new_length);
memcpy(new_data, prev_seg->data, prev_seg->length);
memcpy(new_data + this_offset, data, filesz);
fprintf(stderr, "Note: Extending previous segment from 0x%x to 0x%x bytes\n",
PrintAndLogEx(NORMAL, "Note: Extending previous segment from 0x%x to 0x%x bytes",
prev_seg->length, new_length);
if (hole)
fprintf(stderr, "Note: 0x%x-byte hole created\n", hole);
PrintAndLogEx(NORMAL, "Note: 0x%x-byte hole created", hole);
free(data);
free(prev_seg->data);
prev_seg->data = new_data;
@ -133,7 +133,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
continue;
}
}
fprintf(stderr, "Warning: segment does not begin on a block boundary, will pad\n");
PrintAndLogEx(WARNING, "Warning: segment does not begin on a block boundary, will pad");
memmove(data + block_offset, data, filesz);
memset(data, 0xFF, block_offset);
filesz += block_offset;
@ -158,19 +158,19 @@ static int check_segs(flash_file_t *ctx, int can_write_bl) {
flash_seg_t *seg = &ctx->segments[i];
if (seg->start & (BLOCK_SIZE - 1)) {
fprintf(stderr, "Error: Segment is not aligned\n");
PrintAndLogEx(ERR, "Error: Segment is not aligned");
return -1;
}
if (seg->start < FLASH_START) {
fprintf(stderr, "Error: Segment is outside of flash bounds\n");
PrintAndLogEx(ERR, "Error: Segment is outside of flash bounds");
return -1;
}
if (seg->start + seg->length > FLASH_END) {
fprintf(stderr, "Error: Segment is outside of flash bounds\n");
PrintAndLogEx(ERR, "Error: Segment is outside of flash bounds");
return -1;
}
if (!can_write_bl && seg->start < BOOTLOADER_END) {
fprintf(stderr, "Attempted to write bootloader but bootloader writes are not enabled\n");
PrintAndLogEx(ERR, "Attempted to write bootloader but bootloader writes are not enabled");
return -1;
}
}
@ -187,52 +187,52 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) {
fd = fopen(name, "rb");
if (!fd) {
fprintf(stderr, _RED_("Could not open file") "%s >>> ", name);
PrintAndLogEx(ERR, _RED_("Could not open file") "%s >>> ", name);
perror(NULL);
goto fail;
}
fprintf(stdout, _BLUE_("Loading ELF file") _YELLOW_("%s") "\n", name);
PrintAndLogEx(NORMAL, _BLUE_("Loading ELF file") _YELLOW_("%s"), name);
if (fread(&ehdr, sizeof(ehdr), 1, fd) != 1) {
fprintf(stderr, "Error while reading ELF file header\n");
PrintAndLogEx(ERR, "Error while reading ELF file header");
goto fail;
}
if (memcmp(ehdr.e_ident, elf_ident, sizeof(elf_ident))
|| le32(ehdr.e_version) != 1) {
fprintf(stderr, "Not an ELF file or wrong ELF type\n");
PrintAndLogEx(ERR, "Not an ELF file or wrong ELF type");
goto fail;
}
if (le16(ehdr.e_type) != ET_EXEC) {
fprintf(stderr, "ELF is not executable\n");
PrintAndLogEx(ERR, "ELF is not executable");
goto fail;
}
if (le16(ehdr.e_machine) != EM_ARM) {
fprintf(stderr, "Wrong ELF architecture\n");
PrintAndLogEx(ERR, "Wrong ELF architecture");
goto fail;
}
if (!ehdr.e_phnum || !ehdr.e_phoff) {
fprintf(stderr, "ELF has no PHDRs\n");
PrintAndLogEx(ERR, "ELF has no PHDRs");
goto fail;
}
if (le16(ehdr.e_phentsize) != sizeof(Elf32_Phdr)) {
// could be a structure padding issue...
fprintf(stderr, "Either the ELF file or this code is made of fail\n");
PrintAndLogEx(ERR, "Either the ELF file or this code is made of fail");
goto fail;
}
num_phdrs = le16(ehdr.e_phnum);
phdrs = calloc(le16(ehdr.e_phnum) * sizeof(Elf32_Phdr), sizeof(uint8_t));
if (!phdrs) {
fprintf(stderr, "Out of memory\n");
PrintAndLogEx(ERR, "Out of memory");
goto fail;
}
if (fseek(fd, le32(ehdr.e_phoff), SEEK_SET) < 0) {
fprintf(stderr, "Error while reading ELF PHDRs\n");
PrintAndLogEx(ERR, "Error while reading ELF PHDRs");
goto fail;
}
if (fread(phdrs, sizeof(Elf32_Phdr), num_phdrs, fd) != num_phdrs) {
fprintf(stderr, "Error while reading ELF PHDRs\n");
PrintAndLogEx(ERR, "Error while reading ELF PHDRs");
goto fail;
}
@ -279,7 +279,7 @@ static int get_proxmark_state(uint32_t *state) {
*state = resp.oldarg[0];
break;
default:
fprintf(stderr, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04x\n", resp.cmd);
PrintAndLogEx(ERR, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04x", resp.cmd);
return -1;
break;
}
@ -298,18 +298,18 @@ static int enter_bootloader(char *serial_port_name) {
return 0;
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
fprintf(stdout, _BLUE_("Entering bootloader...") "\n");
PrintAndLogEx(NORMAL, _BLUE_("Entering bootloader..."));
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
&& (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
// New style handover: Send CMD_START_FLASH, which will reset the board
// and enter the bootrom on the next boot.
SendCommandOLD(CMD_START_FLASH, 0, 0, 0, NULL, 0);
fprintf(stdout, "(Press and release the button only to abort)\n");
PrintAndLogEx(NORMAL, "(Press and release the button only to abort)");
} else {
// Old style handover: Ask the user to press the button, then reset the board
SendCommandOLD(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
fprintf(stdout, "Press and hold down button NOW if your bootloader requires it.\n");
PrintAndLogEx(NORMAL, "Press and hold down button NOW if your bootloader requires it.");
}
msleep(100);
CloseProxmark();
@ -318,15 +318,15 @@ static int enter_bootloader(char *serial_port_name) {
bool opened = OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED);
if (opened) {
fprintf(stdout, " " _GREEN_("Found") "\n");
PrintAndLogEx(NORMAL, " " _GREEN_("Found"));
return 0;
} else {
fprintf(stdout, _RED_("Error:") "Proxmark3 not found.\n");
PrintAndLogEx(ERR, _RED_("Error:") "Proxmark3 not found.");
return -1;
}
}
fprintf(stderr, _RED_("Error:") "Unknown Proxmark3 mode\n");
PrintAndLogEx(ERR, _RED_("Error:") "Unknown Proxmark3 mode");
return -1;
}
@ -334,7 +334,7 @@ static int wait_for_ack(PacketResponseNG *ack) {
WaitForResponse(CMD_UNKNOWN, ack);
if (ack->cmd != CMD_ACK) {
printf("Error: Unexpected reply 0x%04x %s (expected ACK)\n",
PrintAndLogEx(ERR, "Error: Unexpected reply 0x%04x %s (expected ACK)",
ack->cmd,
(ack->cmd == CMD_NACK) ? "NACK" : ""
);
@ -365,8 +365,8 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name) {
}
return wait_for_ack(&resp);
} else {
fprintf(stderr, _RED_("Note: Your bootloader does not understand the new START_FLASH command") "\n");
fprintf(stderr, _RED_("It is recommended that you update your bootloader") "\n\n");
PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new START_FLASH command"));
PrintAndLogEx(ERR, _RED_("It is recommended that you update your bootloader") "\n");
}
return 0;
}
@ -383,17 +383,17 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length) {
bool lock_error = resp.oldarg[0] & AT91C_MC_LOCKE;
bool prog_error = resp.oldarg[0] & AT91C_MC_PROGE;
bool security_bit = resp.oldarg[0] & AT91C_MC_SECURITY;
printf("%s", lock_error ? " Lock Error\n" : "");
printf("%s", prog_error ? " Invalid Command or bad Keyword\n" : "");
printf("%s", security_bit ? " Security Bit is set!\n" : "");
printf(" Lock Bits: 0x%04x\n", lock_bits);
PrintAndLogEx(NORMAL, "%s", lock_error ? " Lock Error" : "");
PrintAndLogEx(NORMAL, "%s", prog_error ? " Invalid Command or bad Keyword" : "");
PrintAndLogEx(NORMAL, "%s", security_bit ? " Security Bit is set!" : "");
PrintAndLogEx(NORMAL, " Lock Bits: 0x%04x", lock_bits);
}
return ret;
}
// Write a file's segments to Flash
int flash_write(flash_file_t *ctx) {
fprintf(stdout, "Writing segments for file: %s\n", ctx->filename);
PrintAndLogEx(NORMAL, "Writing segments for file: %s", ctx->filename);
for (int i = 0; i < ctx->num_segs; i++) {
flash_seg_t *seg = &ctx->segments[i];
@ -401,7 +401,7 @@ int flash_write(flash_file_t *ctx) {
uint32_t blocks = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
uint32_t end = seg->start + length;
fprintf(stdout, " 0x%08x..0x%08x [0x%x / %u blocks]", seg->start, end - 1, length, blocks);
PrintAndLogEx(NORMAL, " 0x%08x..0x%08x [0x%x / %u blocks]", seg->start, end - 1, length, blocks);
fflush(stdout);
int block = 0;
uint8_t *data = seg->data;
@ -413,8 +413,7 @@ int flash_write(flash_file_t *ctx) {
block_size = BLOCK_SIZE;
if (write_block(baddr, data, block_size) < 0) {
fprintf(stderr, " ERROR\n");
fprintf(stderr, "Error writing block %d of %u\n", block, blocks);
PrintAndLogEx(ERR, "Error writing block %d of %u", block, blocks);
return -1;
}
@ -425,7 +424,7 @@ int flash_write(flash_file_t *ctx) {
fprintf(stdout, ".");
fflush(stdout);
}
fprintf(stdout, _GREEN_("OK") "\n");
PrintAndLogEx(NORMAL, _GREEN_("OK"));
fflush(stdout);
}
return 0;

View file

@ -17,34 +17,20 @@
#include "flash.h"
#include "comms.h"
#include "pm3_cmd.h"
#include "ui.h"
#define MAX_FILES 4
void cmd_debug(PacketCommandOLD *c) {
// Debug
printf("PacketCommandOLD length[len=%zu]\n", sizeof(PacketCommandOLD));
printf(" cmd[len=%zu]: %016" PRIx64"\n", sizeof(c->cmd), c->cmd);
printf(" arg0[len=%zu]: %016" PRIx64"\n", sizeof(c->arg[0]), c->arg[0]);
printf(" arg1[len=%zu]: %016" PRIx64"\n", sizeof(c->arg[1]), c->arg[1]);
printf(" arg2[len=%zu]: %016" PRIx64"\n", sizeof(c->arg[2]), c->arg[2]);
printf(" data[len=%zu]: ", sizeof(c->d.asBytes));
for (size_t i = 0; i < 16; i++)
printf("%02x", c->d.asBytes[i]);
printf("...\n");
}
static void usage(char *argv0) {
fprintf(stdout, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
fprintf(stdout, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
fprintf(stdout, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf\n", argv0);
PrintAndLogEx(NORMAL, "Usage: %s <port> [-b] image.elf [image.elf...]\n", argv0);
PrintAndLogEx(NORMAL, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n");
PrintAndLogEx(NORMAL, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf", argv0);
#ifdef __linux__
fprintf(stdout, "\nNote (Linux): if the flasher gets stuck in 'Waiting for Proxmark3 to reappear on <DEVICE>',\n");
fprintf(stdout, " you need to blacklist Proxmark3 for modem-manager - see wiki for more details:\n\n");
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/Gentoo Linux\n\n");
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/Ubuntu Linux\n\n");
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/OSX\n\n");
PrintAndLogEx(NORMAL, "\nNote (Linux): if the flasher gets stuck in 'Waiting for Proxmark3 to reappear on <DEVICE>',");
PrintAndLogEx(NORMAL, " you need to blacklist Proxmark3 for modem-manager - see wiki for more details:\n");
PrintAndLogEx(NORMAL, " https://github.com/Proxmark/proxmark3/wiki/Gentoo Linux\n");
PrintAndLogEx(NORMAL, " https://github.com/Proxmark/proxmark3/wiki/Ubuntu Linux\n");
PrintAndLogEx(NORMAL, " https://github.com/Proxmark/proxmark3/wiki/OSX\n");
#endif
}
@ -56,6 +42,14 @@ int main(int argc, char **argv) {
memset(files, 0, sizeof(files));
session.supports_colors = false;
session.stdinOnTTY = isatty(STDIN_FILENO);
session.stdoutOnTTY = isatty(STDOUT_FILENO);
#if defined(__linux__) || (__APPLE__)
if (session.stdinOnTTY && session.stdoutOnTTY)
session.supports_colors = true;
#endif
if (argc < 3) {
usage(argv[0]);
return -1;
@ -74,7 +68,7 @@ int main(int argc, char **argv) {
if (res < 0)
return -1;
fprintf(stderr, "\n");
PrintAndLogEx(NORMAL, "");
num_files++;
}
}
@ -82,27 +76,27 @@ int main(int argc, char **argv) {
char *serial_port_name = argv[1];
if (!OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
fprintf(stderr, "Could not find Proxmark3 on " _RED_("%s") ".\n\n", serial_port_name);
PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name);
return -1;
} else {
fprintf(stderr, _GREEN_("Found") "\n");
PrintAndLogEx(NORMAL, _GREEN_("Found"));
}
res = flash_start_flashing(can_write_bl, serial_port_name);
if (res < 0)
return -1;
fprintf(stdout, "\n" _BLUE_("Flashing...")"\n");
PrintAndLogEx(NORMAL, "\n" _BLUE_("Flashing..."));
for (int i = 0; i < num_files; i++) {
res = flash_write(&files[i]);
if (res < 0)
return -1;
flash_free(&files[i]);
fprintf(stdout, "\n");
PrintAndLogEx(NORMAL, "\n");
}
fprintf(stdout, _BLUE_("Resetting hardware...") "\n");
PrintAndLogEx(NORMAL, _BLUE_("Resetting hardware..."));
res = flash_stop_flashing();
if (res < 0)
@ -110,6 +104,6 @@ int main(int argc, char **argv) {
CloseProxmark();
fprintf(stdout, _BLUE_("All done.") "\n\nHave a nice day!\n");
PrintAndLogEx(NORMAL, _BLUE_("All done.") "\n\nHave a nice day!");
return 0;
}

View file

@ -30,25 +30,25 @@
#include "usart.h"
static void showBanner(void) {
printf("\n\n");
PrintAndLogEx(NORMAL, "\n");
#if defined(__linux__) || (__APPLE__)
printf(_BLUE_("██████╗ ███╗ ███╗ ████╗ ") " ...iceman fork\n");
printf(_BLUE_("██╔══██╗████╗ ████║ ══█║") " ...dedicated to " _BLUE_("RDV40") "\n");
printf(_BLUE_("██████╔╝██╔████╔██║ ████╔╝") "\n");
printf(_BLUE_("██╔═══╝ ██║╚██╔╝██║ ══█║") " iceman@icesql.net\n");
printf(_BLUE_("██║ ██║ ╚═╝ ██║ ████╔╝") " https://github.com/rfidresearchgroup/proxmark3/\n");
printf(_BLUE_("╚═╝ ╚═╝ ╚═╝ ╚═══╝ ") "pre-release v4.0\n");
PrintAndLogEx(NORMAL, _BLUE_("██████╗ ███╗ ███╗ ████╗ ") " ...iceman fork");
PrintAndLogEx(NORMAL, _BLUE_("██╔══██╗████╗ ████║ ══█║") " ...dedicated to " _BLUE_("RDV40"));
PrintAndLogEx(NORMAL, _BLUE_("██████╔╝██╔████╔██║ ████╔╝"));
PrintAndLogEx(NORMAL, _BLUE_("██╔═══╝ ██║╚██╔╝██║ ══█║") " iceman@icesql.net");
PrintAndLogEx(NORMAL, _BLUE_("██║ ██║ ╚═╝ ██║ ████╔╝") " https://github.com/rfidresearchgroup/proxmark3/");
PrintAndLogEx(NORMAL, _BLUE_("╚═╝ ╚═╝ ╚═╝ ╚═══╝ ") "pre-release v4.0");
#else
printf("======. ===. ===. ====. ...iceman fork\n");
printf("==...==.====. ====. ..=. ...dedicated to RDV40\n");
printf("======..==.====.==. ====..\n");
printf("==..... ==..==..==. ..=. iceman@icesql.net\n");
printf("==. ==. ... ==. ====.. https://github.com/rfidresearchgroup/proxmark3/\n");
printf("... ... ... ..... pre-release v4.0\n");
PrintAndLogEx(NORMAL, "======. ===. ===. ====. ...iceman fork");
PrintAndLogEx(NORMAL, "==...==.====. ====. ..=. ...dedicated to RDV40");
PrintAndLogEx(NORMAL, "======..==.====.==. ====..");
PrintAndLogEx(NORMAL, "==..... ==..==..==. ..=. iceman@icesql.net");
PrintAndLogEx(NORMAL, "==. ==. ... ==. ====.. https://github.com/rfidresearchgroup/proxmark3/");
PrintAndLogEx(NORMAL, "... ... ... ..... pre-release v4.0");
#endif
printf("\nSupport iceman on patreon, https://www.patreon.com/iceman1001/");
PrintAndLogEx(NORMAL, "\nSupport iceman on patreon, https://www.patreon.com/iceman1001/");
// printf("\nMonero: 43mNJLpgBVaTvyZmX9ajcohpvVkaRy1kbZPm8tqAb7itZgfuYecgkRF36rXrKFUkwEGeZedPsASRxgv4HPBHvJwyJdyvQuP");
printf("\n\n\n");
PrintAndLogEx(NORMAL, "\n");
fflush(stdout);
}
@ -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,6 +16,7 @@
#endif
#include "ui.h"
session_arg_t session;
double CursorScaleFactor = 1;
int PlotGridX = 0, PlotGridY = 0, PlotGridXdefault = 64, PlotGridYdefault = 64;
@ -27,6 +28,7 @@ bool showDemod = true;
pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
static const char *logfilename = "proxmark3.log";
static void fPrintAndLog(FILE *stream, const char *fmt, ...);
/*
static float complex cexpf(float complex Z) {
@ -73,10 +75,12 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
char *tmp_ptr = NULL;
// {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG}
static const char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "};
FILE* stream = stdout;
switch (level) {
case ERR:
strncpy(prefix, _RED_("[!!]"), sizeof(prefix) - 1);
stream = stderr;
break;
case FAILED:
strncpy(prefix, _RED_("[-]"), sizeof(prefix) - 1);
@ -103,7 +107,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
// no prefixes for normal
if (level == NORMAL) {
PrintAndLog("%s", buffer);
fPrintAndLog(stream, "%s", buffer);
return;
}
@ -113,7 +117,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
// line starts with newline
if (buffer[0] == '\n')
PrintAndLog("");
fPrintAndLog(stream, "");
token = strtok_r(buffer, delim, &tmp_ptr);
@ -128,20 +132,21 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
token = strtok_r(NULL, delim, &tmp_ptr);
}
PrintAndLog("%s", buffer2);
fPrintAndLog(stream, "%s", buffer2);
} else {
snprintf(buffer2, sizeof(buffer2), "%s%s", prefix, buffer);
PrintAndLog("%s", buffer2);
fPrintAndLog(stream, "%s", buffer2);
}
}
void PrintAndLog(const char *fmt, ...) {
static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
char *saved_line;
int saved_point;
va_list argptr, argptr2;
va_list argptr;
static FILE *logfile = NULL;
static int logging = 1;
char buffer[MAX_PRINT_BUFFER] = {0};
char buffer2[MAX_PRINT_BUFFER] = {0};
// lock this section to avoid interlacing prints from different threads
pthread_mutex_lock(&print_lock);
@ -171,11 +176,14 @@ void PrintAndLog(const char *fmt, ...) {
#endif
va_start(argptr, fmt);
va_copy(argptr2, argptr);
vprintf(fmt, argptr);
printf(" "); // cleaning prompt
vsnprintf(buffer, sizeof(buffer), fmt, argptr);
va_end(argptr);
printf("\n");
bool filter_ansi = !session.supports_colors;
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
fprintf(stream, "%s", buffer2);
fprintf(stream, " "); // cleaning prompt
fprintf(stream, "\n");
#ifdef RL_STATE_READCMD
// We are using GNU readline. libedit (OSX) doesn't support this flag.
@ -189,11 +197,14 @@ void PrintAndLog(const char *fmt, ...) {
#endif
if (logging && logfile) {
vfprintf(logfile, fmt, argptr2);
fprintf(logfile, "\n");
if (filter_ansi) { // already done
fprintf(logfile, "%s\n", buffer2);
} else {
memcpy_filter_ansi(buffer, buffer2, sizeof(buffer2), true);
fprintf(logfile, "%s\n", buffer);
}
fflush(logfile);
}
va_end(argptr2);
if (flushAfterWrite)
fflush(stdout);
@ -210,6 +221,44 @@ void SetFlushAfterWrite(bool value) {
flushAfterWrite = value;
}
void memcpy_filter_ansi(void *dest, const void *src, size_t n, bool filter) {
if (filter) {
// Filter out ANSI sequences on these OS
uint8_t *rdest = (uint8_t *)dest;
uint8_t *rsrc = (uint8_t *)src;
uint16_t si = 0;
for (uint16_t i = 0; i < n; i++) {
if ((rsrc[i] == '\x1b')
&& (i < n - 1)
&& (rsrc[i + 1] >= 0x40)
&& (rsrc[i + 1] <= 0x5F)) { // entering ANSI sequence
i++;
if ((rsrc[i] == '[') && (i < n - 1)) { // entering CSI sequence
i++;
while ((i < n - 1) && (rsrc[i] >= 0x30) && (rsrc[i] <= 0x3F)) { // parameter bytes
i++;
}
while ((i < n - 1) && (rsrc[i] >= 0x20) && (rsrc[i] <= 0x2F)) { // intermediate bytes
i++;
}
if ((rsrc[i] >= 0x40) && (rsrc[i] <= 0x7F)) { // final byte
continue;
}
} else {
continue;
}
}
rdest[si++] = rsrc[i];
}
} else {
memcpy(dest, src, n);
}
}
void iceIIR_Butterworth(int *data, const size_t len) {
int *output = (int *) calloc(sizeof(int) * len, sizeof(uint8_t));

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
@ -34,11 +42,11 @@ void ShowGui(void);
void HideGraphWindow(void);
void ShowGraphWindow(void);
void RepaintGraphWindow(void);
void PrintAndLog(const char *fmt, ...);
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space);
void PrintAndLogEx(logLevel_t level, const char *fmt, ...);
void SetLogFilename(char *fn);
void SetFlushAfterWrite(bool value);
void memcpy_filter_ansi(void *dest, const void *src, size_t n, bool filter);
extern double CursorScaleFactor;
extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, GridOffset;

View file

@ -19,6 +19,7 @@
#include <stdio.h>
#include <time.h>
#include "ui.h" // PrintAndLog
#include "commonutil.h"
#ifdef ANDROID
#include <endian.h>
@ -112,42 +113,6 @@
# define FILE_PATH_SIZE 1000
#endif
#if defined(__linux__) || (__APPLE__)
# define _BLUE_(s) "\x1b[34m" s "\x1b[0m "
#else
# define _BLUE_(s) s " "
#endif
#if defined(__linux__) || (__APPLE__)
# define _RED_(s) "\x1b[31m" s "\x1b[0m "
#else
# define _RED_(s) s " "
#endif
#if defined(__linux__) || (__APPLE__)
# define _GREEN_(s) "\x1b[32m" s "\x1b[0m "
#else
# define _GREEN_(s) s " "
#endif
#if defined(__linux__) || (__APPLE__)
# define _YELLOW_(s) "\x1b[33m" s "\x1b[0m "
#else
# define _YELLOW_(s) s " "
#endif
#if defined(__linux__) || (__APPLE__)
# define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m "
#else
# define _MAGENTA_(s) s " "
#endif
#if defined(__linux__) || (__APPLE__)
# define _CYAN_(s) "\x1b[36m" s "\x1b[0m "
#else
# define _CYAN_(s) s " "
#endif
#ifndef DropField
#define DropField() { \
clearCommandBuffer(); SendCommandOLD(CMD_READER_ISO_14443a, 0, 0, 0, NULL, 0); \

View file

@ -53,4 +53,11 @@ void lsl(uint8_t *data, size_t len);
int32_t le24toh(uint8_t data[3]);
void htole24(uint32_t val, uint8_t data[3]);
# define _BLUE_(s) "\x1b[34m" s "\x1b[0m "
# define _RED_(s) "\x1b[31m" s "\x1b[0m "
# define _GREEN_(s) "\x1b[32m" s "\x1b[0m "
# define _YELLOW_(s) "\x1b[33m" s "\x1b[0m "
# define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m "
# define _CYAN_(s) "\x1b[36m" s "\x1b[0m "
#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);