From 9a6ad6597f09f9cc628588b987dc5ae1eb7a78bb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 25 Apr 2019 23:40:51 +0200 Subject: [PATCH 1/5] update standalone readme --- armsrc/Standalone/readme.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/armsrc/Standalone/readme.md b/armsrc/Standalone/readme.md index 1bf1a385f..c9f7946ad 100644 --- a/armsrc/Standalone/readme.md +++ b/armsrc/Standalone/readme.md @@ -9,17 +9,17 @@ As it is now, you can only have one standalone mode installed at the time. ## Implementing a standalone mode -We suggest you keep your standalone code inside the Armsrc/Standalone folder. And that you name your files according to your standalone mode name. +We suggest you keep your standalone code inside the `armsrc/Standalone` folder. And that you name your files according to your standalone mode name. -The `standalone.h` states that you must have two function implemented. +The `standalone.h` states that you must have two functions implemented. The ModInfo function, which is your identification of your standalone mode. This string will show when running the command `hw status` on the client. -The RunMod function, which is your "main" function when running. You need to check for Usb commands, in order to let the pm3 client break the standalone mode. See this basic skeleton of main function RunMod() and Modinfo() below. +The RunMod function, which is your "main" function when running. You need to check for Usb commands, in order to let the pm3 client break the standalone mode. See this basic skeleton of main function RunMod() and Modinfo() below. ```` void ModInfo(void) { - DbpString(" LF good description of your mode - aka FooRun (my name)"); + DbpString(" LF good description of your mode - aka FooRun (your name)"); } void RunMod(void) { @@ -40,27 +40,27 @@ void RunMod(void) { } ```` -Each standalone mode needs to have its own compiler flag to be added in `armsrc\makefile`. +Each standalone mode needs to have its own compiler flag to be added in `armsrc/Makefile`. ## Naming your standalone mode -We suggest that you follow these guidelines, -- Use HF/LF to denote which frequence your mod is targeting. +We suggest that you follow these guidelines: +- Use HF/LF to denote which frequency your mode is targeting. - Use you own github name/similar for perpetual honour to denote your mode. sample: - `LF_FOORUN` + `LF_FOO` Which indicates your mode targets LF and is called FOO. This leads to your next step, your DEFINE name needed in Makefile. -`WITH_STANDALONE_LF_FOORUN` +`WITH_STANDALONE_LF_FOO` ## Update COMMON/MAKEFILE.HAL -Samples of directive flag used in the `common/Makefile.ha` and your suggested DEFINE. +Add your suggested DEFINE to the samples of directive flag provided in the `common/Makefile.hal`. ``` #PLATFORM_DEFS += -DWITH_STANDALONE_LF_SAMYRUN #PLATFORM_DEFS += -DWITH_STANDALONE_LF_ICERUN @@ -70,7 +70,7 @@ Samples of directive flag used in the `common/Makefile.ha` and your suggested DE #PLATFORM_DEFS += -DWITH_STANDALONE_HF_MATTYRUN #PLATFORM_DEFS += -DWITH_STANDALONE_HF_COLIN #PLATFORM_DEFS += -DWITH_STANDALONE_HF_BOG -#PLATFORM_DEFS += -DWITH_STANDALONE_LF_FOORUN +#PLATFORM_DEFS += -DWITH_STANDALONE_LF_FOO ``` ## Update ARMSRC/MAKEFILE @@ -90,11 +90,11 @@ endif ## Adding identification string of your mode Do please add a identification string in a function called `ModInfo` inside your source code file. -This will enable an easy way to detect on client side which standalone mods has been installed on the device. +This will enable an easy way to detect on client side which standalone mode has been installed on the device. ```` void ModInfo(void) { - DbpString(" LF good description of your mode - aka FooRun (my name)"); + DbpString(" LF good description of your mode - aka FooRun (your name)"); } ```` From 7d6f971db4ca1b9c06e166c223e87b8306b5da8e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 26 Apr 2019 00:04:32 +0200 Subject: [PATCH 2/5] archive and fix hid-flasher --- .../flasher}/Info.plist | 0 .../flasher}/Makefile | 11 ++++------- .../flasher}/elf.h | 0 .../flasher}/flash.c | 2 +- .../flasher}/flash.h | 0 .../flasher}/flasher.c | 2 +- .../flasher}/obj/.dummy | 0 .../flasher}/proxendian.h | 0 .../flasher}/proxmark3.h | 0 .../flasher}/proxusb.c | 1 + .../flasher}/proxusb.h | 1 - .../flasher}/sleep.h | 0 .../flasher}/usb_cmd.h | 0 client/{ => deprecated-hid-flasher}/unbind-proxmark | 0 14 files changed, 7 insertions(+), 10 deletions(-) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/Info.plist (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/Makefile (73%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/elf.h (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/flash.c (99%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/flash.h (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/flasher.c (99%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/obj/.dummy (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/proxendian.h (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/proxmark3.h (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/proxusb.c (99%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/proxusb.h (97%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/sleep.h (100%) rename client/{hid-flasher => deprecated-hid-flasher/flasher}/usb_cmd.h (100%) rename client/{ => deprecated-hid-flasher}/unbind-proxmark (100%) diff --git a/client/hid-flasher/Info.plist b/client/deprecated-hid-flasher/flasher/Info.plist similarity index 100% rename from client/hid-flasher/Info.plist rename to client/deprecated-hid-flasher/flasher/Info.plist diff --git a/client/hid-flasher/Makefile b/client/deprecated-hid-flasher/flasher/Makefile similarity index 73% rename from client/hid-flasher/Makefile rename to client/deprecated-hid-flasher/flasher/Makefile index 90b29748f..bff511459 100644 --- a/client/hid-flasher/Makefile +++ b/client/deprecated-hid-flasher/flasher/Makefile @@ -3,26 +3,23 @@ # at your option, any later version. See the LICENSE.txt file for the text of # the license. #----------------------------------------------------------------------------- -include ../../common/Makefile.common CC=gcc CXX=g++ #COMMON_FLAGS = -m32 -VPATH = ../../common OBJDIR = obj +LDLIBS = -lreadline -lpthread +CFLAGS = -std=gnu99 -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3 ifeq ($(platform),Darwin) - LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb-1.0 -lreadline -lpthread - CFLAGS = -std=gnu99 -I. -I../include -I../common -I/usr/local/include -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3 + LDLIBS += -lusb-1.0 else - LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb -lreadline -lpthread - CFLAGS = -std=gnu99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3 + LDLIBS += -lusb endif LDFLAGS = $(COMMON_FLAGS) CXXFLAGS = -QTLDLIBS = RM = rm -f BINS = flasher diff --git a/client/hid-flasher/elf.h b/client/deprecated-hid-flasher/flasher/elf.h similarity index 100% rename from client/hid-flasher/elf.h rename to client/deprecated-hid-flasher/flasher/elf.h diff --git a/client/hid-flasher/flash.c b/client/deprecated-hid-flasher/flasher/flash.c similarity index 99% rename from client/hid-flasher/flash.c rename to client/deprecated-hid-flasher/flasher/flash.c index 22f57a817..48d0f00de 100644 --- a/client/hid-flasher/flash.c +++ b/client/deprecated-hid-flasher/flasher/flash.c @@ -11,11 +11,11 @@ #include #include #include -#include "util_posix.h" #include "proxusb.h" #include "flash.h" #include "elf.h" #include "proxendian.h" +#include "sleep.h" #define FLASH_START 0x100000 #define FLASH_SIZE (256*1024) diff --git a/client/hid-flasher/flash.h b/client/deprecated-hid-flasher/flasher/flash.h similarity index 100% rename from client/hid-flasher/flash.h rename to client/deprecated-hid-flasher/flasher/flash.h diff --git a/client/hid-flasher/flasher.c b/client/deprecated-hid-flasher/flasher/flasher.c similarity index 99% rename from client/hid-flasher/flasher.c rename to client/deprecated-hid-flasher/flasher/flasher.c index 0cc800826..f9d5f49b7 100644 --- a/client/hid-flasher/flasher.c +++ b/client/deprecated-hid-flasher/flasher/flasher.c @@ -9,9 +9,9 @@ #include #include #include -#include "util_posix.h" #include "proxusb.h" #include "flash.h" +#include "sleep.h" static void usage(char *argv0) { fprintf(stderr, "Usage: %s [-b] image.elf [image.elf...]\n\n", argv0); diff --git a/client/hid-flasher/obj/.dummy b/client/deprecated-hid-flasher/flasher/obj/.dummy similarity index 100% rename from client/hid-flasher/obj/.dummy rename to client/deprecated-hid-flasher/flasher/obj/.dummy diff --git a/client/hid-flasher/proxendian.h b/client/deprecated-hid-flasher/flasher/proxendian.h similarity index 100% rename from client/hid-flasher/proxendian.h rename to client/deprecated-hid-flasher/flasher/proxendian.h diff --git a/client/hid-flasher/proxmark3.h b/client/deprecated-hid-flasher/flasher/proxmark3.h similarity index 100% rename from client/hid-flasher/proxmark3.h rename to client/deprecated-hid-flasher/flasher/proxmark3.h diff --git a/client/hid-flasher/proxusb.c b/client/deprecated-hid-flasher/flasher/proxusb.c similarity index 99% rename from client/hid-flasher/proxusb.c rename to client/deprecated-hid-flasher/flasher/proxusb.c index 7563429d8..71bb0708c 100644 --- a/client/hid-flasher/proxusb.c +++ b/client/deprecated-hid-flasher/flasher/proxusb.c @@ -9,6 +9,7 @@ // USB utilities //----------------------------------------------------------------------------- #include "proxusb.h" +#include "sleep.h" // It seems to be missing for mingw #ifndef ETIMEDOUT diff --git a/client/hid-flasher/proxusb.h b/client/deprecated-hid-flasher/flasher/proxusb.h similarity index 97% rename from client/hid-flasher/proxusb.h rename to client/deprecated-hid-flasher/flasher/proxusb.h index 69d47abd2..f79fd7e33 100644 --- a/client/hid-flasher/proxusb.h +++ b/client/deprecated-hid-flasher/flasher/proxusb.h @@ -22,7 +22,6 @@ #include #include "proxmark3.h" #include "usb_cmd.h" -#include "util_posix.h" extern unsigned char return_on_error; extern unsigned char error_occured; diff --git a/client/hid-flasher/sleep.h b/client/deprecated-hid-flasher/flasher/sleep.h similarity index 100% rename from client/hid-flasher/sleep.h rename to client/deprecated-hid-flasher/flasher/sleep.h diff --git a/client/hid-flasher/usb_cmd.h b/client/deprecated-hid-flasher/flasher/usb_cmd.h similarity index 100% rename from client/hid-flasher/usb_cmd.h rename to client/deprecated-hid-flasher/flasher/usb_cmd.h diff --git a/client/unbind-proxmark b/client/deprecated-hid-flasher/unbind-proxmark similarity index 100% rename from client/unbind-proxmark rename to client/deprecated-hid-flasher/unbind-proxmark From acc101ed37fcc1241b935ad63a9e31ce7703ea1c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 26 Apr 2019 08:29:21 +0200 Subject: [PATCH 3/5] doc magic --- include/proxmark3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/proxmark3.h b/include/proxmark3.h index 8fedafb3e..0dc4aea94 100644 --- a/include/proxmark3.h +++ b/include/proxmark3.h @@ -108,7 +108,7 @@ //NVDD goes LOW when USB is attached. #define USB_ATTACHED() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_NVDD_ON) == GPIO_NVDD_ON) -#define VERSION_INFORMATION_MAGIC 0x56334d50 +#define VERSION_INFORMATION_MAGIC 0x56334d50 // "PM3V" struct version_information { int magic; /* Magic sequence to identify this as a correct version information structure. Must be VERSION_INFORMATION_MAGIC */ char versionversion; /* Must be 1 */ @@ -118,7 +118,7 @@ struct version_information { char buildtime[30]; /* string with the build time */ } __attribute__((packed)); -#define COMMON_AREA_MAGIC 0x43334d50 +#define COMMON_AREA_MAGIC 0x43334d50 // "PM3C" #define COMMON_AREA_COMMAND_NONE 0 #define COMMON_AREA_COMMAND_ENTER_FLASH_MODE 1 struct common_area { From 70995f0f1e70e3b3f74f3970ee5b469643d069c8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 26 Apr 2019 08:29:48 +0200 Subject: [PATCH 4/5] use color macros --- client/cmdhw.c | 6 +----- client/mifare/mifarehost.c | 2 +- client/proxmark3.c | 12 ++++++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index bd013e706..a01b72dca 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -477,11 +477,7 @@ void pm3_version(bool verbose) { clearCommandBuffer(); SendCommand(&c); if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { -#ifdef __WIN32 - PrintAndLogEx(NORMAL, "\n [ Proxmark3 RFID instrument ]\n"); -#else - PrintAndLogEx(NORMAL, "\n\e[34m [ Proxmark3 RFID instrument ]\e[0m\n"); -#endif + PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); char s[60] = {0}; #if defined(WITH_FLASH) || defined(WITH_SMARTCARD) || defined(WITH_FPC) strncat(s, "build for RDV40 with ", sizeof(s) - strlen(s) - 1); diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 211eaea02..5677a1849 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -935,7 +935,7 @@ int detect_classic_nackbug(bool verbose) { } else { printf( #if defined(__linux__) || (__APPLE__) - "\e[32m\e[s%c\e[u\e[0m", star[(staridx++ % 4) ] + _GREEN_("\e[s%c\e[u"), star[(staridx++ % 4) ] #else "." #endif diff --git a/client/proxmark3.c b/client/proxmark3.c index 267071c21..aef3c5979 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -32,12 +32,12 @@ static void showBanner(void) { printf("\n\n"); #if defined(__linux__) || (__APPLE__) - printf("\e[34m██████╗ ███╗ ███╗ ████╗\e[0m ...iceman fork\n"); - printf("\e[34m██╔══██╗████╗ ████║ ══█║\e[0m ...dedicated to \e[34mRDV40\e[0m\n"); - printf("\e[34m██████╔╝██╔████╔██║ ████╔╝\e[0m\n"); - printf("\e[34m██╔═══╝ ██║╚██╔╝██║ ══█║\e[0m iceman@icesql.net\n"); - printf("\e[34m██║ ██║ ╚═╝ ██║ ████╔╝\e[0m https://github.com/rfidresearchgroup/proxmark3/\n"); - printf("\e[34m╚═╝ ╚═╝ ╚═╝ ╚═══╝\e[0m pre-release v4.0\n"); + 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"); #else printf("======. ===. ===. ====. ...iceman fork\n"); printf("==...==.====. ====. ..=. ...dedicated to RDV40\n"); From cb452c98ba5053e96de86050849b0aea9fa78a59 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 26 Apr 2019 10:36:06 +0200 Subject: [PATCH 5/5] rework Dbprintf & add color support --- armsrc/BigBuf.c | 4 +- armsrc/Standalone/hf_colin.c | 190 ++++++++++++++++---------------- armsrc/Standalone/hf_mattyrun.c | 22 ++-- armsrc/appmain.c | 20 ++-- armsrc/apps.h | 1 + armsrc/flashmem.c | 2 +- armsrc/fpgaloader.c | 2 +- armsrc/lfops.c | 2 +- armsrc/lfsampling.c | 2 +- armsrc/util.h | 7 ++ client/comms.c | 56 +++++++--- common/i2c.c | 2 +- include/usb_cmd.h | 11 +- 13 files changed, 175 insertions(+), 146 deletions(-) diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 267e6811b..ef768ab2b 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -96,10 +96,10 @@ void BigBuf_free_keep_EM(void) { } void BigBuf_print_status(void) { - Dbprintf("Memory"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Memory")); Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE); Dbprintf(" Available memory........%d", BigBuf_hi); - Dbprintf("Tracing"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Tracing")); Dbprintf(" tracing ................%d", tracing); Dbprintf(" traceLen ...............%d", traceLen); } diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 681223a02..dbec84760 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -54,7 +54,7 @@ void cjPrintBigArray(const char *bigar, int len, uint8_t newlines, uint8_t debug } if (newlines > 0) { - DbprintfEx(FLAG_NOLOG, " "); + DbprintfEx(FLAG_NEWLINE, " "); } } */ @@ -81,7 +81,7 @@ void cjPrintKey(uint64_t key, uint8_t *foundKey, uint16_t sectorNo, uint8_t type char tosendkey[13]; sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[0], foundKey[1], foundKey[2], foundKey[3], foundKey[4], foundKey[5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x | KEY : %s | TYP: %d", sectorNo, tosendkey, type); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x | KEY : %s | TYP: %d", sectorNo, tosendkey, type); } */ @@ -94,7 +94,7 @@ void ReadLastTagFromFlash() { uint32_t startidx = 0; uint16_t len = 1024; - DbprintfEx(FLAG_NOLOG, "Button HELD ! Using LAST Known TAG for Simulation..."); + DbprintfEx(FLAG_NEWLINE, "Button HELD ! Using LAST Known TAG for Simulation..."); cjSetCursLeft(); size_t size = len; @@ -114,7 +114,7 @@ void ReadLastTagFromFlash() { if (isok == len) { emlSetMem(mem, 0, 64); } else { - DbprintfEx(FLAG_NOLOG, "FlashMem reading failed | %d | %d", len, isok); + DbprintfEx(FLAG_NEWLINE, "FlashMem reading failed | %d | %d", len, isok); cjSetCursLeft(); FlashStop(); SpinOff(100); @@ -122,9 +122,9 @@ void ReadLastTagFromFlash() { } } end_time = GetTickCount(); - DbprintfEx(FLAG_NOLOG, "[OK] Last tag recovered from FLASHMEM set to emulator"); + DbprintfEx(FLAG_NEWLINE, "[OK] Last tag recovered from FLASHMEM set to emulator"); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s[IN]%s %s%dms%s for TAG_FLASH_READ", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s[IN]%s %s%dms%s for TAG_FLASH_READ", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_); cjSetCursLeft(); FlashStop(); SpinOff(0); @@ -173,7 +173,7 @@ void WriteTagToFlash(uint8_t index, size_t size) { uint8_t isok = (res == bytes_in_packet) ? 1 : 0; if (!isok) { - DbprintfEx(FLAG_NOLOG, "FlashMem write FAILEd [offset %u]", bytes_sent); + DbprintfEx(FLAG_NEWLINE, "FlashMem write FAILEd [offset %u]", bytes_sent); cjSetCursLeft(); SpinOff(100); return; @@ -186,9 +186,9 @@ void WriteTagToFlash(uint8_t index, size_t size) { } end_time = GetTickCount(); - DbprintfEx(FLAG_NOLOG, "[OK] TAG WRITTEN TO FLASH ! [0-to offset %u]", bytes_sent); + DbprintfEx(FLAG_NEWLINE, "[OK] TAG WRITTEN TO FLASH ! [0-to offset %u]", bytes_sent); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s[IN]%s %s%dms%s for TAG_FLASH_WRITE", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s[IN]%s %s%dms%s for TAG_FLASH_WRITE", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_); cjSetCursLeft(); FlashStop(); SpinOff(0); @@ -328,9 +328,9 @@ void RunMod() { // banner: vtsend_reset(NULL); - DbprintfEx(FLAG_NOLOG, "\r\n%s", clearTerm); - DbprintfEx(FLAG_NOLOG, "%s%s%s", _CYAN_, sub_banner, _WHITE_); - DbprintfEx(FLAG_NOLOG, "%s>>%s C.J.B's MifareFastPwn Started\r\n", _RED_, _WHITE_); + 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_); currline = 20; curlline = 20; @@ -342,7 +342,7 @@ failtag: vtsend_cursor_position_save(NULL); vtsend_set_attribute(NULL, 1); vtsend_set_attribute(NULL, 5); - DbprintfEx(FLAG_NOLOG, "\t\t\t[ Waiting For Tag ]"); + DbprintfEx(FLAG_NEWLINE, "\t\t\t[ Waiting For Tag ]"); vtsend_set_attribute(NULL, 0); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); @@ -360,7 +360,7 @@ failtag: if (BUTTON_HELD(10) > 0) { WDT_HIT(); - DbprintfEx(FLAG_NOLOG, "\t\t\t[ READING FLASH ]"); + DbprintfEx(FLAG_NEWLINE, "\t\t\t[ READING FLASH ]"); ReadLastTagFromFlash(); goto readysim; } @@ -370,16 +370,16 @@ failtag: FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); vtsend_cursor_position_restore(NULL); - DbprintfEx(FLAG_NOLOG, "\t\t\t%s[ GOT a Tag ! ]%s", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "\t\t\t%s[ GOT a Tag ! ]%s", _GREEN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "\t\t\t `---> Breaking keys ---->"); + DbprintfEx(FLAG_NEWLINE, "\t\t\t `---> Breaking keys ---->"); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "\t%sGOT TAG :%s %08x%s", _RED_, _CYAN_, cjcuid, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "\t%sGOT TAG :%s %08x%s", _RED_, _CYAN_, cjcuid, _WHITE_); if (cjcuid == 0) { cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>%s BUG: 0000_CJCUID! Retrying...", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>%s BUG: 0000_CJCUID! Retrying...", _RED_, _WHITE_); SpinErr(0, 100, 8); goto failtag; } @@ -387,11 +387,11 @@ failtag: SpinOff(50); LED_B_ON(); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "--------+--------------------+-------"); + DbprintfEx(FLAG_NEWLINE, "--------+--------------------+-------"); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, " SECTOR | KEY | A/B "); + DbprintfEx(FLAG_NEWLINE, " SECTOR | KEY | A/B "); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "--------+--------------------+-------"); + DbprintfEx(FLAG_NEWLINE, "--------+--------------------+-------"); uint32_t end_time; uint32_t start_time = end_time = GetTickCount(); @@ -445,26 +445,26 @@ failtag: char tosendkey[13]; num_to_bytes(key64, 6, foundKey[type][sec]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %012" PRIx64 " ; TYP: %i", sec, key64, type); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %012" PRIx64 " ; TYP: %i", sec, key64, type); /*cmd_send(CMD_CJB_INFORM_CLIENT_KEY, 12, sec, type, tosendkey, 12);*/ switch (key64) { ///////////////////////////////////////////////////////// // COMMON SCHEME 1 : INFINITRON/HEXACT case 0x484558414354: cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%sDetected: %s INFI_HEXACT_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%sDetected: %s INFI_HEXACT_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_); ; // Type 0 / A first uint16_t t = 0; @@ -473,7 +473,7 @@ failtag: sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][s][0], foundKey[t][s][1], foundKey[t][s][2], foundKey[t][s][3], foundKey[t][s][4], foundKey[t][s][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, t); } t = 1; uint16_t sectorNo = 0; @@ -482,112 +482,112 @@ failtag: foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 1; num_to_bytes(0x49fae4e3849f, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 2; num_to_bytes(0x38fcf33072e0, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 3; num_to_bytes(0x8ad5517b4b18, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 4; num_to_bytes(0x509359f131b1, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 5; num_to_bytes(0x6c78928e1317, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 6; num_to_bytes(0xaa0720018738, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 7; num_to_bytes(0xa6cac2886412, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 8; num_to_bytes(0x62d0c424ed8e, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 9; num_to_bytes(0xe64a986a5d94, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 10; num_to_bytes(0x8fa1d601d0a2, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 11; num_to_bytes(0x89347350bd36, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 12; num_to_bytes(0x66d2b7dc39ef, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 13; num_to_bytes(0x6bc1e1ae547d, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 14; num_to_bytes(0x22729a9bd40f, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); sectorNo = 15; num_to_bytes(0x484558414354, 6, foundKey[t][sectorNo]); sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[t][sectorNo][0], foundKey[t][sectorNo][1], foundKey[t][sectorNo][2], foundKey[t][sectorNo][3], foundKey[t][sectorNo][4], foundKey[t][sectorNo][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", sectorNo, tosendkey, t); trapped = 1; break; ////////////////END OF SCHEME 1////////////////////////////// @@ -597,19 +597,19 @@ failtag: case 0x8829da9daf76: cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%sDetected :%sURMET_CAPTIVE_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%sDetected :%sURMET_CAPTIVE_VIGIK_TAG%s", _ORANGE_, _CYAN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_); cjSetCursLeft(); // emlClearMem(); @@ -626,7 +626,7 @@ failtag: foundKey[i][s][5] ); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, i); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, i); } } trapped = 1; @@ -639,19 +639,19 @@ failtag: case 0x424c41524f4e: cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>>>>>>!*STOP*!<<<<<<<<<<<<<<%s", _RED_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, " .TAG SEEMS %sDETERMINISTIC%s. ", _GREEN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s Detected :%sNORALSY_VIGIK_TAG %s", _ORANGE_, _CYAN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s Detected :%sNORALSY_VIGIK_TAG %s", _ORANGE_, _CYAN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "...%s[%sKey_derivation_schemeTest%s]%s...", _YELLOW_, _GREEN_, _YELLOW_, _GREEN_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>>>>>>!*DONE*!<<<<<<<<<<<<<<%s", _GREEN_, _WHITE_); t = 0; for (uint16_t s = 0; s < sectorsCnt; s++) { @@ -664,7 +664,7 @@ failtag: foundKey[t][s][4], foundKey[t][s][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, t); } t = 1; @@ -678,7 +678,7 @@ failtag: foundKey[t][s][4], foundKey[t][s][5]); cjSetCursRight(); - DbprintfEx(FLAG_NOLOG, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, t); + DbprintfEx(FLAG_NEWLINE, "SEC: %02x ; KEY : %s ; TYP: %d", s, tosendkey, t); } trapped = 1; break; @@ -692,7 +692,7 @@ failtag: if (!allKeysFound) { cjSetCursLeft(); cjTabulize(); - DbprintfEx(FLAG_NOLOG, "%s[ FAIL ]%s\r\n->did not found all the keys :'(", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%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_NOLOG, "%s>>%s Setting Keys->Emulator MEM...[%sOK%s]", _YELLOW_, _WHITE_, _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>%s Setting Keys->Emulator MEM...[%sOK%s]", _YELLOW_, _WHITE_, _GREEN_, _WHITE_); /* filling TAG to emulator */ uint8_t filled = 0; cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>%s Filling Emulator <- from A keys...", _YELLOW_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>%s Filling Emulator <- from A keys...", _YELLOW_, _WHITE_); e_MifareECardLoad(sectorsCnt, 0, 0, &filled); if (filled != 1) { cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>%s W_FAILURE ! %sTrying fallback B keys....", _RED_, _ORANGE_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%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_NOLOG, "FATAL:EML_FALLBACKFILL_B"); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "FATAL:EML_FALLBACKFILL_B"); SpinErr(2, 100, 8); SpinOff(100); return; @@ -739,13 +739,13 @@ failtag: end_time = GetTickCount(); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s>>%s Time for VIGIK break :%s%dms%s", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%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); vtsend_set_attribute(NULL, 5); cjTabulize(); - DbprintfEx(FLAG_NOLOG, "[ WRITING FLASH ]"); + DbprintfEx(FLAG_NEWLINE, "[ WRITING FLASH ]"); cjSetCursLeft(); cjSetCursLeft(); @@ -755,20 +755,20 @@ readysim: // SIM ? cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "-> We launch Emulation ->"); + DbprintfEx(FLAG_NEWLINE, "-> We launch Emulation ->"); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "%s!> HOLD ON : %s When you'll click, simm will stop", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s!> HOLD ON : %s When you'll click, simm will stop", _RED_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "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|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_, _CYAN_, _WHITE_); cjSetCursLeft(); cjSetCursLeft(); cjTabulize(); - DbprintfEx(FLAG_NOLOG, "[ SIMULATION ]"); + DbprintfEx(FLAG_NEWLINE, "[ SIMULATION ]"); vtsend_set_attribute(NULL, 0); SpinOff(100); @@ -777,21 +777,21 @@ readysim: LED_C_OFF(); SpinOff(50); vtsend_cursor_position_restore(NULL); - DbprintfEx(FLAG_NOLOG, "[ SIMUL ENDED ]%s", _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "[ SIMUL ENDED ]%s", _GREEN_, _WHITE_); cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "<- We're out of Emulation"); + DbprintfEx(FLAG_NEWLINE, "<- We're out of Emulation"); // END SIM cjSetCursLeft(); - DbprintfEx(FLAG_NOLOG, "-> Trying a clone !"); + DbprintfEx(FLAG_NEWLINE, "-> Trying a clone !"); saMifareMakeTag(); cjSetCursLeft(); vtsend_cursor_position_restore(NULL); - DbprintfEx(FLAG_NOLOG, "%s[ CLONED? ]", _CYAN_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s[ CLONED? ]", _CYAN_); - DbprintfEx(FLAG_NOLOG, "-> End Cloning."); + DbprintfEx(FLAG_NEWLINE, "-> End Cloning."); WDT_HIT(); // Debunk... @@ -799,7 +799,7 @@ readysim: cjTabulize(); vtsend_set_attribute(NULL, 0); vtsend_set_attribute(NULL, 7); - DbprintfEx(FLAG_NOLOG, "- [ LA FIN ] -\r\n%s`-> You can take shell back :) ...", _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "- [ LA FIN ] -\r\n%s`-> You can take shell back :) ...", _WHITE_); cjSetCursLeft(); vtsend_set_attribute(NULL, 0); SpinErr(3, 100, 16); @@ -844,14 +844,14 @@ void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *dat if (isOK && mifare_classic_auth(pcs, cjcuid, FirstBlockOfSector(s), keyType, ui64Key, AUTH_FIRST)) { if (MF_DBGLEVEL >= 1) - DbprintfEx(FLAG_NOLOG, "Sector[%2d]. Auth error", s); + DbprintfEx(FLAG_NEWLINE, "Sector[%2d]. Auth error", s); break; } } else { if (isOK && mifare_classic_auth(pcs, cjcuid, FirstBlockOfSector(s), keyType, ui64Key, AUTH_NESTED)) { isOK = false; if (MF_DBGLEVEL >= 1) - DbprintfEx(FLAG_NOLOG, "Sector[%2d]. Auth nested error", s); + DbprintfEx(FLAG_NEWLINE, "Sector[%2d]. Auth nested error", s); break; } } @@ -860,7 +860,7 @@ void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *dat if (isOK && mifare_classic_readblock(pcs, cjcuid, FirstBlockOfSector(s) + blockNo, dataoutbuf)) { isOK = false; if (MF_DBGLEVEL >= 1) - DbprintfEx(FLAG_NOLOG, "Error reading sector %2d block %2d", s, blockNo); + DbprintfEx(FLAG_NEWLINE, "Error reading sector %2d block %2d", s, blockNo); break; }; if (isOK) { @@ -881,7 +881,7 @@ void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *dat if (mifare_classic_halt(pcs, cjcuid)) { if (MF_DBGLEVEL >= 1) - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); }; crypto1_destroy(pcs); @@ -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_NOLOG, "%sFATAL%s : E_MF_LOSTTAG", _RED_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%sFATAL%s : E_MF_LOSTTAG", _RED_, _WHITE_); return -1; } @@ -938,12 +938,12 @@ void saMifareMakeTag(void) { cjTabulize(); vtsend_cursor_position_save(NULL); vtsend_set_attribute(NULL, 1); - DbprintfEx(FLAG_NOLOG, "[ CLONING ]"); + DbprintfEx(FLAG_NEWLINE, "[ CLONING ]"); vtsend_set_attribute(NULL, 0); cjSetCursFRight(); - DbprintfEx(FLAG_NOLOG, ">> Write to Special:"); + DbprintfEx(FLAG_NEWLINE, ">> Write to Special:"); int flags = 0; for (int blockNum = 0; blockNum < 16 * 4; blockNum++) { uint8_t mblock[16]; @@ -968,7 +968,7 @@ void saMifareMakeTag(void) { if (currfline > 53) { currfline = 54; } - DbprintfEx(FLAG_NOLOG, "Block :%02x %sOK%s", blockNum, _GREEN_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "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_NOLOG, "`--> %sFAIL%s : CHN_FAIL_BLK_%02x_NOK", _RED_, _WHITE_, blockNum); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "`--> %sFAIL%s : CHN_FAIL_BLK_%02x_NOK", _RED_, _WHITE_, blockNum); cjSetCursFRight(); - DbprintfEx(FLAG_NOLOG, "%s>>>>%s STOP AT %02x", _RED_, _WHITE_, blockNum); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>%s STOP AT %02x", _RED_, _WHITE_, blockNum); cfail++; break; } cjSetCursFRight(); - DbprintfEx(FLAG_NOLOG, "%s>>>>>>>> END <<<<<<<<%s", _YELLOW_, _WHITE_); + DbprintfEx(FLAG_NEWLINE|FLAG_ANSI, "%s>>>>>>>> END <<<<<<<<%s", _YELLOW_, _WHITE_); // break; /*if (cfail == 1) { DbprintfEx(FLAG_RAWPRINT,"FATAL: E_MF_HARA_KIRI_\r\n"); @@ -1039,12 +1039,12 @@ int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *data // get UID from chip if (workFlags & 0x01) { if (!iso14443a_select_card(cjuid, NULL, &cjcuid, true, 0, true)) { - DbprintfEx(FLAG_NOLOG, "Can't select card"); + DbprintfEx(FLAG_NEWLINE, "Can't select card"); break; }; if (mifare_classic_halt(NULL, cjcuid)) { - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); break; }; }; @@ -1053,18 +1053,18 @@ int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *data if (needWipe) { ReaderTransmitBitsPar(wupC1, 7, 0, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wupC1 error"); + DbprintfEx(FLAG_NEWLINE, "wupC1 error"); break; }; ReaderTransmit(wipeC, sizeof(wipeC), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wipeC error"); + DbprintfEx(FLAG_NEWLINE, "wipeC error"); break; }; if (mifare_classic_halt(NULL, cjcuid)) { - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); break; }; }; @@ -1074,19 +1074,19 @@ int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *data if (workFlags & 0x02) { ReaderTransmitBitsPar(wupC1, 7, 0, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wupC1 error"); + DbprintfEx(FLAG_NEWLINE, "wupC1 error"); break; }; ReaderTransmit(wupC2, sizeof(wupC2), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wupC2 errorv"); + DbprintfEx(FLAG_NEWLINE, "wupC2 errorv"); break; }; } if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "write block send command error"); + DbprintfEx(FLAG_NEWLINE, "write block send command error"); break; }; @@ -1094,7 +1094,7 @@ int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *data AddCrc14A(d_block, 16); ReaderTransmit(d_block, sizeof(d_block), NULL); if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "write block send data error"); + DbprintfEx(FLAG_NEWLINE, "write block send data error"); break; }; @@ -1102,7 +1102,7 @@ int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *data if (mifare_classic_halt(NULL, cjcuid)) { cjSetCursFRight(); - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); break; }; } diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index 9bcfd63d3..002a50c51 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -75,12 +75,12 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_ // get UID from chip if (workFlags & 0x01) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - DbprintfEx(FLAG_NOLOG, "Can't select card"); + DbprintfEx(FLAG_NEWLINE, "Can't select card"); break; }; if (mifare_classic_halt(NULL, cuid)) { - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); break; }; }; @@ -89,18 +89,18 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_ if (needWipe) { ReaderTransmitBitsPar(wupC1, 7, 0, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wupC1 error"); + DbprintfEx(FLAG_NEWLINE, "wupC1 error"); break; }; ReaderTransmit(wipeC, sizeof(wipeC), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wipeC error"); + DbprintfEx(FLAG_NEWLINE, "wipeC error"); break; }; if (mifare_classic_halt(NULL, cuid)) { - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); break; }; }; @@ -110,19 +110,19 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_ if (workFlags & 0x02) { ReaderTransmitBitsPar(wupC1, 7, 0, NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wupC1 error"); + DbprintfEx(FLAG_NEWLINE, "wupC1 error"); break; }; ReaderTransmit(wupC2, sizeof(wupC2), NULL); if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "wupC2 errorv"); + DbprintfEx(FLAG_NEWLINE, "wupC2 errorv"); break; }; } if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "write block send command error"); + DbprintfEx(FLAG_NEWLINE, "write block send command error"); break; }; @@ -130,13 +130,13 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_ AddCrc14A(d_block, 16); ReaderTransmit(d_block, sizeof(d_block), NULL); if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) { - DbprintfEx(FLAG_NOLOG, "write block send data error"); + DbprintfEx(FLAG_NEWLINE, "write block send data error"); break; }; if (workFlags & 0x04) { if (mifare_classic_halt(NULL, cuid)) { - DbprintfEx(FLAG_NOLOG, "Halt error"); + DbprintfEx(FLAG_NEWLINE, "Halt error"); break; }; } @@ -168,7 +168,7 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui /* no need for anticollision. just verify tag is still here */ // if (!iso14443a_fast_select_card(cjuid, 0)) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - DbprintfEx(FLAG_NOLOG, "FATAL : E_MF_LOSTTAG"); + DbprintfEx(FLAG_NEWLINE, "FATAL : E_MF_LOSTTAG"); return -1; } diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 8c42a6017..066f3a5d7 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -114,16 +114,16 @@ void print_result(char *name, uint8_t *buf, size_t len) { // Debug print functions, to go out over USB, to the usual PC-side client. //============================================================================= -void DbpStringEx(char *str, uint32_t cmd) { +void DbpStringEx(uint32_t flags, char *str) { #if DEBUG uint8_t len = strlen(str); - cmd_send(CMD_DEBUG_PRINT_STRING, len, cmd, 0, (uint8_t *)str, len); + cmd_send(CMD_DEBUG_PRINT_STRING, len, flags, 0, (uint8_t *)str, len); #endif } void DbpString(char *str) { #if DEBUG - DbpStringEx(str, 0); + DbpStringEx(FLAG_LOG, str); #endif } @@ -132,7 +132,7 @@ void DbpIntegers(int x1, int x2, int x3) { cmd_send(CMD_DEBUG_PRINT_INTEGERS, x1, x2, x3, 0, 0); } #endif -void DbprintfEx(uint32_t cmd, const char *fmt, ...) { +void DbprintfEx(uint32_t flags, const char *fmt, ...) { #if DEBUG // should probably limit size here; oh well, let's just use a big buffer char output_string[128] = {0x00}; @@ -141,7 +141,7 @@ void DbprintfEx(uint32_t cmd, const char *fmt, ...) { kvsprintf(fmt, output_string, 10, ap); va_end(ap); - DbpStringEx(output_string, cmd); + DbpStringEx(flags, output_string); #endif } @@ -310,10 +310,10 @@ void MeasureAntennaTuningHf(void) { } else { volt = (MAX_ADC_HF_VOLTAGE_RDV40 * AvgAdc(ADC_CHAN_HF_RDV40)) >> 10; } - DbprintfEx(FLAG_NONEWLINE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000)); + DbprintfEx(FLAG_INPLACE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000)); } FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - DbprintfEx(FLAG_NOOPT, "\n[+] cancelled", 1); + DbprintfEx(FLAG_LOG, "\n[+] cancelled", 1); } void ReadMem(int addr) { @@ -365,7 +365,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 UsbCommand structure included. void printUSBSpeed(void) { - Dbprintf("USB Speed"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("USB Speed")); Dbprintf(" Sending USB packets to client..."); #define USB_SPEED_TEST_MIN_TIME 1500 // in milliseconds @@ -406,12 +406,12 @@ void SendStatus(void) { printT55xxConfig(); // LF T55XX Config #endif printUSBSpeed(); - Dbprintf("Various"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Various")); Dbprintf(" MF_DBGLEVEL.............%d", MF_DBGLEVEL); Dbprintf(" ToSendMax...............%d", ToSendMax); Dbprintf(" ToSendBit...............%d", ToSendBit); Dbprintf(" ToSend BUFFERSIZE.......%d", TOSEND_BUFFER_SIZE); - DbpString("Installed StandAlone Mode"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Installed StandAlone Mode")); ModInfo(); //DbpString("Running "); diff --git a/armsrc/apps.h b/armsrc/apps.h index b4c38098c..d356fd052 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -45,6 +45,7 @@ void ReadMem(int addr); void __attribute__((noreturn)) AppMain(void); //void DbpIntegers(int a, int b, int c); void DbpString(char *str); +void DbpStringEx(uint32_t cmd, char *str); void Dbprintf(const char *fmt, ...); void DbprintfEx(uint32_t cmd, const char *fmt, ...); void Dbhexdump(int len, uint8_t *d, bool bAsci); diff --git a/armsrc/flashmem.c b/armsrc/flashmem.c index d2010fe6d..e423805a2 100644 --- a/armsrc/flashmem.c +++ b/armsrc/flashmem.c @@ -512,7 +512,7 @@ void Flash_EraseChip(void) { */ void Flashmem_print_status(void) { - DbpString("Flash memory"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Flash memory")); Dbprintf(" Baudrate................%dMHz", FLASHMEM_SPIBAUDRATE / 1000000); if (!FlashInit()) { diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 1be2c6138..4dd4d4403 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -481,7 +481,7 @@ void SetAdcMuxFor(uint32_t whichGpio) { } void Fpga_print_status(void) { - Dbprintf("Currently loaded FPGA image"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Currently loaded FPGA image")); Dbprintf(" mode....................%s", fpga_version_information[downloaded_bitstream - 1]); } diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 613e786c2..2c4569951 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -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) { - Dbprintf("LF T55XX config"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _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); diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 20473f3e6..becf966c8 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -19,7 +19,7 @@ Default LF config is set to: sample_config config = { 1, 8, 1, 95, 0 } ; void printConfig() { - Dbprintf("LF Sampling config"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _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); diff --git a/armsrc/util.h b/armsrc/util.h index f592f1ff3..b31025a0e 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -18,6 +18,13 @@ #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) #endif diff --git a/client/comms.c b/client/comms.c index c6526f881..6bddf33e2 100644 --- a/client/comms.c +++ b/client/comms.c @@ -154,26 +154,48 @@ static void UsbCommandReceived(UsbCommand *c) { char s[USB_CMD_DATA_SIZE + 1]; memset(s, 0x00, sizeof(s)); size_t len = MIN(c->arg[0], USB_CMD_DATA_SIZE); - memcpy(s, c->d.asBytes, len); uint64_t flag = c->arg[1]; - switch (flag) { - case FLAG_RAWPRINT: - printf("%s", s); - break; - case FLAG_NONEWLINE: - printf("\r%s", s); - break; - case FLAG_NOLOG: - printf("%s\r\n", s); - break; - //case FLAG_NOPROMPT: - // break; - case FLAG_NOOPT: - default: - PrintAndLogEx(NORMAL, "#db# %s", s); - break; +#if defined(__linux__) || (__APPLE__) + memcpy(s, c->d.asBytes, len); +#else + if (flag & FLAG_ANSI) + // Filter out ANSI sequences on these OS + uint16_t si=0; + for (uint16_t i=0; i < len; i++) { + if ((c->d.asBytes[i] == '\x1b') && (i < len - 1) && (c->d.asBytes[i+1] >= 0x40) && (c->d.asBytes[i+1] <= 0x5F)) { // entering ANSI sequence + i++; + if ((c->d.asBytes[i] == '[') && (i < len - 1)) { // entering CSI sequence + i++; + while ((i < len - 1) && (c->d.asBytes[i] >= 0x30) && (c->d.asBytes[i] <= 0x3F)) { // parameter bytes + i++; + } + while ((i < len - 1) && (c->d.asBytes[i] >= 0x20) && (c->d.asBytes[i] <= 0x2F)) { // intermediate bytes + i++; + } + if ((c->d.asBytes[i] >= 0x40) && (c->d.asBytes[i] <= 0x7F)) { // final byte + continue; + } + } else { + continue; + } + } + s[si++] = c->d.asBytes[i]; + } + } else { + memcpy(s, c->d.asBytes, len); } +#endif + if (flag & FLAG_LOG) { + PrintAndLogEx(NORMAL, "#db# %s", s); + } else { + if (flag & FLAG_INPLACE) + printf("\r"); + printf("%s", s); + if (flag & FLAG_NEWLINE) + printf("\r\n"); + } + fflush(stdout); break; } diff --git a/common/i2c.c b/common/i2c.c index 5094b450a..8cb88d9b0 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -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) { - DbpString("Smart card module (ISO 7816)"); + DbpStringEx(FLAG_LOG|FLAG_ANSI, _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); diff --git a/include/usb_cmd.h b/include/usb_cmd.h index 57f2c46fd..4d3f61c07 100644 --- a/include/usb_cmd.h +++ b/include/usb_cmd.h @@ -311,12 +311,11 @@ typedef struct { #define FLAG_ICLASS_READER_CEDITKEY 0x40 // Dbprintf flags -#define FLAG_RAWPRINT 0x0111 -#define FLAG_NOOPT 0x0000 -#define FLAG_NOLOG 0x0001 -#define FLAG_NONEWLINE 0x0010 -#define FLAG_NOPROMPT 0x0100 - +#define FLAG_RAWPRINT 0x00 +#define FLAG_LOG 0x01 +#define FLAG_NEWLINE 0x02 +#define FLAG_INPLACE 0x04 +#define FLAG_ANSI 0x08 // CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions: /* Whether a bootloader that understands the common_area is present */