diff --git a/CHANGELOG.md b/CHANGELOG.md index be95a700d..0fa346660 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 'HINTS' command. Will turn off / on hint messages. Default mode is OFF. (@iceman1001) - Add colour to `hf 14a` and `hf mfu` commands (@dunderhay) - Add colour to `lf hid` commands (@dunderhay) - Change `script run hf_bruteforce -s start_id -e end_id -t timeout -x mifare_card_type` - The hf_bruteforce card script now requires Mifare type (mfc or mfu) (@dunderhay) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 389c16fe5..0355abe85 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -1628,13 +1628,13 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { } if (isMifareUltralight) { - PrintAndLogEx(INFO, "Hint: try " _YELLOW_("`hf mfu info`")); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfu info`")); } if (isMifarePlus) { - PrintAndLogEx(INFO, "Hint: try " _YELLOW_("`hf mfp info`")); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfp info`")); } if (isMifareDesfire) { - PrintAndLogEx(INFO, "Hint: try " _YELLOW_("`hf mfdes info`")); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfdes info`")); } diff --git a/client/cmdmain.c b/client/cmdmain.c index c2364d8f1..d9cbbac74 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -36,9 +36,23 @@ #include "cmdwiegand.h" // wiegand commands #include "ui.h" #include "util_posix.h" +#include "commonutil.h" // ARRAYLEN static int CmdHelp(const char *Cmd); +static int usage_hints(void) { + PrintAndLogEx(NORMAL, "Turn on/off hints"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: hints [h] <0|1>"); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " <0|1> off or on"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " hints 1"); + return PM3_SUCCESS; +} + static int usage_msleep(void) { PrintAndLogEx(NORMAL, "Sleep for given amount of milliseconds"); PrintAndLogEx(NORMAL, ""); @@ -78,6 +92,70 @@ static void AppendDate(char *s, size_t slen, char *fmt) { strftime(s, slen, fmt, ct); } +static int lf_search_plus(const char *Cmd) { + + sample_config oldconfig; + memset(&oldconfig, 0, sizeof(sample_config)); + + int retval = lf_getconfig(&oldconfig); + + if (retval != PM3_SUCCESS) { + PrintAndLogEx(ERR, "failed to get current device config"); + return retval; + } + + // Divisor : frequency(khz) + // 95 88 47 31 23 + // 125.00 134.83 250.00 375.00 500.00 + + int16_t default_divisor[] = {95, 88, 47, 31, 23}; + + /* + default LF config is set to: + decimation = 1 + bits_per_sample = 8 + averaging = YES + divisor = 95 (125kHz) + trigger_threshold = 0 + samples_to_skip = 0 + verbose = YES + */ + sample_config config = { + .decimation = 1, + .bits_per_sample = 8, + .averaging = 1, + .trigger_threshold = 0, + .samples_to_skip = 0, + .verbose = false + }; + + // Iteration defaults + for (int i = 0; i < ARRAYLEN(default_divisor); ++i) { + + if (kbd_enter_pressed()) { + PrintAndLogEx(INFO, "Keyboard pressed. Done."); + break; + } + // Try to change config! + uint32_t d; + d = config.divisor = default_divisor[i]; + PrintAndLogEx(INFO, "--> trying ( " _GREEN_("%d.%02d kHz")")", 12000 / (d + 1), ((1200000 + (d + 1) / 2) / (d + 1)) - ((12000 / (d + 1)) * 100)); + + retval = lf_config(&config); + if (retval != PM3_SUCCESS) + break; + + // The config for pm3 is changed, we can trying search! + retval = CmdLFfind(Cmd); + if (retval == PM3_SUCCESS) + break; + + } + + lf_config(&oldconfig); + return retval; +} + static int CmdAuto(const char *Cmd) { char ctmp = tolower(param_getchar(Cmd, 0)); if (ctmp == 'h') return usage_auto(); @@ -90,8 +168,12 @@ static int CmdAuto(const char *Cmd) { if (ret == PM3_SUCCESS) return ret; + ret = lf_search_plus(""); + if (ret == PM3_SUCCESS) + return ret; + PrintAndLogEx(INFO, "Failed both LF / HF SEARCH,"); - PrintAndLogEx(INFO, "Trying 'lf read' and save a trace for you..."); + PrintAndLogEx(INFO, "Trying " _YELLOW_("`lf read`") "and save a trace for you"); CmdPlot(""); lf_read(false, 40000); @@ -109,6 +191,27 @@ int CmdRem(const char *Cmd) { return PM3_SUCCESS; } +static int CmdHints(const char *Cmd) { + uint32_t ms = 0; + char ctmp = tolower(param_getchar(Cmd, 0)); + if (ctmp == 'h') return usage_hints(); + + if (strlen(Cmd) < 1) { + PrintAndLogEx(INFO, "Hints are %s", (g_showhints) ? "ON" : "OFF"); + return PM3_SUCCESS; + } + + if (param_getchar(Cmd, 0) != 0x00) { + ms = param_get32ex(Cmd, 0, 0, 10); + if (ms == 0) + g_showhints = false; + else + g_showhints = true; + } + PrintAndLogEx(INFO, "Hints are %s", (g_showhints) ? "ON" : "OFF"); + return PM3_SUCCESS; +} + static int CmdMsleep(const char *Cmd) { uint32_t ms = 0; char ctmp = tolower(param_getchar(Cmd, 0)); @@ -149,6 +252,7 @@ static command_t CommandTable[] = { {"usart", CmdUsart, IfPm3FpcUsartFromUsb, "{ USART commands... }"}, {"wiegand", CmdWiegand, AlwaysAvailable, "{ Wiegand format manipulation... }"}, {"", CmdHelp, AlwaysAvailable, ""}, + {"hints", CmdHints, AlwaysAvailable, "Turn hints on / off"}, {"msleep", CmdMsleep, AlwaysAvailable, "Add a pause in milliseconds"}, {"rem", CmdRem, AlwaysAvailable, "Add a text line in log file"}, {"quit", CmdQuit, AlwaysAvailable, ""}, diff --git a/client/proxgui.h b/client/proxgui.h index 8e0868b12..fea28d62b 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -55,7 +55,7 @@ extern size_t DemodBufferLen; extern size_t g_DemodStartIdx; extern bool showDemod; extern uint8_t g_debugMode; - +extern uint8_t g_showhints; #ifndef FILE_PATH_SIZE #define FILE_PATH_SIZE 1000 diff --git a/client/ui.c b/client/ui.c index 215bd66bc..91a2a49e6 100644 --- a/client/ui.c +++ b/client/ui.c @@ -127,6 +127,10 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) { // skip debug messages if client debugging is turned off i.e. 'DATA SETDEBUG 0' if (g_debugMode == 0 && level == DEBUG) return; + + // skip HINT messages if client has hints turned off i.e. 'HINT 0' + if (g_showhints == 0 && level == HINT) + return; char prefix[20] = {0}; char buffer[MAX_PRINT_BUFFER] = {0}; @@ -146,6 +150,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) { case DEBUG: strncpy(prefix, _BLUE_("[#]"), sizeof(prefix) - 1); break; + case HINT: case SUCCESS: strncpy(prefix, _GREEN_("[+]"), sizeof(prefix) - 1); break; diff --git a/client/ui.h b/client/ui.h index 7e00ab52b..c67865593 100644 --- a/client/ui.h +++ b/client/ui.h @@ -31,7 +31,7 @@ extern session_arg_t session; #define M_PI 3.14159265358979323846264338327 #endif #define MAX_PRINT_BUFFER 2048 -typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE} logLevel_t; +typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE, HINT} logLevel_t; void ShowGui(void); void HideGraphWindow(void);