From 563050c8ba161cb375eceac2891dc84a5e646505 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Wed, 10 Jul 2019 18:43:19 +0200 Subject: [PATCH 01/40] Fix compilation under MacOSX --- client/Makefile | 7 ++++++- client/jansson/Makefile | 13 ++++++++++++- client/tinycbor/Makefile | 7 +++++++ common/Makefile.common | 6 ++---- common/mbedtls/Makefile | 7 +++++++ liblua/Makefile | 7 +++++++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/client/Makefile b/client/Makefile index 490716eda..a1109a497 100644 --- a/client/Makefile +++ b/client/Makefile @@ -31,7 +31,12 @@ platform = $(shell uname) VPATH = ../common ../zlib ../uart OBJDIR = obj -LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread -lm +LDLIBS = +ifneq ($(platform),Darwin) + LDLIBS += -L/opt/local/lib +endif +LDLIBS += -L/usr/local/lib -lreadline -lpthread -lm + # RPi Zero gcc requires -latomic # but MacOSX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld # doesn't recognize option --as-needed diff --git a/client/jansson/Makefile b/client/jansson/Makefile index 323d26216..1a60613d0 100644 --- a/client/jansson/Makefile +++ b/client/jansson/Makefile @@ -36,15 +36,26 @@ CFILES = $(filter %.c, $(libjansson_la_SOURCES)) CMDOBJS = $(CFILES:%.c=%.o) CLEAN = $(CMDOBJS) +platform = $(shell uname) + CC= gcc -CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function -Wno-format-truncation +CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function +ifneq ($(platform),Darwin) +CFLAGS += -Wno-format-truncation +endif + LDFLAGS= $(SYSLDFLAGS) $(libjansson_la_LDFLAGS) LIBS= $(SYSLIBS) $(MYLIBS) DEFAULT_INCLUDES = -I. DEFS = -DHAVE_STDINT_H +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else AR= ar rcs RANLIB= ranlib +endif RM= rm -f TST= echo diff --git a/client/tinycbor/Makefile b/client/tinycbor/Makefile index 8124196eb..af22846e9 100644 --- a/client/tinycbor/Makefile +++ b/client/tinycbor/Makefile @@ -19,14 +19,21 @@ CFILES = $(filter %.c, $(tinycbor_SOURCES)) CMDOBJS = $(CFILES:%.c=%.o) CLEAN = $(CMDOBJS) +platform = $(shell uname) + CC= gcc CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function LIBS= $(SYSLIBS) $(MYLIBS) DEFAULT_INCLUDES = -I. -I.. DEFS = -DHAVE_STDINT_H +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else AR= ar rcs RANLIB= ranlib +endif RM= rm -f TST= echo diff --git a/common/Makefile.common b/common/Makefile.common index 132507547..2ab434562 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -43,15 +43,13 @@ TARFLAGS = -C .. -rvf # amount of shell command line parsing going on. echo "" on # Windows yields literal "", on Linux yields an empty line ifeq ($(shell echo ""),) - -# This is probably a proper system, so we can use uname -UNAME := $(shell uname) DELETE=rm -rf MOVE=mv COPY=cp PATHSEP=/ FLASH_TOOL=client/flasher -DETECTED_OS=$(UNAME) +# This is probably a proper system, so we can use uname +DETECTED_OS=$(platform) else # Assume that we are running on Windows. diff --git a/common/mbedtls/Makefile b/common/mbedtls/Makefile index fa0dff05f..a16b2cfd9 100644 --- a/common/mbedtls/Makefile +++ b/common/mbedtls/Makefile @@ -59,6 +59,8 @@ CFILES = $(filter %.c, $(mbedtls_SOURCES)) CMDOBJS = $(CFILES:%.c=%.o) CLEAN = $(CMDOBJS) +platform = $(shell uname) + CC= gcc CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function LDFLAGS= $(SYSLDFLAGS) $(mbedtls_LDFLAGS) @@ -66,8 +68,13 @@ LIBS= $(SYSLIBS) $(MYLIBS) DEFAULT_INCLUDES = -I. -I.. DEFS = -DHAVE_STDINT_H +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else AR= ar rcs RANLIB= ranlib +endif RM= rm -f TST= echo diff --git a/liblua/Makefile b/liblua/Makefile index bf2a4fa3c..2b3d7614f 100644 --- a/liblua/Makefile +++ b/liblua/Makefile @@ -12,13 +12,20 @@ endif # Your platform. See PLATS for possible values. PLAT= none +platform= $(shell uname) + CC= gcc CFLAGS= -O3 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rc +RANLIB= /usr/bin/ranlib +else AR= ar rc RANLIB= ranlib +endif RM= rm -f SYSCFLAGS= From fa2595a619d15c49639b8641e474426e1d84ee97 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Wed, 10 Jul 2019 18:46:30 +0200 Subject: [PATCH 02/40] Fix Clang warnings --- client/proxguiqt.h | 4 ++-- client/proxmark3.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/proxguiqt.h b/client/proxguiqt.h index 458a70058..e50bfe073 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -97,8 +97,8 @@ class WorkerThread : public QThread { ~WorkerThread(); void run(); private: - char *script_cmds_file = NULL; - char *script_cmd = NULL; + char *script_cmds_file; + char *script_cmd; }; class ProxGuiQT : public QObject { diff --git a/client/proxmark3.c b/client/proxmark3.c index 879b3630b..480f39fa3 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -388,7 +388,7 @@ int main(int argc, char *argv[]) { show_help(false, exec_name); return 1; } - uint32_t tmpspeed = strtoul(argv[i + 1], NULL, 10); + uint64_t tmpspeed = strtoul(argv[i + 1], NULL, 10); if ((tmpspeed == ULONG_MAX) || (tmpspeed == 0)) { PrintAndLogEx(ERR, _RED_("ERROR:") "invalid baudrate: -b " _YELLOW_("%s") "\n", argv[i + 1]); return 1; From 1740d43655a7d90022b0615bceb33b46a87b7c81 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Wed, 10 Jul 2019 18:48:15 +0200 Subject: [PATCH 03/40] Fix EMV bug --- client/emv/cmdemv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index ca3866805..22fdea153 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -287,8 +287,8 @@ static int CmdEMVGPO(const char *Cmd) { PrintAndLogEx(ERR, "Can't create PDOL data."); tlvdb_free(tmp_ext); tlvdb_free(tlvRoot); - if (pdol_data_tlv != &data_tlv); - free(pdol_data_tlv); + if (pdol_data_tlv != &data_tlv) + free(pdol_data_tlv); return PM3_ESOFT; } PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len)); From 4727ab96d7b5379aa5d448607596328a400c801a Mon Sep 17 00:00:00 2001 From: slurdge Date: Wed, 10 Jul 2019 18:41:42 +0200 Subject: [PATCH 04/40] Dynamic report of the chipID for flashing purposes --- bootrom/bootrom.c | 13 +++++++++++-- client/flash.c | 9 ++++++++- client/flash.h | 2 +- client/flasher.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/pm3_cmd.h | 4 ++++ 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index b2811cc6d..e889bb7da 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -122,8 +122,10 @@ void UsbPacketReceived(uint8_t *packet, int len) { switch (c->cmd) { case CMD_DEVICE_INFO: { dont_ack = 1; - arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM | - DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH; + arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | + DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM | + DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH | + DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO; if (common_area.flags.osimage_present) arg0 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT; @@ -131,6 +133,13 @@ void UsbPacketReceived(uint8_t *packet, int len) { } break; + case CMD_CHIP_INFO: { + dont_ack = 1; + arg0 = *(AT91C_DBGU_CIDR); + reply_old(CMD_CHIP_INFO, arg0, 0, 0, 0, 0); + } + break; + case CMD_SETUP_WRITE: { /* The temporary write buffer of the embedded flash controller is mapped to the * whole memory region, only the last 8 bits are decoded. diff --git a/client/flash.c b/client/flash.c index d8ac983e7..3a1350c7c 100644 --- a/client/flash.c +++ b/client/flash.c @@ -347,7 +347,7 @@ static int wait_for_ack(PacketResponseNG *ack) { } // Go into flashing mode -int flash_start_flashing(int enable_bl_writes, char *serial_port_name) { +int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t * chipinfo) { uint32_t state; if (enter_bootloader(serial_port_name) < 0) @@ -356,6 +356,13 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name) { if (get_proxmark_state(&state) < 0) return -1; + if (state & DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) { + SendCommandBL(CMD_CHIP_INFO, 0, 0, 0, NULL, 0); + PacketResponseNG resp; + WaitForResponse(CMD_CHIP_INFO, &resp); + *chipinfo = resp.oldarg[0]; + } + if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) { // This command is stupid. Why the heck does it care which area we're // flashing, as long as it's not the bootloader area? The mind boggles. diff --git a/client/flash.h b/client/flash.h index a230715d1..7140de673 100644 --- a/client/flash.h +++ b/client/flash.h @@ -38,7 +38,7 @@ typedef struct { } flash_file_t; int flash_load(flash_file_t *ctx, const char *name, int can_write_bl); -int flash_start_flashing(int enable_bl_writes, char *serial_port_name); +int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *chipid); int flash_write(flash_file_t *ctx); void flash_free(flash_file_t *ctx); int flash_stop_flashing(void); diff --git a/client/flasher.c b/client/flasher.c index 88c154605..675f123e8 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -35,6 +35,42 @@ static void usage(char *argv0) { #endif } +int chipid_to_mem_avail(uint32_t iChipID) { + int mem_avail = 0; + switch ((iChipID & 0xF00) >> 8) { + case 0: + mem_avail = 0; + break; + case 1: + mem_avail = 8; + break; + case 2: + mem_avail = 16; + break; + case 3: + mem_avail = 32; + break; + case 5: + mem_avail = 64; + break; + case 7: + mem_avail = 128; + break; + case 9: + mem_avail = 256; + break; + case 10: + mem_avail = 512; + break; + case 12: + mem_avail = 1024; + break; + case 14: + mem_avail = 2048; + } + return mem_avail; +} + int main(int argc, char **argv) { int can_write_bl = 0; int num_files = 0; @@ -84,10 +120,13 @@ int main(int argc, char **argv) { return -1; } - res = flash_start_flashing(can_write_bl, serial_port_name); + uint32_t chipid = 0; + res = flash_start_flashing(can_write_bl, serial_port_name, &chipid); if (res < 0) return -1; + PrintAndLogEx(NORMAL, "Available memory on this board: 0x%08x\n", chipid_to_mem_avail(chipid)); + PrintAndLogEx(SUCCESS, "\n" _BLUE_("Flashing...")); for (int i = 0; i < num_files; i++) { diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 772ec02b9..cd129d3fc 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -216,6 +216,7 @@ typedef struct { #define CMD_FINISH_WRITE 0x0003 #define CMD_HARDWARE_RESET 0x0004 #define CMD_START_FLASH 0x0005 +#define CMD_CHIP_INFO 0x0006 #define CMD_NACK 0x00fe #define CMD_ACK 0x00ff @@ -541,6 +542,9 @@ typedef struct { /* Set if this device understands the extend start flash command */ #define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4) +/* Set if this device understands the extend start flash command */ +#define DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO (1<<5) + /* CMD_START_FLASH may have three arguments: start of area to flash, end of area to flash, optional magic. The bootrom will not allow to overwrite itself unless this magic From 99d2ed224a2817fb5c6f7fe90606c82d746aeaee Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jul 2019 21:49:14 +0200 Subject: [PATCH 05/40] Minor changes on bootloader chip info --- client/flasher.c | 12 +++++++++--- include/pm3_cmd.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/flasher.c b/client/flasher.c index 675f123e8..94e2ef6ba 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -125,10 +125,16 @@ int main(int argc, char **argv) { if (res < 0) return -1; - PrintAndLogEx(NORMAL, "Available memory on this board: 0x%08x\n", chipid_to_mem_avail(chipid)); - + int mem_avail = chipid_to_mem_avail(chipid); + if (mem_avail != 0) { + PrintAndLogEx(NORMAL, "Available memory on this board: %uK bytes\n", mem_avail); + } else { + PrintAndLogEx(NORMAL, "Available memory on this board: "_RED_("UNKNOWN")"\n"); + PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new CHIP_INFO command")); + PrintAndLogEx(ERR, _RED_("It is recommended that you update your bootloader") "\n"); + } PrintAndLogEx(SUCCESS, "\n" _BLUE_("Flashing...")); - +// TODO check if enough space on Pm3 mem to write the given files for (int i = 0; i < num_files; i++) { res = flash_write(&files[i]); if (res < 0) diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index cd129d3fc..8eef7e75d 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -542,7 +542,7 @@ typedef struct { /* Set if this device understands the extend start flash command */ #define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4) -/* Set if this device understands the extend start flash command */ +/* Set if this device understands the chip info command */ #define DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO (1<<5) /* CMD_START_FLASH may have three arguments: start of area to flash, From 73bbb2e9e8d16df071fc923a1d311fbe35ca6f73 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jul 2019 22:32:55 +0200 Subject: [PATCH 06/40] Silent properly GCC format-truncation warnings in jansson --- client/jansson/Makefile | 3 --- client/jansson/load.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/client/jansson/Makefile b/client/jansson/Makefile index 1a60613d0..e06ffbc76 100644 --- a/client/jansson/Makefile +++ b/client/jansson/Makefile @@ -40,9 +40,6 @@ platform = $(shell uname) CC= gcc CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function -ifneq ($(platform),Darwin) -CFLAGS += -Wno-format-truncation -endif LDFLAGS= $(SYSLDFLAGS) $(libjansson_la_LDFLAGS) LIBS= $(SYSLIBS) $(MYLIBS) diff --git a/client/jansson/load.c b/client/jansson/load.c index 43e035cb2..4e05dc87b 100644 --- a/client/jansson/load.c +++ b/client/jansson/load.c @@ -111,7 +111,11 @@ static void error_set(json_error_t *error, const lex_t *lex, if (saved_text && saved_text[0]) { if (lex->saved_text.length <= 20) { - snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text); + int ret = snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text); + if (ret < 0) { + jsonp_error_set(error, line, col, pos, code, "%s", "internal snprint error"); + return; + } msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; result = msg_with_context; } @@ -124,7 +128,11 @@ static void error_set(json_error_t *error, const lex_t *lex, /* No context for UTF-8 decoding errors */ result = msg_text; } else { - snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text); + int ret = snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text); + if (ret < 0) { + jsonp_error_set(error, line, col, pos, code, "%s", "internal snprint error"); + return; + } msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; result = msg_with_context; } From 4bd15d900bdd7bdd578fbf397b2c88f41e5df74c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jul 2019 22:35:29 +0200 Subject: [PATCH 07/40] jtag tools: some factorisation --- tools/jtag_openocd/general.cfg | 3 +++ tools/jtag_openocd/interface-armusbocd.cfg | 4 ---- tools/jtag_openocd/interface-busblaster.cfg | 4 ---- tools/jtag_openocd/interface-buspirate.cfg | 4 ---- tools/jtag_openocd/interface-jlink.cfg | 4 ---- tools/jtag_openocd/interface-jtagkey.cfg | 4 ---- tools/jtag_openocd/interface-shikra.cfg | 4 ---- tools/jtag_openocd/interface-wiggler.cfg | 3 --- tools/jtag_openocd/openocd_configuration.sample | 7 +++++++ tools/jtag_openocd/openocd_flash_dump.sh | 9 +++++++++ tools/jtag_openocd/openocd_flash_recovery.sh | 7 ++----- tools/jtag_openocd/openocd_interactive.sh | 8 ++++++++ 12 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 tools/jtag_openocd/general.cfg create mode 100644 tools/jtag_openocd/openocd_configuration.sample create mode 100755 tools/jtag_openocd/openocd_flash_dump.sh create mode 100755 tools/jtag_openocd/openocd_interactive.sh diff --git a/tools/jtag_openocd/general.cfg b/tools/jtag_openocd/general.cfg new file mode 100644 index 000000000..6151d82bc --- /dev/null +++ b/tools/jtag_openocd/general.cfg @@ -0,0 +1,3 @@ +# Ports +telnet_port 4444 +gdb_port 3333 diff --git a/tools/jtag_openocd/interface-armusbocd.cfg b/tools/jtag_openocd/interface-armusbocd.cfg index e4689e21b..4820136f0 100644 --- a/tools/jtag_openocd/interface-armusbocd.cfg +++ b/tools/jtag_openocd/interface-armusbocd.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Olimex ARM-USB-OCD Dongle interface ft2232 ft2232_device_desc "Olimex OpenOCD JTAG" diff --git a/tools/jtag_openocd/interface-busblaster.cfg b/tools/jtag_openocd/interface-busblaster.cfg index 337e9a2de..bd1df2c5f 100644 --- a/tools/jtag_openocd/interface-busblaster.cfg +++ b/tools/jtag_openocd/interface-busblaster.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Bus Blaster interface ftdi ftdi_device_desc "Dual RS232-HS" diff --git a/tools/jtag_openocd/interface-buspirate.cfg b/tools/jtag_openocd/interface-buspirate.cfg index 4ed5b88a5..8eccadd79 100644 --- a/tools/jtag_openocd/interface-buspirate.cfg +++ b/tools/jtag_openocd/interface-buspirate.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the BusPirate interface buspirate buspirate_port /dev/ttyUSB0 diff --git a/tools/jtag_openocd/interface-jlink.cfg b/tools/jtag_openocd/interface-jlink.cfg index 56a04fef2..011cb7844 100644 --- a/tools/jtag_openocd/interface-jlink.cfg +++ b/tools/jtag_openocd/interface-jlink.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Segger J-Link interface jlink transport select jtag diff --git a/tools/jtag_openocd/interface-jtagkey.cfg b/tools/jtag_openocd/interface-jtagkey.cfg index 3e48c08df..420e6e97e 100644 --- a/tools/jtag_openocd/interface-jtagkey.cfg +++ b/tools/jtag_openocd/interface-jtagkey.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Amontec JTAGKey interface ft2232 ft2232_device_desc "Amontec JTAGkey A" diff --git a/tools/jtag_openocd/interface-shikra.cfg b/tools/jtag_openocd/interface-shikra.cfg index 507c301b4..ba4b21419 100644 --- a/tools/jtag_openocd/interface-shikra.cfg +++ b/tools/jtag_openocd/interface-shikra.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Shikra interface ftdi transport select jtag diff --git a/tools/jtag_openocd/interface-wiggler.cfg b/tools/jtag_openocd/interface-wiggler.cfg index 88448de82..ce9a1da06 100644 --- a/tools/jtag_openocd/interface-wiggler.cfg +++ b/tools/jtag_openocd/interface-wiggler.cfg @@ -1,6 +1,3 @@ -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Wiggler interface parport parport_port 0x378 diff --git a/tools/jtag_openocd/openocd_configuration.sample b/tools/jtag_openocd/openocd_configuration.sample new file mode 100644 index 000000000..466e28d9b --- /dev/null +++ b/tools/jtag_openocd/openocd_configuration.sample @@ -0,0 +1,7 @@ +CONFIG_GEN=general.cfg +CONFIG_CHIP=chip-at91sam7s.cfg +IMAGE=../../recovery/proxmark3_recovery.bin +DUMP="dump_$(date +'%Y%m%d-%H%M%S').bin" + +# Example using Segger Jlink: +CONFIG_IF=interface-jlink.cfg diff --git a/tools/jtag_openocd/openocd_flash_dump.sh b/tools/jtag_openocd/openocd_flash_dump.sh new file mode 100755 index 000000000..497847dd1 --- /dev/null +++ b/tools/jtag_openocd/openocd_flash_dump.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +. openocd_configuration || exit 1 + +if [ -e "$DUMP" ]; then + echo "$DUMP exists already. Abort!" + exit 1 +fi +openocd -f $CONFIG_GEN -f $CONFIG_IF -f $CONFIG_CHIP -c "init;halt;dump_image $DUMP 0x100000 0x80000;exit" diff --git a/tools/jtag_openocd/openocd_flash_recovery.sh b/tools/jtag_openocd/openocd_flash_recovery.sh index b51076d5a..2e88c52e6 100755 --- a/tools/jtag_openocd/openocd_flash_recovery.sh +++ b/tools/jtag_openocd/openocd_flash_recovery.sh @@ -1,12 +1,9 @@ #!/bin/bash -# Example using Segger Jlink: -CONFIG_CHIP=chip-at91sam7s.cfg -CONFIG_IF=interface-jlink.cfg -IMAGE=../../recovery/proxmark3_recovery.bin +. openocd_configuration || exit 1 if [ ! -e "$IMAGE" ]; then echo "$IMAGE missing. Abort!" exit 1 fi -openocd -f $CONFIG_IF -f $CONFIG_CHIP -c "init;halt;flash erase_sector 0 0 15;flash erase_sector 1 0 15;flash write_image $IMAGE 0x100000;exit" +openocd -f $CONFIG_GEN -f $CONFIG_IF -f $CONFIG_CHIP -c "init;halt;flash erase_sector 0 0 15;flash erase_sector 1 0 15;flash write_image $IMAGE 0x100000;exit" diff --git a/tools/jtag_openocd/openocd_interactive.sh b/tools/jtag_openocd/openocd_interactive.sh new file mode 100755 index 000000000..ea7919da8 --- /dev/null +++ b/tools/jtag_openocd/openocd_interactive.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +. openocd_configuration || exit 1 + +echo "*********************************************" +echo "Connect to OpenOCD via: telnet localhost $(awk '/^telnet_port/{print$2}' $CONFIG_GEN)" +echo "*********************************************" +openocd -f $CONFIG_GEN -f $CONFIG_IF -f $CONFIG_CHIP From 1ae85d20d74f06fc4d8ccfe5df5745ae8e50d929 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jul 2019 22:37:30 +0200 Subject: [PATCH 08/40] jtag tools: add config for FTDI C232HM-DDHSL-0 --- tools/jtag_openocd/interface-c232hm.cfg | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tools/jtag_openocd/interface-c232hm.cfg diff --git a/tools/jtag_openocd/interface-c232hm.cfg b/tools/jtag_openocd/interface-c232hm.cfg new file mode 100644 index 000000000..f4d0f471a --- /dev/null +++ b/tools/jtag_openocd/interface-c232hm.cfg @@ -0,0 +1,23 @@ +# Commands specific to the FTDI USB Hi-Speed to MPSSE Cable +# http://www.ftdichip.com/Products/Cables/USBMPSSE.htm +# C232HM-DDHSL-0 => 3.3V +# C232HM-EDSL-0 => 5V !! don't apply 5V on the 3.3v pm3 pin !! + +# Pinouts: +# Brown <> TMS +# Yellow <> TDI +# Green <> TDO +# Orange <> TCK +# Black <> GND +# Red <> 3.3 (don't connect if C232HM-EDSL-0! power via USB instead) + +interface ftdi +#ftdi_device_desc "C232HM-DDHSL-0" +#ftdi_device_desc "C232HM-EDHSL-0" +ftdi_vid_pid 0x0403 0x6014 + +ftdi_layout_init 0x0008 0x400b +ftdi_layout_signal LED -ndata 0x4000 + +transport select jtag +adapter_khz 1000 From fd5c30f555012d8e93621e86d6eb918359532529 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jul 2019 22:51:42 +0200 Subject: [PATCH 09/40] jtag tools: add config for RaspberryPi --- tools/jtag_openocd/interface-raspberrypi.cfg | 37 +++++++++++++++++++ tools/jtag_openocd/interface-raspberrypi2.cfg | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tools/jtag_openocd/interface-raspberrypi.cfg create mode 100644 tools/jtag_openocd/interface-raspberrypi2.cfg diff --git a/tools/jtag_openocd/interface-raspberrypi.cfg b/tools/jtag_openocd/interface-raspberrypi.cfg new file mode 100644 index 000000000..984afe41b --- /dev/null +++ b/tools/jtag_openocd/interface-raspberrypi.cfg @@ -0,0 +1,37 @@ +# Config for using Raspberry Pi's expansion header +# Using BCM2835 chip present in models Pi1, Pi2 and Pi Zero + +# Use short cables! +# Make sure the CPU is not busy with other processes! +# Connect pm3 before booting to avoid power loss & reboot problems +# Pinouts: +# 22 <> TMS +# 19 <> TDI +# 21 <> TDO +# 23 <> TCK +# 6 <> GND +# 1 <> 3.3 + +interface bcm2835gpio + +# This file is meant for first versions of Raspberry Pi +# You can check yours with: +# dd if=/proc/device-tree/soc/ranges bs=4 skip=1 count=1 2>/dev/null|xxd -p +# if it returns 20000000, you're fine +# if it returns 3F000000, use interface-raspberrypi2.cfg +bcm2835gpio_peripheral_base 0x20000000 + +# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET +# These depend on system clock, calibrated for stock 700MHz +# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET +bcm2835gpio_speed_coeffs 113714 28 + +# Each of the JTAG lines need a gpio number set: tck tms tdi tdo +# Header pin numbers: 23 22 19 21 +bcm2835gpio_jtag_nums 11 25 10 9 + +bcm2835gpio_srst_num 18 +reset_config srst_only srst_push_pull + +transport select jtag +adapter_khz 1000 diff --git a/tools/jtag_openocd/interface-raspberrypi2.cfg b/tools/jtag_openocd/interface-raspberrypi2.cfg new file mode 100644 index 000000000..b779cd290 --- /dev/null +++ b/tools/jtag_openocd/interface-raspberrypi2.cfg @@ -0,0 +1,37 @@ +# Config for using Raspberry Pi's expansion header +# Using BCM2835 chip present in models 2+ and above + +# Use short cables! +# Make sure the CPU is not busy with other processes! +# Connect pm3 before booting to avoid power loss & reboot problems +# Pinouts: +# 22 <> TMS +# 19 <> TDI +# 21 <> TDO +# 23 <> TCK +# 6 <> GND +# 1 <> 3.3 + +interface bcm2835gpio + +# This file is meant for recent versions of Raspberry Pi +# You can check yours with: +# dd if=/proc/device-tree/soc/ranges bs=4 skip=1 count=1 2>/dev/null|xxd -p +# if it returns 20000000, use interface-raspberrypi2.cfg +# if it returns 3F000000, you're fine +bcm2835gpio_peripheral_base 0x3F000000 + +# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET +# These depend on system clock, calibrated for stock 700MHz +# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET +bcm2835gpio_speed_coeffs 146203 36 + +# Each of the JTAG lines need a gpio number set: tck tms tdi tdo +# Header pin numbers: 23 22 19 21 +bcm2835gpio_jtag_nums 11 25 10 9 + +bcm2835gpio_srst_num 18 +reset_config srst_only srst_push_pull + +transport select jtag +adapter_khz 1000 From 6f457873ccac8c47c5d797367bad17b6f4f0417b Mon Sep 17 00:00:00 2001 From: 3ldidi94 Date: Thu, 11 Jul 2019 10:37:00 +0200 Subject: [PATCH 10/40] Update default_keys.dic with keys from an APK Update the dic with keys from Android application "Scan Badge". I did the diff between keys already present and keys from the application. --- client/default_keys.dic | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/default_keys.dic b/client/default_keys.dic index 13e289e0c..4810e56da 100644 --- a/client/default_keys.dic +++ b/client/default_keys.dic @@ -930,3 +930,17 @@ BB3D7B11D224 b210cfa436d2 b8b1cfa646a8 a9f95891f0a4 +# +# Keys from APK application "Scan Badge" +4A4C474F524D +444156494442 +434143445649 +434456495243 +A00002000021 +EF61A3D48E2A +A23456789123 +010000000000 +363119000001 +A00003000084 +675A32413770 +395244733978 From 844d732297d12f52fb43a3ac0696420605aa9af2 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 11 Jul 2019 13:01:34 +0200 Subject: [PATCH 11/40] Replace ukbhit by kbd_enter_pressed, not requiring tcgetattr: Note that it behaves differently now * it looks for Enter key only, not any key * it "eats" the input, no need for (void)getchar() after it * it works the same no matter the value of ICANON * the mingw version has been adapted to act the similarly This should fix its usage on Android where tcgetattr always returns -1 --- client/cmdanalyse.c | 3 +- client/cmdhf.c | 8 ++--- client/cmdhf14a.c | 6 ++-- client/cmdhffelica.c | 6 ++-- client/cmdhficlass.c | 24 +++++-------- client/cmdhfmf.c | 24 +++++-------- client/cmdlfawid.c | 6 ++-- client/cmdlfem4x.c | 8 ++--- client/cmdlfhid.c | 4 +-- client/cmdlft55xx.c | 4 +-- client/cmdsmartcard.c | 4 +-- client/cmdusart.c | 11 +++--- client/lualibs/hf_reader.lua | 4 +-- client/lualibs/read14a.lua | 4 +-- client/lualibs/read14b.lua | 4 +-- client/lualibs/read15.lua | 4 +-- client/mifare/mifarehost.c | 12 ++----- client/scripting.c | 6 ++-- client/scripts/didump.lua | 2 +- client/scripts/formatMifare.lua | 2 +- client/scripts/lf_bulk.lua | 2 +- client/scripts/mfkeys.lua | 2 +- client/scripts/mifare_autopwn.lua | 4 +-- client/scripts/tnp3dump.lua | 2 +- client/scripts/tracetest.lua | 2 +- client/util.c | 56 ++++++++++++++++++------------- client/util.h | 2 +- 27 files changed, 90 insertions(+), 126 deletions(-) diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 1eee47c78..0821cc4d1 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -623,8 +623,7 @@ static int CmdAnalyseA(const char *Cmd) { for (uint8_t k=0; k<4; k = (k+1) % 4 ) { PrintAndLogEx(NORMAL, "\e[s%c\e[u", star[k]); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); (void)gc; + if (kbd_enter_pressed()) { break; } } diff --git a/client/cmdhf.c b/client/cmdhf.c index 7e42202a9..03a5c1681 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -40,7 +40,7 @@ static int usage_hf_sniff() { static int usage_hf_tune() { PrintAndLogEx(NORMAL, "Usage: hf tune []"); PrintAndLogEx(NORMAL, "Continuously measure HF antenna tuning."); - PrintAndLogEx(NORMAL, "Press button or keyboard to interrupt."); + PrintAndLogEx(NORMAL, "Press button or Enter to interrupt."); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " - number of iterations (default: infinite)"); PrintAndLogEx(NORMAL, ""); @@ -98,7 +98,7 @@ int CmdHFTune(const char *Cmd) { int iter = param_get32ex(Cmd, 0, 0, 10); PacketResponseNG resp; - PrintAndLogEx(SUCCESS, "Measuring HF antenna, click button or press a key to exit"); + PrintAndLogEx(SUCCESS, "Measuring HF antenna, click button or press Enter to exit"); clearCommandBuffer(); uint8_t mode[] = {1}; SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); @@ -109,9 +109,7 @@ int CmdHFTune(const char *Cmd) { mode[0] = 2; // loop forever (till button pressed) if iter = 0 (default) for (uint8_t i = 0; iter == 0 || i < iter; i++) { - if (ukbhit()) { // abort by keyboard press - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { // abort by keyboard press break; } SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 018431a28..bb5144f0b 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -375,9 +375,7 @@ static int CmdHF14ACUIDs(const char *Cmd) { // repeat n times for (int i = 0; i < n; i++) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); break; } @@ -489,7 +487,7 @@ int CmdHF14ASim(const char *Cmd) { PrintAndLogEx(SUCCESS, "press pm3-button to abort simulation"); - while (!ukbhit()) { + while (!kbd_enter_pressed()) { if (WaitForResponseTimeout(CMD_SIMULATE_MIFARE_CARD, &resp, 1500) == 0) continue; if (resp.status != PM3_SUCCESS) break; diff --git a/client/cmdhffelica.c b/client/cmdhffelica.c index 6f3e28737..91d171149 100644 --- a/client/cmdhffelica.c +++ b/client/cmdhffelica.c @@ -135,7 +135,7 @@ static int CmdHFFelicaSim(const char *Cmd) { if (verbose) PrintAndLogEx(NORMAL, "Press pm3-button to abort simulation"); - while (!ukbhit()) { + while (!kbd_enter_pressed()) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue; } return 0; @@ -357,9 +357,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) { timeout++; printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); DropField(); return 1; diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 2bdb91fa1..ec2179ab3 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -176,7 +176,7 @@ static int usage_hf_iclass_managekeys(void) { return 0; } static int usage_hf_iclass_reader(void) { - PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until a key or the pm3 button is pressed\n"); + PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until Enter or the pm3 button is pressed\n"); PrintAndLogEx(NORMAL, "Usage: hf iclass reader [h] [1]\n"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help text"); @@ -376,16 +376,14 @@ static int CmdHFiClassSim(const char *Cmd) { case 2: { PrintAndLogEx(INFO, "Starting iCLASS sim 2 attack (elite mode)"); - PrintAndLogEx(INFO, "press keyboard to cancel"); + PrintAndLogEx(INFO, "press Enter to cancel"); PacketResponseNG resp; clearCommandBuffer(); SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, NUM_CSNS, 0, csns, 8 * NUM_CSNS); while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { tries++; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard."); return 0; } @@ -427,16 +425,14 @@ static int CmdHFiClassSim(const char *Cmd) { case 4: { // reader in key roll mode, when it has two keys it alternates when trying to verify. PrintAndLogEx(INFO, "Starting iCLASS sim 4 attack (elite mode, reader in key roll mode)"); - PrintAndLogEx(INFO, "press keyboard to cancel"); + PrintAndLogEx(INFO, "press Enter to cancel"); PacketResponseNG resp; clearCommandBuffer(); SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, NUM_CSNS, 0, csns, 8 * NUM_CSNS); while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { tries++; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard."); return 0; } @@ -969,9 +965,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); DropField(); return 0; @@ -1945,9 +1939,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { uint64_t t2 = msclock(); uint8_t timeout = 0; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] Aborted via keyboard!\n"); goto out; } @@ -2446,7 +2438,7 @@ int readIclass(bool loop, bool verbose) { // loop in client not device - else on windows have a communication error PacketResponseNG resp; - while (!ukbhit()) { + while (!kbd_enter_pressed()) { clearCommandBuffer(); SendCommandMIX(CMD_READER_ICLASS, flags, 0, 0, NULL, 0); diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 4fa3d8dc0..a81209215 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1692,9 +1692,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { // main keychunk loop for (i = 0; i < keycnt; i += chunksize) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); goto out; } @@ -1974,9 +1972,7 @@ static int CmdHF14AMfChk(const char *Cmd) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "\naborted via keyboard!\n"); goto out; } @@ -2281,7 +2277,7 @@ static int CmdHF14AMfSim(const char *Cmd) { if (flags & FLAG_INTERACTIVE) { PrintAndLogEx(INFO, "Press pm3-button or send another cmd to abort simulation"); - while (!ukbhit()) { + while (!kbd_enter_pressed()) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue; if (!(flags & FLAG_NR_AR_ATTACK)) break; if ((resp.oldarg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD) break; @@ -2328,8 +2324,8 @@ static int CmdHF14AMfSniff(const char *Cmd) { PrintAndLogEx(NORMAL, "-------------------------------------------------------------------------\n"); PrintAndLogEx(NORMAL, "Executing mifare sniffing command. \n"); - PrintAndLogEx(NORMAL, "Press the key on the Proxmark3 device to abort both Proxmark3 and client.\n"); - PrintAndLogEx(NORMAL, "Press the key on pc keyboard to abort the client.\n"); + PrintAndLogEx(NORMAL, "Press the button on the Proxmark3 device to abort both Proxmark3 and client.\n"); + PrintAndLogEx(NORMAL, "Press Enter to abort the client.\n"); PrintAndLogEx(NORMAL, "-------------------------------------------------------------------------\n"); clearCommandBuffer(); @@ -2341,9 +2337,7 @@ static int CmdHF14AMfSniff(const char *Cmd) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "\naborted via keyboard!\n"); break; } @@ -3242,7 +3236,7 @@ static int CmdHf14AMfNack(const char *Cmd) { bool verbose = (ctmp == 'v'); if (verbose) - PrintAndLogEx(INFO, "Started testing card for NACK bug. Press key to abort"); + PrintAndLogEx(INFO, "Started testing card for NACK bug. Press Enter to abort"); detect_classic_nackbug(verbose); return PM3_SUCCESS; @@ -3307,9 +3301,7 @@ static int CmdHF14AMfice(const char *Cmd) { uint64_t t1 = msclock(); do { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "\naborted via keyboard!\n"); break; } diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 7cb24d9c2..1c2d96004 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -491,7 +491,7 @@ static int CmdAWIDBrute(const char *Cmd) { } PrintAndLogEx(SUCCESS, "Bruteforceing AWID %d Reader", fmtlen); - PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or press key"); + PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or press Enter"); uint16_t up = cn; uint16_t down = cn; @@ -503,9 +503,7 @@ static int CmdAWIDBrute(const char *Cmd) { PrintAndLogEx(WARNING, "Device offline\n"); return PM3_ENODATA; } - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "aborted via keyboard!"); return sendPing(); } diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 6a5fae76f..aa0add5fa 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -544,9 +544,7 @@ static int CmdEM410xBrute(const char *Cmd) { char testuid[11]; testuid[10] = 0; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\nAborted via keyboard!\n"); free(uidBlock); return PM3_EOPABORTED; @@ -580,9 +578,7 @@ static int CmdEM410xBrute(const char *Cmd) { static int CmdEM410xWatch(const char *Cmd) { (void)Cmd; // Cmd is not used so far do { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); break; } diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index b300858d2..cc395c8c5 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -580,9 +580,7 @@ static int CmdHIDBrute(const char *Cmd) { return PM3_ENODATA; } - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "aborted via keyboard!"); return sendPing(); } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 923e50110..04b2c6e9e 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -1843,9 +1843,7 @@ static int CmdT55xxWipe(const char *Cmd) { } static bool IsCancelled(void) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); return true; } diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index c8529fa23..f936f10a9 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -914,9 +914,7 @@ static int smart_brute_sfi(bool decodeTLV) { for (uint16_t rec = 1; rec <= 255; rec++) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); free(buf); return 1; diff --git a/client/cmdusart.c b/client/cmdusart.c index e57834545..d632901ef 100644 --- a/client/cmdusart.c +++ b/client/cmdusart.c @@ -312,11 +312,9 @@ static int CmdUsartBtFactory(const char *Cmd) { PrintAndLogEx(WARNING, _RED_("WARNING: process only if strictly needed!")); PrintAndLogEx(WARNING, "This requires BT turned ON and NOT connected!"); PrintAndLogEx(WARNING, "Is the add-on blue light blinking? (Say 'n' if you want to abort) [y/n]"); - while (!ukbhit()) { - msleep(200); - } - if (tolower(getchar()) != 'y') { + char input[3]; + if ((fgets(input,sizeof(input),stdin) == NULL) || (strncmp(input, "y\n", sizeof(input)) != 0)) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(FAILED, "Aborting."); return PM3_EOPABORTED; @@ -448,11 +446,10 @@ static int CmdUsartBtFactory(const char *Cmd) { } if ((baudrate != USART_BAUD_RATE) || (parity != USART_PARITY)) { - PrintAndLogEx(WARNING, "Add-on uart settings changed, please turn BT add-on OFF and ON again, then press any key."); - while (!ukbhit()) { + PrintAndLogEx(WARNING, "Add-on uart settings changed, please turn BT add-on OFF and ON again, then press Enter."); + while (!kbd_enter_pressed()) { msleep(200); } - getchar(); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Trying to connect add-on with the new settings."); found = usart_bt_testcomm(USART_BAUD_RATE, USART_PARITY) == PM3_SUCCESS; diff --git a/client/lualibs/hf_reader.lua b/client/lualibs/hf_reader.lua index b99b521da..ba7e3a17c 100644 --- a/client/lualibs/hf_reader.lua +++ b/client/lualibs/hf_reader.lua @@ -15,10 +15,10 @@ local reader15693 = require('read15') -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitForTag() - print("Waiting for card... press any key to quit") + print("Waiting for card... press Enter to quit") local readers = {reader14443A, reader14443B, reader15693} local i = 0; - while not core.ukbhit() do + while not core.kbd_enter_pressed() do i = (i % 3) +1 r = readers[i] print("Reading with ",i) diff --git a/client/lualibs/read14a.lua b/client/lualibs/read14a.lua index 5cdf5a2e4..f68dfff81 100644 --- a/client/lualibs/read14a.lua +++ b/client/lualibs/read14a.lua @@ -121,8 +121,8 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor14443a() - print('Waiting for card... press any key to quit') - while not core.ukbhit() do + print('Waiting for card... press Enter to quit') + while not core.kbd_enter_pressed() do res, err = read14443a() if res then return res end -- err means that there was no response from card diff --git a/client/lualibs/read14b.lua b/client/lualibs/read14b.lua index 0421bee5b..0be958e25 100644 --- a/client/lualibs/read14b.lua +++ b/client/lualibs/read14b.lua @@ -99,8 +99,8 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor14443b() - print('Waiting for card... press any key to quit') - while not core.ukbhit() do + print('Waiting for card... press Enter to quit') + while not core.kbd_enter_pressed() do res, err = read14443b(false) if res then return res end -- err means that there was no response from card diff --git a/client/lualibs/read15.lua b/client/lualibs/read15.lua index 0b9a6476e..a70641186 100644 --- a/client/lualibs/read15.lua +++ b/client/lualibs/read15.lua @@ -133,8 +133,8 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor15693() - print('Waiting for card... press any key to quit') - while not core.ukbhit() do + print('Waiting for card... press Enter to quit') + while not core.kbd_enter_pressed() do res, err = read15693() if res then return res end -- err means that there was no response from card diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 893664e86..e9810e71a 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -28,9 +28,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { SendCommandMIX(CMD_READER_MIFARE, arg0, blockno, key_type, NULL, 0); //flush queue - while (ukbhit()) { - int gc = getchar(); - (void)gc; + while (kbd_enter_pressed()) { return PM3_EOPABORTED; } @@ -38,9 +36,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { return PM3_EOPABORTED; } @@ -955,9 +951,7 @@ int detect_classic_nackbug(bool verbose) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { return PM3_EOPABORTED; } diff --git a/client/scripting.c b/client/scripting.c index cfa361256..572899e2d 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -411,8 +411,8 @@ static int l_foobar(lua_State *L) { * @param L * @return boolean, true if kbhit, false otherwise. */ -static int l_ukbhit(lua_State *L) { - lua_pushboolean(L, ukbhit() ? true : false); +static int l_kbd_enter_pressed(lua_State *L) { + lua_pushboolean(L, kbd_enter_pressed() ? true : false); return 1; } @@ -1064,7 +1064,7 @@ int set_pm3_libraries(lua_State *L) { {"WaitForResponseTimeout", l_WaitForResponseTimeout}, {"mfDarkside", l_mfDarkside}, {"foobar", l_foobar}, - {"ukbhit", l_ukbhit}, + {"kbd_enter_pressed", l_kbd_enter_pressed}, {"clearCommandBuffer", l_clearCommandBuffer}, {"console", l_CmdConsole}, {"iso15693_crc", l_iso15693_crc}, diff --git a/client/scripts/didump.lua b/client/scripts/didump.lua index b0cc964ee..d5ac6f873 100644 --- a/client/scripts/didump.lua +++ b/client/scripts/didump.lua @@ -488,7 +488,7 @@ local function readtag(mfkey, aeskey ) for blockNo = 0, numBlocks-1 do - if core.ukbhit() then + if core.kbd_enter_pressed() then print("[fail] aborted by user") return nil end diff --git a/client/scripts/formatMifare.lua b/client/scripts/formatMifare.lua index e200d92cb..7c6fd92c0 100644 --- a/client/scripts/formatMifare.lua +++ b/client/scripts/formatMifare.lua @@ -206,7 +206,7 @@ local function main(args) if x then core.console(cmd) end end - if core.ukbhit() then + if core.kbd_enter_pressed() then print('aborted by user') break end diff --git a/client/scripts/lf_bulk.lua b/client/scripts/lf_bulk.lua index 5e8562ae7..54c60fb89 100644 --- a/client/scripts/lf_bulk.lua +++ b/client/scripts/lf_bulk.lua @@ -186,7 +186,7 @@ local function main(args) for cardnum = baseid, endid do local card = cardHex(cardnum, facility) print('Press enter to program card '..cardnum..':'..facility..' (hex: '..card..')') - --This would be better with 'press any key', but we'll take what we can get. + --This would be better with 'press Enter', but we'll take what we can get. io.read() core.console( ('lf hid clone %s'):format(card) ) end diff --git a/client/scripts/mfkeys.lua b/client/scripts/mfkeys.lua index 7d4a726d6..65f50eb9c 100644 --- a/client/scripts/mfkeys.lua +++ b/client/scripts/mfkeys.lua @@ -208,7 +208,7 @@ local function perform_check(numsectors) for sector = 0, #keys do -- Check if user aborted - if core.ukbhit() then + if core.kbd_enter_pressed() then print('Aborted by user') break end diff --git a/client/scripts/mifare_autopwn.lua b/client/scripts/mifare_autopwn.lua index a9859ac25..7a04cd641 100644 --- a/client/scripts/mifare_autopwn.lua +++ b/client/scripts/mifare_autopwn.lua @@ -70,7 +70,7 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function wait_for_mifare() - while not core.ukbhit() do + while not core.kbd_enter_pressed() do res, err = lib14a.read() if res then return res end -- err means that there was no response from card @@ -161,7 +161,7 @@ local function main(args) while not _exit do if print_message then - print('Waiting for card or press any key to stop') + print('Waiting for card or press Enter to stop') print_message = false end res, err = wait_for_mifare() diff --git a/client/scripts/tnp3dump.lua b/client/scripts/tnp3dump.lua index 00070eacc..0faadecaf 100644 --- a/client/scripts/tnp3dump.lua +++ b/client/scripts/tnp3dump.lua @@ -198,7 +198,7 @@ local function main(args) io.flush() - if core.ukbhit() then + if core.kbd_enter_pressed() then print("aborted by user") break end diff --git a/client/scripts/tracetest.lua b/client/scripts/tracetest.lua index e5943fd6a..44cd66b58 100644 --- a/client/scripts/tracetest.lua +++ b/client/scripts/tracetest.lua @@ -118,7 +118,7 @@ local function main(args) core.clearCommandBuffer() - if core.ukbhit() then + if core.kbd_enter_pressed() then print('aborted by user') break end diff --git a/client/util.c b/client/util.c index 568a022f1..a805b9c84 100644 --- a/client/util.c +++ b/client/util.c @@ -26,38 +26,46 @@ uint8_t g_debugMode = 0; #define MAX_BIN_BREAK_LENGTH (3072+384+1) #ifndef _WIN32 -#include -#include #include -#include +#include -int ukbhit(void) { - int cnt = 0; - int error; - static struct termios Otty, Ntty; - - if (tcgetattr(STDIN_FILENO, &Otty) == -1) return -1; - - Ntty = Otty; - - Ntty.c_iflag = 0x0000; // input mode - Ntty.c_oflag = 0x0000; // output mode - Ntty.c_lflag &= ~ICANON; // control mode = raw - Ntty.c_cc[VMIN] = 1; // return if at least 1 character is in the queue - Ntty.c_cc[VTIME] = 0; // no timeout. Wait forever - - if (0 == (error = tcsetattr(STDIN_FILENO, TCSANOW, &Ntty))) { // set new attributes - error += ioctl(STDIN_FILENO, FIONREAD, &cnt); // get number of characters available - error += tcsetattr(STDIN_FILENO, TCSANOW, &Otty); // reset attributes +int kbd_enter_pressed(void) { + int flags; + if ((flags = fcntl(STDIN_FILENO, F_GETFL, 0)) < 0) { + PrintAndLogEx(ERR, "fcntl failed in kbd_enter_pressed"); + return -1; } - return (error == 0 ? cnt : -1); + //non-blocking + flags |= O_NONBLOCK; + if (fcntl(STDIN_FILENO, F_SETFL, flags) < 0) { + PrintAndLogEx(ERR, "fcntl failed in kbd_enter_pressed"); + return -1; + } + int c; + int ret = 0; + do { //get all available chars + c = getchar(); + ret |= c == '\n'; + } while (c != EOF); + //blocking + flags &= ~O_NONBLOCK; + if (fcntl(STDIN_FILENO, F_SETFL, flags) < 0) { + PrintAndLogEx(ERR, "fcntl failed in kbd_enter_pressed"); + return -1; + } + return ret; } #else #include -int ukbhit(void) { - return kbhit(); +int kbd_enter_pressed(void) { + int ret = 0; + while(kbhit()) + { + ret |= getch() == '\r'; + } + return ret; } #endif diff --git a/client/util.h b/client/util.h index e194bb5be..b2c84f4e5 100644 --- a/client/util.h +++ b/client/util.h @@ -129,7 +129,7 @@ uint8_t g_debugMode; -int ukbhit(void); +int kbd_enter_pressed(void); void AddLogLine(const char *fn, const char *data, const char *c); void AddLogHex(const char *fn, const char *extData, const uint8_t *data, const size_t len); void AddLogUint64(const char *fn, const char *data, const uint64_t value); From e51b4f0fdd8ca3af14772f2a287fdc740169be21 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 11 Jul 2019 14:08:58 +0200 Subject: [PATCH 12/40] changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46c8222b..343d9ce88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox) + - Add config for RaspberryPi in JTAG tools (@doegox) + - Add config for FTDI C232HM-DDHSL-0 in JTAG tools (@doegox) + - Fix compilation under MacOSX with binutils (@matrix) + - Add dynamic report of the chipID for flashing purposes (@slurdge) + - Fix Clang warnings (@matrix) + - Fix EMVGPO bug (@matrix) + - Add hitag2 write password auth (@ViRb3) - Add check if bootloader segment is within bounds (@slurdge) - Add `hf 15 csetuid` - set UID on ISO-15693 Magic tags (@t0m4-null) - Change: Print help if unknown arg for hitag reader/writer (@ViRb3) From cbfd195abfb483556cd3413d447d6a892f072300 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 12 Jul 2019 01:48:39 +0200 Subject: [PATCH 13/40] Document compilation options --- README.md | 3 +- .../0_Compilation-Instructions.md | 50 ++++------- .../4_Advanced-compilation-parameters.md | 82 +++++++++++++++++++ 3 files changed, 102 insertions(+), 33 deletions(-) create mode 100644 doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md diff --git a/README.md b/README.md index e63e41ae2..a1e7ad76c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Proxmark3 RDV4.0 Dedicated Github This repo is based on iceman fork for Proxmark3. It is dedicated to bringing the most out of the new features for Proxmark3 RDV4.0 new hardware and design. +Note that it also supports other Proxmark3 platforms as well! [![Build status](https://ci.appveyor.com/api/projects/status/ct5blik2wa96bv0x/branch/master?svg=true)](https://ci.appveyor.com/project/iceman1001/proxmark3-ji4wj/branch/master) [![Latest release](https://img.shields.io/github/release/RfidResearchGroup/proxmark3.svg)](https://github.com/RfidResearchGroup/proxmark3/releases/latest) @@ -15,7 +16,7 @@ This repo is based on iceman fork for Proxmark3. It is dedicated to bringing the |[Development](#development) | [Important notes on ModemManager for Linux users](/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md) | [Validating proxmark client functionality](/doc/md/Use_of_Proxmark/1_Validation.md) | |[Why didn't you base it on official PM3 Master?](#why-didnt-you-base-it-on-official-pm3-master)| [Homebrew (Mac OS X) & Upgrading HomeBrew Tap Formula](/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md) | [First Use and Verification](/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md)| |[PM3 GUI](#pm3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| -|[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) || +|[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| |[Notes on UART](/doc/uart_notes.md)||| |[Notes on Frame format](/doc/new_frame_format.md)||| |[Notes on Termux / Android](/doc/termux_notes.md)||| diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index bb3699a72..7493fba1a 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -1,5 +1,16 @@ # Compilation instructions +## Tuning compilation parameters + +The client and the Proxmark3 firmware should always be in sync. +Nevertheless, the firmware can be tuned depending on the Proxmark3 platform and options. + +Indeed, the RRG/Iceman fork can be used on other Proxmark3 hardware platforms as well. + +Via some definitions, you can adjust the firmware for a given platform, but also to add features like the support of the Blue Shark add-on or to select which standalone mode to embed. + +To learn how to adjust the firmware, please read [Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md). + ## Get the latest commits ```sh @@ -15,48 +26,23 @@ make clean && make all ## Flash the BOOTROM & FULLIMAGE +In most cases, you can run the script `flash-all.sh` which try to auto-detect the port to use, on several OS. + +For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: + ```sh client/flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` ## Run the client -```sh -cd client -./proxmark3 /dev/ttyACM0 -``` +In most cases, you can run the script `proxmark3.sh` which try to auto-detect the port to use, on several OS. -## Compiling for other boards +For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: -Available boards - -| BOARD | PLATFORM | -|:---------------:|:---------------------------------------| -| `PM3RDV4` (def) | Proxmark3 rdv4 with AT91SAM7S512 | -| `PM3EVO` | Proxmark3 EVO with AT91SAM7S512 | -| `PM3EASY` | Proxmark3 rdv3 Easy with AT91SAM7S256 | -| `PM3RDV2` | Proxmark3 rdv2 with AT91SAM7S512 | -| `PM3OLD256` | Proxmark3 V1 with AT91SAM7S256 | -| `PM3OLD512` | Proxmark3 V1 with AT91SAM7S512 | - -Create a file named `Makefile.platform` in the root directory of the repository: +Here, for example, for a Proxmark3 connected via USB under Linux: ```sh -# PLATFORM=${BOARD} -# Following example is to compile sources for Proxmark3 rdv3 Easy -PLATFORM=PM3EASY -``` - -From this point: - -```sh -# Clean and compile -make clean && make all - -# Flash the BOOTROM & FULLIMAGE -client/flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf - -# Run the client cd client ./proxmark3 /dev/ttyACM0 ``` diff --git a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md new file mode 100644 index 000000000..aea5b5e30 --- /dev/null +++ b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md @@ -0,0 +1,82 @@ +# Advanced compilation parameters + +The client and the Proxmark3 firmware should always be in sync. +Nevertheless, the firmware can be tuned depending on the Proxmark3 platform and options. + +Indeed, the RRG/Iceman fork can be used on other Proxmark3 hardware platforms as well. + +Via some definitions, you can adjust the firmware for a given platform, but also to add features like the support of the Blue Shark add-on or to select which standalone mode to embed. + +## Client + +The client doesn't depend on the capabilities of the Proxmark3 it's connected to. +So you can use the same client for different Proxmark3 platforms, given that everything is running the same version. + +## Firmware + +By default, the firmware is of course tuned for the Proxmark3 Rdv4.0 device, which has built-in support for 256kb onboard flash SPI memory, Sim module (smart card support), FPC connector. +These features make it very different from all other devices, there is non other like this one. + +**Recommendation**: if you don't have a RDV4, we strongly recommend your device to have at least a 512kb arm chip, since this repo is on the very edge of 256kb limit. + +A firmware built for the RDV4 can still run on the other platforms as it will auto-detect during boot that external SPI and Sim are not present, still it will boot faster if it's tuned to the platform. + +If you need to tune things and save the configuration, create a file `Makefile.platform` in the root directory of the repository, see `Makefile.platform.sample`. +For an up-to-date exhaustive list of options, you can run `make PLATFORM=`. + +## PLATFORM + +Here are the supported values you can assign to `PLATFORM` in `Makefile.platform`: + +| PLATFORM | DESCRIPTION | +|-----------------|----------------------------------------| +| PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | +| PM3EVO | Proxmark3 EVO with AT91SAM7S512 | +| PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | +| PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | +| PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 | +| PM3OLD512 | Proxmark3 V1 with AT91SAM7S512 | + +By default `PLATFORM=PM3RDV4`. + +Known issues: + +* 256kb Arm chip devices: The compiled firmware image from this repo may/will be too large for your device. +* PM3 Evo: it has a different led/button pin assignment. It tends to be messed up. + +## PLATFORM_EXTRAS + +Here are the supported values you can assign to `PLATFORM_EXTRAS` in `Makefile.platform`: + +| PLATFORM_EXTRAS | DESCRIPTION | +|-----------------|----------------------------------------| +| BTADDON | Proxmark3 rdv4 BT add-on | + +By default `PLATFORM_EXTRAS=`. + +If you have installed a Blue Shark add-on on your RDV4, define `PLATFORM_EXTRAS=BTADDON` in your `Makefile.platform`. + + +## STANDALONE + +The RRG/Iceman fork gives you to easily choose which standalone mode to embed in the firmware. + +Here are the supported values you can assign to `STANDALONE` in `Makefile.platform`: + +| STANDALONE | DESCRIPTION | +|-----------------|----------------------------------------| +| | No standalone mode +| LF_SAMYRUN (def)| HID26 read/clone/sim - Samy Kamkar +| LF_ICERUN | standalone mode skeleton - iceman +| LF_PROXBRUTE | HID ProxII bruteforce - Brad Antoniewicz +| LF_HIDBRUTE | HID corporate 1000 bruteforce - Federico dotta & Maurizio Agazzini +| HF_YOUNG | Mifare sniff/simulation - Craig Young +| HF_MATTYRUN | Mifare sniff/clone - Matías A. Ré Medina +| HF_COLIN | Mifare ultra fast sniff/sim/clone - Colin Brigato +| HF_BOG | 14a sniff with ULC/ULEV1/NTAG auth storing in flashmem - Bogito + +By default `STANDALONE=LF_SAMYRUN`. + +## Next step + +See [Compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md) From ec534305de9073b3028e55edb726510ecaa778a5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 12 Jul 2019 21:16:51 +0200 Subject: [PATCH 14/40] Document WSL and update ProxSpace instructions --- CHANGELOG.md | 1 + .../Windows-Installation-Instructions.md | 153 ++++++++++++++---- 2 files changed, 122 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 343d9ce88..a276440d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Add documentation for usage of Proxmark3 under WSL (@doegox) - Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox) - Add config for RaspberryPi in JTAG tools (@doegox) - Add config for FTDI C232HM-DDHSL-0 in JTAG tools (@doegox) diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index ac88906da..1617ec6ec 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -1,60 +1,149 @@ -# Building on Windows -You will need to use the Gator96100 Proxspace package to assist in your windows installation. -This can be downloaded from https://github.com/Gator96100/ProxSpace/ +# Installing on Windows + +There are two ways to install, build and use Proxmark3 on Windows: + +* Using Gator96100 **ProxSpace**, a package to assist in your Windows installation of MinGW +* Using native **WSL**, if you're running a Windows 10 version recent enough (FCU 1709 or later) --- -# Video Installation guide + +# Installing on Windows with ProxSpace + +## Video Installation guide [![Windows Installation tutorial](https://github.com/5w0rdfish/Proxmark3-RDV4-ParrotOS/blob/master/screenshot-www.youtube.com-2019.03.17-20-44-33.png)](https://youtu.be/zzF0NCMJnYU "Windows Installation Tutorial") -## Manual Installation +## Driver Installation -### Driver Installation +Install required drivers for your Windows installation. You may need admin privileges to do this. +Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs/news/how-to-install-a-proxmark3-driver-on-windows-10). -Install required drivers for your windows installation. You will may need admin privileges to do this. -(This is covered in the video) Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs/news/how-to-install-a-proxmark3-driver-on-windows-10) +## Download / clone ProxSpace repo -### Install Github +Download the Gator96100 ProxSpace package from https://github.com/Gator96100/ProxSpace/ -Install Github for Windows https://desktop.github.com/ +If you prefer, you can clone it, provided that you installed Github for Windows https://desktop.github.com/. -### Download / clone Proxspace repo - -Download the required proxspace repo. https://github.com/Gator96100/ProxSpace/ - -Extract 'ProxSpace' to a location on drive without spaces. +Extract 'ProxSpace' to a location path without spaces. For example D:\OneDrive\Documents\GitHub is ok whereas C:\My Documents\My Projects\proxspace is not. -### Clone the RRG/Iceman repository +If you're running Windows in a Virtualbox guest, make sure not to install ProxSpace on a vbox shared drive. (It's ok later to move the `/pm3` subfolder to a shared drive and edit the `*.bat`) -```sh -git clone https://github.com/RfidResearchGroup/proxmark3.git -``` - -### Copy files to Proxspace - -Copy all the contents from the `proxmark3` folder into the proxspace `pm3` folder - -### Run the .bat +## Launch ProxSpace Run `runme.bat` or `runme64.bat` depending on your Windows architecture. -Please note you will need to use `/` as you are using BASH. +You'll get a Bash prompt and your home directory should become the ProxSpace `pm3` sub-directory. -### Compile and use the project +Please note you will need to use `/` in paths as you are using Bash. + +## Clone the RRG/Iceman repository + +```sh +cd +git clone https://github.com/RfidResearchGroup/proxmark3.git +cd proxmark3 +``` + +## Compile and use the project Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -The only differences are that executables end with `.exe` (e.g. `client/flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. +To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `client/flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. -So flashing will resemble +To flash: In principle, the helper script `flash-all.sh` should auto-detect your COM port, so you can just try: + +```sh +./flash-all.sh +``` + +If COM port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh client/flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` -And running the client will resemble +Similarly, to run the client, you may try: ```sh -cd client -./proxmark3.exe comX +./proxmark3.sh +``` + +Or, by specifying the COM port manually: + +```sh +client/proxmark3.exe comX +``` + +# Installing on Windows with WSL + +It requires to run a Windows 10 version 1709 or above. Previous versions didn't have support for COM ports. + +Install WSL with e.g. the standard Ubuntu. + +For WSL configuration, see [Manage and configure Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/wsl-config). + +## Driver Installation + +Install required drivers for your Windows installation. You may need admin privileges to do this. +Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs/news/how-to-install-a-proxmark3-driver-on-windows-10). + +## X Server Installation + +If you want to run the graphical components of the Proxmark3 client, you need to install a X Server such as [VcXsrv](https://sourceforge.net/projects/vcxsrv/) or [Xming](https://sourceforge.net/projects/xming/). + +## Dependencies + +Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instructions](/doc/md/Installation_Instructions/Linux-Installation-Instructions.md) for Ubuntu, summarized here below: + +```sh +sudo apt-get update +sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ +libusb-dev perl pkg-config wget libncurses5-dev gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ +libqt4-dev +``` + +If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. + +## Clone the RRG/Iceman repository + +```sh +git clone https://github.com/RfidResearchGroup/proxmark3.git +``` + +## Compile and use the project + +Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). + +To use the compiled client and flasher, the only difference is that the Proxmark3 port is translated from your `comX` port where "X" is the com port number assigned to proxmark3 under Windows, to a `/dev/ttySX`. + +You will need to give permission to the current user to access `/dev/ttySX`: (change X to your port number) + +```sh +sudo chmod 666 /dev/ttySX +``` + +Unfortunately the access rights of the port won't survive and will have to be fixed again next time. + +If you installed a X Server and compiled the Proxmark3 with QT4 support, you've to export the `DISPLAY` environment variable: + +```sh +export DISPLAY=:0 +``` + +and add it to your Bash profile for the next times: + +```sh +echo "export DISPLAY=:0" >> ~/.bashrc +``` + +To flash, you've to call the flasher manually and specify the correct port: + +```sh +client/flasher /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +``` + +Similarly, to run the client: + +```sh +client/proxmark3 /dev/ttySX ``` From 996ed197fbfb9af8af6b8437adbe177e8d5a14db Mon Sep 17 00:00:00 2001 From: slurdge Date: Fri, 12 Jul 2019 23:48:54 +0200 Subject: [PATCH 15/40] Remove aes.c in favor of mbedtls implementation. Changelog --- CHANGELOG.md | 1 + armsrc/Makefile | 2 +- armsrc/aes.c | 1170 -------------------------------- armsrc/aes.h | 34 - armsrc/desfire_crypto.c | 16 +- armsrc/mifaredesfire.c | 28 +- common/Makefile.common | 2 +- common/desfire.h | 6 +- common/mbedtls/platform_util.c | 4 +- 9 files changed, 34 insertions(+), 1229 deletions(-) delete mode 100644 armsrc/aes.c delete mode 100644 armsrc/aes.h diff --git a/CHANGELOG.md b/CHANGELOG.md index a276440d7..a312e3992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] - Add documentation for usage of Proxmark3 under WSL (@doegox) + - Change: replace aes.c with mbedtls version (@slurdge) - Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox) - Add config for RaspberryPi in JTAG tools (@doegox) - Add config for FTDI C232HM-DDHSL-0 in JTAG tools (@doegox) diff --git a/armsrc/Makefile b/armsrc/Makefile index 7fda76b99..7fee5c79b 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -30,7 +30,7 @@ SRC_ISO15693 = iso15693.c iso15693tools.c SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c SRC_ISO14443b = iso14443b.c SRC_FELICA = felica.c -SRC_CRAPTO1 = crypto1.c des.c aes.c desfire_key.c desfire_crypto.c mifaredesfire.c +SRC_CRAPTO1 = crypto1.c des.c desfire_key.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c SRC_CRC = crc.c crc16.c crc32.c SRC_ICLASS = iclass.c optimized_cipher.c SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c diff --git a/armsrc/aes.c b/armsrc/aes.c deleted file mode 100644 index f8a36f28c..000000000 --- a/armsrc/aes.c +++ /dev/null @@ -1,1170 +0,0 @@ -#include "aes.h" - -static const unsigned int Te0[256] = { - 0xc66363a5UL, 0xf87c7c84UL, 0xee777799UL, 0xf67b7b8dUL, - 0xfff2f20dUL, 0xd66b6bbdUL, 0xde6f6fb1UL, 0x91c5c554UL, - 0x60303050UL, 0x02010103UL, 0xce6767a9UL, 0x562b2b7dUL, - 0xe7fefe19UL, 0xb5d7d762UL, 0x4dababe6UL, 0xec76769aUL, - 0x8fcaca45UL, 0x1f82829dUL, 0x89c9c940UL, 0xfa7d7d87UL, - 0xeffafa15UL, 0xb25959ebUL, 0x8e4747c9UL, 0xfbf0f00bUL, - 0x41adadecUL, 0xb3d4d467UL, 0x5fa2a2fdUL, 0x45afafeaUL, - 0x239c9cbfUL, 0x53a4a4f7UL, 0xe4727296UL, 0x9bc0c05bUL, - 0x75b7b7c2UL, 0xe1fdfd1cUL, 0x3d9393aeUL, 0x4c26266aUL, - 0x6c36365aUL, 0x7e3f3f41UL, 0xf5f7f702UL, 0x83cccc4fUL, - 0x6834345cUL, 0x51a5a5f4UL, 0xd1e5e534UL, 0xf9f1f108UL, - 0xe2717193UL, 0xabd8d873UL, 0x62313153UL, 0x2a15153fUL, - 0x0804040cUL, 0x95c7c752UL, 0x46232365UL, 0x9dc3c35eUL, - 0x30181828UL, 0x379696a1UL, 0x0a05050fUL, 0x2f9a9ab5UL, - 0x0e070709UL, 0x24121236UL, 0x1b80809bUL, 0xdfe2e23dUL, - 0xcdebeb26UL, 0x4e272769UL, 0x7fb2b2cdUL, 0xea75759fUL, - 0x1209091bUL, 0x1d83839eUL, 0x582c2c74UL, 0x341a1a2eUL, - 0x361b1b2dUL, 0xdc6e6eb2UL, 0xb45a5aeeUL, 0x5ba0a0fbUL, - 0xa45252f6UL, 0x763b3b4dUL, 0xb7d6d661UL, 0x7db3b3ceUL, - 0x5229297bUL, 0xdde3e33eUL, 0x5e2f2f71UL, 0x13848497UL, - 0xa65353f5UL, 0xb9d1d168UL, 0x00000000UL, 0xc1eded2cUL, - 0x40202060UL, 0xe3fcfc1fUL, 0x79b1b1c8UL, 0xb65b5bedUL, - 0xd46a6abeUL, 0x8dcbcb46UL, 0x67bebed9UL, 0x7239394bUL, - 0x944a4adeUL, 0x984c4cd4UL, 0xb05858e8UL, 0x85cfcf4aUL, - 0xbbd0d06bUL, 0xc5efef2aUL, 0x4faaaae5UL, 0xedfbfb16UL, - 0x864343c5UL, 0x9a4d4dd7UL, 0x66333355UL, 0x11858594UL, - 0x8a4545cfUL, 0xe9f9f910UL, 0x04020206UL, 0xfe7f7f81UL, - 0xa05050f0UL, 0x783c3c44UL, 0x259f9fbaUL, 0x4ba8a8e3UL, - 0xa25151f3UL, 0x5da3a3feUL, 0x804040c0UL, 0x058f8f8aUL, - 0x3f9292adUL, 0x219d9dbcUL, 0x70383848UL, 0xf1f5f504UL, - 0x63bcbcdfUL, 0x77b6b6c1UL, 0xafdada75UL, 0x42212163UL, - 0x20101030UL, 0xe5ffff1aUL, 0xfdf3f30eUL, 0xbfd2d26dUL, - 0x81cdcd4cUL, 0x180c0c14UL, 0x26131335UL, 0xc3ecec2fUL, - 0xbe5f5fe1UL, 0x359797a2UL, 0x884444ccUL, 0x2e171739UL, - 0x93c4c457UL, 0x55a7a7f2UL, 0xfc7e7e82UL, 0x7a3d3d47UL, - 0xc86464acUL, 0xba5d5de7UL, 0x3219192bUL, 0xe6737395UL, - 0xc06060a0UL, 0x19818198UL, 0x9e4f4fd1UL, 0xa3dcdc7fUL, - 0x44222266UL, 0x542a2a7eUL, 0x3b9090abUL, 0x0b888883UL, - 0x8c4646caUL, 0xc7eeee29UL, 0x6bb8b8d3UL, 0x2814143cUL, - 0xa7dede79UL, 0xbc5e5ee2UL, 0x160b0b1dUL, 0xaddbdb76UL, - 0xdbe0e03bUL, 0x64323256UL, 0x743a3a4eUL, 0x140a0a1eUL, - 0x924949dbUL, 0x0c06060aUL, 0x4824246cUL, 0xb85c5ce4UL, - 0x9fc2c25dUL, 0xbdd3d36eUL, 0x43acacefUL, 0xc46262a6UL, - 0x399191a8UL, 0x319595a4UL, 0xd3e4e437UL, 0xf279798bUL, - 0xd5e7e732UL, 0x8bc8c843UL, 0x6e373759UL, 0xda6d6db7UL, - 0x018d8d8cUL, 0xb1d5d564UL, 0x9c4e4ed2UL, 0x49a9a9e0UL, - 0xd86c6cb4UL, 0xac5656faUL, 0xf3f4f407UL, 0xcfeaea25UL, - 0xca6565afUL, 0xf47a7a8eUL, 0x47aeaee9UL, 0x10080818UL, - 0x6fbabad5UL, 0xf0787888UL, 0x4a25256fUL, 0x5c2e2e72UL, - 0x381c1c24UL, 0x57a6a6f1UL, 0x73b4b4c7UL, 0x97c6c651UL, - 0xcbe8e823UL, 0xa1dddd7cUL, 0xe874749cUL, 0x3e1f1f21UL, - 0x964b4bddUL, 0x61bdbddcUL, 0x0d8b8b86UL, 0x0f8a8a85UL, - 0xe0707090UL, 0x7c3e3e42UL, 0x71b5b5c4UL, 0xcc6666aaUL, - 0x904848d8UL, 0x06030305UL, 0xf7f6f601UL, 0x1c0e0e12UL, - 0xc26161a3UL, 0x6a35355fUL, 0xae5757f9UL, 0x69b9b9d0UL, - 0x17868691UL, 0x99c1c158UL, 0x3a1d1d27UL, 0x279e9eb9UL, - 0xd9e1e138UL, 0xebf8f813UL, 0x2b9898b3UL, 0x22111133UL, - 0xd26969bbUL, 0xa9d9d970UL, 0x078e8e89UL, 0x339494a7UL, - 0x2d9b9bb6UL, 0x3c1e1e22UL, 0x15878792UL, 0xc9e9e920UL, - 0x87cece49UL, 0xaa5555ffUL, 0x50282878UL, 0xa5dfdf7aUL, - 0x038c8c8fUL, 0x59a1a1f8UL, 0x09898980UL, 0x1a0d0d17UL, - 0x65bfbfdaUL, 0xd7e6e631UL, 0x844242c6UL, 0xd06868b8UL, - 0x824141c3UL, 0x299999b0UL, 0x5a2d2d77UL, 0x1e0f0f11UL, - 0x7bb0b0cbUL, 0xa85454fcUL, 0x6dbbbbd6UL, 0x2c16163aUL, -}; -static const unsigned int Te1[256] = { - 0xa5c66363UL, 0x84f87c7cUL, 0x99ee7777UL, 0x8df67b7bUL, - 0x0dfff2f2UL, 0xbdd66b6bUL, 0xb1de6f6fUL, 0x5491c5c5UL, - 0x50603030UL, 0x03020101UL, 0xa9ce6767UL, 0x7d562b2bUL, - 0x19e7fefeUL, 0x62b5d7d7UL, 0xe64dababUL, 0x9aec7676UL, - 0x458fcacaUL, 0x9d1f8282UL, 0x4089c9c9UL, 0x87fa7d7dUL, - 0x15effafaUL, 0xebb25959UL, 0xc98e4747UL, 0x0bfbf0f0UL, - 0xec41adadUL, 0x67b3d4d4UL, 0xfd5fa2a2UL, 0xea45afafUL, - 0xbf239c9cUL, 0xf753a4a4UL, 0x96e47272UL, 0x5b9bc0c0UL, - 0xc275b7b7UL, 0x1ce1fdfdUL, 0xae3d9393UL, 0x6a4c2626UL, - 0x5a6c3636UL, 0x417e3f3fUL, 0x02f5f7f7UL, 0x4f83ccccUL, - 0x5c683434UL, 0xf451a5a5UL, 0x34d1e5e5UL, 0x08f9f1f1UL, - 0x93e27171UL, 0x73abd8d8UL, 0x53623131UL, 0x3f2a1515UL, - 0x0c080404UL, 0x5295c7c7UL, 0x65462323UL, 0x5e9dc3c3UL, - 0x28301818UL, 0xa1379696UL, 0x0f0a0505UL, 0xb52f9a9aUL, - 0x090e0707UL, 0x36241212UL, 0x9b1b8080UL, 0x3ddfe2e2UL, - 0x26cdebebUL, 0x694e2727UL, 0xcd7fb2b2UL, 0x9fea7575UL, - 0x1b120909UL, 0x9e1d8383UL, 0x74582c2cUL, 0x2e341a1aUL, - 0x2d361b1bUL, 0xb2dc6e6eUL, 0xeeb45a5aUL, 0xfb5ba0a0UL, - 0xf6a45252UL, 0x4d763b3bUL, 0x61b7d6d6UL, 0xce7db3b3UL, - 0x7b522929UL, 0x3edde3e3UL, 0x715e2f2fUL, 0x97138484UL, - 0xf5a65353UL, 0x68b9d1d1UL, 0x00000000UL, 0x2cc1ededUL, - 0x60402020UL, 0x1fe3fcfcUL, 0xc879b1b1UL, 0xedb65b5bUL, - 0xbed46a6aUL, 0x468dcbcbUL, 0xd967bebeUL, 0x4b723939UL, - 0xde944a4aUL, 0xd4984c4cUL, 0xe8b05858UL, 0x4a85cfcfUL, - 0x6bbbd0d0UL, 0x2ac5efefUL, 0xe54faaaaUL, 0x16edfbfbUL, - 0xc5864343UL, 0xd79a4d4dUL, 0x55663333UL, 0x94118585UL, - 0xcf8a4545UL, 0x10e9f9f9UL, 0x06040202UL, 0x81fe7f7fUL, - 0xf0a05050UL, 0x44783c3cUL, 0xba259f9fUL, 0xe34ba8a8UL, - 0xf3a25151UL, 0xfe5da3a3UL, 0xc0804040UL, 0x8a058f8fUL, - 0xad3f9292UL, 0xbc219d9dUL, 0x48703838UL, 0x04f1f5f5UL, - 0xdf63bcbcUL, 0xc177b6b6UL, 0x75afdadaUL, 0x63422121UL, - 0x30201010UL, 0x1ae5ffffUL, 0x0efdf3f3UL, 0x6dbfd2d2UL, - 0x4c81cdcdUL, 0x14180c0cUL, 0x35261313UL, 0x2fc3ececUL, - 0xe1be5f5fUL, 0xa2359797UL, 0xcc884444UL, 0x392e1717UL, - 0x5793c4c4UL, 0xf255a7a7UL, 0x82fc7e7eUL, 0x477a3d3dUL, - 0xacc86464UL, 0xe7ba5d5dUL, 0x2b321919UL, 0x95e67373UL, - 0xa0c06060UL, 0x98198181UL, 0xd19e4f4fUL, 0x7fa3dcdcUL, - 0x66442222UL, 0x7e542a2aUL, 0xab3b9090UL, 0x830b8888UL, - 0xca8c4646UL, 0x29c7eeeeUL, 0xd36bb8b8UL, 0x3c281414UL, - 0x79a7dedeUL, 0xe2bc5e5eUL, 0x1d160b0bUL, 0x76addbdbUL, - 0x3bdbe0e0UL, 0x56643232UL, 0x4e743a3aUL, 0x1e140a0aUL, - 0xdb924949UL, 0x0a0c0606UL, 0x6c482424UL, 0xe4b85c5cUL, - 0x5d9fc2c2UL, 0x6ebdd3d3UL, 0xef43acacUL, 0xa6c46262UL, - 0xa8399191UL, 0xa4319595UL, 0x37d3e4e4UL, 0x8bf27979UL, - 0x32d5e7e7UL, 0x438bc8c8UL, 0x596e3737UL, 0xb7da6d6dUL, - 0x8c018d8dUL, 0x64b1d5d5UL, 0xd29c4e4eUL, 0xe049a9a9UL, - 0xb4d86c6cUL, 0xfaac5656UL, 0x07f3f4f4UL, 0x25cfeaeaUL, - 0xafca6565UL, 0x8ef47a7aUL, 0xe947aeaeUL, 0x18100808UL, - 0xd56fbabaUL, 0x88f07878UL, 0x6f4a2525UL, 0x725c2e2eUL, - 0x24381c1cUL, 0xf157a6a6UL, 0xc773b4b4UL, 0x5197c6c6UL, - 0x23cbe8e8UL, 0x7ca1ddddUL, 0x9ce87474UL, 0x213e1f1fUL, - 0xdd964b4bUL, 0xdc61bdbdUL, 0x860d8b8bUL, 0x850f8a8aUL, - 0x90e07070UL, 0x427c3e3eUL, 0xc471b5b5UL, 0xaacc6666UL, - 0xd8904848UL, 0x05060303UL, 0x01f7f6f6UL, 0x121c0e0eUL, - 0xa3c26161UL, 0x5f6a3535UL, 0xf9ae5757UL, 0xd069b9b9UL, - 0x91178686UL, 0x5899c1c1UL, 0x273a1d1dUL, 0xb9279e9eUL, - 0x38d9e1e1UL, 0x13ebf8f8UL, 0xb32b9898UL, 0x33221111UL, - 0xbbd26969UL, 0x70a9d9d9UL, 0x89078e8eUL, 0xa7339494UL, - 0xb62d9b9bUL, 0x223c1e1eUL, 0x92158787UL, 0x20c9e9e9UL, - 0x4987ceceUL, 0xffaa5555UL, 0x78502828UL, 0x7aa5dfdfUL, - 0x8f038c8cUL, 0xf859a1a1UL, 0x80098989UL, 0x171a0d0dUL, - 0xda65bfbfUL, 0x31d7e6e6UL, 0xc6844242UL, 0xb8d06868UL, - 0xc3824141UL, 0xb0299999UL, 0x775a2d2dUL, 0x111e0f0fUL, - 0xcb7bb0b0UL, 0xfca85454UL, 0xd66dbbbbUL, 0x3a2c1616UL, -}; -static const unsigned int Te2[256] = { - 0x63a5c663UL, 0x7c84f87cUL, 0x7799ee77UL, 0x7b8df67bUL, - 0xf20dfff2UL, 0x6bbdd66bUL, 0x6fb1de6fUL, 0xc55491c5UL, - 0x30506030UL, 0x01030201UL, 0x67a9ce67UL, 0x2b7d562bUL, - 0xfe19e7feUL, 0xd762b5d7UL, 0xabe64dabUL, 0x769aec76UL, - 0xca458fcaUL, 0x829d1f82UL, 0xc94089c9UL, 0x7d87fa7dUL, - 0xfa15effaUL, 0x59ebb259UL, 0x47c98e47UL, 0xf00bfbf0UL, - 0xadec41adUL, 0xd467b3d4UL, 0xa2fd5fa2UL, 0xafea45afUL, - 0x9cbf239cUL, 0xa4f753a4UL, 0x7296e472UL, 0xc05b9bc0UL, - 0xb7c275b7UL, 0xfd1ce1fdUL, 0x93ae3d93UL, 0x266a4c26UL, - 0x365a6c36UL, 0x3f417e3fUL, 0xf702f5f7UL, 0xcc4f83ccUL, - 0x345c6834UL, 0xa5f451a5UL, 0xe534d1e5UL, 0xf108f9f1UL, - 0x7193e271UL, 0xd873abd8UL, 0x31536231UL, 0x153f2a15UL, - 0x040c0804UL, 0xc75295c7UL, 0x23654623UL, 0xc35e9dc3UL, - 0x18283018UL, 0x96a13796UL, 0x050f0a05UL, 0x9ab52f9aUL, - 0x07090e07UL, 0x12362412UL, 0x809b1b80UL, 0xe23ddfe2UL, - 0xeb26cdebUL, 0x27694e27UL, 0xb2cd7fb2UL, 0x759fea75UL, - 0x091b1209UL, 0x839e1d83UL, 0x2c74582cUL, 0x1a2e341aUL, - 0x1b2d361bUL, 0x6eb2dc6eUL, 0x5aeeb45aUL, 0xa0fb5ba0UL, - 0x52f6a452UL, 0x3b4d763bUL, 0xd661b7d6UL, 0xb3ce7db3UL, - 0x297b5229UL, 0xe33edde3UL, 0x2f715e2fUL, 0x84971384UL, - 0x53f5a653UL, 0xd168b9d1UL, 0x00000000UL, 0xed2cc1edUL, - 0x20604020UL, 0xfc1fe3fcUL, 0xb1c879b1UL, 0x5bedb65bUL, - 0x6abed46aUL, 0xcb468dcbUL, 0xbed967beUL, 0x394b7239UL, - 0x4ade944aUL, 0x4cd4984cUL, 0x58e8b058UL, 0xcf4a85cfUL, - 0xd06bbbd0UL, 0xef2ac5efUL, 0xaae54faaUL, 0xfb16edfbUL, - 0x43c58643UL, 0x4dd79a4dUL, 0x33556633UL, 0x85941185UL, - 0x45cf8a45UL, 0xf910e9f9UL, 0x02060402UL, 0x7f81fe7fUL, - 0x50f0a050UL, 0x3c44783cUL, 0x9fba259fUL, 0xa8e34ba8UL, - 0x51f3a251UL, 0xa3fe5da3UL, 0x40c08040UL, 0x8f8a058fUL, - 0x92ad3f92UL, 0x9dbc219dUL, 0x38487038UL, 0xf504f1f5UL, - 0xbcdf63bcUL, 0xb6c177b6UL, 0xda75afdaUL, 0x21634221UL, - 0x10302010UL, 0xff1ae5ffUL, 0xf30efdf3UL, 0xd26dbfd2UL, - 0xcd4c81cdUL, 0x0c14180cUL, 0x13352613UL, 0xec2fc3ecUL, - 0x5fe1be5fUL, 0x97a23597UL, 0x44cc8844UL, 0x17392e17UL, - 0xc45793c4UL, 0xa7f255a7UL, 0x7e82fc7eUL, 0x3d477a3dUL, - 0x64acc864UL, 0x5de7ba5dUL, 0x192b3219UL, 0x7395e673UL, - 0x60a0c060UL, 0x81981981UL, 0x4fd19e4fUL, 0xdc7fa3dcUL, - 0x22664422UL, 0x2a7e542aUL, 0x90ab3b90UL, 0x88830b88UL, - 0x46ca8c46UL, 0xee29c7eeUL, 0xb8d36bb8UL, 0x143c2814UL, - 0xde79a7deUL, 0x5ee2bc5eUL, 0x0b1d160bUL, 0xdb76addbUL, - 0xe03bdbe0UL, 0x32566432UL, 0x3a4e743aUL, 0x0a1e140aUL, - 0x49db9249UL, 0x060a0c06UL, 0x246c4824UL, 0x5ce4b85cUL, - 0xc25d9fc2UL, 0xd36ebdd3UL, 0xacef43acUL, 0x62a6c462UL, - 0x91a83991UL, 0x95a43195UL, 0xe437d3e4UL, 0x798bf279UL, - 0xe732d5e7UL, 0xc8438bc8UL, 0x37596e37UL, 0x6db7da6dUL, - 0x8d8c018dUL, 0xd564b1d5UL, 0x4ed29c4eUL, 0xa9e049a9UL, - 0x6cb4d86cUL, 0x56faac56UL, 0xf407f3f4UL, 0xea25cfeaUL, - 0x65afca65UL, 0x7a8ef47aUL, 0xaee947aeUL, 0x08181008UL, - 0xbad56fbaUL, 0x7888f078UL, 0x256f4a25UL, 0x2e725c2eUL, - 0x1c24381cUL, 0xa6f157a6UL, 0xb4c773b4UL, 0xc65197c6UL, - 0xe823cbe8UL, 0xdd7ca1ddUL, 0x749ce874UL, 0x1f213e1fUL, - 0x4bdd964bUL, 0xbddc61bdUL, 0x8b860d8bUL, 0x8a850f8aUL, - 0x7090e070UL, 0x3e427c3eUL, 0xb5c471b5UL, 0x66aacc66UL, - 0x48d89048UL, 0x03050603UL, 0xf601f7f6UL, 0x0e121c0eUL, - 0x61a3c261UL, 0x355f6a35UL, 0x57f9ae57UL, 0xb9d069b9UL, - 0x86911786UL, 0xc15899c1UL, 0x1d273a1dUL, 0x9eb9279eUL, - 0xe138d9e1UL, 0xf813ebf8UL, 0x98b32b98UL, 0x11332211UL, - 0x69bbd269UL, 0xd970a9d9UL, 0x8e89078eUL, 0x94a73394UL, - 0x9bb62d9bUL, 0x1e223c1eUL, 0x87921587UL, 0xe920c9e9UL, - 0xce4987ceUL, 0x55ffaa55UL, 0x28785028UL, 0xdf7aa5dfUL, - 0x8c8f038cUL, 0xa1f859a1UL, 0x89800989UL, 0x0d171a0dUL, - 0xbfda65bfUL, 0xe631d7e6UL, 0x42c68442UL, 0x68b8d068UL, - 0x41c38241UL, 0x99b02999UL, 0x2d775a2dUL, 0x0f111e0fUL, - 0xb0cb7bb0UL, 0x54fca854UL, 0xbbd66dbbUL, 0x163a2c16UL, -}; -static const unsigned int Te3[256] = { - 0x6363a5c6UL, 0x7c7c84f8UL, 0x777799eeUL, 0x7b7b8df6UL, - 0xf2f20dffUL, 0x6b6bbdd6UL, 0x6f6fb1deUL, 0xc5c55491UL, - 0x30305060UL, 0x01010302UL, 0x6767a9ceUL, 0x2b2b7d56UL, - 0xfefe19e7UL, 0xd7d762b5UL, 0xababe64dUL, 0x76769aecUL, - 0xcaca458fUL, 0x82829d1fUL, 0xc9c94089UL, 0x7d7d87faUL, - 0xfafa15efUL, 0x5959ebb2UL, 0x4747c98eUL, 0xf0f00bfbUL, - 0xadadec41UL, 0xd4d467b3UL, 0xa2a2fd5fUL, 0xafafea45UL, - 0x9c9cbf23UL, 0xa4a4f753UL, 0x727296e4UL, 0xc0c05b9bUL, - 0xb7b7c275UL, 0xfdfd1ce1UL, 0x9393ae3dUL, 0x26266a4cUL, - 0x36365a6cUL, 0x3f3f417eUL, 0xf7f702f5UL, 0xcccc4f83UL, - 0x34345c68UL, 0xa5a5f451UL, 0xe5e534d1UL, 0xf1f108f9UL, - 0x717193e2UL, 0xd8d873abUL, 0x31315362UL, 0x15153f2aUL, - 0x04040c08UL, 0xc7c75295UL, 0x23236546UL, 0xc3c35e9dUL, - 0x18182830UL, 0x9696a137UL, 0x05050f0aUL, 0x9a9ab52fUL, - 0x0707090eUL, 0x12123624UL, 0x80809b1bUL, 0xe2e23ddfUL, - 0xebeb26cdUL, 0x2727694eUL, 0xb2b2cd7fUL, 0x75759feaUL, - 0x09091b12UL, 0x83839e1dUL, 0x2c2c7458UL, 0x1a1a2e34UL, - 0x1b1b2d36UL, 0x6e6eb2dcUL, 0x5a5aeeb4UL, 0xa0a0fb5bUL, - 0x5252f6a4UL, 0x3b3b4d76UL, 0xd6d661b7UL, 0xb3b3ce7dUL, - 0x29297b52UL, 0xe3e33eddUL, 0x2f2f715eUL, 0x84849713UL, - 0x5353f5a6UL, 0xd1d168b9UL, 0x00000000UL, 0xeded2cc1UL, - 0x20206040UL, 0xfcfc1fe3UL, 0xb1b1c879UL, 0x5b5bedb6UL, - 0x6a6abed4UL, 0xcbcb468dUL, 0xbebed967UL, 0x39394b72UL, - 0x4a4ade94UL, 0x4c4cd498UL, 0x5858e8b0UL, 0xcfcf4a85UL, - 0xd0d06bbbUL, 0xefef2ac5UL, 0xaaaae54fUL, 0xfbfb16edUL, - 0x4343c586UL, 0x4d4dd79aUL, 0x33335566UL, 0x85859411UL, - 0x4545cf8aUL, 0xf9f910e9UL, 0x02020604UL, 0x7f7f81feUL, - 0x5050f0a0UL, 0x3c3c4478UL, 0x9f9fba25UL, 0xa8a8e34bUL, - 0x5151f3a2UL, 0xa3a3fe5dUL, 0x4040c080UL, 0x8f8f8a05UL, - 0x9292ad3fUL, 0x9d9dbc21UL, 0x38384870UL, 0xf5f504f1UL, - 0xbcbcdf63UL, 0xb6b6c177UL, 0xdada75afUL, 0x21216342UL, - 0x10103020UL, 0xffff1ae5UL, 0xf3f30efdUL, 0xd2d26dbfUL, - 0xcdcd4c81UL, 0x0c0c1418UL, 0x13133526UL, 0xecec2fc3UL, - 0x5f5fe1beUL, 0x9797a235UL, 0x4444cc88UL, 0x1717392eUL, - 0xc4c45793UL, 0xa7a7f255UL, 0x7e7e82fcUL, 0x3d3d477aUL, - 0x6464acc8UL, 0x5d5de7baUL, 0x19192b32UL, 0x737395e6UL, - 0x6060a0c0UL, 0x81819819UL, 0x4f4fd19eUL, 0xdcdc7fa3UL, - 0x22226644UL, 0x2a2a7e54UL, 0x9090ab3bUL, 0x8888830bUL, - 0x4646ca8cUL, 0xeeee29c7UL, 0xb8b8d36bUL, 0x14143c28UL, - 0xdede79a7UL, 0x5e5ee2bcUL, 0x0b0b1d16UL, 0xdbdb76adUL, - 0xe0e03bdbUL, 0x32325664UL, 0x3a3a4e74UL, 0x0a0a1e14UL, - 0x4949db92UL, 0x06060a0cUL, 0x24246c48UL, 0x5c5ce4b8UL, - 0xc2c25d9fUL, 0xd3d36ebdUL, 0xacacef43UL, 0x6262a6c4UL, - 0x9191a839UL, 0x9595a431UL, 0xe4e437d3UL, 0x79798bf2UL, - 0xe7e732d5UL, 0xc8c8438bUL, 0x3737596eUL, 0x6d6db7daUL, - 0x8d8d8c01UL, 0xd5d564b1UL, 0x4e4ed29cUL, 0xa9a9e049UL, - 0x6c6cb4d8UL, 0x5656faacUL, 0xf4f407f3UL, 0xeaea25cfUL, - 0x6565afcaUL, 0x7a7a8ef4UL, 0xaeaee947UL, 0x08081810UL, - 0xbabad56fUL, 0x787888f0UL, 0x25256f4aUL, 0x2e2e725cUL, - 0x1c1c2438UL, 0xa6a6f157UL, 0xb4b4c773UL, 0xc6c65197UL, - 0xe8e823cbUL, 0xdddd7ca1UL, 0x74749ce8UL, 0x1f1f213eUL, - 0x4b4bdd96UL, 0xbdbddc61UL, 0x8b8b860dUL, 0x8a8a850fUL, - 0x707090e0UL, 0x3e3e427cUL, 0xb5b5c471UL, 0x6666aaccUL, - 0x4848d890UL, 0x03030506UL, 0xf6f601f7UL, 0x0e0e121cUL, - 0x6161a3c2UL, 0x35355f6aUL, 0x5757f9aeUL, 0xb9b9d069UL, - 0x86869117UL, 0xc1c15899UL, 0x1d1d273aUL, 0x9e9eb927UL, - 0xe1e138d9UL, 0xf8f813ebUL, 0x9898b32bUL, 0x11113322UL, - 0x6969bbd2UL, 0xd9d970a9UL, 0x8e8e8907UL, 0x9494a733UL, - 0x9b9bb62dUL, 0x1e1e223cUL, 0x87879215UL, 0xe9e920c9UL, - 0xcece4987UL, 0x5555ffaaUL, 0x28287850UL, 0xdfdf7aa5UL, - 0x8c8c8f03UL, 0xa1a1f859UL, 0x89898009UL, 0x0d0d171aUL, - 0xbfbfda65UL, 0xe6e631d7UL, 0x4242c684UL, 0x6868b8d0UL, - 0x4141c382UL, 0x9999b029UL, 0x2d2d775aUL, 0x0f0f111eUL, - 0xb0b0cb7bUL, 0x5454fca8UL, 0xbbbbd66dUL, 0x16163a2cUL, -}; -static const unsigned int Te4[256] = { - 0x63636363UL, 0x7c7c7c7cUL, 0x77777777UL, 0x7b7b7b7bUL, - 0xf2f2f2f2UL, 0x6b6b6b6bUL, 0x6f6f6f6fUL, 0xc5c5c5c5UL, - 0x30303030UL, 0x01010101UL, 0x67676767UL, 0x2b2b2b2bUL, - 0xfefefefeUL, 0xd7d7d7d7UL, 0xababababUL, 0x76767676UL, - 0xcacacacaUL, 0x82828282UL, 0xc9c9c9c9UL, 0x7d7d7d7dUL, - 0xfafafafaUL, 0x59595959UL, 0x47474747UL, 0xf0f0f0f0UL, - 0xadadadadUL, 0xd4d4d4d4UL, 0xa2a2a2a2UL, 0xafafafafUL, - 0x9c9c9c9cUL, 0xa4a4a4a4UL, 0x72727272UL, 0xc0c0c0c0UL, - 0xb7b7b7b7UL, 0xfdfdfdfdUL, 0x93939393UL, 0x26262626UL, - 0x36363636UL, 0x3f3f3f3fUL, 0xf7f7f7f7UL, 0xccccccccUL, - 0x34343434UL, 0xa5a5a5a5UL, 0xe5e5e5e5UL, 0xf1f1f1f1UL, - 0x71717171UL, 0xd8d8d8d8UL, 0x31313131UL, 0x15151515UL, - 0x04040404UL, 0xc7c7c7c7UL, 0x23232323UL, 0xc3c3c3c3UL, - 0x18181818UL, 0x96969696UL, 0x05050505UL, 0x9a9a9a9aUL, - 0x07070707UL, 0x12121212UL, 0x80808080UL, 0xe2e2e2e2UL, - 0xebebebebUL, 0x27272727UL, 0xb2b2b2b2UL, 0x75757575UL, - 0x09090909UL, 0x83838383UL, 0x2c2c2c2cUL, 0x1a1a1a1aUL, - 0x1b1b1b1bUL, 0x6e6e6e6eUL, 0x5a5a5a5aUL, 0xa0a0a0a0UL, - 0x52525252UL, 0x3b3b3b3bUL, 0xd6d6d6d6UL, 0xb3b3b3b3UL, - 0x29292929UL, 0xe3e3e3e3UL, 0x2f2f2f2fUL, 0x84848484UL, - 0x53535353UL, 0xd1d1d1d1UL, 0x00000000UL, 0xededededUL, - 0x20202020UL, 0xfcfcfcfcUL, 0xb1b1b1b1UL, 0x5b5b5b5bUL, - 0x6a6a6a6aUL, 0xcbcbcbcbUL, 0xbebebebeUL, 0x39393939UL, - 0x4a4a4a4aUL, 0x4c4c4c4cUL, 0x58585858UL, 0xcfcfcfcfUL, - 0xd0d0d0d0UL, 0xefefefefUL, 0xaaaaaaaaUL, 0xfbfbfbfbUL, - 0x43434343UL, 0x4d4d4d4dUL, 0x33333333UL, 0x85858585UL, - 0x45454545UL, 0xf9f9f9f9UL, 0x02020202UL, 0x7f7f7f7fUL, - 0x50505050UL, 0x3c3c3c3cUL, 0x9f9f9f9fUL, 0xa8a8a8a8UL, - 0x51515151UL, 0xa3a3a3a3UL, 0x40404040UL, 0x8f8f8f8fUL, - 0x92929292UL, 0x9d9d9d9dUL, 0x38383838UL, 0xf5f5f5f5UL, - 0xbcbcbcbcUL, 0xb6b6b6b6UL, 0xdadadadaUL, 0x21212121UL, - 0x10101010UL, 0xffffffffUL, 0xf3f3f3f3UL, 0xd2d2d2d2UL, - 0xcdcdcdcdUL, 0x0c0c0c0cUL, 0x13131313UL, 0xececececUL, - 0x5f5f5f5fUL, 0x97979797UL, 0x44444444UL, 0x17171717UL, - 0xc4c4c4c4UL, 0xa7a7a7a7UL, 0x7e7e7e7eUL, 0x3d3d3d3dUL, - 0x64646464UL, 0x5d5d5d5dUL, 0x19191919UL, 0x73737373UL, - 0x60606060UL, 0x81818181UL, 0x4f4f4f4fUL, 0xdcdcdcdcUL, - 0x22222222UL, 0x2a2a2a2aUL, 0x90909090UL, 0x88888888UL, - 0x46464646UL, 0xeeeeeeeeUL, 0xb8b8b8b8UL, 0x14141414UL, - 0xdedededeUL, 0x5e5e5e5eUL, 0x0b0b0b0bUL, 0xdbdbdbdbUL, - 0xe0e0e0e0UL, 0x32323232UL, 0x3a3a3a3aUL, 0x0a0a0a0aUL, - 0x49494949UL, 0x06060606UL, 0x24242424UL, 0x5c5c5c5cUL, - 0xc2c2c2c2UL, 0xd3d3d3d3UL, 0xacacacacUL, 0x62626262UL, - 0x91919191UL, 0x95959595UL, 0xe4e4e4e4UL, 0x79797979UL, - 0xe7e7e7e7UL, 0xc8c8c8c8UL, 0x37373737UL, 0x6d6d6d6dUL, - 0x8d8d8d8dUL, 0xd5d5d5d5UL, 0x4e4e4e4eUL, 0xa9a9a9a9UL, - 0x6c6c6c6cUL, 0x56565656UL, 0xf4f4f4f4UL, 0xeaeaeaeaUL, - 0x65656565UL, 0x7a7a7a7aUL, 0xaeaeaeaeUL, 0x08080808UL, - 0xbabababaUL, 0x78787878UL, 0x25252525UL, 0x2e2e2e2eUL, - 0x1c1c1c1cUL, 0xa6a6a6a6UL, 0xb4b4b4b4UL, 0xc6c6c6c6UL, - 0xe8e8e8e8UL, 0xddddddddUL, 0x74747474UL, 0x1f1f1f1fUL, - 0x4b4b4b4bUL, 0xbdbdbdbdUL, 0x8b8b8b8bUL, 0x8a8a8a8aUL, - 0x70707070UL, 0x3e3e3e3eUL, 0xb5b5b5b5UL, 0x66666666UL, - 0x48484848UL, 0x03030303UL, 0xf6f6f6f6UL, 0x0e0e0e0eUL, - 0x61616161UL, 0x35353535UL, 0x57575757UL, 0xb9b9b9b9UL, - 0x86868686UL, 0xc1c1c1c1UL, 0x1d1d1d1dUL, 0x9e9e9e9eUL, - 0xe1e1e1e1UL, 0xf8f8f8f8UL, 0x98989898UL, 0x11111111UL, - 0x69696969UL, 0xd9d9d9d9UL, 0x8e8e8e8eUL, 0x94949494UL, - 0x9b9b9b9bUL, 0x1e1e1e1eUL, 0x87878787UL, 0xe9e9e9e9UL, - 0xcecececeUL, 0x55555555UL, 0x28282828UL, 0xdfdfdfdfUL, - 0x8c8c8c8cUL, 0xa1a1a1a1UL, 0x89898989UL, 0x0d0d0d0dUL, - 0xbfbfbfbfUL, 0xe6e6e6e6UL, 0x42424242UL, 0x68686868UL, - 0x41414141UL, 0x99999999UL, 0x2d2d2d2dUL, 0x0f0f0f0fUL, - 0xb0b0b0b0UL, 0x54545454UL, 0xbbbbbbbbUL, 0x16161616UL, -}; -static const unsigned int Td0[256] = { - 0x51f4a750UL, 0x7e416553UL, 0x1a17a4c3UL, 0x3a275e96UL, - 0x3bab6bcbUL, 0x1f9d45f1UL, 0xacfa58abUL, 0x4be30393UL, - 0x2030fa55UL, 0xad766df6UL, 0x88cc7691UL, 0xf5024c25UL, - 0x4fe5d7fcUL, 0xc52acbd7UL, 0x26354480UL, 0xb562a38fUL, - 0xdeb15a49UL, 0x25ba1b67UL, 0x45ea0e98UL, 0x5dfec0e1UL, - 0xc32f7502UL, 0x814cf012UL, 0x8d4697a3UL, 0x6bd3f9c6UL, - 0x038f5fe7UL, 0x15929c95UL, 0xbf6d7aebUL, 0x955259daUL, - 0xd4be832dUL, 0x587421d3UL, 0x49e06929UL, 0x8ec9c844UL, - 0x75c2896aUL, 0xf48e7978UL, 0x99583e6bUL, 0x27b971ddUL, - 0xbee14fb6UL, 0xf088ad17UL, 0xc920ac66UL, 0x7dce3ab4UL, - 0x63df4a18UL, 0xe51a3182UL, 0x97513360UL, 0x62537f45UL, - 0xb16477e0UL, 0xbb6bae84UL, 0xfe81a01cUL, 0xf9082b94UL, - 0x70486858UL, 0x8f45fd19UL, 0x94de6c87UL, 0x527bf8b7UL, - 0xab73d323UL, 0x724b02e2UL, 0xe31f8f57UL, 0x6655ab2aUL, - 0xb2eb2807UL, 0x2fb5c203UL, 0x86c57b9aUL, 0xd33708a5UL, - 0x302887f2UL, 0x23bfa5b2UL, 0x02036abaUL, 0xed16825cUL, - 0x8acf1c2bUL, 0xa779b492UL, 0xf307f2f0UL, 0x4e69e2a1UL, - 0x65daf4cdUL, 0x0605bed5UL, 0xd134621fUL, 0xc4a6fe8aUL, - 0x342e539dUL, 0xa2f355a0UL, 0x058ae132UL, 0xa4f6eb75UL, - 0x0b83ec39UL, 0x4060efaaUL, 0x5e719f06UL, 0xbd6e1051UL, - 0x3e218af9UL, 0x96dd063dUL, 0xdd3e05aeUL, 0x4de6bd46UL, - 0x91548db5UL, 0x71c45d05UL, 0x0406d46fUL, 0x605015ffUL, - 0x1998fb24UL, 0xd6bde997UL, 0x894043ccUL, 0x67d99e77UL, - 0xb0e842bdUL, 0x07898b88UL, 0xe7195b38UL, 0x79c8eedbUL, - 0xa17c0a47UL, 0x7c420fe9UL, 0xf8841ec9UL, 0x00000000UL, - 0x09808683UL, 0x322bed48UL, 0x1e1170acUL, 0x6c5a724eUL, - 0xfd0efffbUL, 0x0f853856UL, 0x3daed51eUL, 0x362d3927UL, - 0x0a0fd964UL, 0x685ca621UL, 0x9b5b54d1UL, 0x24362e3aUL, - 0x0c0a67b1UL, 0x9357e70fUL, 0xb4ee96d2UL, 0x1b9b919eUL, - 0x80c0c54fUL, 0x61dc20a2UL, 0x5a774b69UL, 0x1c121a16UL, - 0xe293ba0aUL, 0xc0a02ae5UL, 0x3c22e043UL, 0x121b171dUL, - 0x0e090d0bUL, 0xf28bc7adUL, 0x2db6a8b9UL, 0x141ea9c8UL, - 0x57f11985UL, 0xaf75074cUL, 0xee99ddbbUL, 0xa37f60fdUL, - 0xf701269fUL, 0x5c72f5bcUL, 0x44663bc5UL, 0x5bfb7e34UL, - 0x8b432976UL, 0xcb23c6dcUL, 0xb6edfc68UL, 0xb8e4f163UL, - 0xd731dccaUL, 0x42638510UL, 0x13972240UL, 0x84c61120UL, - 0x854a247dUL, 0xd2bb3df8UL, 0xaef93211UL, 0xc729a16dUL, - 0x1d9e2f4bUL, 0xdcb230f3UL, 0x0d8652ecUL, 0x77c1e3d0UL, - 0x2bb3166cUL, 0xa970b999UL, 0x119448faUL, 0x47e96422UL, - 0xa8fc8cc4UL, 0xa0f03f1aUL, 0x567d2cd8UL, 0x223390efUL, - 0x87494ec7UL, 0xd938d1c1UL, 0x8ccaa2feUL, 0x98d40b36UL, - 0xa6f581cfUL, 0xa57ade28UL, 0xdab78e26UL, 0x3fadbfa4UL, - 0x2c3a9de4UL, 0x5078920dUL, 0x6a5fcc9bUL, 0x547e4662UL, - 0xf68d13c2UL, 0x90d8b8e8UL, 0x2e39f75eUL, 0x82c3aff5UL, - 0x9f5d80beUL, 0x69d0937cUL, 0x6fd52da9UL, 0xcf2512b3UL, - 0xc8ac993bUL, 0x10187da7UL, 0xe89c636eUL, 0xdb3bbb7bUL, - 0xcd267809UL, 0x6e5918f4UL, 0xec9ab701UL, 0x834f9aa8UL, - 0xe6956e65UL, 0xaaffe67eUL, 0x21bccf08UL, 0xef15e8e6UL, - 0xbae79bd9UL, 0x4a6f36ceUL, 0xea9f09d4UL, 0x29b07cd6UL, - 0x31a4b2afUL, 0x2a3f2331UL, 0xc6a59430UL, 0x35a266c0UL, - 0x744ebc37UL, 0xfc82caa6UL, 0xe090d0b0UL, 0x33a7d815UL, - 0xf104984aUL, 0x41ecdaf7UL, 0x7fcd500eUL, 0x1791f62fUL, - 0x764dd68dUL, 0x43efb04dUL, 0xccaa4d54UL, 0xe49604dfUL, - 0x9ed1b5e3UL, 0x4c6a881bUL, 0xc12c1fb8UL, 0x4665517fUL, - 0x9d5eea04UL, 0x018c355dUL, 0xfa877473UL, 0xfb0b412eUL, - 0xb3671d5aUL, 0x92dbd252UL, 0xe9105633UL, 0x6dd64713UL, - 0x9ad7618cUL, 0x37a10c7aUL, 0x59f8148eUL, 0xeb133c89UL, - 0xcea927eeUL, 0xb761c935UL, 0xe11ce5edUL, 0x7a47b13cUL, - 0x9cd2df59UL, 0x55f2733fUL, 0x1814ce79UL, 0x73c737bfUL, - 0x53f7cdeaUL, 0x5ffdaa5bUL, 0xdf3d6f14UL, 0x7844db86UL, - 0xcaaff381UL, 0xb968c43eUL, 0x3824342cUL, 0xc2a3405fUL, - 0x161dc372UL, 0xbce2250cUL, 0x283c498bUL, 0xff0d9541UL, - 0x39a80171UL, 0x080cb3deUL, 0xd8b4e49cUL, 0x6456c190UL, - 0x7bcb8461UL, 0xd532b670UL, 0x486c5c74UL, 0xd0b85742UL, -}; -static const unsigned int Td1[256] = { - 0x5051f4a7UL, 0x537e4165UL, 0xc31a17a4UL, 0x963a275eUL, - 0xcb3bab6bUL, 0xf11f9d45UL, 0xabacfa58UL, 0x934be303UL, - 0x552030faUL, 0xf6ad766dUL, 0x9188cc76UL, 0x25f5024cUL, - 0xfc4fe5d7UL, 0xd7c52acbUL, 0x80263544UL, 0x8fb562a3UL, - 0x49deb15aUL, 0x6725ba1bUL, 0x9845ea0eUL, 0xe15dfec0UL, - 0x02c32f75UL, 0x12814cf0UL, 0xa38d4697UL, 0xc66bd3f9UL, - 0xe7038f5fUL, 0x9515929cUL, 0xebbf6d7aUL, 0xda955259UL, - 0x2dd4be83UL, 0xd3587421UL, 0x2949e069UL, 0x448ec9c8UL, - 0x6a75c289UL, 0x78f48e79UL, 0x6b99583eUL, 0xdd27b971UL, - 0xb6bee14fUL, 0x17f088adUL, 0x66c920acUL, 0xb47dce3aUL, - 0x1863df4aUL, 0x82e51a31UL, 0x60975133UL, 0x4562537fUL, - 0xe0b16477UL, 0x84bb6baeUL, 0x1cfe81a0UL, 0x94f9082bUL, - 0x58704868UL, 0x198f45fdUL, 0x8794de6cUL, 0xb7527bf8UL, - 0x23ab73d3UL, 0xe2724b02UL, 0x57e31f8fUL, 0x2a6655abUL, - 0x07b2eb28UL, 0x032fb5c2UL, 0x9a86c57bUL, 0xa5d33708UL, - 0xf2302887UL, 0xb223bfa5UL, 0xba02036aUL, 0x5ced1682UL, - 0x2b8acf1cUL, 0x92a779b4UL, 0xf0f307f2UL, 0xa14e69e2UL, - 0xcd65daf4UL, 0xd50605beUL, 0x1fd13462UL, 0x8ac4a6feUL, - 0x9d342e53UL, 0xa0a2f355UL, 0x32058ae1UL, 0x75a4f6ebUL, - 0x390b83ecUL, 0xaa4060efUL, 0x065e719fUL, 0x51bd6e10UL, - 0xf93e218aUL, 0x3d96dd06UL, 0xaedd3e05UL, 0x464de6bdUL, - 0xb591548dUL, 0x0571c45dUL, 0x6f0406d4UL, 0xff605015UL, - 0x241998fbUL, 0x97d6bde9UL, 0xcc894043UL, 0x7767d99eUL, - 0xbdb0e842UL, 0x8807898bUL, 0x38e7195bUL, 0xdb79c8eeUL, - 0x47a17c0aUL, 0xe97c420fUL, 0xc9f8841eUL, 0x00000000UL, - 0x83098086UL, 0x48322bedUL, 0xac1e1170UL, 0x4e6c5a72UL, - 0xfbfd0effUL, 0x560f8538UL, 0x1e3daed5UL, 0x27362d39UL, - 0x640a0fd9UL, 0x21685ca6UL, 0xd19b5b54UL, 0x3a24362eUL, - 0xb10c0a67UL, 0x0f9357e7UL, 0xd2b4ee96UL, 0x9e1b9b91UL, - 0x4f80c0c5UL, 0xa261dc20UL, 0x695a774bUL, 0x161c121aUL, - 0x0ae293baUL, 0xe5c0a02aUL, 0x433c22e0UL, 0x1d121b17UL, - 0x0b0e090dUL, 0xadf28bc7UL, 0xb92db6a8UL, 0xc8141ea9UL, - 0x8557f119UL, 0x4caf7507UL, 0xbbee99ddUL, 0xfda37f60UL, - 0x9ff70126UL, 0xbc5c72f5UL, 0xc544663bUL, 0x345bfb7eUL, - 0x768b4329UL, 0xdccb23c6UL, 0x68b6edfcUL, 0x63b8e4f1UL, - 0xcad731dcUL, 0x10426385UL, 0x40139722UL, 0x2084c611UL, - 0x7d854a24UL, 0xf8d2bb3dUL, 0x11aef932UL, 0x6dc729a1UL, - 0x4b1d9e2fUL, 0xf3dcb230UL, 0xec0d8652UL, 0xd077c1e3UL, - 0x6c2bb316UL, 0x99a970b9UL, 0xfa119448UL, 0x2247e964UL, - 0xc4a8fc8cUL, 0x1aa0f03fUL, 0xd8567d2cUL, 0xef223390UL, - 0xc787494eUL, 0xc1d938d1UL, 0xfe8ccaa2UL, 0x3698d40bUL, - 0xcfa6f581UL, 0x28a57adeUL, 0x26dab78eUL, 0xa43fadbfUL, - 0xe42c3a9dUL, 0x0d507892UL, 0x9b6a5fccUL, 0x62547e46UL, - 0xc2f68d13UL, 0xe890d8b8UL, 0x5e2e39f7UL, 0xf582c3afUL, - 0xbe9f5d80UL, 0x7c69d093UL, 0xa96fd52dUL, 0xb3cf2512UL, - 0x3bc8ac99UL, 0xa710187dUL, 0x6ee89c63UL, 0x7bdb3bbbUL, - 0x09cd2678UL, 0xf46e5918UL, 0x01ec9ab7UL, 0xa8834f9aUL, - 0x65e6956eUL, 0x7eaaffe6UL, 0x0821bccfUL, 0xe6ef15e8UL, - 0xd9bae79bUL, 0xce4a6f36UL, 0xd4ea9f09UL, 0xd629b07cUL, - 0xaf31a4b2UL, 0x312a3f23UL, 0x30c6a594UL, 0xc035a266UL, - 0x37744ebcUL, 0xa6fc82caUL, 0xb0e090d0UL, 0x1533a7d8UL, - 0x4af10498UL, 0xf741ecdaUL, 0x0e7fcd50UL, 0x2f1791f6UL, - 0x8d764dd6UL, 0x4d43efb0UL, 0x54ccaa4dUL, 0xdfe49604UL, - 0xe39ed1b5UL, 0x1b4c6a88UL, 0xb8c12c1fUL, 0x7f466551UL, - 0x049d5eeaUL, 0x5d018c35UL, 0x73fa8774UL, 0x2efb0b41UL, - 0x5ab3671dUL, 0x5292dbd2UL, 0x33e91056UL, 0x136dd647UL, - 0x8c9ad761UL, 0x7a37a10cUL, 0x8e59f814UL, 0x89eb133cUL, - 0xeecea927UL, 0x35b761c9UL, 0xede11ce5UL, 0x3c7a47b1UL, - 0x599cd2dfUL, 0x3f55f273UL, 0x791814ceUL, 0xbf73c737UL, - 0xea53f7cdUL, 0x5b5ffdaaUL, 0x14df3d6fUL, 0x867844dbUL, - 0x81caaff3UL, 0x3eb968c4UL, 0x2c382434UL, 0x5fc2a340UL, - 0x72161dc3UL, 0x0cbce225UL, 0x8b283c49UL, 0x41ff0d95UL, - 0x7139a801UL, 0xde080cb3UL, 0x9cd8b4e4UL, 0x906456c1UL, - 0x617bcb84UL, 0x70d532b6UL, 0x74486c5cUL, 0x42d0b857UL, -}; -static const unsigned int Td2[256] = { - 0xa75051f4UL, 0x65537e41UL, 0xa4c31a17UL, 0x5e963a27UL, - 0x6bcb3babUL, 0x45f11f9dUL, 0x58abacfaUL, 0x03934be3UL, - 0xfa552030UL, 0x6df6ad76UL, 0x769188ccUL, 0x4c25f502UL, - 0xd7fc4fe5UL, 0xcbd7c52aUL, 0x44802635UL, 0xa38fb562UL, - 0x5a49deb1UL, 0x1b6725baUL, 0x0e9845eaUL, 0xc0e15dfeUL, - 0x7502c32fUL, 0xf012814cUL, 0x97a38d46UL, 0xf9c66bd3UL, - 0x5fe7038fUL, 0x9c951592UL, 0x7aebbf6dUL, 0x59da9552UL, - 0x832dd4beUL, 0x21d35874UL, 0x692949e0UL, 0xc8448ec9UL, - 0x896a75c2UL, 0x7978f48eUL, 0x3e6b9958UL, 0x71dd27b9UL, - 0x4fb6bee1UL, 0xad17f088UL, 0xac66c920UL, 0x3ab47dceUL, - 0x4a1863dfUL, 0x3182e51aUL, 0x33609751UL, 0x7f456253UL, - 0x77e0b164UL, 0xae84bb6bUL, 0xa01cfe81UL, 0x2b94f908UL, - 0x68587048UL, 0xfd198f45UL, 0x6c8794deUL, 0xf8b7527bUL, - 0xd323ab73UL, 0x02e2724bUL, 0x8f57e31fUL, 0xab2a6655UL, - 0x2807b2ebUL, 0xc2032fb5UL, 0x7b9a86c5UL, 0x08a5d337UL, - 0x87f23028UL, 0xa5b223bfUL, 0x6aba0203UL, 0x825ced16UL, - 0x1c2b8acfUL, 0xb492a779UL, 0xf2f0f307UL, 0xe2a14e69UL, - 0xf4cd65daUL, 0xbed50605UL, 0x621fd134UL, 0xfe8ac4a6UL, - 0x539d342eUL, 0x55a0a2f3UL, 0xe132058aUL, 0xeb75a4f6UL, - 0xec390b83UL, 0xefaa4060UL, 0x9f065e71UL, 0x1051bd6eUL, - 0x8af93e21UL, 0x063d96ddUL, 0x05aedd3eUL, 0xbd464de6UL, - 0x8db59154UL, 0x5d0571c4UL, 0xd46f0406UL, 0x15ff6050UL, - 0xfb241998UL, 0xe997d6bdUL, 0x43cc8940UL, 0x9e7767d9UL, - 0x42bdb0e8UL, 0x8b880789UL, 0x5b38e719UL, 0xeedb79c8UL, - 0x0a47a17cUL, 0x0fe97c42UL, 0x1ec9f884UL, 0x00000000UL, - 0x86830980UL, 0xed48322bUL, 0x70ac1e11UL, 0x724e6c5aUL, - 0xfffbfd0eUL, 0x38560f85UL, 0xd51e3daeUL, 0x3927362dUL, - 0xd9640a0fUL, 0xa621685cUL, 0x54d19b5bUL, 0x2e3a2436UL, - 0x67b10c0aUL, 0xe70f9357UL, 0x96d2b4eeUL, 0x919e1b9bUL, - 0xc54f80c0UL, 0x20a261dcUL, 0x4b695a77UL, 0x1a161c12UL, - 0xba0ae293UL, 0x2ae5c0a0UL, 0xe0433c22UL, 0x171d121bUL, - 0x0d0b0e09UL, 0xc7adf28bUL, 0xa8b92db6UL, 0xa9c8141eUL, - 0x198557f1UL, 0x074caf75UL, 0xddbbee99UL, 0x60fda37fUL, - 0x269ff701UL, 0xf5bc5c72UL, 0x3bc54466UL, 0x7e345bfbUL, - 0x29768b43UL, 0xc6dccb23UL, 0xfc68b6edUL, 0xf163b8e4UL, - 0xdccad731UL, 0x85104263UL, 0x22401397UL, 0x112084c6UL, - 0x247d854aUL, 0x3df8d2bbUL, 0x3211aef9UL, 0xa16dc729UL, - 0x2f4b1d9eUL, 0x30f3dcb2UL, 0x52ec0d86UL, 0xe3d077c1UL, - 0x166c2bb3UL, 0xb999a970UL, 0x48fa1194UL, 0x642247e9UL, - 0x8cc4a8fcUL, 0x3f1aa0f0UL, 0x2cd8567dUL, 0x90ef2233UL, - 0x4ec78749UL, 0xd1c1d938UL, 0xa2fe8ccaUL, 0x0b3698d4UL, - 0x81cfa6f5UL, 0xde28a57aUL, 0x8e26dab7UL, 0xbfa43fadUL, - 0x9de42c3aUL, 0x920d5078UL, 0xcc9b6a5fUL, 0x4662547eUL, - 0x13c2f68dUL, 0xb8e890d8UL, 0xf75e2e39UL, 0xaff582c3UL, - 0x80be9f5dUL, 0x937c69d0UL, 0x2da96fd5UL, 0x12b3cf25UL, - 0x993bc8acUL, 0x7da71018UL, 0x636ee89cUL, 0xbb7bdb3bUL, - 0x7809cd26UL, 0x18f46e59UL, 0xb701ec9aUL, 0x9aa8834fUL, - 0x6e65e695UL, 0xe67eaaffUL, 0xcf0821bcUL, 0xe8e6ef15UL, - 0x9bd9bae7UL, 0x36ce4a6fUL, 0x09d4ea9fUL, 0x7cd629b0UL, - 0xb2af31a4UL, 0x23312a3fUL, 0x9430c6a5UL, 0x66c035a2UL, - 0xbc37744eUL, 0xcaa6fc82UL, 0xd0b0e090UL, 0xd81533a7UL, - 0x984af104UL, 0xdaf741ecUL, 0x500e7fcdUL, 0xf62f1791UL, - 0xd68d764dUL, 0xb04d43efUL, 0x4d54ccaaUL, 0x04dfe496UL, - 0xb5e39ed1UL, 0x881b4c6aUL, 0x1fb8c12cUL, 0x517f4665UL, - 0xea049d5eUL, 0x355d018cUL, 0x7473fa87UL, 0x412efb0bUL, - 0x1d5ab367UL, 0xd25292dbUL, 0x5633e910UL, 0x47136dd6UL, - 0x618c9ad7UL, 0x0c7a37a1UL, 0x148e59f8UL, 0x3c89eb13UL, - 0x27eecea9UL, 0xc935b761UL, 0xe5ede11cUL, 0xb13c7a47UL, - 0xdf599cd2UL, 0x733f55f2UL, 0xce791814UL, 0x37bf73c7UL, - 0xcdea53f7UL, 0xaa5b5ffdUL, 0x6f14df3dUL, 0xdb867844UL, - 0xf381caafUL, 0xc43eb968UL, 0x342c3824UL, 0x405fc2a3UL, - 0xc372161dUL, 0x250cbce2UL, 0x498b283cUL, 0x9541ff0dUL, - 0x017139a8UL, 0xb3de080cUL, 0xe49cd8b4UL, 0xc1906456UL, - 0x84617bcbUL, 0xb670d532UL, 0x5c74486cUL, 0x5742d0b8UL, -}; -static const unsigned int Td3[256] = { - 0xf4a75051UL, 0x4165537eUL, 0x17a4c31aUL, 0x275e963aUL, - 0xab6bcb3bUL, 0x9d45f11fUL, 0xfa58abacUL, 0xe303934bUL, - 0x30fa5520UL, 0x766df6adUL, 0xcc769188UL, 0x024c25f5UL, - 0xe5d7fc4fUL, 0x2acbd7c5UL, 0x35448026UL, 0x62a38fb5UL, - 0xb15a49deUL, 0xba1b6725UL, 0xea0e9845UL, 0xfec0e15dUL, - 0x2f7502c3UL, 0x4cf01281UL, 0x4697a38dUL, 0xd3f9c66bUL, - 0x8f5fe703UL, 0x929c9515UL, 0x6d7aebbfUL, 0x5259da95UL, - 0xbe832dd4UL, 0x7421d358UL, 0xe0692949UL, 0xc9c8448eUL, - 0xc2896a75UL, 0x8e7978f4UL, 0x583e6b99UL, 0xb971dd27UL, - 0xe14fb6beUL, 0x88ad17f0UL, 0x20ac66c9UL, 0xce3ab47dUL, - 0xdf4a1863UL, 0x1a3182e5UL, 0x51336097UL, 0x537f4562UL, - 0x6477e0b1UL, 0x6bae84bbUL, 0x81a01cfeUL, 0x082b94f9UL, - 0x48685870UL, 0x45fd198fUL, 0xde6c8794UL, 0x7bf8b752UL, - 0x73d323abUL, 0x4b02e272UL, 0x1f8f57e3UL, 0x55ab2a66UL, - 0xeb2807b2UL, 0xb5c2032fUL, 0xc57b9a86UL, 0x3708a5d3UL, - 0x2887f230UL, 0xbfa5b223UL, 0x036aba02UL, 0x16825cedUL, - 0xcf1c2b8aUL, 0x79b492a7UL, 0x07f2f0f3UL, 0x69e2a14eUL, - 0xdaf4cd65UL, 0x05bed506UL, 0x34621fd1UL, 0xa6fe8ac4UL, - 0x2e539d34UL, 0xf355a0a2UL, 0x8ae13205UL, 0xf6eb75a4UL, - 0x83ec390bUL, 0x60efaa40UL, 0x719f065eUL, 0x6e1051bdUL, - 0x218af93eUL, 0xdd063d96UL, 0x3e05aeddUL, 0xe6bd464dUL, - 0x548db591UL, 0xc45d0571UL, 0x06d46f04UL, 0x5015ff60UL, - 0x98fb2419UL, 0xbde997d6UL, 0x4043cc89UL, 0xd99e7767UL, - 0xe842bdb0UL, 0x898b8807UL, 0x195b38e7UL, 0xc8eedb79UL, - 0x7c0a47a1UL, 0x420fe97cUL, 0x841ec9f8UL, 0x00000000UL, - 0x80868309UL, 0x2bed4832UL, 0x1170ac1eUL, 0x5a724e6cUL, - 0x0efffbfdUL, 0x8538560fUL, 0xaed51e3dUL, 0x2d392736UL, - 0x0fd9640aUL, 0x5ca62168UL, 0x5b54d19bUL, 0x362e3a24UL, - 0x0a67b10cUL, 0x57e70f93UL, 0xee96d2b4UL, 0x9b919e1bUL, - 0xc0c54f80UL, 0xdc20a261UL, 0x774b695aUL, 0x121a161cUL, - 0x93ba0ae2UL, 0xa02ae5c0UL, 0x22e0433cUL, 0x1b171d12UL, - 0x090d0b0eUL, 0x8bc7adf2UL, 0xb6a8b92dUL, 0x1ea9c814UL, - 0xf1198557UL, 0x75074cafUL, 0x99ddbbeeUL, 0x7f60fda3UL, - 0x01269ff7UL, 0x72f5bc5cUL, 0x663bc544UL, 0xfb7e345bUL, - 0x4329768bUL, 0x23c6dccbUL, 0xedfc68b6UL, 0xe4f163b8UL, - 0x31dccad7UL, 0x63851042UL, 0x97224013UL, 0xc6112084UL, - 0x4a247d85UL, 0xbb3df8d2UL, 0xf93211aeUL, 0x29a16dc7UL, - 0x9e2f4b1dUL, 0xb230f3dcUL, 0x8652ec0dUL, 0xc1e3d077UL, - 0xb3166c2bUL, 0x70b999a9UL, 0x9448fa11UL, 0xe9642247UL, - 0xfc8cc4a8UL, 0xf03f1aa0UL, 0x7d2cd856UL, 0x3390ef22UL, - 0x494ec787UL, 0x38d1c1d9UL, 0xcaa2fe8cUL, 0xd40b3698UL, - 0xf581cfa6UL, 0x7ade28a5UL, 0xb78e26daUL, 0xadbfa43fUL, - 0x3a9de42cUL, 0x78920d50UL, 0x5fcc9b6aUL, 0x7e466254UL, - 0x8d13c2f6UL, 0xd8b8e890UL, 0x39f75e2eUL, 0xc3aff582UL, - 0x5d80be9fUL, 0xd0937c69UL, 0xd52da96fUL, 0x2512b3cfUL, - 0xac993bc8UL, 0x187da710UL, 0x9c636ee8UL, 0x3bbb7bdbUL, - 0x267809cdUL, 0x5918f46eUL, 0x9ab701ecUL, 0x4f9aa883UL, - 0x956e65e6UL, 0xffe67eaaUL, 0xbccf0821UL, 0x15e8e6efUL, - 0xe79bd9baUL, 0x6f36ce4aUL, 0x9f09d4eaUL, 0xb07cd629UL, - 0xa4b2af31UL, 0x3f23312aUL, 0xa59430c6UL, 0xa266c035UL, - 0x4ebc3774UL, 0x82caa6fcUL, 0x90d0b0e0UL, 0xa7d81533UL, - 0x04984af1UL, 0xecdaf741UL, 0xcd500e7fUL, 0x91f62f17UL, - 0x4dd68d76UL, 0xefb04d43UL, 0xaa4d54ccUL, 0x9604dfe4UL, - 0xd1b5e39eUL, 0x6a881b4cUL, 0x2c1fb8c1UL, 0x65517f46UL, - 0x5eea049dUL, 0x8c355d01UL, 0x877473faUL, 0x0b412efbUL, - 0x671d5ab3UL, 0xdbd25292UL, 0x105633e9UL, 0xd647136dUL, - 0xd7618c9aUL, 0xa10c7a37UL, 0xf8148e59UL, 0x133c89ebUL, - 0xa927eeceUL, 0x61c935b7UL, 0x1ce5ede1UL, 0x47b13c7aUL, - 0xd2df599cUL, 0xf2733f55UL, 0x14ce7918UL, 0xc737bf73UL, - 0xf7cdea53UL, 0xfdaa5b5fUL, 0x3d6f14dfUL, 0x44db8678UL, - 0xaff381caUL, 0x68c43eb9UL, 0x24342c38UL, 0xa3405fc2UL, - 0x1dc37216UL, 0xe2250cbcUL, 0x3c498b28UL, 0x0d9541ffUL, - 0xa8017139UL, 0x0cb3de08UL, 0xb4e49cd8UL, 0x56c19064UL, - 0xcb84617bUL, 0x32b670d5UL, 0x6c5c7448UL, 0xb85742d0UL, -}; -static const unsigned int Td4[256] = { - 0x52525252UL, 0x09090909UL, 0x6a6a6a6aUL, 0xd5d5d5d5UL, - 0x30303030UL, 0x36363636UL, 0xa5a5a5a5UL, 0x38383838UL, - 0xbfbfbfbfUL, 0x40404040UL, 0xa3a3a3a3UL, 0x9e9e9e9eUL, - 0x81818181UL, 0xf3f3f3f3UL, 0xd7d7d7d7UL, 0xfbfbfbfbUL, - 0x7c7c7c7cUL, 0xe3e3e3e3UL, 0x39393939UL, 0x82828282UL, - 0x9b9b9b9bUL, 0x2f2f2f2fUL, 0xffffffffUL, 0x87878787UL, - 0x34343434UL, 0x8e8e8e8eUL, 0x43434343UL, 0x44444444UL, - 0xc4c4c4c4UL, 0xdedededeUL, 0xe9e9e9e9UL, 0xcbcbcbcbUL, - 0x54545454UL, 0x7b7b7b7bUL, 0x94949494UL, 0x32323232UL, - 0xa6a6a6a6UL, 0xc2c2c2c2UL, 0x23232323UL, 0x3d3d3d3dUL, - 0xeeeeeeeeUL, 0x4c4c4c4cUL, 0x95959595UL, 0x0b0b0b0bUL, - 0x42424242UL, 0xfafafafaUL, 0xc3c3c3c3UL, 0x4e4e4e4eUL, - 0x08080808UL, 0x2e2e2e2eUL, 0xa1a1a1a1UL, 0x66666666UL, - 0x28282828UL, 0xd9d9d9d9UL, 0x24242424UL, 0xb2b2b2b2UL, - 0x76767676UL, 0x5b5b5b5bUL, 0xa2a2a2a2UL, 0x49494949UL, - 0x6d6d6d6dUL, 0x8b8b8b8bUL, 0xd1d1d1d1UL, 0x25252525UL, - 0x72727272UL, 0xf8f8f8f8UL, 0xf6f6f6f6UL, 0x64646464UL, - 0x86868686UL, 0x68686868UL, 0x98989898UL, 0x16161616UL, - 0xd4d4d4d4UL, 0xa4a4a4a4UL, 0x5c5c5c5cUL, 0xccccccccUL, - 0x5d5d5d5dUL, 0x65656565UL, 0xb6b6b6b6UL, 0x92929292UL, - 0x6c6c6c6cUL, 0x70707070UL, 0x48484848UL, 0x50505050UL, - 0xfdfdfdfdUL, 0xededededUL, 0xb9b9b9b9UL, 0xdadadadaUL, - 0x5e5e5e5eUL, 0x15151515UL, 0x46464646UL, 0x57575757UL, - 0xa7a7a7a7UL, 0x8d8d8d8dUL, 0x9d9d9d9dUL, 0x84848484UL, - 0x90909090UL, 0xd8d8d8d8UL, 0xababababUL, 0x00000000UL, - 0x8c8c8c8cUL, 0xbcbcbcbcUL, 0xd3d3d3d3UL, 0x0a0a0a0aUL, - 0xf7f7f7f7UL, 0xe4e4e4e4UL, 0x58585858UL, 0x05050505UL, - 0xb8b8b8b8UL, 0xb3b3b3b3UL, 0x45454545UL, 0x06060606UL, - 0xd0d0d0d0UL, 0x2c2c2c2cUL, 0x1e1e1e1eUL, 0x8f8f8f8fUL, - 0xcacacacaUL, 0x3f3f3f3fUL, 0x0f0f0f0fUL, 0x02020202UL, - 0xc1c1c1c1UL, 0xafafafafUL, 0xbdbdbdbdUL, 0x03030303UL, - 0x01010101UL, 0x13131313UL, 0x8a8a8a8aUL, 0x6b6b6b6bUL, - 0x3a3a3a3aUL, 0x91919191UL, 0x11111111UL, 0x41414141UL, - 0x4f4f4f4fUL, 0x67676767UL, 0xdcdcdcdcUL, 0xeaeaeaeaUL, - 0x97979797UL, 0xf2f2f2f2UL, 0xcfcfcfcfUL, 0xcecececeUL, - 0xf0f0f0f0UL, 0xb4b4b4b4UL, 0xe6e6e6e6UL, 0x73737373UL, - 0x96969696UL, 0xacacacacUL, 0x74747474UL, 0x22222222UL, - 0xe7e7e7e7UL, 0xadadadadUL, 0x35353535UL, 0x85858585UL, - 0xe2e2e2e2UL, 0xf9f9f9f9UL, 0x37373737UL, 0xe8e8e8e8UL, - 0x1c1c1c1cUL, 0x75757575UL, 0xdfdfdfdfUL, 0x6e6e6e6eUL, - 0x47474747UL, 0xf1f1f1f1UL, 0x1a1a1a1aUL, 0x71717171UL, - 0x1d1d1d1dUL, 0x29292929UL, 0xc5c5c5c5UL, 0x89898989UL, - 0x6f6f6f6fUL, 0xb7b7b7b7UL, 0x62626262UL, 0x0e0e0e0eUL, - 0xaaaaaaaaUL, 0x18181818UL, 0xbebebebeUL, 0x1b1b1b1bUL, - 0xfcfcfcfcUL, 0x56565656UL, 0x3e3e3e3eUL, 0x4b4b4b4bUL, - 0xc6c6c6c6UL, 0xd2d2d2d2UL, 0x79797979UL, 0x20202020UL, - 0x9a9a9a9aUL, 0xdbdbdbdbUL, 0xc0c0c0c0UL, 0xfefefefeUL, - 0x78787878UL, 0xcdcdcdcdUL, 0x5a5a5a5aUL, 0xf4f4f4f4UL, - 0x1f1f1f1fUL, 0xddddddddUL, 0xa8a8a8a8UL, 0x33333333UL, - 0x88888888UL, 0x07070707UL, 0xc7c7c7c7UL, 0x31313131UL, - 0xb1b1b1b1UL, 0x12121212UL, 0x10101010UL, 0x59595959UL, - 0x27272727UL, 0x80808080UL, 0xececececUL, 0x5f5f5f5fUL, - 0x60606060UL, 0x51515151UL, 0x7f7f7f7fUL, 0xa9a9a9a9UL, - 0x19191919UL, 0xb5b5b5b5UL, 0x4a4a4a4aUL, 0x0d0d0d0dUL, - 0x2d2d2d2dUL, 0xe5e5e5e5UL, 0x7a7a7a7aUL, 0x9f9f9f9fUL, - 0x93939393UL, 0xc9c9c9c9UL, 0x9c9c9c9cUL, 0xefefefefUL, - 0xa0a0a0a0UL, 0xe0e0e0e0UL, 0x3b3b3b3bUL, 0x4d4d4d4dUL, - 0xaeaeaeaeUL, 0x2a2a2a2aUL, 0xf5f5f5f5UL, 0xb0b0b0b0UL, - 0xc8c8c8c8UL, 0xebebebebUL, 0xbbbbbbbbUL, 0x3c3c3c3cUL, - 0x83838383UL, 0x53535353UL, 0x99999999UL, 0x61616161UL, - 0x17171717UL, 0x2b2b2b2bUL, 0x04040404UL, 0x7e7e7e7eUL, - 0xbabababaUL, 0x77777777UL, 0xd6d6d6d6UL, 0x26262626UL, - 0xe1e1e1e1UL, 0x69696969UL, 0x14141414UL, 0x63636363UL, - 0x55555555UL, 0x21212121UL, 0x0c0c0c0cUL, 0x7d7d7d7dUL, -}; -static const unsigned int rcon[] = { - 0x01000000UL, 0x02000000UL, 0x04000000UL, 0x08000000UL, - 0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL, - 0x1B000000UL, 0x36000000UL, -}; - -#define GETU32(pt) (((unsigned int)(pt)[0] << 24) ^ \ - ((unsigned int)(pt)[1] << 16) ^ \ - ((unsigned int)(pt)[2] << 8) ^ \ - ((unsigned int)(pt)[3])) - -#define PUTU32(ct, st) { (ct)[0] = (unsigned char)((st) >> 24); \ - (ct)[1] = (unsigned char)((st) >> 16); \ - (ct)[2] = (unsigned char)((st) >> 8); \ - (ct)[3] = (unsigned char)(st); } - -/* -* Expand the cipher key into the encryption key schedule and return the -* number of rounds for the given cipher key size. -*/ -int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBytes) { - int i = 0; - unsigned int temp; - - rk[0] = GETU32(cipherKey); - rk[1] = GETU32(cipherKey + 4); - rk[2] = GETU32(cipherKey + 8); - rk[3] = GETU32(cipherKey + 12); - if (keyBytes == 16) { // 128 bits - for (;;) { - temp = rk[3]; - rk[4] = rk[0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[5] = rk[1] ^ rk[4]; - rk[6] = rk[2] ^ rk[5]; - rk[7] = rk[3] ^ rk[6]; - if (++i == 10) { - return 10; - } - rk += 4; - } - } - rk[4] = GETU32(cipherKey + 16); - rk[5] = GETU32(cipherKey + 20); - if (keyBytes == 24) { // 192 bits - for (;;) { - temp = rk[ 5]; - rk[ 6] = rk[ 0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[ 7] = rk[ 1] ^ rk[ 6]; - rk[ 8] = rk[ 2] ^ rk[ 7]; - rk[ 9] = rk[ 3] ^ rk[ 8]; - if (++i == 8) { - return 12; - } - rk[10] = rk[ 4] ^ rk[ 9]; - rk[11] = rk[ 5] ^ rk[10]; - rk += 6; - } - } - rk[6] = GETU32(cipherKey + 24); - rk[7] = GETU32(cipherKey + 28); - if (keyBytes == 32) { // 256 bits - for (;;) { - temp = rk[ 7]; - rk[ 8] = rk[ 0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[ 9] = rk[ 1] ^ rk[ 8]; - rk[10] = rk[ 2] ^ rk[ 9]; - rk[11] = rk[ 3] ^ rk[10]; - if (++i == 7) { - return 14; - } - temp = rk[11]; - rk[12] = rk[ 4] ^ - (Te4[(temp >> 24) ] & 0xff000000) ^ - (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(temp) & 0xff] & 0x000000ff); - rk[13] = rk[ 5] ^ rk[12]; - rk[14] = rk[ 6] ^ rk[13]; - rk[15] = rk[ 7] ^ rk[14]; - - rk += 8; - } - } - return 0; -} - -/* -* Expand the cipher key into encryption and decryption key schedule and -* return the number of rounds for the given cipher key size. -*/ -int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char cipherKey[], int keyBytes) { - int Nr, i; - - // expand the cipher key - Nr = aes_setkey_enc(rk, cipherKey, keyBytes); - // invert the order of the first round keys - rrk += Nr * 4; - rrk[0] = rk[0]; - rrk[1] = rk[1]; - rrk[2] = rk[2]; - rrk[3] = rk[3]; - - /* - * apply the inverse MixColumn transform to all round keys but the first - * and the last - */ - for (i = 1; i < Nr; i++) { - rrk -= 4; - rk += 4; - rrk[0] = - Td0[Te4[(rk[0] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[0]) & 0xff] & 0xff]; - rrk[1] = - Td0[Te4[(rk[1] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[1]) & 0xff] & 0xff]; - rrk[2] = - Td0[Te4[(rk[2] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[2]) & 0xff] & 0xff]; - rrk[3] = - Td0[Te4[(rk[3] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[3]) & 0xff] & 0xff]; - } - // invert the order of the last round keys - rrk -= 4; - rk += 4; - rrk[0] = rk[0]; - rrk[1] = rk[1]; - rrk[2] = rk[2]; - rrk[3] = rk[3]; - - return Nr; -} - -/* -* Encrypt the plain text into cipher -*/ -void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[]) { - unsigned int s0, s1, s2, s3, t0, t1, t2, t3, *iv; - const unsigned int *rk; - int r; - - rk = pCtx->Ek; - iv = pCtx->Iv; - /* - * map byte array block to cipher state - * and add initial round key: - */ - s0 = GETU32(pt) ^ rk[0]; - s1 = GETU32(pt + 4) ^ rk[1]; - s2 = GETU32(pt + 8) ^ rk[2]; - s3 = GETU32(pt + 12) ^ rk[3]; - if (pCtx->Mode) { - s0 = s0 ^ iv[0]; - s1 = s1 ^ iv[1]; - s2 = s2 ^ iv[2]; - s3 = s3 ^ iv[3]; - } - /* - * Nr - 1 full rounds: - */ - r = pCtx->Nr >> 1; - for (;;) { - t0 = - Te0[(s0 >> 24) ] ^ - Te1[(s1 >> 16) & 0xff] ^ - Te2[(s2 >> 8) & 0xff] ^ - Te3[(s3) & 0xff] ^ - rk[4]; - t1 = - Te0[(s1 >> 24) ] ^ - Te1[(s2 >> 16) & 0xff] ^ - Te2[(s3 >> 8) & 0xff] ^ - Te3[(s0) & 0xff] ^ - rk[5]; - t2 = - Te0[(s2 >> 24) ] ^ - Te1[(s3 >> 16) & 0xff] ^ - Te2[(s0 >> 8) & 0xff] ^ - Te3[(s1) & 0xff] ^ - rk[6]; - t3 = - Te0[(s3 >> 24) ] ^ - Te1[(s0 >> 16) & 0xff] ^ - Te2[(s1 >> 8) & 0xff] ^ - Te3[(s2) & 0xff] ^ - rk[7]; - - rk += 8; - if (--r == 0) { - break; - } - - s0 = - Te0[(t0 >> 24) ] ^ - Te1[(t1 >> 16) & 0xff] ^ - Te2[(t2 >> 8) & 0xff] ^ - Te3[(t3) & 0xff] ^ - rk[0]; - s1 = - Te0[(t1 >> 24) ] ^ - Te1[(t2 >> 16) & 0xff] ^ - Te2[(t3 >> 8) & 0xff] ^ - Te3[(t0) & 0xff] ^ - rk[1]; - s2 = - Te0[(t2 >> 24) ] ^ - Te1[(t3 >> 16) & 0xff] ^ - Te2[(t0 >> 8) & 0xff] ^ - Te3[(t1) & 0xff] ^ - rk[2]; - s3 = - Te0[(t3 >> 24) ] ^ - Te1[(t0 >> 16) & 0xff] ^ - Te2[(t1 >> 8) & 0xff] ^ - Te3[(t2) & 0xff] ^ - rk[3]; - } - /* - * apply last round and - * map cipher state to byte array block: - */ - s0 = - (Te4[(t0 >> 24) ] & 0xff000000) ^ - (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t3) & 0xff] & 0x000000ff) ^ - rk[0]; - PUTU32(ct, s0); - s1 = - (Te4[(t1 >> 24) ] & 0xff000000) ^ - (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t0) & 0xff] & 0x000000ff) ^ - rk[1]; - PUTU32(ct + 4, s1); - s2 = - (Te4[(t2 >> 24) ] & 0xff000000) ^ - (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t1) & 0xff] & 0x000000ff) ^ - rk[2]; - PUTU32(ct + 8, s2); - s3 = - (Te4[(t3 >> 24) ] & 0xff000000) ^ - (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t2) & 0xff] & 0x000000ff) ^ - rk[3]; - PUTU32(ct + 12, s3); - - if (pCtx->Mode) { - iv[0] = s0; - iv[1] = s1; - iv[2] = s2; - iv[3] = s3; - } -} - -/* -* Decrypt the cipher into plain text -*/ -void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[]) { - unsigned int s0, s1, s2, s3, t0, t1, t2, t3, v0, v1, v2, v3, *iv; - const unsigned int *rk; - int r; - - rk = pCtx->Dk; - iv = pCtx->Iv; - /* - * map byte array block to cipher state - * and add initial round key: - */ - v0 = GETU32(ct); - s0 = v0 ^ rk[0]; - v1 = GETU32(ct + 4); - s1 = v1 ^ rk[1]; - v2 = GETU32(ct + 8); - s2 = v2 ^ rk[2]; - v3 = GETU32(ct + 12); - s3 = v3 ^ rk[3]; - /* - * Nr - 1 full rounds: - */ - r = pCtx->Nr >> 1; - for (;;) { - t0 = - Td0[(s0 >> 24) ] ^ - Td1[(s3 >> 16) & 0xff] ^ - Td2[(s2 >> 8) & 0xff] ^ - Td3[(s1) & 0xff] ^ - rk[4]; - t1 = - Td0[(s1 >> 24) ] ^ - Td1[(s0 >> 16) & 0xff] ^ - Td2[(s3 >> 8) & 0xff] ^ - Td3[(s2) & 0xff] ^ - rk[5]; - t2 = - Td0[(s2 >> 24) ] ^ - Td1[(s1 >> 16) & 0xff] ^ - Td2[(s0 >> 8) & 0xff] ^ - Td3[(s3) & 0xff] ^ - rk[6]; - t3 = - Td0[(s3 >> 24) ] ^ - Td1[(s2 >> 16) & 0xff] ^ - Td2[(s1 >> 8) & 0xff] ^ - Td3[(s0) & 0xff] ^ - rk[7]; - - rk += 8; - if (--r == 0) { - break; - } - - s0 = - Td0[(t0 >> 24) ] ^ - Td1[(t3 >> 16) & 0xff] ^ - Td2[(t2 >> 8) & 0xff] ^ - Td3[(t1) & 0xff] ^ - rk[0]; - s1 = - Td0[(t1 >> 24) ] ^ - Td1[(t0 >> 16) & 0xff] ^ - Td2[(t3 >> 8) & 0xff] ^ - Td3[(t2) & 0xff] ^ - rk[1]; - s2 = - Td0[(t2 >> 24) ] ^ - Td1[(t1 >> 16) & 0xff] ^ - Td2[(t0 >> 8) & 0xff] ^ - Td3[(t3) & 0xff] ^ - rk[2]; - s3 = - Td0[(t3 >> 24) ] ^ - Td1[(t2 >> 16) & 0xff] ^ - Td2[(t1 >> 8) & 0xff] ^ - Td3[(t0) & 0xff] ^ - rk[3]; - } - /* - * apply last round and - * map cipher state to byte array block: - */ - s0 = - (Td4[(t0 >> 24) ] & 0xff000000) ^ - (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t1) & 0xff] & 0x000000ff) ^ - rk[0]; - s1 = - (Td4[(t1 >> 24) ] & 0xff000000) ^ - (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t2) & 0xff] & 0x000000ff) ^ - rk[1]; - s2 = - (Td4[(t2 >> 24) ] & 0xff000000) ^ - (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t3) & 0xff] & 0x000000ff) ^ - rk[2]; - s3 = - (Td4[(t3 >> 24) ] & 0xff000000) ^ - (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t0) & 0xff] & 0x000000ff) ^ - rk[3]; - - if (pCtx->Mode) { - s0 = s0 ^ iv[0]; - iv[0] = v0; - s1 = s1 ^ iv[1]; - iv[1] = v1; - s2 = s2 ^ iv[2]; - iv[2] = v2; - s3 = s3 ^ iv[3]; - iv[3] = v3; - } - - PUTU32(pt, s0); - PUTU32(pt + 4, s1); - PUTU32(pt + 8, s2); - PUTU32(pt + 12, s3); -} - -////////////////////////////////////////////////////////////////////////////// -// API functions // -////////////////////////////////////////////////////////////////////////////// - -/* -* initialize AES context -*/ -int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode) { - if (pKey == 0 || pCtx == 0 || (KeyLen != KEY128 && KeyLen != KEY192 && KeyLen != KEY256)) - return -1; - - // generate key schedule - pCtx->Nr = AesGenKeySched(pCtx->Ek, pCtx->Dk, pKey, KeyLen); - - // initialize IV - if (pIV != 0) { - pCtx->Iv[0] = GETU32(pIV); - pCtx->Iv[1] = GETU32(pIV + 4); - pCtx->Iv[2] = GETU32(pIV + 8); - pCtx->Iv[3] = GETU32(pIV + 12); - } - - // mode - pCtx->Mode = Mode; - - return 0; -} - -/* -* Encrypt plain text -*/ -int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen) { - int i; - - if (pData == 0 || pCipher == 0 || pCtx == 0 || (DataLen & 0xf) != 0) - return -1; - - for (i = 0; i < DataLen; i += BLOCKSZ) { - // encrypt block by block - AesEncBlk(pCtx, pData, pCipher); - pCipher += BLOCKSZ; - pData += BLOCKSZ; - } - return DataLen; -} - -/* -* Decrypt cipher -*/ -int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen) { - int i; - - if (pData == 0 || pCipher == 0 || pCtx == 0 || (CipherLen & 0xf) != 0) - return -1; - - for (i = 0; i < CipherLen; i += BLOCKSZ) { - // decrypt block by block - AesDecBlk(pCtx, pCipher, pData); - pCipher += BLOCKSZ; - pData += BLOCKSZ; - } - return CipherLen; -} - -////////////////////////////////////////////////////////////////////////////// -// Sample main program // -////////////////////////////////////////////////////////////////////////////// - -#ifndef EMBEDDED - -#include - -int main() { - AesCtx ctx; - unsigned char iv[] = "INI VECTINI VECT"; - unsigned char key[] = "This is a sample AESKey"; - unsigned char databuf[] = "Data : AES Test"; // must be in multiple of 16 - - // initialize context and encrypt data at one end - - if (AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0) - printf("init error\n"); - - if (AesEncrypt(&ctx, databuf, databuf, sizeof(databuf)) < 0) - printf("error in encryption\n"); - - // initialize context and decrypt cipher at other end - - if (AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0) - printf("init error\n"); - - if (AesDecrypt(&ctx, databuf, databuf, sizeof(databuf)) < 0) - printf("error in decryption\n"); - - printf("%s\n", databuf); - - return 0; -} -#endif diff --git a/armsrc/aes.h b/armsrc/aes.h deleted file mode 100644 index aa9f0c582..000000000 --- a/armsrc/aes.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* AES Cryptographic Algorithm Header File. Include this header file in -* your source which uses these given APIs. (This source is kept under -* public domain) -*/ -#ifndef __AES_H -#define __AES_H - -// AES context structure -typedef struct { - unsigned int Ek[60]; - unsigned int Dk[60]; - unsigned int Iv[4]; - unsigned char Nr; - unsigned char Mode; -} AesCtx; - -// key length in bytes -#define KEY128 16 -#define KEY192 24 -#define KEY256 32 -// block size in bytes -#define BLOCKSZ 16 -// mode -#define EBC 0 -#define CBC 1 - -// AES API function prototype - -int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode); -int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen); -int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen); - -#endif diff --git a/armsrc/desfire_crypto.c b/armsrc/desfire_crypto.c index 10ddf4162..2e9d5a8d3 100644 --- a/armsrc/desfire_crypto.c +++ b/armsrc/desfire_crypto.c @@ -571,15 +571,19 @@ void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, case T_AES: switch (operation) { case MCO_ENCYPHER: { - AesCtx ctx; - AesCtxIni(&ctx, ivect, key->data, KEY128, CBC); - AesEncrypt(&ctx, data, edata, sizeof(edata)); + mbedtls_aes_context ctx; + mbedtls_aes_init(&ctx); + mbedtls_aes_setkey_enc(&ctx, key->data, 128); + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, sizeof(edata), ivect, data, edata); + mbedtls_aes_free(&ctx); break; } case MCO_DECYPHER: { - AesCtx ctx; - AesCtxIni(&ctx, ivect, key->data, KEY128, CBC); - AesDecrypt(&ctx, edata, data, sizeof(edata)); + mbedtls_aes_context ctx; + mbedtls_aes_init(&ctx); + mbedtls_aes_setkey_dec(&ctx, key->data, 128); + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, sizeof(edata), ivect, edata, data); + mbedtls_aes_free(&ctx); break; } } diff --git a/armsrc/mifaredesfire.c b/armsrc/mifaredesfire.c index bda31790d..c57fed866 100644 --- a/armsrc/mifaredesfire.c +++ b/armsrc/mifaredesfire.c @@ -433,15 +433,9 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) desfirekey_t key = &defaultkey; Desfire_aes_key_new(keybytes, key); - AesCtx ctx; + mbedtls_aes_context ctx; uint8_t IV[16] = {0x00}; - if (AesCtxIni(&ctx, IV, key->data, KEY128, CBC) < 0) { - if (DBGLEVEL >= 4) { - DbpString("AES context failed to init"); - } - OnError(7); - return; - } + mbedtls_aes_init(&ctx); cmd[0] = AUTHENTICATE_AES; cmd[1] = 0x00; //keynumber @@ -457,13 +451,27 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) memcpy(encRndB, resp + 3, 16); // dekryptera tagnonce. - AesDecrypt(&ctx, encRndB, decRndB, 16); + if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) { + if (DBGLEVEL >= 4) { + DbpString("mbedtls_aes_setkey_dec failed"); + } + OnError(7); + return; + } + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, 16, IV, encRndB, decRndB); rol(decRndB, 16); uint8_t nonce[16] = {0x00}; memcpy(both, nonce, 16); memcpy(both + 16, decRndB, 16); uint8_t encBoth[32] = {0x00}; - AesEncrypt(&ctx, both, encBoth, 32); + if (mbedtls_aes_setkey_enc(&ctx, key->data, 128) != 0) { + if (DBGLEVEL >= 4) { + DbpString("mbedtls_aes_setkey_enc failed"); + } + OnError(7); + return; + } + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 32, IV, both, encBoth); cmd[0] = ADDITIONAL_FRAME; memcpy(cmd + 1, encBoth, 32); diff --git a/common/Makefile.common b/common/Makefile.common index 2ab434562..282f242d9 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -63,7 +63,7 @@ DETECTED_OS=Windows endif # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory -VPATH = . ../common ../common/crapto1 ../common/polarssl ../fpga ../zlib ../armsrc/Standalone ../uart +VPATH = . ../common ../common/crapto1 ../common/mbedtls ../fpga ../zlib ../armsrc/Standalone ../uart INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h $(APP_INCLUDES) diff --git a/common/desfire.h b/common/desfire.h index 3cffd2967..41e5b6e12 100644 --- a/common/desfire.h +++ b/common/desfire.h @@ -3,7 +3,7 @@ #include #include -#include "aes.h" +#include "mbedtls/aes.h" #include "mifare.h" #define MAX_CRYPTO_BLOCK_SIZE 16 @@ -71,10 +71,6 @@ enum DESFIRE_CRYPTOALGO { struct desfire_key { enum DESFIRE_CRYPTOALGO type; uint8_t data[24]; - // DES_key_schedule ks1; - // DES_key_schedule ks2; - // DES_key_schedule ks3; - AesCtx aes_ks; uint8_t cmac_sk1[24]; uint8_t cmac_sk2[24]; uint8_t aes_version; diff --git a/common/mbedtls/platform_util.c b/common/mbedtls/platform_util.c index a3634e246..c30a52c08 100644 --- a/common/mbedtls/platform_util.c +++ b/common/mbedtls/platform_util.c @@ -60,9 +60,9 @@ * mbedtls_platform_zeroize() to use a suitable implementation for their * platform and needs. */ -static void *(* const volatile memset_func)(void *, int, size_t) = memset; +//static void *(* const volatile memset_func)(void *, int, size_t) = memset; void mbedtls_platform_zeroize(void *buf, size_t len) { - memset_func(buf, 0, len); + memset(buf, 0, len); } #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ From d11684fcabc4545647d12f033c89eeabdd20a8c0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 13 Jul 2019 00:06:19 +0200 Subject: [PATCH 16/40] Get proxmark.sh supporting WSL --- CHANGELOG.md | 1 + .../Windows-Installation-Instructions.md | 28 +++++++++++++++---- proxmark3.sh | 21 ++++++++++++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a276440d7..2fb002175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Add support for WSL in proxmark.sh (@doegox) - Add documentation for usage of Proxmark3 under WSL (@doegox) - Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox) - Add config for RaspberryPi in JTAG tools (@doegox) diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 1617ec6ec..69f24dcf8 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -116,14 +116,19 @@ Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmar To use the compiled client and flasher, the only difference is that the Proxmark3 port is translated from your `comX` port where "X" is the com port number assigned to proxmark3 under Windows, to a `/dev/ttySX`. -You will need to give permission to the current user to access `/dev/ttySX`: (change X to your port number) +Depending on the Windows version, you might need to give permission to the current user to access `/dev/ttySX`: (change X to your port number) + +```sh +ls -al /dev/ttySX +groups|grep dialout +``` + +If group ownership is `dialout` and your user is member of `dialout` group, all is fine. Else you'll have to provide access to `/dev/ttySX`: (Unfortunately the access rights of the port won't survive and will have to be fixed again next time.) ```sh sudo chmod 666 /dev/ttySX ``` -Unfortunately the access rights of the port won't survive and will have to be fixed again next time. - If you installed a X Server and compiled the Proxmark3 with QT4 support, you've to export the `DISPLAY` environment variable: ```sh @@ -136,14 +141,27 @@ and add it to your Bash profile for the next times: echo "export DISPLAY=:0" >> ~/.bashrc ``` -To flash, you've to call the flasher manually and specify the correct port: +To flash: In principle, the helper script `flash-all.sh` should auto-detect your COMX==/dev/ttySX port, so you can just try: + +```sh +./flash-all.sh +``` + +If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh client/flasher /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` -Similarly, to run the client: +Similarly, to run the client, you may try: + +```sh +./proxmark3.sh +``` + +Or, by specifying the COM port manually: ```sh client/proxmark3 /dev/ttySX ``` + diff --git a/proxmark3.sh b/proxmark3.sh index b4aa51ffb..39eb80779 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -11,7 +11,6 @@ function wait4proxmark_Linux { sleep .1 done local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1` - echo >&2 -e "Found proxmark on ${PM3}\n" echo $PM3 } @@ -41,6 +40,20 @@ function wait4proxmark_Windows { echo $PM3 } +function wait4proxmark_WSL { + echo >&2 "Waiting for Proxmark to appear..." + while true; do + device=$(wmic.exe path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2') + if [[ $device != "" ]]; then + PM3=${device/ */} + PM3="/dev/ttyS${PM3#COM}" + break + fi + sleep .1 + done + echo $PM3 +} + SCRIPT=$(basename -- "$0") if [ "$SCRIPT" = "proxmark3.sh" ]; then @@ -61,7 +74,11 @@ else fi HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then - PORT=$(wait4proxmark_Linux) + if uname -a|grep -q Microsoft; then + PORT=$(wait4proxmark_WSL) + else + PORT=$(wait4proxmark_Linux) + fi elif [ "$HOSTOS" = "DARWIN" ]; then PORT=$(wait4proxmark_macOS) elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then From ed47ca7186239fc25a8a9cbdec3d06ab991d72bf Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 13 Jul 2019 00:36:10 +0200 Subject: [PATCH 17/40] tuning windows doc --- .../Windows-Installation-Instructions.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 69f24dcf8..73a5358e9 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -44,6 +44,12 @@ git clone https://github.com/RfidResearchGroup/proxmark3.git cd proxmark3 ``` +If you're a contributing developer, you probably want to be able to use `make style`. If so, you've to install astyle: + +```sh +pacman -S mingw-w64-x86_64-astyle +``` + ## Compile and use the project Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). @@ -89,7 +95,7 @@ Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs ## X Server Installation -If you want to run the graphical components of the Proxmark3 client, you need to install a X Server such as [VcXsrv](https://sourceforge.net/projects/vcxsrv/) or [Xming](https://sourceforge.net/projects/xming/). +If you want to run the graphical components of the Proxmark3 client, you need to install a X Server such as [VcXsrv](https://sourceforge.net/projects/vcxsrv/) or [Xming](https://sourceforge.net/projects/xming/) and launch it, e.g. by executing XLaunch. ## Dependencies From b0dbbd3683afeafcf45bfb79c9a2c0a01f88d14d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 13 Jul 2019 00:38:30 +0200 Subject: [PATCH 18/40] make style --- armsrc/appmain.c | 4 ++-- armsrc/hitag2.c | 2 +- armsrc/lfsampling.c | 24 +++++++++---------- armsrc/mifaresim.c | 4 ++-- bootrom/bootrom.c | 2 +- client/cmdhf15.c | 2 +- client/cmdlf.c | 6 ++--- client/cmdlfem4x.c | 10 ++++---- client/cmdlft55xx.c | 8 +++---- client/cmdusart.c | 2 +- client/comms.c | 2 +- client/deprecated-hid-flasher/flasher/sleep.h | 22 ++++++++--------- client/flash.c | 2 +- client/util.c | 15 ++++++------ common/lfdemod.c | 6 ++--- 15 files changed, 55 insertions(+), 56 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 3213fbe14..facce653c 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -347,9 +347,9 @@ void SendVersion(void) { strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); #if defined(__clang__) - strncat(VersionString, " compiled with Clang/LLVM "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); + strncat(VersionString, " compiled with Clang/LLVM "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); #elif defined(__GNUC__) || defined(__GNUG__) - strncat(VersionString, " compiled with GCC "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); + strncat(VersionString, " compiled with GCC "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); #endif strncat(VersionString, "\n [ FPGA ]\n ", sizeof(VersionString) - strlen(VersionString) - 1); diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 46e9a43dd..682dd950a 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -434,7 +434,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t break; } } - + return true; } diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index c5a075e7a..c88401229 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -136,11 +136,11 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag uint32_t sample_total_numbers = 0; uint32_t sample_total_saved = 0; uint32_t cancel_counter = 0; - + uint16_t checker = 0; - + while (true) { - if ( checker == 1000 ) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else @@ -148,7 +148,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag } else { ++checker; } - + WDT_HIT(); if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { @@ -293,11 +293,11 @@ void doT55x7Acquisition(size_t sample_size) { bool startFound = false; bool highFound = false; bool lowFound = false; - + uint16_t checker = 0; - - while ( skipCnt < 1000 && (i < bufsize)) { - if ( checker == 1000 ) { + + while (skipCnt < 1000 && (i < bufsize)) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else @@ -371,9 +371,9 @@ void doCotagAcquisition(size_t sample_size) { uint16_t noise_counter = 0; uint16_t checker = 0; - + while ((i < bufsize) && (noise_counter < (COTAG_T1 << 1))) { - if ( checker == 1000 ) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else @@ -431,9 +431,9 @@ uint32_t doCotagAcquisitionManchester() { uint8_t curr = 0, prev = 0; uint16_t noise_counter = 0; uint16_t checker = 0; - + while ((sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1))) { - if ( checker == 1000 ) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 714beb284..8f21882be 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -606,8 +606,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (receivedCmd_len == 9 && receivedCmd[1] == 0x70) { if (memcmp(&receivedCmd[2], responses[uid_index].response, 4) == 0) { bool cl_finished = (uid_len == 4 && uid_index == UIDBCC1) || - (uid_len == 7 && uid_index == UIDBCC2) || - (uid_len == 10 && uid_index == UIDBCC3); + (uid_len == 7 && uid_index == UIDBCC2) || + (uid_len == 10 && uid_index == UIDBCC3); EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]); if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]); if (cl_finished) { diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index e889bb7da..4e92bc95b 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -122,7 +122,7 @@ void UsbPacketReceived(uint8_t *packet, int len) { switch (c->cmd) { case CMD_DEVICE_INFO: { dont_ack = 1; - arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | + arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM | DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH | DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO; diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 9a40d03cd..9d5f3802d 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -1348,7 +1348,7 @@ static int CmdHF15CSetUID(const char *Cmd) { data[3][5] = uid[1]; data[3][6] = uid[0]; - for (int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { AddCrc15(data[i], 7); clearCommandBuffer(); diff --git a/client/cmdlf.c b/client/cmdlf.c index 8459eca3a..389e76ca9 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -957,7 +957,7 @@ static bool CheckChipType(bool getDeviceData) { retval = true; goto out; } - + //check for t55xx chip... if (tryDetectP1(true)) { PrintAndLogEx(SUCCESS, "\nChipset detection : " _GREEN_("T55xx") "found"); @@ -1084,8 +1084,8 @@ int CmdLFfind(const char *Cmd) { } out: // identify chipset - if ( CheckChipType(isOnline) == false ) { - PrintAndLogEx(DEBUG, "Automatic chip type detection " _RED_("failed") ); + if (CheckChipType(isOnline) == false) { + PrintAndLogEx(DEBUG, "Automatic chip type detection " _RED_("failed")); } return PM3_SUCCESS; } diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index aa0add5fa..ce9a9ea0a 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -1373,10 +1373,10 @@ static void printEM4x05config(uint32_t wordData) { PrintAndLogEx(NORMAL, " PSK CF: %u | %s", PSKcf, cf); PrintAndLogEx(NORMAL, " Delay: %u | %s", delay, cdelay); PrintAndLogEx(NORMAL, " LastWordR: %02u | Address of last word for default read - meaning %u blocks are output", LWR, numblks); - PrintAndLogEx(NORMAL, " ReadLogin: %u | Read login is %s", readLogin, readLogin ? _YELLOW_("required") : _GREEN_("not required") ); - PrintAndLogEx(NORMAL, " ReadHKL: %u | Read housekeeping words login is %s", readHKL, readHKL ? _YELLOW_("required") : _GREEN_("not required") ); - PrintAndLogEx(NORMAL, "WriteLogin: %u | Write login is %s", writeLogin, writeLogin ? _YELLOW_("required") : _GREEN_("not required") ); - PrintAndLogEx(NORMAL, " WriteHKL: %u | Write housekeeping words login is %s", writeHKL, writeHKL ? _YELLOW_("required") : _GREEN_("not Required") ); + PrintAndLogEx(NORMAL, " ReadLogin: %u | Read login is %s", readLogin, readLogin ? _YELLOW_("required") : _GREEN_("not required")); + PrintAndLogEx(NORMAL, " ReadHKL: %u | Read housekeeping words login is %s", readHKL, readHKL ? _YELLOW_("required") : _GREEN_("not required")); + PrintAndLogEx(NORMAL, "WriteLogin: %u | Write login is %s", writeLogin, writeLogin ? _YELLOW_("required") : _GREEN_("not required")); + PrintAndLogEx(NORMAL, " WriteHKL: %u | Write housekeeping words login is %s", writeHKL, writeHKL ? _YELLOW_("required") : _GREEN_("not Required")); PrintAndLogEx(NORMAL, " R.A.W.: %u | Read after write is %s", raw, raw ? "on" : "off"); PrintAndLogEx(NORMAL, " Disable: %u | Disable command is %s", disable, disable ? "accepted" : "not accepted"); PrintAndLogEx(NORMAL, " R.T.F.: %u | Reader talk first is %s", rtf, rtf ? _YELLOW_("enabled") : "disabled"); @@ -1396,7 +1396,7 @@ static void printEM4x05info(uint32_t block0, uint32_t serial) { snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "EM4305"); break; case 8: - snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "EM4205"); + snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "EM4205"); break; case 4: snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "Unknown"); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 04b2c6e9e..b1c03b514 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2153,7 +2153,7 @@ bool tryDetectP1(bool getData) { } return false; } - + // try ask clock detect. it could be another type even if successful. clk = GetAskClock("", false); if (clk > 0) { @@ -2162,14 +2162,14 @@ bool tryDetectP1(bool getData) { (DemodBufferLen == 32 || DemodBufferLen == 64)) { return true; } - + st = true; if ((ASKDemod_ext("0 1 1", false, false, 1, &st) == PM3_SUCCESS) && preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) && (DemodBufferLen == 32 || DemodBufferLen == 64)) { return true; } - + if ((ASKbiphaseDemod("0 0 0 2", false) == PM3_SUCCESS) && preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) && (DemodBufferLen == 32 || DemodBufferLen == 64)) { @@ -2182,7 +2182,7 @@ bool tryDetectP1(bool getData) { return true; } } - + // try NRZ clock detect. it could be another type even if successful. clk = GetNrzClock("", false); //has the most false positives :( if (clk > 0) { diff --git a/client/cmdusart.c b/client/cmdusart.c index d632901ef..60b977430 100644 --- a/client/cmdusart.c +++ b/client/cmdusart.c @@ -314,7 +314,7 @@ static int CmdUsartBtFactory(const char *Cmd) { PrintAndLogEx(WARNING, "Is the add-on blue light blinking? (Say 'n' if you want to abort) [y/n]"); char input[3]; - if ((fgets(input,sizeof(input),stdin) == NULL) || (strncmp(input, "y\n", sizeof(input)) != 0)) { + if ((fgets(input, sizeof(input), stdin) == NULL) || (strncmp(input, "y\n", sizeof(input)) != 0)) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(FAILED, "Aborting."); return PM3_EOPABORTED; diff --git a/client/comms.c b/client/comms.c index 5aa704728..6fd41ecad 100644 --- a/client/comms.c +++ b/client/comms.c @@ -136,7 +136,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool txBufferNG.pre.ng = ng; txBufferNG.pre.length = len; txBufferNG.pre.cmd = cmd; - if ( len > 0 && data ) + if (len > 0 && data) memcpy(&txBufferNG.data, data, len); if ((conn.send_via_fpc_usart && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc_usart) && conn.send_with_crc_on_usb)) { diff --git a/client/deprecated-hid-flasher/flasher/sleep.h b/client/deprecated-hid-flasher/flasher/sleep.h index f3aac0c8f..ffb5486aa 100644 --- a/client/deprecated-hid-flasher/flasher/sleep.h +++ b/client/deprecated-hid-flasher/flasher/sleep.h @@ -6,18 +6,18 @@ #define SLEEP_H__ #ifdef _WIN32 - #include - #define msleep(n) Sleep(n) +#include +#define msleep(n) Sleep(n) #else - #include - #include - static void nsleep(uint64_t n) { - struct timespec timeout; - timeout.tv_sec = n / 1000000000; - timeout.tv_nsec = n % 1000000000; - while (nanosleep(&timeout, &timeout) && errno == EINTR); - } - #define msleep(n) nsleep(1000000 * (uint64_t)n) +#include +#include +static void nsleep(uint64_t n) { + struct timespec timeout; + timeout.tv_sec = n / 1000000000; + timeout.tv_nsec = n % 1000000000; + while (nanosleep(&timeout, &timeout) && errno == EINTR); +} +#define msleep(n) nsleep(1000000 * (uint64_t)n) #endif #endif diff --git a/client/flash.c b/client/flash.c index 3a1350c7c..5b4cd205e 100644 --- a/client/flash.c +++ b/client/flash.c @@ -347,7 +347,7 @@ static int wait_for_ack(PacketResponseNG *ack) { } // Go into flashing mode -int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t * chipinfo) { +int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *chipinfo) { uint32_t state; if (enter_bootloader(serial_port_name) < 0) diff --git a/client/util.c b/client/util.c index a805b9c84..f6f89e0ff 100644 --- a/client/util.c +++ b/client/util.c @@ -61,8 +61,7 @@ int kbd_enter_pressed(void) { #include int kbd_enter_pressed(void) { int ret = 0; - while(kbhit()) - { + while (kbhit()) { ret |= getch() == '\r'; } return ret; @@ -178,8 +177,8 @@ bool CheckStringIsHEXValue(const char *value) { void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between, bool uppercase) { - if (buf == NULL ) return; - + if (buf == NULL) return; + char *tmp = (char *)buf; size_t i; memset(tmp, 0x00, hex_max_len); @@ -205,16 +204,16 @@ void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex // printing and converting functions void print_hex(const uint8_t *data, const size_t len) { - if (data == NULL || len == 0 ) return; - + if (data == NULL || len == 0) return; + for (size_t i = 0; i < len; i++) printf("%02x ", data[i]); printf("\n"); } void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) { - if (data == NULL || len == 0 ) return; - + if (data == NULL || len == 0) return; + int rownum = 0; printf("[%02d] | ", rownum); for (size_t i = 0; i < len; ++i) { diff --git a/common/lfdemod.c b/common/lfdemod.c index ef18b59ef..f8daec079 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -103,7 +103,7 @@ void computeSignalProperties(uint8_t *samples, uint32_t size) { // we can detect noise signalprop.isnoise = signalprop.amplitude < NOISE_AMPLITUDE_THRESHOLD; - if (g_debugMode) + if (g_debugMode) printSignal(); } @@ -1365,8 +1365,8 @@ static int millerRawDecode(uint8_t *bits, size_t *size, int invert) { int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert) { //sanity check if (*size < 51) return -1; - - if ( *offset < 0 ) *offset = 0; + + if (*offset < 0) *offset = 0; uint16_t bitnum = 0; uint16_t errCnt = 0; From edcd2b974e8e88bc296a52319887e8bd870622c0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 13 Jul 2019 13:05:38 +0200 Subject: [PATCH 19/40] wsl: no driver required --- .../Windows-Installation-Instructions.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 73a5358e9..eacdc4b62 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -88,11 +88,6 @@ Install WSL with e.g. the standard Ubuntu. For WSL configuration, see [Manage and configure Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/wsl-config). -## Driver Installation - -Install required drivers for your Windows installation. You may need admin privileges to do this. -Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs/news/how-to-install-a-proxmark3-driver-on-windows-10). - ## X Server Installation If you want to run the graphical components of the Proxmark3 client, you need to install a X Server such as [VcXsrv](https://sourceforge.net/projects/vcxsrv/) or [Xming](https://sourceforge.net/projects/xming/) and launch it, e.g. by executing XLaunch. From 735077f358ced58fa6604d9b712fc0a6a6c5644f Mon Sep 17 00:00:00 2001 From: Eloff Date: Sat, 13 Jul 2019 18:26:52 +0300 Subject: [PATCH 20/40] Does clear trace log only at first call 'hf mf chk', to save whole process history --- client/cmdhfmf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index a81209215..0bed91dfd 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1959,6 +1959,8 @@ static int CmdHF14AMfChk(const char *Cmd) { // fast push mode conn.block_after_ACK = true; + // clear trace log by first check keys call only + bool clearLog = true; // check keys. for (trgKeyType = (keyType == 2) ? 0 : keyType; trgKeyType < 2; (keyType == 2) ? (++trgKeyType) : (trgKeyType = 2)) { @@ -1979,11 +1981,13 @@ static int CmdHF14AMfChk(const char *Cmd) { uint16_t size = keycnt - c > max_keys ? max_keys : keycnt - c; - if (mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6 * c], &key64) == PM3_SUCCESS) { + if (mfCheckKeys(b, trgKeyType, clearLog, size, &keyBlock[6 * c], &key64) == PM3_SUCCESS) { e_sector[i].Key[trgKeyType] = key64; e_sector[i].foundKey[trgKeyType] = true; + clearLog = false; break; } + clearLog = false; } b < 127 ? (b += 4) : (b += 16); } From 25e2ab9a4c55a0de2d4656e50e46f20f4f880d16 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 13 Jul 2019 18:29:36 +0200 Subject: [PATCH 21/40] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb002175..8dd057c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Change: Don't clear trace log during 'hf mf chk', to save whole process history (@McEloff) - Add support for WSL in proxmark.sh (@doegox) - Add documentation for usage of Proxmark3 under WSL (@doegox) - Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox) From bb3c5e364ef3c9b94a1fa6f344380f7cbbdfafbb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 00:30:57 +0200 Subject: [PATCH 22/40] remove perror --- client/emv/emv_pk.c | 4 ++-- client/flash.c | 1 - uart/uart_posix.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/client/emv/emv_pk.c b/client/emv/emv_pk.c index ae23c8470..b03567440 100644 --- a/client/emv/emv_pk.c +++ b/client/emv/emv_pk.c @@ -24,7 +24,7 @@ #include "emv_pk.h" #include "crypto.h" #include "proxmark3.h" - +#include "util.h" #include #include #include @@ -398,7 +398,7 @@ static struct emv_pk *emv_pk_get_ca_pk_from_file(const char *fname, FILE *f = fopen(fname, "r"); if (!f) { - perror("fopen"); + PrintAndLogEx(ERR, "Error: can't open file %s.", fname); return NULL; } diff --git a/client/flash.c b/client/flash.c index 5b4cd205e..e41b47fb0 100644 --- a/client/flash.c +++ b/client/flash.c @@ -192,7 +192,6 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) { fd = fopen(name, "rb"); if (!fd) { PrintAndLogEx(ERR, _RED_("Could not open file") "%s >>> ", name); - perror(NULL); goto fail; } diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 93b7229ce..22cc75207 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -238,7 +238,7 @@ void uart_close(const serial_port sp) { // Does the system allows us to place a lock on this file descriptor int err = fcntl(spu->fd, F_SETLK, &fl); if (err == -1) { - //perror("fcntl"); + printf("[!] UART error while closing port\n"); } close(spu->fd); free(sp); From 8bf4b4ad97b213da18481bc18ea6942a2a79b873 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 00:35:18 +0200 Subject: [PATCH 23/40] Promote WARNING to ERR on some error msgs --- client/cmdcrc.c | 2 +- client/cmddata.c | 14 ++++++------ client/cmdflashmem.c | 6 ++--- client/cmdhf14a.c | 2 +- client/cmdhf15.c | 8 +++---- client/cmdhffido.c | 4 ++-- client/cmdhficlass.c | 18 +++++++-------- client/cmdhflegic.c | 4 ++-- client/cmdhfmf.c | 34 ++++++++++++++-------------- client/cmdhfmfhard.c | 24 ++++++++++---------- client/cmdhfmfu.c | 18 +++++++-------- client/cmdhftopaz.c | 10 ++++---- client/cmdlf.c | 6 ++--- client/cmdlfawid.c | 8 +++---- client/cmdlfem4x.c | 18 +++++++-------- client/cmdlffdx.c | 4 ++-- client/cmdlfguard.c | 6 ++--- client/cmdlfhitag.c | 2 +- client/cmdlfio.c | 4 ++-- client/cmdlfjablotron.c | 4 ++-- client/cmdlfkeri.c | 2 +- client/cmdlfnedap.c | 6 ++--- client/cmdlfnoralsy.c | 6 ++--- client/cmdlfparadox.c | 2 +- client/cmdlfpresco.c | 2 +- client/cmdlfpyramid.c | 6 ++--- client/cmdlft55xx.c | 8 +++---- client/cmdlfti.c | 4 ++-- client/cmdlfviking.c | 2 +- client/cmdlfvisa2000.c | 2 +- client/cmdsmartcard.c | 6 ++--- client/comms.c | 8 +++---- client/emv/cmdemv.c | 14 ++++++------ client/emv/emvcore.c | 44 ++++++++++++++++++------------------ client/fido/fidocore.c | 2 +- client/loclass/elite_crack.c | 14 ++++++------ client/mifare/mad.c | 2 +- client/mifare/mifarehost.c | 6 ++--- 38 files changed, 166 insertions(+), 166 deletions(-) diff --git a/client/cmdcrc.c b/client/cmdcrc.c index 58cab45e5..af4baae45 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -248,7 +248,7 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res //set model c = mbynam(&model, inModel); if (!c) { - PrintAndLogEx(WARNING, "error: preset model '%s' not found. Use reveng -D to list presets. [%d]", inModel, c); + PrintAndLogEx(ERR, "error: preset model '%s' not found. Use reveng -D to list presets. [%d]", inModel, c); return 0; } if (c < 0) { diff --git a/client/cmddata.c b/client/cmddata.c index d6a4e8e73..e0e0f73c1 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -602,7 +602,7 @@ static int Cmdmandecoderaw(const char *Cmd) { } if (high > 7 || low < 0) { - PrintAndLogEx(WARNING, "Error: please raw demod the wave first then manchester raw decode"); + PrintAndLogEx(ERR, "Error: please raw demod the wave first then manchester raw decode"); return PM3_ESOFT; } @@ -611,7 +611,7 @@ static int Cmdmandecoderaw(const char *Cmd) { uint8_t alignPos = 0; errCnt = manrawdecode(bits, &size, invert, &alignPos); if (errCnt >= maxErr) { - PrintAndLogEx(WARNING, "Too many errors: %u", errCnt); + PrintAndLogEx(ERR, "Too many errors: %u", errCnt); return PM3_ESOFT; } @@ -658,16 +658,16 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) { errCnt = BiphaseRawDecode(bits, &size, &offset, invert); if (errCnt < 0) { - PrintAndLogEx(WARNING, "Error during decode:%d", errCnt); + PrintAndLogEx(ERR, "Error during decode:%d", errCnt); return PM3_ESOFT; } if (errCnt > maxErr) { - PrintAndLogEx(WARNING, "Too many errors attempting to decode: %d", errCnt); + PrintAndLogEx(ERR, "Too many errors attempting to decode: %d", errCnt); return PM3_ESOFT; } if (errCnt > 0) - PrintAndLogEx(WARNING, "# Errors found during Demod (shown as " _YELLOW_("7")" in bit stream): %d", errCnt); + PrintAndLogEx(ERR, "# Errors found during Demod (shown as " _YELLOW_("7")" in bit stream): %d", errCnt); PrintAndLogEx(NORMAL, "Biphase Decoded using offset: %d - # invert:%d - data:", offset, invert); PrintAndLogEx(NORMAL, "%s", sprint_bin_break(bits, size, 32)); @@ -1290,7 +1290,7 @@ int CmdPSK1rawDemod(const char *Cmd) { int ans = PSKDemod(Cmd, true); //output if (ans != PM3_SUCCESS) { - if (g_debugMode) PrintAndLogEx(WARNING, "Error demoding: %d", ans); + if (g_debugMode) PrintAndLogEx(ERR, "Error demoding: %d", ans); return PM3_ESOFT; } PrintAndLogEx(NORMAL, "PSK1 demoded bitstream:"); @@ -1307,7 +1307,7 @@ static int CmdPSK2rawDemod(const char *Cmd) { int ans = PSKDemod(Cmd, true); if (ans != PM3_SUCCESS) { - if (g_debugMode) PrintAndLogEx(WARNING, "Error demoding: %d", ans); + if (g_debugMode) PrintAndLogEx(ERR, "Error demoding: %d", ans); return PM3_ESOFT; } psk1TOpsk2(DemodBuffer, DemodBufferLen); diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index dafda3ae6..6bab15cd9 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -136,7 +136,7 @@ static int CmdFlashMemRead(const char *Cmd) { return PM3_EINVARG; } if (start_index + len > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(WARNING, "error, start_index + length is larger than available memory"); + PrintAndLogDevice(ERR, "error, start_index + length is larger than available memory"); return PM3_EOVFLOW; } @@ -258,7 +258,7 @@ static int CmdFlashMemLoad(const char *Cmd) { } if (datalen > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(WARNING, "error, filesize is larger than available memory"); + PrintAndLogDevice(ERR, "error, filesize is larger than available memory"); free(data); return PM3_EOVFLOW; } @@ -354,7 +354,7 @@ static int CmdFlashMemSave(const char *Cmd) { uint8_t *dump = calloc(len, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(WARNING, "error, cannot allocate memory "); + PrintAndLogDevice(ERR, "error, cannot allocate memory "); return PM3_EMALLOC; } diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index bb5144f0b..c138aefa1 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -798,7 +798,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea vActivateField = false; if (*dataoutlen) { if (clen != datainlen) - PrintAndLogEx(WARNING, "APDU: I-block/R-block sequence error. Data len=%d, Sent=%d, Last packet len=%d", datainlen, clen, *dataoutlen); + PrintAndLogEx(ERR, "APDU: I-block/R-block sequence error. Data len=%d, Sent=%d, Last packet len=%d", datainlen, clen, *dataoutlen); break; } } while (clen < datainlen); diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 9d5f3802d..65bc26010 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -564,7 +564,7 @@ static int CmdHF15Demod(const char *Cmd) { } if (mask != 0x01) { - PrintAndLogEx(WARNING, "Error, uneven octet! (discard extra bits!)"); + PrintAndLogEx(ERR, "Error, uneven octet! (discard extra bits!)"); PrintAndLogEx(NORMAL, " mask = %02x", mask); } PrintAndLogEx(NORMAL, "%d octets", k); @@ -634,7 +634,7 @@ static int CmdHF15Info(const char *Cmd) { recv = resp.data.asBytes; if (recv[0] & ISO15_RES_ERROR) { - PrintAndLogEx(WARNING, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); + PrintAndLogEx(ERR, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); return 3; } @@ -1069,7 +1069,7 @@ static int CmdHF15Read(const char *Cmd) { } if (recv[0] & ISO15_RES_ERROR) { - PrintAndLogEx(WARNING, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); + PrintAndLogEx(ERR, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); return 3; } @@ -1246,7 +1246,7 @@ static int CmdHF15Restore(const char *Cmd) { fclose(f); return 0; } else if (bytes_read != blocksize) { - PrintAndLogEx(WARNING, "File reading error (%s), %u bytes read instead of %u bytes.", filename, bytes_read, blocksize); + PrintAndLogEx(ERR, "File reading error (%s), %u bytes read instead of %u bytes.", filename, bytes_read, blocksize); fclose(f); return 2; } diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 39b080dca..9db6583f6 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -351,7 +351,7 @@ static int CmdHFFidoRegister(const char *cmd) { if (res == -0x4e00) { PrintAndLogEx(WARNING, "Signature is NOT VALID."); } else { - PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); + PrintAndLogEx(ERR, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); } } else { PrintAndLogEx(SUCCESS, "Signature is OK."); @@ -577,7 +577,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) { if (res == -0x4e00) { PrintAndLogEx(WARNING, "Signature is NOT VALID."); } else { - PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); + PrintAndLogEx(ERR, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); } } else { PrintAndLogEx(SUCCESS, "Signature is OK."); diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index ec2179ab3..f8d57556f 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -550,14 +550,14 @@ static int CmdHFiClassELoad(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(WARNING, "error, when getting filesize"); + PrintAndLogDevice(ERR, "error, when getting filesize"); fclose(f); return 1; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(WARNING, "error, cannot allocate memory "); + PrintAndLogDevice(ERR, "error, cannot allocate memory "); fclose(f); return 1; } @@ -569,7 +569,7 @@ static int CmdHFiClassELoad(const char *Cmd) { //Validate if (bytes_read < fsize) { - PrintAndLogDevice(WARNING, "error, could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogDevice(ERR, "error, could only read %d bytes (should be %d)", bytes_read, fsize); free(dump); return 1; } @@ -650,7 +650,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "error, when getting filesize"); + PrintAndLogEx(ERR, "error, when getting filesize"); fclose(f); return 2; } @@ -665,7 +665,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { size_t bytes_read = fread(decrypted, 1, fsize, f); fclose(f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "file reading error"); + PrintAndLogEx(ERR, "file reading error"); free(decrypted); return 3; } @@ -1281,7 +1281,7 @@ static int CmdHFiClassCloneTag(const char *Cmd) { fseek(f, startblock * 8, SEEK_SET); size_t bytes_read = fread(tag_data, sizeof(iclass_block_t), endblock - startblock + 1, f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "file reading error."); + PrintAndLogEx(ERR, "file reading error."); fclose(f); return 2; } @@ -1448,7 +1448,7 @@ static int CmdHFiClass_loclass(const char *Cmd) { errors += testMAC(); errors += doKeyTests(0); errors += testElite(); - if (errors) PrintAndLogDevice(WARNING, "There were errors!!!"); + if (errors) PrintAndLogDevice(ERR, "There were errors!!!"); return errors; } return PM3_SUCCESS; @@ -1518,7 +1518,7 @@ static int CmdHFiClassReadTagFile(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -1676,7 +1676,7 @@ static int loadKeys(char *filename) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 8bd976030..03c5ecfcd 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -1037,7 +1037,7 @@ static int CmdLegicRestore(const char *Cmd) { fclose(f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "File reading error"); + PrintAndLogEx(ERR, "File reading error"); free(data); return 2; } @@ -1139,7 +1139,7 @@ static int CmdLegicELoad(const char *Cmd) { // load file size_t bytes_read = fread(data, 1, numofbytes, f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "File reading error"); + PrintAndLogEx(ERR, "File reading error"); free(data); fclose(f); f = NULL; diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 0bed91dfd..3ca958f80 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -765,7 +765,7 @@ static int CmdHF14AMfDump(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyA[sectorNo], 1, 6, f); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error."); + PrintAndLogEx(ERR, "File reading error."); fclose(f); return PM3_EFILE; } @@ -775,7 +775,7 @@ static int CmdHF14AMfDump(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyB[sectorNo], 1, 6, f); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error."); + PrintAndLogEx(ERR, "File reading error."); fclose(f); return PM3_EFILE; } @@ -984,7 +984,7 @@ static int CmdHF14AMfRestore(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyA[sectorNo], 1, 6, fkeys); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error " _YELLOW_("%s"), keyFilename); + PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), keyFilename); fclose(fkeys); return 2; } @@ -993,7 +993,7 @@ static int CmdHF14AMfRestore(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyB[sectorNo], 1, 6, fkeys); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error " _YELLOW_("%s"), keyFilename); + PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), keyFilename); fclose(fkeys); return 2; } @@ -1021,7 +1021,7 @@ static int CmdHF14AMfRestore(const char *Cmd) { memcpy(data, key, 6); bytes_read = fread(bldata, 1, 16, fdump); if (bytes_read != 16) { - PrintAndLogEx(WARNING, "File reading error " _YELLOW_("%s"), dataFilename); + PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), dataFilename); fclose(fdump); fdump = NULL; return 2; @@ -1129,7 +1129,7 @@ static int CmdHF14AMfNested(const char *Cmd) { int16_t isOK = mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock, true); switch (isOK) { case -1 : - PrintAndLogEx(WARNING, "Error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); break; case -2 : PrintAndLogEx(WARNING, "Button pressed. Aborted.\n"); @@ -1162,7 +1162,7 @@ static int CmdHF14AMfNested(const char *Cmd) { } return PM3_SUCCESS; default : - PrintAndLogEx(WARNING, "Unknown Error.\n"); + PrintAndLogEx(ERR, "Unknown Error.\n"); } return PM3_SUCCESS; } else { // ------------------------------------ multiple sectors working @@ -1199,7 +1199,7 @@ static int CmdHF14AMfNested(const char *Cmd) { int16_t isOK = mfnested(blockNo, keyType, key, FirstBlockOfSector(sectorNo), trgKeyType, keyBlock, calibrate); switch (isOK) { case -1 : - PrintAndLogEx(WARNING, "error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "error: No response from Proxmark3.\n"); break; case -2 : PrintAndLogEx(WARNING, "button pressed. Aborted.\n"); @@ -1221,7 +1221,7 @@ static int CmdHF14AMfNested(const char *Cmd) { continue; default : - PrintAndLogEx(WARNING, "unknown Error.\n"); + PrintAndLogEx(ERR, "unknown Error.\n"); } free(e_sector); return PM3_ESOFT; @@ -1502,7 +1502,7 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { if (isOK) { switch (isOK) { case 1 : - PrintAndLogEx(WARNING, "Error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); break; case 2 : PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); @@ -2765,7 +2765,7 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) { PrintAndLogEx(NORMAL, "|---|----------------|----------------|"); for (i = 0; i < numSectors; i++) { if (mfEmlGetMem(data, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "error get block %d", FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1); + PrintAndLogEx(ERR, "error get block %d", FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1); break; } uint64_t keyA = bytes_to_num(data, 6); @@ -2828,7 +2828,7 @@ static int CmdHF14AMfCSetUID(const char *Cmd) { res = mfCSetUID(uid, (atqaPresent) ? atqa : NULL, (atqaPresent) ? sak : NULL, oldUid, wipeCard); if (res) { - PrintAndLogEx(WARNING, "Can't set UID. error=%d", res); + PrintAndLogEx(ERR, "Can't set UID. error=%d", res); return PM3_ESOFT; } @@ -2858,7 +2858,7 @@ static int CmdHF14AMfCSetBlk(const char *Cmd) { res = mfCSetBlock(blockNo, block, NULL, params); if (res) { - PrintAndLogEx(WARNING, "Can't write block. error=%d", res); + PrintAndLogEx(ERR, "Can't write block. error=%d", res); return PM3_ESOFT; } return PM3_SUCCESS; @@ -2933,7 +2933,7 @@ static int CmdHF14AMfCLoad(const char *Cmd) { // 64 or 256blocks. if (datalen != 1024 && datalen != 4096) { - PrintAndLogEx(WARNING, "File content error. "); + PrintAndLogEx(ERR, "File content error. "); free(data); return PM3_EFILE; } @@ -2972,7 +2972,7 @@ static int CmdHF14AMfCLoad(const char *Cmd) { // 64 or 256blocks. if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16) { - PrintAndLogEx(WARNING, "File content error. There must be 64 blocks"); + PrintAndLogEx(ERR, "File content error. There must be 64 blocks"); free(data); return PM3_EFILE; } @@ -2994,7 +2994,7 @@ static int CmdHF14AMfCGetBlk(const char *Cmd) { int res = mfCGetBlock(blockNo, data, MAGIC_SINGLE); if (res) { - PrintAndLogEx(WARNING, "Can't read block. error=%d", res); + PrintAndLogEx(ERR, "Can't read block. error=%d", res); return PM3_ESOFT; } @@ -3045,7 +3045,7 @@ static int CmdHF14AMfCGetSc(const char *Cmd) { int res = mfCGetBlock(start + i, data, flags); if (res) { - PrintAndLogEx(WARNING, "Can't read block. %d error=%d", start + i, res); + PrintAndLogEx(ERR, "Can't read block. %d error=%d", start + i, res); return PM3_ESOFT; } PrintAndLogEx(NORMAL, "%3d | %s", start + i, sprint_hex(data, 16)); diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index 2b96d8d77..4de46d36a 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -258,7 +258,7 @@ static void init_bitflip_bitarrays(void) { fseek(statesfile, 0, SEEK_END); int fsize = ftell(statesfile); if (fsize == -1) { - PrintAndLogEx(WARNING, "File read error with %s. Aborting...\n", state_file_name); + PrintAndLogEx(ERR, "File read error with %s. Aborting...\n", state_file_name); fclose(statesfile); exit(5); } @@ -267,7 +267,7 @@ static void init_bitflip_bitarrays(void) { uint8_t input_buffer[filesize]; size_t bytesread = fread(input_buffer, 1, filesize, statesfile); if (bytesread != filesize) { - PrintAndLogEx(WARNING, "File read error with %s. Aborting...\n", state_file_name); + PrintAndLogEx(ERR, "File read error with %s. Aborting...\n", state_file_name); fclose(statesfile); //inflateEnd(&compressed_stream); exit(5); @@ -279,7 +279,7 @@ static void init_bitflip_bitarrays(void) { if ((float)count / (1 << 24) < IGNORE_BITFLIP_THRESHOLD) { uint32_t *bitset = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (bitset == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_bitflip_statelists(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_bitflip_statelists(). Aborting...\n"); inflateEnd(&compressed_stream); exit(4); } @@ -390,7 +390,7 @@ static void init_part_sum_bitarrays(void) { for (uint16_t part_sum_a0 = 0; part_sum_a0 < NUM_PART_SUMS; part_sum_a0++) { part_sum_a0_bitarrays[odd_even][part_sum_a0] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (part_sum_a0_bitarrays[odd_even][part_sum_a0] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_part_suma0_statelists(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_part_suma0_statelists(). Aborting...\n"); exit(4); } clear_bitarray24(part_sum_a0_bitarrays[odd_even][part_sum_a0]); @@ -410,7 +410,7 @@ static void init_part_sum_bitarrays(void) { for (uint16_t part_sum_a8 = 0; part_sum_a8 < NUM_PART_SUMS; part_sum_a8++) { part_sum_a8_bitarrays[odd_even][part_sum_a8] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (part_sum_a8_bitarrays[odd_even][part_sum_a8] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_part_suma8_statelists(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_part_suma8_statelists(). Aborting...\n"); exit(4); } clear_bitarray24(part_sum_a8_bitarrays[odd_even][part_sum_a8]); @@ -449,7 +449,7 @@ static void init_sum_bitarrays(void) { for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) { sum_a0_bitarrays[odd_even][sum_a0] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (sum_a0_bitarrays[odd_even][sum_a0] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_sum_bitarrays(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_sum_bitarrays(). Aborting...\n"); exit(4); } clear_bitarray24(sum_a0_bitarrays[odd_even][sum_a0]); @@ -564,14 +564,14 @@ static void init_nonce_memory(void) { } nonces[i].states_bitarray[EVEN_STATE] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (nonces[i].states_bitarray[EVEN_STATE] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_nonce_memory(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_nonce_memory(). Aborting...\n"); exit(4); } set_bitarray24(nonces[i].states_bitarray[EVEN_STATE]); nonces[i].num_states_bitarray[EVEN_STATE] = 1 << 24; nonces[i].states_bitarray[ODD_STATE] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (nonces[i].states_bitarray[ODD_STATE] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_nonce_memory(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_nonce_memory(). Aborting...\n"); exit(4); } set_bitarray24(nonces[i].states_bitarray[ODD_STATE]); @@ -1048,7 +1048,7 @@ static int read_nonce_file(char *filename) { hardnested_print_progress(0, progress_text, (float)(1LL << 47), 0); size_t bytes_read = fread(read_buf, 1, 6, fnonces); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error."); + PrintAndLogEx(ERR, "File reading error."); fclose(fnonces); return 1; } @@ -1711,12 +1711,12 @@ static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, ui const uint32_t worstcase_size = 1 << 20; candidates->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size); if (candidates->states[odd_even] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in add_matching_states() - statelist.\n"); + PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - statelist.\n"); exit(4); } uint32_t *candidates_bitarray = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * worstcase_size); if (candidates_bitarray == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in add_matching_states() - bitarray.\n"); + PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - bitarray.\n"); free(candidates->states[odd_even]); exit(4); } @@ -1772,7 +1772,7 @@ static void add_bitflip_candidates(uint8_t byte) { uint32_t worstcase_size = nonces[byte].num_states_bitarray[odd_even] + 1; candidates1->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size); if (candidates1->states[odd_even] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in add_bitflip_candidates().\n"); + PrintAndLogEx(ERR, "Out of memory error in add_bitflip_candidates().\n"); exit(4); } diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index eb7d26c4f..91e223427 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -1232,7 +1232,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { status = ul_read(0, data, sizeof(data)); if (status == -1) { DropField(); - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ"); return status; } else if (status == 16) { ul_print_default(data); @@ -1248,7 +1248,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { uint8_t ulc_conf[16] = {0x00}; status = ul_read(0x28, ulc_conf, sizeof(ulc_conf)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ UL-C"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ UL-C"); DropField(); return status; } @@ -1263,7 +1263,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey)); if (status == -1) { DropField(); - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ magic"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ magic"); return status; } if (status == 16) ulc_print_3deskey(ulc_deskey); @@ -1306,7 +1306,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { uint8_t ulev1_signature[32] = {0x00}; status = ulev1_readSignature(ulev1_signature, sizeof(ulev1_signature)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ SIGNATURE"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ SIGNATURE"); DropField(); return status; } @@ -1322,7 +1322,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { uint8_t version[10] = {0x00}; status = ulev1_getVersion(version, sizeof(version)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to GETVERSION"); + PrintAndLogEx(ERR, "Error: tag didn't answer to GETVERSION"); DropField(); return status; } else if (status == 10) { @@ -1346,7 +1346,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { if (startconfigblock) { // if we know where the config block is... status = ul_read(startconfigblock, ulev1_conf, sizeof(ulev1_conf)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ EV1"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ EV1"); DropField(); return status; } else if (status == 16) { @@ -2134,7 +2134,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { long fsize = ftell(f); fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -2150,7 +2150,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { size_t bytes_read = fread(dump, 1, fsize, f); fclose(f); if (bytes_read < MFU_DUMP_PREFIX_LENGTH) { - PrintAndLogEx(WARNING, "Error, dump file is too small"); + PrintAndLogEx(ERR, "Error, dump file is too small"); free(dump); return 1; } @@ -2167,7 +2167,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { uint8_t pages = (bytes_read - MFU_DUMP_PREFIX_LENGTH) / 4; if (pages - 1 != mem->pages) { - PrintAndLogEx(WARNING, "Error, invalid dump, wrong page count"); + PrintAndLogEx(ERR, "Error, invalid dump, wrong page count"); free(dump); return 1; } diff --git a/client/cmdhftopaz.c b/client/cmdhftopaz.c index 2b743a574..d604d4baf 100644 --- a/client/cmdhftopaz.c +++ b/client/cmdhftopaz.c @@ -321,7 +321,7 @@ static void topaz_print_control_TLVs(uint8_t *memory) { static int topaz_read_dynamic_data(void) { // first read the remaining block of segment 0 if (topaz_read_block(topaz_tag.uid, 0x0f, &topaz_tag.dynamic_memory[0]) == -1) { - PrintAndLogEx(WARNING, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); + PrintAndLogEx(ERR, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); return -1; } @@ -329,7 +329,7 @@ static int topaz_read_dynamic_data(void) { uint8_t max_segment = topaz_tag.size / 128 - 1; for (uint8_t segment = 1; segment <= max_segment; segment++) { if (topaz_read_segment(topaz_tag.uid, segment, &topaz_tag.dynamic_memory[(segment - 1) * 128 + 8]) == -1) { - PrintAndLogEx(WARNING, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); + PrintAndLogEx(ERR, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); return -1; } } @@ -381,7 +381,7 @@ static int CmdHFTopazReader(const char *Cmd) { status = topaz_select(atqa, rid_response); if (status == -1) { - if (verbose) PrintAndLogEx(WARNING, "Error: couldn't receive ATQA"); + if (verbose) PrintAndLogEx(ERR, "Error: couldn't receive ATQA"); return -1; } @@ -393,7 +393,7 @@ static int CmdHFTopazReader(const char *Cmd) { } if (status == -2) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to RID"); + PrintAndLogEx(ERR, "Error: tag didn't answer to RID"); topaz_switch_off_field(); return -1; } @@ -411,7 +411,7 @@ static int CmdHFTopazReader(const char *Cmd) { status = topaz_rall(uid_echo, rall_response); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to RALL"); + PrintAndLogEx(ERR, "Error: tag didn't answer to RALL"); topaz_switch_off_field(); return -1; } diff --git a/client/cmdlf.c b/client/cmdlf.c index 389e76ca9..42b26be0d 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -573,7 +573,7 @@ int CmdLFfskSim(const char *Cmd) { dataLen = hextobinarray((char *)data, hexData); if (dataLen == 0) errors = true; - if (errors) PrintAndLogEx(WARNING, "Error getting hex data"); + if (errors) PrintAndLogEx(ERR, "Error getting hex data"); cmdp += 2; break; default: @@ -685,7 +685,7 @@ int CmdLFaskSim(const char *Cmd) { dataLen = hextobinarray((char *)data, hexData); if (dataLen == 0) errors = true; - if (errors) PrintAndLogEx(WARNING, "Error getting hex data, datalen: %d", dataLen); + if (errors) PrintAndLogEx(ERR, "Error getting hex data, datalen: %d", dataLen); cmdp += 2; break; default: @@ -788,7 +788,7 @@ int CmdLFpskSim(const char *Cmd) { dataLen = hextobinarray((char *)data, hexData); if (dataLen == 0) errors = true; - if (errors) PrintAndLogEx(WARNING, "Error getting hex data"); + if (errors) PrintAndLogEx(ERR, "Error getting hex data"); cmdp += 2; break; default: diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 1c2d96004..386d14e5e 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -103,7 +103,7 @@ static int sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uin PrintAndLogEx(INFO, "Trying FC: %u; CN: %u", fc, cn); if (getAWIDBits(fmtlen, fc, cn, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -333,7 +333,7 @@ static int CmdAWIDSim(const char *Cmd) { verify_values(&fmtlen, &fc, &cn); if (getAWIDBits(fmtlen, fc, cn, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -388,7 +388,7 @@ static int CmdAWIDClone(const char *Cmd) { verify_values(&fmtlen, &fc, &cn); if (getAWIDBits(fmtlen, fc, cn, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -419,7 +419,7 @@ static int CmdAWIDClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index ce9a9ea0a..aaf8c0db4 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -482,12 +482,12 @@ static int CmdEM410xBrute(const char *Cmd) { int filelen = param_getstr(Cmd, 0, filename, FILE_PATH_SIZE); if (filelen == 0) { - PrintAndLogEx(WARNING, "Error: Please specify a filename"); + PrintAndLogEx(ERR, "Error: Please specify a filename"); return PM3_EINVARG; } if ((f = fopen(filename, "r")) == NULL) { - PrintAndLogEx(WARNING, "Error: Could not open UIDs file ["_YELLOW_("%s")"]", filename); + PrintAndLogEx(ERR, "Error: Could not open UIDs file ["_YELLOW_("%s")"]", filename); return PM3_EFILE; } @@ -613,21 +613,21 @@ static int CmdEM410xWrite(const char *Cmd) { // Check ID if (id == 0xFFFFFFFFFFFFFFFF) { - PrintAndLogEx(WARNING, "Error! ID is required.\n"); + PrintAndLogEx(ERR, "Error! ID is required.\n"); return PM3_EINVARG; } if (id >= 0x10000000000) { - PrintAndLogEx(WARNING, "Error! Given EM410x ID is longer than 40 bits.\n"); + PrintAndLogEx(ERR, "Error! Given EM410x ID is longer than 40 bits.\n"); return PM3_EINVARG; } // Check Card if (card == 0xFF) { - PrintAndLogEx(WARNING, "Error! Card type required.\n"); + PrintAndLogEx(ERR, "Error! Card type required.\n"); return PM3_EINVARG; } if (card < 0) { - PrintAndLogEx(WARNING, "Error! Bad card type selected.\n"); + PrintAndLogEx(ERR, "Error! Bad card type selected.\n"); return PM3_EINVARG; } @@ -637,7 +637,7 @@ static int CmdEM410xWrite(const char *Cmd) { // Allowed clock rates: 16, 32, 40 and 64 if ((clock1 != 16) && (clock1 != 32) && (clock1 != 64) && (clock1 != 40)) { - PrintAndLogEx(WARNING, "Error! Clock rate" _YELLOW_("%d")" not valid. Supported clock rates are 16, 32, 40 and 64.\n", clock1); + PrintAndLogEx(ERR, "Error! Clock rate" _YELLOW_("%d")" not valid. Supported clock rates are 16, 32, 40 and 64.\n", clock1); return PM3_EINVARG; } @@ -837,7 +837,7 @@ int EM4x50Read(const char *Cmd, bool verbose) { } } if (!clk) { - if (verbose || g_debugMode) PrintAndLogEx(WARNING, "Error: EM4x50 - didn't find a clock"); + if (verbose || g_debugMode) PrintAndLogEx(ERR, "Error: EM4x50 - didn't find a clock"); return PM3_ESOFT; } } else tol = clk / 8; @@ -1262,7 +1262,7 @@ static int CmdEM4x05Write(const char *Cmd) { SendCommandNG(CMD_EM4X_WRITE_WORD, (uint8_t *)&payload, sizeof(payload)); PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_EM4X_WRITE_WORD, &resp, 2000)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index 8cf93b12f..35f3216ad 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -264,7 +264,7 @@ static int CmdFdxClone(const char *Cmd) { // getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits) if (getFDXBits(animalid, countryid, 1, 0, 0, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -300,7 +300,7 @@ static int CmdFdxClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfguard.c b/client/cmdlfguard.c index 54073fc02..1b09eb18d 100644 --- a/client/cmdlfguard.c +++ b/client/cmdlfguard.c @@ -155,7 +155,7 @@ static int CmdGuardClone(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getGuardBits(fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -189,7 +189,7 @@ static int CmdGuardClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -213,7 +213,7 @@ static int CmdGuardSim(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getGuardBits(fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index 47e08eb2e..69ba874c1 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -177,7 +177,7 @@ static int CmdLFHitagList(const char *Cmd) { if (strlen(filename) > 0) { f = fopen(filename, "wb"); if (!f) { - PrintAndLogEx(WARNING, "Error: Could not open file [%s]", filename); + PrintAndLogEx(ERR, "Error: Could not open file [%s]", filename); return PM3_EFILE; } } diff --git a/client/cmdlfio.c b/client/cmdlfio.c index ad37b9fd7..d187daaab 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -199,7 +199,7 @@ static int CmdIOProxSim(const char *Cmd) { PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or run another command"); if (getIOProxBits(version, fc, cn, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } // IOProx uses: fcHigh: 10, fcLow: 8, clk: 64, invert: 1 @@ -249,7 +249,7 @@ static int CmdIOProxClone(const char *Cmd) { } if (getIOProxBits(version, fc, cn, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index a5b9166ac..c2478705c 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -145,7 +145,7 @@ static int CmdJablotronClone(const char *Cmd) { } if (getJablotronBits(fullcode, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -174,7 +174,7 @@ static int CmdJablotronClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 82d1b9f84..b3761055f 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -164,7 +164,7 @@ static int CmdKeriClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfnedap.c b/client/cmdlfnedap.c index d081ff56c..0b998d716 100644 --- a/client/cmdlfnedap.c +++ b/client/cmdlfnedap.c @@ -182,7 +182,7 @@ static int CmdLFNedapClone(const char *Cmd) { cardnumber = (cn & 0x00FFFFFF); if ( getNedapBits(cardnumber, bits) == PM3_SUCCESS ) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -220,7 +220,7 @@ static int CmdLFNedapClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -243,7 +243,7 @@ static int CmdLFNedapSim(const char *Cmd) { memset(bs, 0x00, sizeof(bs)); if (getNedapBits(cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfnoralsy.c b/client/cmdlfnoralsy.c index 9e3413405..34ad1023f 100644 --- a/client/cmdlfnoralsy.c +++ b/client/cmdlfnoralsy.c @@ -142,7 +142,7 @@ static int CmdNoralsyClone(const char *Cmd) { blocks[0] = T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(32) | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT; if (getnoralsyBits(id, year, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -172,7 +172,7 @@ static int CmdNoralsyClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -195,7 +195,7 @@ static int CmdNoralsySim(const char *Cmd) { year = param_get32ex(Cmd, 1, 2000, 10); if (getnoralsyBits(id, year, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 684730ef3..c5c022d9b 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -128,7 +128,7 @@ static int CmdParadoxSim(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); // if ( GetParadoxBits(facilitycode, cardnumber, bs) != PM3_SUCCESS) { - // PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + // PrintAndLogEx(ERR, "Error with tag bitstream generation."); // return 1; // } diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index a51155e78..3f1ce71f3 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -138,7 +138,7 @@ static int CmdPrescoClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index 91b895bcb..4e5588ec6 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -212,7 +212,7 @@ static int CmdPyramidClone(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getPyramidBits(facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -249,7 +249,7 @@ static int CmdPyramidClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -272,7 +272,7 @@ static int CmdPyramidSim(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getPyramidBits(facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index b1c03b514..07285053b 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -1103,7 +1103,7 @@ static int CmdT55xxWriteBlock(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, 2000)) { - PrintAndLogEx(WARNING, "Error occurred, device did not ACK write operation. (May be due to old firmware)"); + PrintAndLogEx(ERR, "Error occurred, device did not ACK write operation. (May be due to old firmware)"); return PM3_ETIMEOUT; } return PM3_SUCCESS; @@ -1829,13 +1829,13 @@ static int CmdT55xxWipe(const char *Cmd) { else snprintf(ptrData, sizeof(writeData), "b 0 d 000880E0 p 0"); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Error writing blk 0"); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(ERR, "Error writing blk 0"); for (uint8_t blk = 1; blk < 8; blk++) { snprintf(ptrData, sizeof(writeData), "b %d d 0", blk); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Error writing blk %d", blk); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(ERR, "Error writing blk %d", blk); memset(writeData, 0x00, sizeof(writeData)); } @@ -1919,7 +1919,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { // TODO, a way of reallocating memory if file was larger keyBlock = calloc(4 * 200, sizeof(uint8_t)); if (keyBlock == NULL) { - PrintAndLogDevice(WARNING, "error, cannot allocate memory "); + PrintAndLogDevice(ERR, "error, cannot allocate memory "); return PM3_ESOFT; } diff --git a/client/cmdlfti.c b/client/cmdlfti.c index 3baa8c2e6..b37a6fdc1 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -233,7 +233,7 @@ static int CmdTIDemod(const char *Cmd) { // only 15 bits compare, last bit of ident is not valid if ((shift3 ^ shift0) & 0x7FFF) { - PrintAndLogEx(WARNING, "Error: Ident mismatch!"); + PrintAndLogEx(ERR, "Error: Ident mismatch!"); } // WARNING the order of the bytes in which we calc crc below needs checking // i'm 99% sure the crc algorithm is correct, but it may need to eat the @@ -257,7 +257,7 @@ static int CmdTIDemod(const char *Cmd) { PrintAndLogEx(INFO, "Tag data = %08X%08X [Crc %04X %s]", shift1, shift0, crc, crcStr); if (crc != (shift2 & 0xFFFF)) - PrintAndLogEx(WARNING, "Error: CRC mismatch, calculated %04X, got %04X", crc, shift2 & 0xFFFF); + PrintAndLogEx(ERR, "Error: CRC mismatch, calculated %04X, got %04X", crc, shift2 & 0xFFFF); retval = PM3_SUCCESS; goto out; diff --git a/client/cmdlfviking.c b/client/cmdlfviking.c index 750070a34..41193ea12 100644 --- a/client/cmdlfviking.c +++ b/client/cmdlfviking.c @@ -91,7 +91,7 @@ static int CmdVikingClone(const char *Cmd) { SendCommandMIX(CMD_VIKING_CLONE_TAG, rawID >> 32, rawID & 0xFFFFFFFF, Q5, NULL, 0); PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } return PM3_SUCCESS; diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index b717f65dd..12d4ba1c6 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -186,7 +186,7 @@ static int CmdVisa2kClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index f936f10a9..f7a0b4ca4 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -284,7 +284,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) { vxor ^= atr[i]; if (vxor) - PrintAndLogEx(WARNING, "Check sum error. Must be 0 got 0x%02X", vxor); + PrintAndLogEx(ERR, "Check sum error. Must be 0 got 0x%02X", vxor); else PrintAndLogEx(INFO, "Check sum OK."); } @@ -568,14 +568,14 @@ static int CmdSmartUpgrade(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "error, when getting filesize"); + PrintAndLogEx(ERR, "error, when getting filesize"); fclose(f); return 1; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogEx(WARNING, "error, cannot allocate memory "); + PrintAndLogEx(ERR, "error, cannot allocate memory "); fclose(f); return 1; } diff --git a/client/comms.c b/client/comms.c index 6fd41ecad..dad7c1640 100644 --- a/client/comms.c +++ b/client/comms.c @@ -359,7 +359,7 @@ __attribute__((force_align_arg_pointer)) res = uart_receive(sp, (uint8_t *)&rx_raw.data, length, &rxlen); if ((res != PM3_SUCCESS) || (rxlen != length)) { - PrintAndLogEx(WARNING, "Received packet frame error variable part too short? %d/%d", rxlen, length); + PrintAndLogEx(ERR, "Received packet frame error variable part too short? %d/%d", rxlen, length); error = true; } else { @@ -392,7 +392,7 @@ __attribute__((force_align_arg_pointer)) if (!error) { // Get the postamble res = uart_receive(sp, (uint8_t *)&rx_raw.foopost, sizeof(PacketResponseNGPostamble), &rxlen); if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseNGPostamble))) { - PrintAndLogEx(WARNING, "Received packet frame error fetching postamble"); + PrintAndLogEx(ERR, "Received packet frame error fetching postamble"); error = true; } } @@ -402,7 +402,7 @@ __attribute__((force_align_arg_pointer)) uint8_t first, second; compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(PacketResponseNGPreamble) + length, &first, &second); if ((first << 8) + second != rx.crc) { - PrintAndLogEx(WARNING, "Received packet frame CRC error %02X%02X <> %04X", first, second, rx.crc); + PrintAndLogEx(ERR, "Received packet frame CRC error %02X%02X <> %04X", first, second, rx.crc); error = true; } } @@ -424,7 +424,7 @@ __attribute__((force_align_arg_pointer)) res = uart_receive(sp, ((uint8_t *)&rx_old) + sizeof(PacketResponseNGPreamble), sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble), &rxlen); if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble))) { - PrintAndLogEx(WARNING, "Received packet OLD frame payload error too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble)); + PrintAndLogEx(ERR, "Received packet OLD frame payload error too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble)); error = true; } if (!error) { diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 22fdea153..0585c1661 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -931,7 +931,7 @@ static int CmdEMVExec(const char *Cmd) { while (AFL && AFL->len) { if (AFL->len % 4) { - PrintAndLogEx(WARNING, "Error: Wrong AFL length: %d", AFL->len); + PrintAndLogEx(ERR, "Error: Wrong AFL length: %d", AFL->len); break; } @@ -952,7 +952,7 @@ static int CmdEMVExec(const char *Cmd) { res = EMVReadRecord(channel, true, SFI, n, buf, sizeof(buf), &len, &sw, tlvRoot); if (res) { - PrintAndLogEx(WARNING, "Error SFI[%02x]. APDU error %4x", SFI, sw); + PrintAndLogEx(ERR, "Error SFI[%02x]. APDU error %4x", SFI, sw); continue; } @@ -972,7 +972,7 @@ static int CmdEMVExec(const char *Cmd) { memcpy(&ODAiList[ODAiListLen], &buf[len - elmlen], elmlen); ODAiListLen += elmlen; } else { - PrintAndLogEx(WARNING, "Error SFI[%02x]. Creating input list for Offline Data Authentication error.", SFI); + PrintAndLogEx(ERR, "Error SFI[%02x]. Creating input list for Offline Data Authentication error.", SFI); } } else { memcpy(&ODAiList[ODAiListLen], buf, len); @@ -1051,7 +1051,7 @@ static int CmdEMVExec(const char *Cmd) { } } else { - PrintAndLogEx(WARNING, "Error AC: Application Transaction Counter (ATC) not found."); + PrintAndLogEx(ERR, "Error AC: Application Transaction Counter (ATC) not found."); } } } @@ -1131,14 +1131,14 @@ static int CmdEMVExec(const char *Cmd) { PrintAndLogEx(NORMAL, "Transaction approved ONLINE."); break; default: - PrintAndLogEx(WARNING, "Error: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK); + PrintAndLogEx(ERR, "Error: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK); break; } } else { - PrintAndLogEx(WARNING, "Error: Wrong CID length %d", CID->len); + PrintAndLogEx(ERR, "Error: Wrong CID length %d", CID->len); } } else { - PrintAndLogEx(WARNING, "Error: CID(9F27) not found."); + PrintAndLogEx(ERR, "Error: CID(9F27) not found."); } } diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index e9e725448..e7bda4be5 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -511,7 +511,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO PrintAndLogEx(WARNING, "%s ERROR: Can't get TLV from response.", PSE_or_PPSE); } } else { - PrintAndLogEx(WARNING, "%s ERROR: Can't select PPSE AID. Error: %d", PSE_or_PPSE, res); + PrintAndLogEx(ERR, "%s ERROR: Can't select PPSE AID. Error: %d", PSE_or_PPSE, res); } if (!LeaveFieldON) @@ -654,14 +654,14 @@ int trSDA(struct tlvdb *tlv) { struct emv_pk *pk = get_ca_pk(tlv); if (!pk) { - PrintAndLogEx(WARNING, "Error: Key not found. Exit."); + PrintAndLogEx(ERR, "Error: Key not found. Exit."); return 2; } struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv); if (!issuer_pk) { emv_pk_free(pk); - PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit."); return 2; } @@ -693,7 +693,7 @@ int trSDA(struct tlvdb *tlv) { } else { emv_pk_free(issuer_pk); emv_pk_free(pk); - PrintAndLogEx(WARNING, "SSAD verify error"); + PrintAndLogEx(ERR, "SSAD verify error"); return 4; } @@ -712,21 +712,21 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct emv_pk *pk = get_ca_pk(tlv); if (!pk) { - PrintAndLogEx(WARNING, "Error: Key not found. Exit."); + PrintAndLogEx(ERR, "Error: Key not found. Exit."); return 2; } const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL); /* if (!sda_tlv || sda_tlv->len < 1) { it may be 0!!!! emv_pk_free(pk); - PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit."); + PrintAndLogEx(ERR, "Error: Can't find input list for Offline Data Authentication. Exit."); return 3; } */ struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv); if (!issuer_pk) { emv_pk_free(pk); - PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit."); return 2; } PrintAndLogEx(SUCCESS, "Issuer PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n", @@ -745,7 +745,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { if (!icc_pk) { emv_pk_free(pk); emv_pk_free(issuer_pk); - PrintAndLogEx(WARNING, "Error: ICC certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: ICC certificate not found. Exit."); return 2; } PrintAndLogEx(SUCCESS, "ICC PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n", @@ -763,7 +763,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { if (tlvdb_get(tlv, 0x9f2d, NULL)) { struct emv_pk *icc_pe_pk = emv_pki_recover_icc_pe_cert(issuer_pk, tlv); if (!icc_pe_pk) { - PrintAndLogEx(WARNING, "WARNING: ICC PE PK recover error. "); + PrintAndLogEx(ERR, "WARNING: ICC PE PK recover error. "); } else { PrintAndLogEx(SUCCESS, "ICC PE PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n", icc_pe_pk->rid[0], @@ -790,7 +790,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { const struct tlvdb *atc_db = emv_pki_recover_atc_ex(icc_pk, tlv, true); if (!atc_db) { - PrintAndLogEx(WARNING, "Error: Can't recover IDN (ICC Dynamic Number)"); + PrintAndLogEx(ERR, "Error: Can't recover IDN (ICC Dynamic Number)"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); @@ -807,7 +807,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { PrintAndLogEx(SUCCESS, "ATC check OK."); PrintAndLogEx(SUCCESS, "fDDA (fast DDA) verified OK."); } else { - PrintAndLogEx(WARNING, "Error: fDDA verified, but ATC in the certificate and ATC in the record not the same."); + PrintAndLogEx(ERR, "Error: fDDA verified, but ATC in the certificate and ATC in the record not the same."); } } else { PrintAndLogEx(NORMAL, "\nERROR: fDDA (fast DDA) verify error"); @@ -823,7 +823,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { PrintAndLogEx(NORMAL, "SDAD verified OK. (Data Authentication Code: %02hhx:%02hhx)\n", dac_tlv->value[0], dac_tlv->value[1]); tlvdb_add(tlv, dac_db); } else { - PrintAndLogEx(WARNING, "Error: SSAD verify error"); + PrintAndLogEx(ERR, "Error: SSAD verify error"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); @@ -839,7 +839,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlv *ddol_data_tlv = dol_process(ddol_tlv, tlv, 0); if (!ddol_data_tlv) { - PrintAndLogEx(WARNING, "Error: Can't create DDOL TLV"); + PrintAndLogEx(ERR, "Error: Can't create DDOL TLV"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); @@ -851,7 +851,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { PrintAndLogEx(NORMAL, "\n* Internal Authenticate"); int res = EMVInternalAuthenticate(channel, true, (uint8_t *)ddol_data_tlv->value, ddol_data_tlv->len, buf, sizeof(buf), &len, &sw, NULL); if (res) { - PrintAndLogEx(WARNING, "Internal Authenticate error(%d): %4x. Exit...", res, sw); + PrintAndLogEx(ERR, "Internal Authenticate error(%d): %4x. Exit...", res, sw); free(ddol_data_tlv); emv_pk_free(pk); emv_pk_free(issuer_pk); @@ -862,7 +862,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlvdb *dda_db = NULL; if (buf[0] == 0x80) { if (len < 3) { - PrintAndLogEx(WARNING, "Error: Internal Authenticate format1 parsing error. length=%d", len); + PrintAndLogEx(ERR, "Error: Internal Authenticate format1 parsing error. length=%d", len); } else { // parse response 0x80 struct tlvdb *t80 = tlvdb_parse_multi(buf, len); @@ -882,7 +882,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { } else { dda_db = tlvdb_parse_multi(buf, len); if (!dda_db) { - PrintAndLogEx(WARNING, "Error: Can't parse Internal Authenticate result as TLV"); + PrintAndLogEx(ERR, "Error: Can't parse Internal Authenticate result as TLV"); free(ddol_data_tlv); emv_pk_free(pk); emv_pk_free(issuer_pk); @@ -898,7 +898,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlvdb *idn_db = emv_pki_recover_idn_ex(icc_pk, dda_db, ddol_data_tlv, true); free(ddol_data_tlv); if (!idn_db) { - PrintAndLogEx(WARNING, "Error: Can't recover IDN (ICC Dynamic Number)"); + PrintAndLogEx(ERR, "Error: Can't recover IDN (ICC Dynamic Number)"); tlvdb_free(dda_db); emv_pk_free(pk); emv_pk_free(issuer_pk); @@ -935,20 +935,20 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st struct emv_pk *pk = get_ca_pk(tlv); if (!pk) { - PrintAndLogEx(WARNING, "Error: Key not found. Exit."); + PrintAndLogEx(ERR, "Error: Key not found. Exit."); return 2; } const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL); if (!sda_tlv || sda_tlv->len < 1) { - PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit."); + PrintAndLogEx(ERR, "Error: Can't find input list for Offline Data Authentication. Exit."); emv_pk_free(pk); return 3; } struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv); if (!issuer_pk) { - PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit."); emv_pk_free(pk); return 2; } @@ -966,7 +966,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st struct emv_pk *icc_pk = emv_pki_recover_icc_cert(issuer_pk, tlv, sda_tlv); if (!icc_pk) { - PrintAndLogEx(WARNING, "Error: ICC certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: ICC certificate not found. Exit."); emv_pk_free(pk); emv_pk_free(issuer_pk); return 2; @@ -989,7 +989,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st PrintAndLogEx(NORMAL, "SSAD verified OK. (%02hhx:%02hhx)", dac_tlv->value[0], dac_tlv->value[1]); tlvdb_add(tlv, dac_db); } else { - PrintAndLogEx(WARNING, "Error: SSAD verify error"); + PrintAndLogEx(ERR, "Error: SSAD verify error"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index c356c3456..21079eb34 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -386,7 +386,7 @@ static int FIDO2CheckSignature(json_t *root, uint8_t *publickey, uint8_t *sign, if (res == -0x4e00) { PrintAndLogEx(WARNING, "Signature is NOT VALID."); } else { - PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); + PrintAndLogEx(ERR, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); } return res; } else { diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index a461557b1..3e0aa1dc5 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -517,7 +517,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { first16bytes[i] = keytable[i] & 0xFF; if (!(keytable[i] & CRACKED)) - PrintAndLogDevice(WARNING, "error, we are missing byte %d, custom key calculation will fail...", i); + PrintAndLogDevice(ERR, "error, we are missing byte %d, custom key calculation will fail...", i); } errors += calculateMasterKey(first16bytes, NULL); return errors; @@ -541,7 +541,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(WARNING, "Error, when getting filesize"); + PrintAndLogDevice(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -557,7 +557,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fclose(f); if (bytes_read < fsize) { - PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogDevice(ERR, "Error, could only read %d bytes (should be %d)", bytes_read, fsize); } uint8_t res = bruteforceDump(dump, fsize, keytable); @@ -612,7 +612,7 @@ static int _testBruteforce() { } else if (fileExists("client/loclass/iclass_dump.bin")) { errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable); } else { - PrintAndLogDevice(WARNING, "Error: The file iclass_dump.bin was not found!"); + PrintAndLogDevice(ERR, "Error: The file iclass_dump.bin was not found!"); } } return errors; @@ -627,14 +627,14 @@ static int _test_iclass_key_permutation() { permutekey_rev(testcase_output, testcase_output_rev); if (memcmp(testcase_output, testcase_output_correct, 8) != 0) { - PrintAndLogDevice(WARNING, "Error with iclass key permute!"); + PrintAndLogDevice(ERR, "Error with iclass key permute!"); printarr("testcase_output", testcase_output, 8); printarr("testcase_output_correct", testcase_output_correct, 8); return 1; } if (memcmp(testcase, testcase_output_rev, 8) != 0) { - PrintAndLogDevice(WARNING, "Error with reverse iclass key permute"); + PrintAndLogDevice(ERR, "Error with reverse iclass key permute"); printarr("testcase", testcase, 8); printarr("testcase_output_rev", testcase_output_rev, 8); return 1; @@ -651,7 +651,7 @@ static int _testHash1() { hash1(csn, k); if (memcmp(k, expected, 8) != 0) { - PrintAndLogDevice(WARNING, "Error with hash1!"); + PrintAndLogDevice(ERR, "Error with hash1!"); printarr("calculated", k, 8); printarr("expected", expected, 8); return 1; diff --git a/client/mifare/mad.c b/client/mifare/mad.c index 47b7cb70a..fa5b7d259 100644 --- a/client/mifare/mad.c +++ b/client/mifare/mad.c @@ -225,7 +225,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool verbose, bool *haveMAD2) { PrintAndLogEx(NORMAL, "Card publisher sector not present."); } if (InfoByte == 0x10 || InfoByte >= 0x28) - PrintAndLogEx(WARNING, "Info byte error"); + PrintAndLogEx(ERR, "Info byte error"); PrintAndLogEx(NORMAL, "00 MAD1"); for (int i = 1; i < 16; i++) { diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index e9810e71a..100b595ce 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -914,7 +914,7 @@ int detect_classic_prng(void) { // if select tag failed. if (resp.oldarg[0] == 0) { - PrintAndLogEx(WARNING, "error: selecting tag failed, can't detect prng\n"); + PrintAndLogEx(ERR, "error: selecting tag failed, can't detect prng\n"); return PM3_ERFTRANS; } if (!WaitForResponseTimeout(CMD_ACK, &respA, 2500)) { @@ -924,7 +924,7 @@ int detect_classic_prng(void) { // check respA if (respA.oldarg[0] != 4) { - PrintAndLogEx(WARNING, "PRNG data error: Wrong length: %d", respA.oldarg[0]); + PrintAndLogEx(ERR, "PRNG data error: Wrong length: %d", respA.oldarg[0]); return PM3_ESOFT; } @@ -996,7 +996,7 @@ int detect_classic_nackbug(bool verbose) { PrintAndLogEx(SUCCESS, "No NACK bug detected"); return PM3_SUCCESS; default : - PrintAndLogEx(WARNING, "errorcode from device [%i]", ok); + PrintAndLogEx(ERR, "errorcode from device [%i]", ok); return PM3_EUNDEF; } break; From 55602bf833c5a9c1c4c1dcb07e11cd89d73d58dd Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 12:17:34 +0200 Subject: [PATCH 24/40] Fix few zelaous WARNING->ERR --- client/cmddata.c | 2 +- client/cmdhf15.c | 2 +- client/cmdhffido.c | 4 ++-- client/cmdhfmf.c | 2 +- client/cmdlft55xx.c | 4 ++-- client/cmdlfti.c | 4 ++-- client/cmdsmartcard.c | 4 ++-- client/comms.c | 8 ++++---- client/emv/cmdemv.c | 18 +++++++++--------- client/emv/emvcore.c | 6 +++--- client/fido/fidocore.c | 2 +- client/loclass/elite_crack.c | 4 ++-- client/mifare/mad.c | 2 +- 13 files changed, 31 insertions(+), 31 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index e0e0f73c1..ba6790c93 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -667,7 +667,7 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) { } if (errCnt > 0) - PrintAndLogEx(ERR, "# Errors found during Demod (shown as " _YELLOW_("7")" in bit stream): %d", errCnt); + PrintAndLogEx(WARNING, "# Errors found during Demod (shown as " _YELLOW_("7")" in bit stream): %d", errCnt); PrintAndLogEx(NORMAL, "Biphase Decoded using offset: %d - # invert:%d - data:", offset, invert); PrintAndLogEx(NORMAL, "%s", sprint_bin_break(bits, size, 32)); diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 65bc26010..33c3957fe 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -564,7 +564,7 @@ static int CmdHF15Demod(const char *Cmd) { } if (mask != 0x01) { - PrintAndLogEx(ERR, "Error, uneven octet! (discard extra bits!)"); + PrintAndLogEx(WARNING, "Warning, uneven octet! (discard extra bits!)"); PrintAndLogEx(NORMAL, " mask = %02x", mask); } PrintAndLogEx(NORMAL, "%d octets", k); diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 9db6583f6..39b080dca 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -351,7 +351,7 @@ static int CmdHFFidoRegister(const char *cmd) { if (res == -0x4e00) { PrintAndLogEx(WARNING, "Signature is NOT VALID."); } else { - PrintAndLogEx(ERR, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); + PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); } } else { PrintAndLogEx(SUCCESS, "Signature is OK."); @@ -577,7 +577,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) { if (res == -0x4e00) { PrintAndLogEx(WARNING, "Signature is NOT VALID."); } else { - PrintAndLogEx(ERR, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); + PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); } } else { PrintAndLogEx(SUCCESS, "Signature is OK."); diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 3ca958f80..a62924787 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2765,7 +2765,7 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) { PrintAndLogEx(NORMAL, "|---|----------------|----------------|"); for (i = 0; i < numSectors; i++) { if (mfEmlGetMem(data, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1) != PM3_SUCCESS) { - PrintAndLogEx(ERR, "error get block %d", FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1); + PrintAndLogEx(WARNING, "error get block %d", FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1); break; } uint64_t keyA = bytes_to_num(data, 6); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 07285053b..9a23e660b 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -1829,13 +1829,13 @@ static int CmdT55xxWipe(const char *Cmd) { else snprintf(ptrData, sizeof(writeData), "b 0 d 000880E0 p 0"); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(ERR, "Error writing blk 0"); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk 0"); for (uint8_t blk = 1; blk < 8; blk++) { snprintf(ptrData, sizeof(writeData), "b %d d 0", blk); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(ERR, "Error writing blk %d", blk); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk %d", blk); memset(writeData, 0x00, sizeof(writeData)); } diff --git a/client/cmdlfti.c b/client/cmdlfti.c index b37a6fdc1..5236550b2 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -233,7 +233,7 @@ static int CmdTIDemod(const char *Cmd) { // only 15 bits compare, last bit of ident is not valid if ((shift3 ^ shift0) & 0x7FFF) { - PrintAndLogEx(ERR, "Error: Ident mismatch!"); + PrintAndLogEx(WARNING, "Warning: Ident mismatch!"); } // WARNING the order of the bytes in which we calc crc below needs checking // i'm 99% sure the crc algorithm is correct, but it may need to eat the @@ -257,7 +257,7 @@ static int CmdTIDemod(const char *Cmd) { PrintAndLogEx(INFO, "Tag data = %08X%08X [Crc %04X %s]", shift1, shift0, crc, crcStr); if (crc != (shift2 & 0xFFFF)) - PrintAndLogEx(ERR, "Error: CRC mismatch, calculated %04X, got %04X", crc, shift2 & 0xFFFF); + PrintAndLogEx(WARNING, "Warning: CRC mismatch, calculated %04X, got %04X", crc, shift2 & 0xFFFF); retval = PM3_SUCCESS; goto out; diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index f7a0b4ca4..c49f0d0e7 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -284,7 +284,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) { vxor ^= atr[i]; if (vxor) - PrintAndLogEx(ERR, "Check sum error. Must be 0 got 0x%02X", vxor); + PrintAndLogEx(WARNING, "Invalid check sum. Must be 0 got 0x%02X", vxor); else PrintAndLogEx(INFO, "Check sum OK."); } @@ -295,7 +295,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) { uint8_t calen = 2 + T1len + TD1len + TDilen + K; if (atrlen != calen && atrlen != calen + 1) // may be CRC - PrintAndLogEx(ERR, "ATR length error. len: %d, T1len: %d, TD1len: %d, TDilen: %d, K: %d", atrlen, T1len, TD1len, TDilen, K); + PrintAndLogEx(WARNING, "Invalid ATR length. len: %d, T1len: %d, TD1len: %d, TDilen: %d, K: %d", atrlen, T1len, TD1len, TDilen, K); if (K > 0) PrintAndLogEx(INFO, "\nHistorical bytes | len 0x%02d | format %02x", K, atr[2 + T1len + TD1len + TDilen]); diff --git a/client/comms.c b/client/comms.c index dad7c1640..304948a4d 100644 --- a/client/comms.c +++ b/client/comms.c @@ -359,7 +359,7 @@ __attribute__((force_align_arg_pointer)) res = uart_receive(sp, (uint8_t *)&rx_raw.data, length, &rxlen); if ((res != PM3_SUCCESS) || (rxlen != length)) { - PrintAndLogEx(ERR, "Received packet frame error variable part too short? %d/%d", rxlen, length); + PrintAndLogEx(WARNING, "Received packet frame with variable part too short? %d/%d", rxlen, length); error = true; } else { @@ -392,7 +392,7 @@ __attribute__((force_align_arg_pointer)) if (!error) { // Get the postamble res = uart_receive(sp, (uint8_t *)&rx_raw.foopost, sizeof(PacketResponseNGPostamble), &rxlen); if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseNGPostamble))) { - PrintAndLogEx(ERR, "Received packet frame error fetching postamble"); + PrintAndLogEx(WARNING, "Received packet frame without postamble"); error = true; } } @@ -402,7 +402,7 @@ __attribute__((force_align_arg_pointer)) uint8_t first, second; compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(PacketResponseNGPreamble) + length, &first, &second); if ((first << 8) + second != rx.crc) { - PrintAndLogEx(ERR, "Received packet frame CRC error %02X%02X <> %04X", first, second, rx.crc); + PrintAndLogEx(WARNING, "Received packet frame with invalid CRC %02X%02X <> %04X", first, second, rx.crc); error = true; } } @@ -424,7 +424,7 @@ __attribute__((force_align_arg_pointer)) res = uart_receive(sp, ((uint8_t *)&rx_old) + sizeof(PacketResponseNGPreamble), sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble), &rxlen); if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble))) { - PrintAndLogEx(ERR, "Received packet OLD frame payload error too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble)); + PrintAndLogEx(WARNING, "Received packet OLD frame with payload too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble)); error = true; } if (!error) { diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 0585c1661..0b50ecfe1 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -931,7 +931,7 @@ static int CmdEMVExec(const char *Cmd) { while (AFL && AFL->len) { if (AFL->len % 4) { - PrintAndLogEx(ERR, "Error: Wrong AFL length: %d", AFL->len); + PrintAndLogEx(WARNING, "Warning: Wrong AFL length: %d", AFL->len); break; } @@ -952,7 +952,7 @@ static int CmdEMVExec(const char *Cmd) { res = EMVReadRecord(channel, true, SFI, n, buf, sizeof(buf), &len, &sw, tlvRoot); if (res) { - PrintAndLogEx(ERR, "Error SFI[%02x]. APDU error %4x", SFI, sw); + PrintAndLogEx(WARNING, "Error SFI[%02x]. APDU error %4x", SFI, sw); continue; } @@ -972,7 +972,7 @@ static int CmdEMVExec(const char *Cmd) { memcpy(&ODAiList[ODAiListLen], &buf[len - elmlen], elmlen); ODAiListLen += elmlen; } else { - PrintAndLogEx(ERR, "Error SFI[%02x]. Creating input list for Offline Data Authentication error.", SFI); + PrintAndLogEx(WARNING, "Error SFI[%02x]. Creating input list for Offline Data Authentication error.", SFI); } } else { memcpy(&ODAiList[ODAiListLen], buf, len); @@ -1001,7 +1001,7 @@ static int CmdEMVExec(const char *Cmd) { AIP = AIPtlv->value[0] + AIPtlv->value[1] * 0x100; PrintAndLogEx(NORMAL, "* * AIP=%04x", AIP); } else { - PrintAndLogEx(ERR, "Can't found AIP."); + PrintAndLogEx(ERR, "Can't find AIP."); } // SDA @@ -1047,11 +1047,11 @@ static int CmdEMVExec(const char *Cmd) { TLVPrintFromTLVLev(cvr, 1); } } else { - PrintAndLogEx(NORMAL, "WARNING: IAD not found."); + PrintAndLogEx(WARNING, "WARNING: IAD not found."); } } else { - PrintAndLogEx(ERR, "Error AC: Application Transaction Counter (ATC) not found."); + PrintAndLogEx(WARNING, "Warning AC: Application Transaction Counter (ATC) not found."); } } } @@ -1131,14 +1131,14 @@ static int CmdEMVExec(const char *Cmd) { PrintAndLogEx(NORMAL, "Transaction approved ONLINE."); break; default: - PrintAndLogEx(ERR, "Error: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK); + PrintAndLogEx(WARNING, "Warning: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK); break; } } else { - PrintAndLogEx(ERR, "Error: Wrong CID length %d", CID->len); + PrintAndLogEx(WARNING, "Warning: Wrong CID length %d", CID->len); } } else { - PrintAndLogEx(ERR, "Error: CID(9F27) not found."); + PrintAndLogEx(WARNING, "Warning: CID(9F27) not found."); } } diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index e7bda4be5..2d96b567a 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -763,7 +763,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { if (tlvdb_get(tlv, 0x9f2d, NULL)) { struct emv_pk *icc_pe_pk = emv_pki_recover_icc_pe_cert(issuer_pk, tlv); if (!icc_pe_pk) { - PrintAndLogEx(ERR, "WARNING: ICC PE PK recover error. "); + PrintAndLogEx(WARNING, "WARNING: ICC PE PK recover error. "); } else { PrintAndLogEx(SUCCESS, "ICC PE PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n", icc_pe_pk->rid[0], @@ -807,7 +807,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { PrintAndLogEx(SUCCESS, "ATC check OK."); PrintAndLogEx(SUCCESS, "fDDA (fast DDA) verified OK."); } else { - PrintAndLogEx(ERR, "Error: fDDA verified, but ATC in the certificate and ATC in the record not the same."); + PrintAndLogEx(WARNING, "Error: fDDA verified, but ATC in the certificate and ATC in the record not the same."); } } else { PrintAndLogEx(NORMAL, "\nERROR: fDDA (fast DDA) verify error"); @@ -862,7 +862,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlvdb *dda_db = NULL; if (buf[0] == 0x80) { if (len < 3) { - PrintAndLogEx(ERR, "Error: Internal Authenticate format1 parsing error. length=%d", len); + PrintAndLogEx(WARNING, "Warning: Internal Authenticate format1 parsing error. length=%d", len); } else { // parse response 0x80 struct tlvdb *t80 = tlvdb_parse_multi(buf, len); diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index 21079eb34..c356c3456 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -386,7 +386,7 @@ static int FIDO2CheckSignature(json_t *root, uint8_t *publickey, uint8_t *sign, if (res == -0x4e00) { PrintAndLogEx(WARNING, "Signature is NOT VALID."); } else { - PrintAndLogEx(ERR, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); + PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res)); } return res; } else { diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 3e0aa1dc5..5b019d8e0 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -517,7 +517,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { first16bytes[i] = keytable[i] & 0xFF; if (!(keytable[i] & CRACKED)) - PrintAndLogDevice(ERR, "error, we are missing byte %d, custom key calculation will fail...", i); + PrintAndLogDevice(WARNING, "Warning: we are missing byte %d, custom key calculation will fail...", i); } errors += calculateMasterKey(first16bytes, NULL); return errors; @@ -557,7 +557,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fclose(f); if (bytes_read < fsize) { - PrintAndLogDevice(ERR, "Error, could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogDevice(WARNING, "Warning: could only read %d bytes (should be %d)", bytes_read, fsize); } uint8_t res = bruteforceDump(dump, fsize, keytable); diff --git a/client/mifare/mad.c b/client/mifare/mad.c index fa5b7d259..47b7cb70a 100644 --- a/client/mifare/mad.c +++ b/client/mifare/mad.c @@ -225,7 +225,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool verbose, bool *haveMAD2) { PrintAndLogEx(NORMAL, "Card publisher sector not present."); } if (InfoByte == 0x10 || InfoByte >= 0x28) - PrintAndLogEx(ERR, "Info byte error"); + PrintAndLogEx(WARNING, "Info byte error"); PrintAndLogEx(NORMAL, "00 MAD1"); for (int i = 1; i < 16; i++) { From 2fc26fbf3553c3c5497342174f2cf108582b0bbe Mon Sep 17 00:00:00 2001 From: "Colin J. Brigato" Date: Sun, 14 Jul 2019 13:29:40 +0200 Subject: [PATCH 25/40] HF_COLIN/STANDALONE: FIX Simulation/Writing Tag to flash/Reading back from flash * Simulation was broke by the 4/7/10 UID lenght pseudo-support (which, in regard of the whole, will never be of any use unless complete reimplementaiton). Kept this part as respect, but enforced UID_IN_EMUL, since it will _ALWAYS_ be the case, be it direct simulation after tag breaking or from reading back tag. * Writing tag was broken when flashmem driver had SPI settings changed, enforcing 48MHz speed as necessity for some work (like in hf_bog), so now it is * Reading back, however, should absolutely be done at 24Mhz to avoid those unecessary and unstable [On this chip] FAST_READS. Should worsk flawlessly now. If one has spare time, handling getting new keys or defining whole Schemes in Flashmem would be perfect. Just has to be a conditional and a 8/16key ordered answer. --- armsrc/Standalone/hf_colin.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 63366259e..060c4af06 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -101,6 +101,8 @@ void ReadLastTagFromFlash() { size_t size = len; uint8_t *mem = BigBuf_malloc(size); + FlashmemSetSpiBaudrate(24000000); + if (!FlashInit()) { return; } @@ -148,6 +150,9 @@ void WriteTagToFlash(uint8_t index, size_t size) { emlGetMem(data, 0, (size * 64) / 1024); + + FlashmemSetSpiBaudrate(48000000); + if (!FlashInit()) { return; } @@ -424,7 +429,7 @@ failtag: //----------------------------------------------------------------------------- // also we could avoid first UID check for every block - // then let’s expose this “optimal case” of “well known vigik schemes” : + // then let's expose this “optimal case” of “well known vigik schemes” : for (uint8_t type = 0; type < 2 && !err && !trapped; type++) { for (int sec = 0; sec < sectorsCnt && !err && !trapped; ++sec) { key = cjat91_saMifareChkKeys(sec * 4, type, NULL, size, &keyBlock[0], &key64); @@ -783,10 +788,18 @@ readysim: case 7: flags = FLAG_7B_UID_IN_DATA; break; - default: + case 4: flags = FLAG_4B_UID_IN_DATA; break; + default: + flags = FLAG_UID_IN_EMUL; + break; } + + // Use UID, SAK, ATQA from EMUL, if uid not defined + //if ((flags & (FLAG_4B_UID_IN_DATA | FLAG_7B_UID_IN_DATA | FLAG_10B_UID_IN_DATA)) == 0) { + flags |= FLAG_UID_IN_EMUL; + //} Mifare1ksim(flags | FLAG_MF_1K, 0, cjuid); LED_C_OFF(); SpinOff(50); @@ -902,7 +915,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { return (isOK) ? PM3_SUCCESS : PM3_EUNDEF; } -/* the chk function is a piwi’ed(tm) check that will try all keys for +/* the chk function is a piwi'ed(tm) check that will try all keys for a particular sector. also no tracing no dbg */ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) { DBGLEVEL = DBG_NONE; From d746847d134f9272c4c7565e9242c38b32e990a3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 17:58:47 +0200 Subject: [PATCH 26/40] proxmark3.sh for WSL: handle case when chmod is needed --- .../Windows-Installation-Instructions.md | 1 + proxmark3.sh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index eacdc4b62..db9a9084f 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -166,3 +166,4 @@ Or, by specifying the COM port manually: client/proxmark3 /dev/ttySX ``` +Note that it may take a quite long time for a freshly plugged Proxmark3 to be visible on a WSL /dev/ttySX port. diff --git a/proxmark3.sh b/proxmark3.sh index 39eb80779..b45887a23 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -51,6 +51,10 @@ function wait4proxmark_WSL { fi sleep .1 done + if [ -e "$PM3" ] && ! [ -w "$PM3" ]; then + echo "We need to give current user read/write access to $PM3" + sudo chmod 666 "$PM3" + fi echo $PM3 } From 82e0568e65abf13af613f28c4ed418de4b78f8e5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 18:20:41 +0200 Subject: [PATCH 27/40] shellcheck bash scripts --- flash-all.sh | 3 ++- flash-bootrom.sh | 3 ++- flash-fullimage.sh | 3 ++- proxmark3.sh | 40 +++++++++++++++++++--------------------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/flash-all.sh b/flash-all.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-all.sh +++ b/flash-all.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/flash-bootrom.sh b/flash-bootrom.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-bootrom.sh +++ b/flash-bootrom.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/flash-fullimage.sh b/flash-fullimage.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-fullimage.sh +++ b/flash-fullimage.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/proxmark3.sh b/proxmark3.sh index b45887a23..b8d6acabb 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -3,28 +3,31 @@ FULLIMAGE="armsrc/obj/fullimage.elf" BOOTIMAGE="bootrom/obj/bootrom.elf" -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 function wait4proxmark_Linux { echo >&2 "Waiting for Proxmark to appear..." - while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do + while true; do + PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1) + if [[ $PM3 != "" ]]; then + break + fi sleep .1 done - local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1` - echo $PM3 + echo "$PM3" } function wait4proxmark_macOS { echo >&2 "Waiting for Proxmark to appear..." while true; do - PM3=$(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) + PM3=$(find /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) if [[ $PM3 != "" ]]; then - #echo >&2 -e "Found proxmark on $(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)\n" break fi sleep .1 done - echo $PM3 + echo "$PM3" } function wait4proxmark_Windows { @@ -37,7 +40,7 @@ function wait4proxmark_Windows { fi sleep .1 done - echo $PM3 + echo "$PM3" } function wait4proxmark_WSL { @@ -51,27 +54,23 @@ function wait4proxmark_WSL { fi sleep .1 done - if [ -e "$PM3" ] && ! [ -w "$PM3" ]; then + if [ -e "$PM3" ] && [ ! -w "$PM3" ]; then echo "We need to give current user read/write access to $PM3" sudo chmod 666 "$PM3" fi - echo $PM3 + echo "$PM3" } SCRIPT=$(basename -- "$0") if [ "$SCRIPT" = "proxmark3.sh" ]; then - CMD=client/proxmark3 + CMD() { client/proxmark3 "$@"; } elif [ "$SCRIPT" = "flash-all.sh" ]; then - CMD=client/flasher - ARG1="-b $BOOTIMAGE" - ARG2="$FULLIMAGE" -elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then - CMD=client/flasher - ARG2="$FULLIMAGE" + CMD() { client/flasher "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } +elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then CMD=client/flasher + CMD() { client/flasher "$1" "$FULLIMAGE"; } elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then - CMD=client/flasher - ARG1="-b $BOOTIMAGE" + CMD() { client/flasher "$1" -b "$BOOTIMAGE"; } else echo "Script ran under unknown name, abort: $SCRIPT" exit 1 @@ -96,6 +95,5 @@ if [ "$PORT" = "" ]; then exit 1 fi -#echo Running "$CMD" "$PORT" $ARG1 $ARG2 "$@" -"$CMD" "$PORT" $ARG1 $ARG2 "$@" +CMD "$PORT" "$@" exit $? From fee9c0ef847b8b7471d7e7af3cbf17fcb9fa4ee8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 18:26:04 +0200 Subject: [PATCH 28/40] silent uart_close error message as it can be called from uart_open failing modes, e.g. when waiting for port to appear --- uart/uart_posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 22cc75207..ea535fd73 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -238,7 +238,8 @@ void uart_close(const serial_port sp) { // Does the system allows us to place a lock on this file descriptor int err = fcntl(spu->fd, F_SETLK, &fl); if (err == -1) { - printf("[!] UART error while closing port\n"); + //silent error message as it can be called from uart_open failing modes, e.g. when waiting for port to appear + //printf("[!] UART error while closing port\n"); } close(spu->fd); free(sp); From 383d3327be40c3a276971bd0b371d9b3520b1dac Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 18:42:11 +0200 Subject: [PATCH 29/40] remove spurious changes in make style --- Makefile | 4 ++-- client/fpga_compress.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 910aa62f6..64dbea4eb 100644 --- a/Makefile +++ b/Makefile @@ -145,12 +145,12 @@ style: # Make sure astyle is installed @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile - find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ + find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ -exec perl -pi -e 's/[ \t]+$$//' {} \; \ -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \ -exec sh -c "echo >> {}" \; # Apply astyle on *.c, *.h, *.cpp - find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \ + find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) \) -exec astyle --formatted --mode=c --suffix=none \ --indent=spaces=4 --indent-switches \ --keep-one-line-blocks --max-instatement-indent=60 \ --style=google --pad-oper --unpad-paren --pad-header \ diff --git a/client/fpga_compress.c b/client/fpga_compress.c index 7cd4652e1..a030afe81 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -375,7 +375,7 @@ static void print_version_info_preamble(FILE *outfile, int num_infiles) { fprintf(outfile, "\n"); fprintf(outfile, "\n"); fprintf(outfile, "const int fpga_bitstream_num = %d;\n", num_infiles); - fprintf(outfile, "const char* const fpga_version_information[%d] = {\n", num_infiles); + fprintf(outfile, "const char *const fpga_version_information[%d] = {\n", num_infiles); } static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int num_infiles, FILE *outfile) { @@ -386,7 +386,7 @@ static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int for (int i = 0; i < num_infiles; i++) { FpgaGatherVersion(infile[i], infile_names[i], version_string, sizeof(version_string)); - fprintf(outfile, "\t\" %s\"", version_string); + fprintf(outfile, " \" %s\"", version_string); if (i != num_infiles - 1) { fprintf(outfile, ","); } From f6f7e7a9f62de7ef37e44b2001a50f4c6900219b Mon Sep 17 00:00:00 2001 From: Eloff Date: Sun, 14 Jul 2019 23:12:39 +0300 Subject: [PATCH 30/40] hf_mf_sim. Really tags not respond NACK on invalid authentication --- armsrc/mifaresim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 8f21882be..36f5c3593 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -1036,8 +1036,9 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { ); } cardAUTHKEY = AUTHKEYNONE; // not authenticated - EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); cardSTATE_TO_IDLE(); + // Really tags not respond NACK on invalid authentication + LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); break; } From 055efaff88b5f387d2cbaaee1bf2dcd1045d7b1e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 22:13:40 +0200 Subject: [PATCH 31/40] proxmark.sh: remove leftover var --- proxmark3.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxmark3.sh b/proxmark3.sh index b8d6acabb..4cd6d76bc 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -67,7 +67,7 @@ if [ "$SCRIPT" = "proxmark3.sh" ]; then CMD() { client/proxmark3 "$@"; } elif [ "$SCRIPT" = "flash-all.sh" ]; then CMD() { client/flasher "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } -elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then CMD=client/flasher +elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then CMD() { client/flasher "$1" "$FULLIMAGE"; } elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then CMD() { client/flasher "$1" -b "$BOOTIMAGE"; } From a28e359095f395ee7153c1eeda39d825bb35be97 Mon Sep 17 00:00:00 2001 From: Eloff Date: Sun, 14 Jul 2019 23:18:07 +0300 Subject: [PATCH 32/40] Fix. More flexible anti-collision frame check --- armsrc/mifaresim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 8f21882be..f17381ecd 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -625,7 +625,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { } // Incoming anti-collision frame - if (receivedCmd_len >= 2 && receivedCmd_len <= 6 && receivedCmd[1] == 0x50) { + // receivedCmd[1] indicates number of byte and bit collision, supports only for bit collision is zero + if (receivedCmd_len >= 3 && receivedCmd_len <= 6 && (receivedCmd[1] & 0x0f) == 0) { // we can process only full-byte frame anti-collision procedure if (memcmp(&receivedCmd[2], responses[uid_index].response, receivedCmd_len - 2) == 0) { // response missing part of UID via relative array index From 0a845df8c3fee8db399268b2b8658a594b3518e2 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 14 Jul 2019 22:52:34 +0200 Subject: [PATCH 33/40] chg: 'script run read_pwd_mem' - now can correctly deal with more than 4096 bytes when printing mifare classic keys --- client/scripts/read_pwd_mem.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/scripts/read_pwd_mem.lua b/client/scripts/read_pwd_mem.lua index 4aa2e6299..7dbfa6fba 100644 --- a/client/scripts/read_pwd_mem.lua +++ b/client/scripts/read_pwd_mem.lua @@ -81,18 +81,19 @@ local function main(args) if o == 'o' then offset = tonumber(a) end -- num of bytes to read - if o == 'l' then length = tonumber(a) end + if o == 'l' then + length = tonumber(a) + if length < 0 or length > 256 then + return oops('Error: Length is not valid. Must be less than 256') + end + end -- keylength if o == 'k' then keylength = tonumber(a); usedkey = true end - if o == 'm' then keylength =6; usedkey = true; offset = 0x3F000-0x6000; end - if o == 't' then keylength =4; usedkey = true; offset = 0x3F000-0x3000; end - if o == 'i' then keylength =8; usedkey = true; offset = 0x3F000-0x4000; end - end - - if length < 0 or length > 256 then - return oops('Error: Length is not valid. Must be less than 256') + if o == 'm' then keylength = 6; usedkey = true; length = 8192; offset = 0x3F000-0x6000; end + if o == 't' then keylength = 4; usedkey = true; length = 4096; offset = 0x3F000-0x3000; end + if o == 'i' then keylength = 8; usedkey = true; length = 4096; offset = 0x3F000-0x4000; end end if (offset < 0) or (offset % 4 ~= 0) then @@ -102,9 +103,7 @@ local function main(args) print('Memory offset', offset) print('Length ', length) print('Key length ', keylength) - print( string.rep('--',20) ) - - if usedkey then length = 4096 end + print( string.rep('--', 20) ) data, err = core.GetFromFlashMem(offset, length) if err then return oops(err) end @@ -116,7 +115,6 @@ local function main(args) local kl = keylength * 2 for i = 1, keys do - key = string.sub(s, (i - 1) * kl + 1, i * kl ) print(string.format('[%02d] %s',i, key)) end From 0c3d2cee2baf7c18d98e027b3a902aba467240a5 Mon Sep 17 00:00:00 2001 From: Eloff Date: Mon, 15 Jul 2019 00:00:34 +0300 Subject: [PATCH 34/40] Changelog for PR #245, #246 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dd057c73..3b9a41a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Fix Mifare Classic simulation more flexible anti-collision check (@McEloff) + - Change: Mifare Classic simulation not respond NACK on invalid authentication request (@McEloff) - Change: Don't clear trace log during 'hf mf chk', to save whole process history (@McEloff) - Add support for WSL in proxmark.sh (@doegox) - Add documentation for usage of Proxmark3 under WSL (@doegox) From 1f9eb10d15ee648a5a75c3f0a1964abd9eaa6557 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 14 Jul 2019 23:02:24 +0200 Subject: [PATCH 35/40] textual --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dd057c73..7cb72cea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Change: 'read_pwd_mem.lua' now handles Mifare Classic dictionaries large than 4096 bytes (@iceman) - Change: Don't clear trace log during 'hf mf chk', to save whole process history (@McEloff) - Add support for WSL in proxmark.sh (@doegox) - Add documentation for usage of Proxmark3 under WSL (@doegox) From cad1d500ca928f34c607a05d6eff955eaeb71a0b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 15 Jul 2019 00:31:38 +0200 Subject: [PATCH 36/40] add msleep command --- client/cmdmain.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/client/cmdmain.c b/client/cmdmain.c index 311e2d6de..6748f81f0 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -31,6 +31,32 @@ static int CmdRem(const char *Cmd) { return PM3_SUCCESS; } +static int usage_msleep(void) { + PrintAndLogEx(NORMAL, "Sleep for given amount of milliseconds"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: msleep "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " time in milliseconds"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " msleep 100"); + return PM3_SUCCESS; +} + +static int CmdMsleep(const char *Cmd) { + uint32_t ms = 0; + char ctmp = tolower(param_getchar(Cmd, 0)); + if (strlen(Cmd) < 1 || ctmp == 'h') return usage_msleep(); + if (param_getchar(Cmd, 0) != 0x00) { + ms = param_get32ex(Cmd, 0, 0, 10); + if (ms == 0) + return usage_msleep(); + } + msleep(ms); + return PM3_SUCCESS; +} + static int CmdQuit(const char *Cmd) { (void)Cmd; // Cmd is not used so far return PM3_EFATAL; @@ -50,8 +76,9 @@ static command_t CommandTable[] = { {"hw", CmdHW, AlwaysAvailable, "{ Hardware commands... }"}, {"lf", CmdLF, AlwaysAvailable, "{ Low Frequency commands... }"}, {"mem", CmdFlashMem, IfPm3Flash, "{ Flash Memory manipulation... }"}, - {"rem", CmdRem, AlwaysAvailable, "{ Add text to row in log file }"}, - {"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software... }"}, + {"msleep", CmdMsleep, AlwaysAvailable, "Add a pause in milliseconds"}, + {"rem", CmdRem, AlwaysAvailable, "Add text to row in log file"}, + {"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software }"}, {"sc", CmdSmartcard, IfPm3Smartcard, "{ Smart card ISO7816 commands... }"}, {"script", CmdScript, AlwaysAvailable, "{ Scripting commands }"}, {"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"}, From 2209a0c00d415870751fed9f66ddabbd56537336 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 15 Jul 2019 01:13:11 +0200 Subject: [PATCH 37/40] BUSY_TIMEOUT for mem wipe was too short, thanks @cjbrigato --- armsrc/flashmem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/flashmem.h b/armsrc/flashmem.h index 4016e66bd..59d3bef9c 100644 --- a/armsrc/flashmem.h +++ b/armsrc/flashmem.h @@ -62,7 +62,7 @@ #define RESUME 0x7A // Flash busy timeout: 20ms is the strict minimum when writing 256kb -#define BUSY_TIMEOUT 50000L +#define BUSY_TIMEOUT 200000L #define WINBOND_MANID 0xEF #define WINBOND_DEVID 0x11 From 6a54de1184ba9861785cbd724e717b3bdb7dc646 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 15 Jul 2019 12:47:42 +0200 Subject: [PATCH 38/40] changelog --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f7f952c..d53738a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Fix: timeout for mem wipe was too short, thanks @cjbrigato (@doegox) - Fix 'hf mf sim' - Mifare Classic simulation more flexible anti-collision check (@McEloff) - - Change: 'hf mf sim ' - Mifare Classic simulation not respond NACK on invalid authentication request (@McEloff) + - Change: 'hf mf sim' - Mifare Classic simulation not respond NACK on invalid authentication request (@McEloff) - Change: 'read_pwd_mem.lua' now handles Mifare Classic dictionaries large than 4096 bytes (@iceman) - Change: Don't clear trace log during 'hf mf chk', to save whole process history (@McEloff) + - Add 'msleep' command, for pauses in scripts (@doegox) - Add support for WSL in proxmark.sh (@doegox) - Add documentation for usage of Proxmark3 under WSL (@doegox) - Change: replace aes.c with mbedtls version (@slurdge) @@ -19,14 +21,14 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fix EMVGPO bug (@matrix) - Add hitag2 write password auth (@ViRb3) - Add check if bootloader segment is within bounds (@slurdge) - - Add `hf 15 csetuid` - set UID on ISO-15693 Magic tags (@t0m4-null) + - Add 'hf 15 csetuid' - set UID on ISO-15693 Magic tags (@t0m4-null) - Change: Print help if unknown arg for hitag reader/writer (@ViRb3) - Fix clock deadlock in hitag sniff (@ViRb3) - Add compiler info in client & ARM sections (@slurdge) - Add support for automatic COM detection on Windows (@slurdge) - Add support for compilation on RaspberryPiZero (armv6) (@doegox) - Change: updates to README (@iceman) - - Change: hf mf/mfu dbg => hw dbg (@doegox) + - Change: 'hf mf/mfu dbg' => 'hw dbg' (@doegox) - Change: replace usb_poll_validate_length() by data_available() that supports USART too (@doegox) - Make sure standalone modes can be launched when connected on USB without client (@doegox) - Change: cleaner makefile execution, use 'make V=1' if you want to see full lines (@doegox) From 0ea7fa7784f99f95a4629ac4619e70adeacb43fc Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 15 Jul 2019 12:48:43 +0200 Subject: [PATCH 39/40] buggy 'mem read' removed, 'mem save' renamed 'mem dump', can now display too --- CHANGELOG.md | 1 + armsrc/Standalone/hf_bog.c | 2 +- armsrc/appmain.c | 32 -------------- client/cmdflashmem.c | 90 +++++++++++--------------------------- doc/new_frame_format.md | 4 +- include/pm3_cmd.h | 1 - 6 files changed, 30 insertions(+), 100 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d53738a29..df03c68c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Change: buggy 'mem read' removed, 'mem save' renamed 'mem dump', can now display too (@doegox) - Fix: timeout for mem wipe was too short, thanks @cjbrigato (@doegox) - Fix 'hf mf sim' - Mifare Classic simulation more flexible anti-collision check (@McEloff) - Change: 'hf mf sim' - Mifare Classic simulation not respond NACK on invalid authentication request (@McEloff) diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index 093bc841f..ca0b0eeeb 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -15,7 +15,7 @@ The retrieved sniffing session can be acquired by connecting the device to a client that supports the reconnect capability and issue 'hf 14a list'. In order to view the grabbed authentication attempts in the flash mem, -you can simply run 'script run read_pwd_mem' or just 'mem read l 256' +you can simply run 'script run read_pwd_mem' or just 'mem dump p l 256' from the client to view the stored quadlets. */ diff --git a/armsrc/appmain.c b/armsrc/appmain.c index facce653c..b91853199 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1592,38 +1592,6 @@ static void PacketReceived(PacketCommandNG *packet) { FlashmemSetSpiBaudrate(packet->oldarg[0]); break; } - case CMD_FLASHMEM_READ: { - LED_B_ON(); - uint32_t startidx = packet->oldarg[0]; - uint16_t len = packet->oldarg[1]; - - Dbprintf("FlashMem read | %d - %d | ", startidx, len); - - size_t size = MIN(PM3_CMD_DATA_SIZE, len); - - if (!FlashInit()) { - break; - } - - uint8_t *mem = BigBuf_malloc(size); - - for (size_t i = 0; i < len; i += size) { - len = MIN((len - i), size); - - Dbprintf("FlashMem reading | %d | %d | %d |", startidx + i, i, len); - uint16_t isok = Flash_ReadDataCont(startidx + i, mem, len); - if (isok == len) { - print_result("Chunk: ", mem, len); - } else { - Dbprintf("FlashMem reading failed | %d | %d", len, isok); - break; - } - } - BigBuf_free(); - FlashStop(); - LED_B_OFF(); - break; - } case CMD_FLASHMEM_WRITE: { LED_B_ON(); uint8_t isok = 0; diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 6bab15cd9..9546b421f 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -37,17 +37,6 @@ static int usage_flashmem_spibaud(void) { return PM3_SUCCESS; } -static int usage_flashmem_read(void) { - PrintAndLogEx(NORMAL, "Read flash memory on device"); - PrintAndLogEx(NORMAL, "Usage: mem read o l "); - PrintAndLogEx(NORMAL, " o : offset in memory"); - PrintAndLogEx(NORMAL, " l : length"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " mem read o 0 l 32"); // read 32 bytes starting at offset 0 - PrintAndLogEx(NORMAL, " mem read o 1024 l 10"); // read 10 bytes starting at offset 1024 - return PM3_SUCCESS; -} static int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, "Loads binary file into flash memory on device"); PrintAndLogEx(NORMAL, "Usage: mem load [o ] f [m|t|i]"); @@ -67,17 +56,19 @@ static int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, " mem load f default_iclass_keys i"); return PM3_SUCCESS; } -static int usage_flashmem_save(void) { - PrintAndLogEx(NORMAL, "Saves flash memory on device into the file"); - PrintAndLogEx(NORMAL, " Usage: mem save [o ] [l ] f "); +static int usage_flashmem_dump(void) { + PrintAndLogEx(NORMAL, "Dumps flash memory on device into a file or in console"); + PrintAndLogEx(NORMAL, " Usage: mem dump [o ] [l ] [f ] [p]"); PrintAndLogEx(NORMAL, " o : offset in memory"); PrintAndLogEx(NORMAL, " l : length"); PrintAndLogEx(NORMAL, " f : file name"); + PrintAndLogEx(NORMAL, " p : print dump in console"); + PrintAndLogEx(NORMAL, " You must specify at lease option f or option p, both if you wish"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " mem save f myfile"); // download whole flashmem to file myfile - PrintAndLogEx(NORMAL, " mem save f myfile l 4096"); // download 4096 bytes from default offset 0 to file myfile - PrintAndLogEx(NORMAL, " mem save f myfile o 1024 l 4096"); // downlowd 4096 bytes from offset 1024 to file myfile + PrintAndLogEx(NORMAL, " mem dump f myfile"); // download whole flashmem to file myfile + PrintAndLogEx(NORMAL, " mem dump p o 262015 l 128"); // display 128 bytes from offset 262015 (RSA sig) + PrintAndLogEx(NORMAL, " mem dump p f myfile o 241664 l 58"); // download and display 58 bytes from offset 241664 to file myfile return PM3_SUCCESS; } static int usage_flashmem_wipe(void) { @@ -105,46 +96,6 @@ static int usage_flashmem_info(void) { return PM3_SUCCESS; } -static int CmdFlashMemRead(const char *Cmd) { - - uint8_t cmdp = 0; - bool errors = false; - uint32_t start_index = 0, len = 0; - - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'o': - start_index = param_get32ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - case 'l': - len = param_get32ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - case 'h': - return usage_flashmem_read(); - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - //Validations - if (errors || cmdp == 0) { - usage_flashmem_read(); - return PM3_EINVARG; - } - if (start_index + len > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(ERR, "error, start_index + length is larger than available memory"); - return PM3_EOVFLOW; - } - - clearCommandBuffer(); - SendCommandMIX(CMD_FLASHMEM_READ, start_index, len, 0, NULL, 0); - return PM3_SUCCESS; -} - static int CmdFlashmemSpiBaudrate(const char *Cmd) { char ctmp = tolower(param_getchar(Cmd, 0)); @@ -311,17 +262,18 @@ static int CmdFlashMemLoad(const char *Cmd) { PrintAndLogEx(SUCCESS, "Wrote "_GREEN_("%u")"bytes to offset "_GREEN_("%u"), datalen, start_index); return PM3_SUCCESS; } -static int CmdFlashMemSave(const char *Cmd) { +static int CmdFlashMemDump(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0}; uint8_t cmdp = 0; bool errors = false; + bool print = false; uint32_t start_index = 0, len = FLASH_MEM_MAX_SIZE; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': - return usage_flashmem_save(); + return usage_flashmem_dump(); case 'l': len = param_get32ex(Cmd, cmdp + 1, FLASH_MEM_MAX_SIZE, 10); cmdp += 2; @@ -330,6 +282,10 @@ static int CmdFlashMemSave(const char *Cmd) { start_index = param_get32ex(Cmd, cmdp + 1, 0, 10); cmdp += 2; break; + case 'p': + print = true; + cmdp += 1; + break; case 'f': //File handling if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { @@ -348,7 +304,7 @@ static int CmdFlashMemSave(const char *Cmd) { //Validations if (errors || cmdp == 0) { - usage_flashmem_save(); + usage_flashmem_dump(); return PM3_EINVARG; } @@ -365,8 +321,15 @@ static int CmdFlashMemSave(const char *Cmd) { return PM3_EFLASH; } - saveFile(filename, ".bin", dump, len); - saveFileEML(filename, dump, len, 16); + if (print) { + print_hex_break(dump, len, 32); + } + + if (filename[0] != '\0') { + saveFile(filename, ".bin", dump, len); + saveFileEML(filename, dump, len, 16); + } + free(dump); return PM3_SUCCESS; } @@ -612,10 +575,9 @@ static int CmdFlashMemInfo(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"spibaud", CmdFlashmemSpiBaudrate, IfPm3Flash, "Set Flash memory Spi baudrate [rdv40]"}, - {"read", CmdFlashMemRead, IfPm3Flash, "Read Flash memory [rdv40]"}, {"info", CmdFlashMemInfo, IfPm3Flash, "Flash memory information [rdv40]"}, {"load", CmdFlashMemLoad, IfPm3Flash, "Load data into flash memory [rdv40]"}, - {"save", CmdFlashMemSave, IfPm3Flash, "Save data from flash memory [rdv40]"}, + {"dump", CmdFlashMemDump, IfPm3Flash, "Dump data from flash memory [rdv40]"}, {"wipe", CmdFlashMemWipe, IfPm3Flash, "Wipe data from flash memory [rdv40]"}, {NULL, NULL, NULL, NULL} }; diff --git a/doc/new_frame_format.md b/doc/new_frame_format.md index 76424f8b6..17c94120a 100644 --- a/doc/new_frame_format.md +++ b/doc/new_frame_format.md @@ -373,9 +373,9 @@ It was needed to tune pm3 RX usart `maxtry` : time client/proxmark3 -p /dev/ttyUSB0 -b 115200 -c "lf read" 6.28s - time client/proxmark3 -p /dev/ttyACM0 -c "mem save f foo_usb" + time client/proxmark3 -p /dev/ttyACM0 -c "mem dump f foo_usb" 1.48s - time client/proxmark3 -p /dev/ttyUSB0 -b 115200 -c "mem save f foo_fpc" + time client/proxmark3 -p /dev/ttyUSB0 -b 115200 -c "mem dump f foo_fpc" 25.34s diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 8eef7e75d..e19cbf686 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -238,7 +238,6 @@ typedef struct { #define CMD_SET_DBGMODE 0x0114 // RDV40, Flash memory operations -#define CMD_FLASHMEM_READ 0x0120 #define CMD_FLASHMEM_WRITE 0x0121 #define CMD_FLASHMEM_WIPE 0x0122 #define CMD_FLASHMEM_DOWNLOAD 0x0123 From caceea24a4c61b84eb12b8ff4b0c366113d47aec Mon Sep 17 00:00:00 2001 From: Iceman Date: Mon, 15 Jul 2019 15:36:12 +0200 Subject: [PATCH 40/40] Update default_keys.dic --- client/default_keys.dic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/default_keys.dic b/client/default_keys.dic index 4810e56da..c8d96bd44 100644 --- a/client/default_keys.dic +++ b/client/default_keys.dic @@ -944,3 +944,5 @@ A23456789123 A00003000084 675A32413770 395244733978 +# +B069D0D03D17